Class: RedminePluginAssetPipeline::SprocketsProcessor

Inherits:
Sprockets::DirectiveProcessor
  • Object
show all
Defined in:
lib/redmine_plugin_asset_pipeline/sprockets_processor.rb

Instance Method Summary collapse

Instance Method Details

#process_require_redmine_plugins_directive(type) ⇒ Object

This processor subclasses the standard Sprockets::DirectiveProcessor as advised in Sprockets, to add a new directive called “require_redmine_plugins”. This directive is relative to the #Rails.root/plugins/ directory and accepts wildcards.

For convenience, it also replaces “ALL” by a star (“*”) before evaluating the globing. Otherwise, “*/” is interpreted as the end of the comment in CSS files, which is obviously problematic.

For the record, here’s the example custom require provided in sprockets:

def process_require_glob_directive

Dir["#{pathname.dirname}/#{glob}"].sort.each do |filename|
  require(filename)
end

end



21
22
23
24
25
26
# File 'lib/redmine_plugin_asset_pipeline/sprockets_processor.rb', line 21

def process_require_redmine_plugins_directive(type)
  mask = Rails.root.join(Redmine::Plugin.private_directory,  "*/#{type}/_common_part*").expand_path
  Dir.glob(mask).sort.each do |entry|
    context.require_asset(pathname.dirname.join(entry).expand_path)
  end
end