Class: Middleman::Sprockets::ImportedAsset

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

Overview

ImportedAsset

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logical_path, determine_output_path = proc { nil }) ⇒ ImportedAsset

Create instance

Parameters:

  • logical_path (Pathname)

    The logical path to the asset given in config.rb

  • output_dir (proc)

    An individual output directory for that particular asset



15
16
17
18
19
20
21
22
# File 'lib/middleman-sprockets/imported_asset.rb', line 15

def initialize(logical_path, determine_output_path = proc { nil })
  @logical_path = Pathname.new(logical_path)
  @output_path  = if output_path = determine_output_path.call(@logical_path)
                    Pathname.new(output_path)
                  else
                    nil
                  end
end

Instance Attribute Details

#logical_pathObject (readonly)

Returns the value of attribute logical_path.



6
7
8
# File 'lib/middleman-sprockets/imported_asset.rb', line 6

def logical_path
  @logical_path
end

#output_pathObject (readonly)

Returns the value of attribute output_path.



6
7
8
# File 'lib/middleman-sprockets/imported_asset.rb', line 6

def output_path
  @output_path
end

#real_pathObject (readonly)

Returns the value of attribute real_path.



6
7
8
# File 'lib/middleman-sprockets/imported_asset.rb', line 6

def real_path
  @real_path
end

Instance Method Details

#match?(path) ⇒ Boolean

Does the given patch matches asset

Parameters:

  • path (Pathname)

    The path to be checked

Returns:

  • (Boolean)


46
47
48
# File 'lib/middleman-sprockets/imported_asset.rb', line 46

def match?(path)
  has_real_path? path
end

#resolve_path_with(resolver) ⇒ Object

Resolve logical path to real path

Parameters:

  • resolver (#resolve)

    The objects which is able to resolve a logical path

Raises:

  • (::Sprockets::FileNotFound)


28
29
30
31
32
# File 'lib/middleman-sprockets/imported_asset.rb', line 28

def resolve_path_with(resolver)
  @real_path = resolver.resolve(logical_path)

  raise ::Sprockets::FileNotFound, "Couldn't find asset '#{logical_path}'" if real_path == nil || real_path == ''
end

#to_sString

String representation of asset

Returns:

  • (String)

    The logical path as string



38
39
40
# File 'lib/middleman-sprockets/imported_asset.rb', line 38

def to_s
  logical_path.to_s
end