Class: Yarrow::Assets::Pipeline
- Inherits:
-
Object
- Object
- Yarrow::Assets::Pipeline
- Includes:
- Loggable
- Defined in:
- lib/yarrow/assets/pipeline.rb
Overview
Processes static assets using Sprockets.
Instance Attribute Summary collapse
-
#append_paths ⇒ Object
readonly
Returns the value of attribute append_paths.
-
#assets ⇒ Object
readonly
Returns the value of attribute assets.
-
#bundles ⇒ Object
readonly
Returns the value of attribute bundles.
-
#input_dir ⇒ Object
readonly
Returns the value of attribute input_dir.
-
#output_dir ⇒ Object
readonly
Returns the value of attribute output_dir.
Instance Method Summary collapse
-
#compile(bundles = []) ⇒ Object
Compiles an asset manifest and processed output files from the given input bundles.
-
#copy(bundles = []) ⇒ Object
Copy the given files to the output path without processing or renaming.
-
#environment ⇒ Sprockets::Environment
Access instance of the Sprockets environment.
-
#initialize(config) ⇒ Pipeline
constructor
A new instance of Pipeline.
-
#purge(keep = 2, age = 3600) ⇒ Object
Purges redundant compiled assets from the output path.
Methods included from Loggable
Constructor Details
#initialize(config) ⇒ Pipeline
Returns a new instance of Pipeline.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/yarrow/assets/pipeline.rb', line 17 def initialize(config) raise Yarrow::ConfigurationError if config.assets.nil? @input_dir = config.assets.input_dir || default_input_dir if config.assets.output_dir @output_dir = config.assets.output_dir else @output_dir = config.output_dir || default_output_dir end @append_paths = [] case config.assets.append_paths when Array @append_paths = config.assets.append_paths when '*' @append_paths = Dir[@input_dir + '/*'].select do |path| File.directory?(path) end.map do |path| File.basename(path) end when String @append_paths << config.assets.append_paths end end |
Instance Attribute Details
#append_paths ⇒ Object (readonly)
Returns the value of attribute append_paths.
13 14 15 |
# File 'lib/yarrow/assets/pipeline.rb', line 13 def append_paths @append_paths end |
#assets ⇒ Object (readonly)
Returns the value of attribute assets.
13 14 15 |
# File 'lib/yarrow/assets/pipeline.rb', line 13 def assets @assets end |
#bundles ⇒ Object (readonly)
Returns the value of attribute bundles.
13 14 15 |
# File 'lib/yarrow/assets/pipeline.rb', line 13 def bundles @bundles end |
#input_dir ⇒ Object (readonly)
Returns the value of attribute input_dir.
13 14 15 |
# File 'lib/yarrow/assets/pipeline.rb', line 13 def input_dir @input_dir end |
#output_dir ⇒ Object (readonly)
Returns the value of attribute output_dir.
13 14 15 |
# File 'lib/yarrow/assets/pipeline.rb', line 13 def output_dir @output_dir end |
Instance Method Details
#compile(bundles = []) ⇒ Object
Compiles an asset manifest and processed output files from the given input bundles. Also generates a manifest linking each output bundle to its given input name.
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/yarrow/assets/pipeline.rb', line 49 def compile(bundles = []) bundles.each do |bundle| if bundle.include? '*' Dir["#{@input_dir}/#{bundle}"].each do |asset| logger.info "Compiling: #{asset}" manifest.compile(File.basename(asset)) end else logger.info "Compiling: #{bundle}" manifest.compile(bundle) end end end |
#copy(bundles = []) ⇒ Object
Copy the given files to the output path without processing or renaming.
67 68 69 70 71 |
# File 'lib/yarrow/assets/pipeline.rb', line 67 def copy(bundles = []) bundles.each do |bundle| FileUtils.cp_r "#{@input_dir}/#{bundle}", "#{@output_dir}/#{bundle}" end end |
#environment ⇒ Sprockets::Environment
Access instance of the Sprockets environment.
90 91 92 93 |
# File 'lib/yarrow/assets/pipeline.rb', line 90 def environment # TODO: decouple dependency on Sprockets @environment ||= create_environment end |
#purge(keep = 2, age = 3600) ⇒ Object
Purges redundant compiled assets from the output path.
81 82 83 84 |
# File 'lib/yarrow/assets/pipeline.rb', line 81 def purge(keep = 2, age = 3600) # TODO: upgrade to Sprockets 3.0 to support the age arg manifest.clean(keep) end |