Skip to content
This repository has been archived by the owner on Apr 28, 2019. It is now read-only.

Commit

Permalink
use specific folder for bower
Browse files Browse the repository at this point in the history
  • Loading branch information
gregory committed Oct 13, 2014
1 parent 2ddf047 commit 50fe363
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 64 deletions.
9 changes: 2 additions & 7 deletions lib/locomotive/mounter/extensions/sprockets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,9 @@ def self.environment(site_path)
%w(fonts stylesheets javascripts).each do |name|
env.append_path File.join(site_path, 'public', name)
end
bower_file_path = "#{site_path}/.bowerrc"

if File.exist?(bower_file_path)
bower_config = JSON.parse(IO.read("#{site_path}/.bowerrc"))
bower_folder = bower_config["directory"]

env.append_path File.join(site_path, bower_folder) if bower_folder
end
bower_folder = File.join site_path, "bower_components"
env.append_path bower_folder if File.directory? bower_folder
end
end

Expand Down
6 changes: 3 additions & 3 deletions lib/locomotive/mounter/models/theme_asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ThemeAsset < Base

PRECOMPILED_FILE_TYPES = PRECOMPILED_CSS_TYPES + PRECOMPILED_JS_TYPES

CSS_JS_SHORT_PATH_REGEXP = /^(javascripts|stylesheets|fonts)\/(.*)$/
CSS_JS_SHORT_PATH_REGEXP = /^.*(javascripts|stylesheets|fonts)\/(.*)$/

## fields ##
field :folder
Expand Down Expand Up @@ -51,7 +51,7 @@ def path
# @return [ String ] The path of the asset without the first folder
#
def short_path
self.path =~ /^(javascripts|stylesheets|fonts)\/(.*)$/
self.path =~ /.*(javascripts|stylesheets|fonts|bower_components)\/(.*)$/
$2
end

Expand Down Expand Up @@ -145,4 +145,4 @@ def to_s

end
end
end
end
2 changes: 1 addition & 1 deletion lib/locomotive/mounter/mounting_point.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ def inspect

end
end
end
end
68 changes: 16 additions & 52 deletions lib/locomotive/mounter/reader/file_system/theme_assets_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,7 @@ class ThemeAssetsReader < Base
# @return [ Array ] The cached list of theme assets
#
def read
theme_assets_array_opts = {}
theme_assets_array_opts[:bower_config_path] = bower_config_path if File.file? bower_config_path

ThemeAssetsArray.new(self.root_dir, theme_assets_array_opts)
end

protected

# Return the directory where all the theme assets
# are stored in the filesystem.
#
# @return [ String ] The theme assets directory
#
def root_dir
File.join(self.runner.path, 'public')
end

def bower_used?
File.exist?(bower_config_path) && File.exist?(bower_root_dir)
end

def bower_root_dir
@bower_root_dir ||= JSON.parse(IO.read(bower_config_path))["directory"]
end

def bower_config_path
File.join(self.runner.path, '.bowerrc')
ThemeAssetsArray.new(self.runner.path)
end

end
Expand All @@ -45,34 +19,35 @@ def bower_config_path

class ThemeAssetsArray
DEFAULT_IGNORED_FOLDER = ['samples']
ASSETS_FODLERS = {
bower: 'bower_components',
public: 'public'
}

attr_accessor :root_dir, :ignored_folders

def initialize(root_dir, opts={})
def initialize(root_dir)
self.root_dir = root_dir
@bower_config_path = opts[:bower_config_path]
@ignored_folders = DEFAULT_IGNORED_FOLDER.map{ |folder| File.join(self.root_dir, folder) }
@ignored_folders.push(*opts[:ignored_folder_paths]).uniq!
end

def list
return @list unless @list.nil?

@list = []
@list.tap do
load_bower_assets if bower_used?
load_public_assets
end
load_bower_assets
load_public_assets
@list
end

def load_public_assets
# Follows symlinks and makes sure subdirectories are handled
glob_pattern = '**/*/**/*'

Dir.glob(File.join(self.root_dir, glob_pattern)).each_with_object(@list) do |file, array|
Dir.glob(File.join(self.root_dir, 'public', glob_pattern)).each_with_object(@list) do |file, array|
next if self.exclude?(file)

folder = File.dirname(file.gsub("#{self.root_dir}/", ''))
folder = File.dirname(file.gsub("#{self.root_dir}/public/", ''))

array.push Locomotive::Mounter::Models::ThemeAsset.new(folder: folder, filepath: file)
end
Expand All @@ -81,30 +56,19 @@ def load_public_assets
def load_bower_assets
bower_files_pattern = '**/bower.json'

Dir.glob(File.join(self.bower_root_dir, bower_files_pattern)).each_with_object(@list) do |bower_file, array|
Dir.glob(File.join(self.root_dir, 'bower_components', bower_files_pattern)).each_with_object(@list) do |bower_file, array|
bower_project_folder, _ = bower_file.split("/bower.json")

[*JSON.parse(IO.read(bower_file))["main"]].each do |relative_file_path|
filepath = File.expand_path File.join(bower_project_folder, relative_file_path)
next if self.exclude?(filepath)
file = File.join(bower_project_folder, relative_file_path)
next if self.exclude?(file)

folder = File.dirname(filepath)
array.push Locomotive::Mounter::Models::ThemeAsset.new(folder: folder, filepath: filepath)
folder = File.dirname(file.gsub("#{self.root_dir}/", ''))
array.push Locomotive::Mounter::Models::ThemeAsset.new(folder: folder, filepath: file)
end
end
end

def bower_used?
@bower_config_path.present? && File.file?(@bower_config_path) && File.exist?(bower_root_dir)
end

def bower_root_dir
return @bower_root_dir if @bower_root_dir
bower_relative_folder, _ = @bower_config_path.split("/.bowerrc")
bower_folder = JSON.parse(IO.read(@bower_config_path))["directory"]
@bower_root_dir = File.expand_path File.join(bower_relative_folder, bower_folder)
end

alias :values :list

# Tell if the file has to be excluded from the array
Expand Down
2 changes: 1 addition & 1 deletion lib/locomotive/mounter/writer/api/theme_assets_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,4 @@ def sprockets
end
end
end
end
end

0 comments on commit 50fe363

Please sign in to comment.