diff --git a/lib/locomotive/mounter/extensions/sprockets.rb b/lib/locomotive/mounter/extensions/sprockets.rb index 6c278dc..d48f6de 100644 --- a/lib/locomotive/mounter/extensions/sprockets.rb +++ b/lib/locomotive/mounter/extensions/sprockets.rb @@ -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 diff --git a/lib/locomotive/mounter/models/theme_asset.rb b/lib/locomotive/mounter/models/theme_asset.rb index 8addbe0..99a53a1 100644 --- a/lib/locomotive/mounter/models/theme_asset.rb +++ b/lib/locomotive/mounter/models/theme_asset.rb @@ -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 @@ -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 @@ -145,4 +145,4 @@ def to_s end end -end \ No newline at end of file +end diff --git a/lib/locomotive/mounter/mounting_point.rb b/lib/locomotive/mounter/mounting_point.rb index b03e398..04079b1 100644 --- a/lib/locomotive/mounter/mounting_point.rb +++ b/lib/locomotive/mounter/mounting_point.rb @@ -62,4 +62,4 @@ def inspect end end -end \ No newline at end of file +end diff --git a/lib/locomotive/mounter/reader/file_system/theme_assets_reader.rb b/lib/locomotive/mounter/reader/file_system/theme_assets_reader.rb index 61cb93c..5a1a36b 100644 --- a/lib/locomotive/mounter/reader/file_system/theme_assets_reader.rb +++ b/lib/locomotive/mounter/reader/file_system/theme_assets_reader.rb @@ -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 @@ -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 @@ -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 diff --git a/lib/locomotive/mounter/writer/api/theme_assets_writer.rb b/lib/locomotive/mounter/writer/api/theme_assets_writer.rb index 127a1f0..50bcfca 100644 --- a/lib/locomotive/mounter/writer/api/theme_assets_writer.rb +++ b/lib/locomotive/mounter/writer/api/theme_assets_writer.rb @@ -198,4 +198,4 @@ def sprockets end end end -end \ No newline at end of file +end