Class: Middleman::SprocketsExtension
- Inherits:
-
Extension
- Object
- Extension
- Middleman::SprocketsExtension
- Defined in:
- lib/middleman-sprockets/extension.rb
Defined Under Namespace
Modules: SprocketsAccessor
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
Instance Method Summary collapse
- #after_configuration ⇒ Object
-
#initialize(app, options_hash = {}, &block) ⇒ SprocketsExtension
constructor
A new instance of SprocketsExtension.
-
#manipulate_resource_list(resources) ⇒ Object
Add sitemap resource for every image in the sprockets load path.
Constructor Details
#initialize(app, options_hash = {}, &block) ⇒ SprocketsExtension
Returns a new instance of SprocketsExtension.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/middleman-sprockets/extension.rb', line 38 def initialize(app, ={}, &block) require "middleman-sprockets/sass_function_hack" require "middleman-sprockets/sass_utils" super # Start out with a stub environment that can only be configured (paths and such) @environment = ::Middleman::Sprockets::ConfigOnlyEnvironment.new # v4 if app.respond_to? :add_to_config_context app.add_to_config_context :sprockets, &method(:environment) else app.send :include, SprocketsAccessor end end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
26 27 28 |
# File 'lib/middleman-sprockets/extension.rb', line 26 def environment @environment end |
Instance Method Details
#after_configuration ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/middleman-sprockets/extension.rb', line 60 def after_configuration ::Tilt.register ::Sprockets::EjsTemplate, 'ejs' ::Tilt.register ::Sprockets::EcoTemplate, 'eco' ::Tilt.register ::Sprockets::JstProcessor, 'jst' if app.respond_to?(:template_extensions) app.template_extensions :jst => :js, :eco => :js, :ejs => :js end if app.config.defines_setting?(:debug_assets) && !.setting(:debug_assets).value_set? [:debug_assets] = app.config[:debug_assets] end config_environment = @environment debug_assets = !app.build? && [:debug_assets] @environment = ::Middleman::Sprockets::Environment.new(app, :debug_assets => debug_assets) config_environment.apply_to_environment(@environment) append_paths_from_gems import_images_and_fonts_from_gems # Setup Sprockets Sass options if app.config.defines_setting?(:sass) app.config[:sass].each { |k, v| ::Sprockets::Sass.[k] = v } end # Intercept requests to /javascripts and /stylesheets and pass to sprockets our_sprockets = self.environment [app.config[:js_dir], app.config[:css_dir], app.config[:images_dir], app.config[:fonts_dir]].each do |dir| app.map("/#{dir}") { run our_sprockets } end end |
#manipulate_resource_list(resources) ⇒ Object
Add sitemap resource for every image in the sprockets load path
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/middleman-sprockets/extension.rb', line 95 def manipulate_resource_list(resources) resources_list = [] environment.imported_assets.each do |imported_asset| asset = Middleman::Sprockets::Asset.new @app, imported_asset.logical_path, environment if imported_asset.output_path destination = imported_asset.output_path else destination = @app.sitemap.extensionless_path( asset.destination_path.to_s ) end next if @app.sitemap.find_resource_by_destination_path destination.to_s resource = ::Middleman::Sitemap::Resource.new( @app.sitemap, destination.to_s, asset.source_path.to_s ) resource. options: { sprockets: { logical_path: imported_asset.logical_path }} resources_list << resource end resources + resources_list end |