Class: Middleman::Condenser
- Inherits:
-
Extension
- Object
- Extension
- Middleman::Condenser
- Defined in:
- lib/middleman/condenser.rb
Defined Under Namespace
Classes: Middleware
Instance Method Summary collapse
- #after_configuration ⇒ Object
- #before_build(builder) ⇒ Object
- #before_clean(builder) ⇒ Object
- #export(file) ⇒ Object
-
#initialize(app, options_hash = {}, &block) ⇒ Condenser
constructor
A new instance of Condenser.
- #manipulate_resource_list(resources) ⇒ Object
Constructor Details
#initialize(app, options_hash = {}, &block) ⇒ Condenser
Returns a new instance of Condenser.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/middleman/condenser.rb', line 26 def initialize(app, ={}, &block) # Call super to build options from the options_hash super # Require libraries only when activated require 'condenser' require 'condenser/server' cache = Condenser::Cache::FileStore.new(File.join(app.root, 'tmp/cache')) @condenser = Condenser.new(app.root, cache: cache) app.use(Middleware, app) Middleman::Application.send(:attr_reader, :condenser) app.instance_variable_set(:@condenser, @condenser) [:path].each { |p| @condenser.append_path(p) } # Append sources asset_dir = File.join(app.source_dir, 'assets') if File.exist?(asset_dir) && File.directory?(asset_dir) Dir.each_child(asset_dir).each do |child| child = File.join(asset_dir, child) @condenser.append_path(child) if File.directory?(child) end end # Append npm sources asset_dir = File.join(app.root, 'node_modules') if File.exist?(asset_dir) && File.directory?(asset_dir) @condenser.append_npm_path(asset_dir) end end |
Instance Method Details
#after_configuration ⇒ Object
68 69 70 |
# File 'lib/middleman/condenser.rb', line 68 def after_configuration # Do something end |
#before_build(builder) ⇒ Object
59 60 61 62 |
# File 'lib/middleman/condenser.rb', line 59 def before_build(builder) builder.instance_variable_set(:@parallel, false) @required_assets = [] end |
#before_clean(builder) ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/middleman/condenser.rb', line 78 def before_clean(builder) build_dir = File.join(app.config[:build_dir], [:prefix]) manifest = Condenser::Manifest.new(@condenser, build_dir) puts @required_assets.inspect manifest.compile(@required_assets).each do |a| puts a.inspect builder.instance_variable_get(:@to_clean).delete_if! { |x| a.to_s == a } end end |
#export(file) ⇒ Object
64 65 66 |
# File 'lib/middleman/condenser.rb', line 64 def export(file) @required_assets << file if @required_assets end |
#manipulate_resource_list(resources) ⇒ Object
72 73 74 75 76 |
# File 'lib/middleman/condenser.rb', line 72 def manipulate_resource_list resources resources.reject do |resource| resource.path.start_with?([:prefix]) end end |