Class: Middleman::Sprockets::Asset
- Inherits:
-
Object
- Object
- Middleman::Sprockets::Asset
- Defined in:
- lib/middleman-sprockets/asset.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#asset ⇒ Object
readonly
Returns the value of attribute asset.
-
#sprockets ⇒ Object
readonly
Returns the value of attribute sprockets.
Instance Method Summary collapse
- #destination_path ⇒ Object
-
#initialize(app, lookup_path, sprockets = app.sprockets) ⇒ Asset
constructor
A new instance of Asset.
- #source_dir ⇒ Object
- #source_path ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(app, lookup_path, sprockets = app.sprockets) ⇒ Asset
Returns a new instance of Asset.
9 10 11 12 13 14 15 |
# File 'lib/middleman-sprockets/asset.rb', line 9 def initialize app, lookup_path, sprockets = app.sprockets @app = app @sprockets = sprockets @asset = sprockets[ sprockets.resolve(lookup_path) ] raise ::Sprockets::FileNotFound, "Couldn't find asset '#{lookup_path}'" if @asset.nil? end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
7 8 9 |
# File 'lib/middleman-sprockets/asset.rb', line 7 def app @app end |
#asset ⇒ Object (readonly)
Returns the value of attribute asset.
7 8 9 |
# File 'lib/middleman-sprockets/asset.rb', line 7 def asset @asset end |
#sprockets ⇒ Object (readonly)
Returns the value of attribute sprockets.
7 8 9 |
# File 'lib/middleman-sprockets/asset.rb', line 7 def sprockets @sprockets end |
Instance Method Details
#destination_path ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/middleman-sprockets/asset.rb', line 17 def destination_path case type when :image then Pathname.new(app.config[:images_dir]) + remove_asset_dir(asset.logical_path, image_paths) when :script then Pathname.new(app.config[:js_dir]) + remove_asset_dir(asset.logical_path, script_paths) when :font then Pathname.new(app.config[:fonts_dir]) + remove_asset_dir(asset.logical_path, font_paths) when :stylesheet then Pathname.new(app.config[:css_dir]) + remove_asset_dir(asset.logical_path, stylesheet_paths) else asset.logical_path end end |
#source_dir ⇒ Object
32 33 34 |
# File 'lib/middleman-sprockets/asset.rb', line 32 def source_dir @source_dir ||= source_path.sub /\/?#{asset.logical_path}$/, '' end |
#source_path ⇒ Object
36 37 38 |
# File 'lib/middleman-sprockets/asset.rb', line 36 def source_path asset.pathname end |
#type ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/middleman-sprockets/asset.rb', line 40 def type @type ||= if is_image? :image elsif is_script? :script elsif is_stylesheet? :stylesheet elsif is_font? :font else :unknown end end |