Class: Middleman::Sprockets::Asset

Inherits:
Object
  • Object
show all
Defined in:
lib/middleman-sprockets/asset.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, lookup_path, sprockets = app.sprockets) ⇒ Asset

Returns a new instance of Asset.

Raises:

  • (::Sprockets::FileNotFound)


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

#appObject (readonly)

Returns the value of attribute app.



7
8
9
# File 'lib/middleman-sprockets/asset.rb', line 7

def app
  @app
end

#assetObject (readonly)

Returns the value of attribute asset.



7
8
9
# File 'lib/middleman-sprockets/asset.rb', line 7

def asset
  @asset
end

#sprocketsObject (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_pathObject



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_dirObject



32
33
34
# File 'lib/middleman-sprockets/asset.rb', line 32

def source_dir
  @source_dir ||= source_path.sub /\/?#{asset.logical_path}$/, ''
end

#source_pathObject



36
37
38
# File 'lib/middleman-sprockets/asset.rb', line 36

def source_path
  asset.pathname
end

#typeObject



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