Class: Middleman::Presentation::Asset

Inherits:
Object
  • Object
show all
Includes:
Comparable, FeduxOrgStdlib::Roles::Typable
Defined in:
lib/middleman-presentation-core/asset.rb

Overview

External asset

It represents a single asset - an image, a stylesheets, a font etc. An assets will be placed in a default directory by ‘middleman-sprockes`. To change the default directory one needs to tell the `Asset`-class that on initialization.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_path:, relative_source_path:, destination_path:, importable: false, loadable: false) ⇒ Asset

Create instance

Parameters:

  • source_path (String)

    The source path for the asset

  • destination_path (String)

    The directory where the asset should be placed when building the static version of the web application



31
32
33
34
35
36
37
38
# File 'lib/middleman-presentation-core/asset.rb', line 31

def initialize(source_path:, relative_source_path:, destination_path:, importable: false, loadable: false)
  @source_path          = Pathname.new(source_path)
  @relative_source_path = Pathname.new(relative_source_path)
  @importable           = importable
  @loadable             = loadable

  self.destination_path = destination_path
end

Instance Attribute Details

#destination_pathObject

Returns the value of attribute destination_path.



20
21
22
# File 'lib/middleman-presentation-core/asset.rb', line 20

def destination_path
  @destination_path
end

#importable=(value) ⇒ Object

Sets the attribute importable

Parameters:

  • value

    the value to set the attribute importable to.



21
22
23
# File 'lib/middleman-presentation-core/asset.rb', line 21

def importable=(value)
  @importable = value
end

#loadable=(value) ⇒ Object

Sets the attribute loadable

Parameters:

  • value

    the value to set the attribute loadable to.



21
22
23
# File 'lib/middleman-presentation-core/asset.rb', line 21

def loadable=(value)
  @loadable = value
end

#relative_source_pathObject (readonly)

Returns the value of attribute relative_source_path.



20
21
22
# File 'lib/middleman-presentation-core/asset.rb', line 20

def relative_source_path
  @relative_source_path
end

#source_pathObject (readonly)

Returns the value of attribute source_path.



20
21
22
# File 'lib/middleman-presentation-core/asset.rb', line 20

def source_path
  @source_path
end

Instance Method Details

#<=>(other) ⇒ Object



70
71
72
# File 'lib/middleman-presentation-core/asset.rb', line 70

def <=>(other)
  source_path <=> other.source_path
end

#destination_path_resolverObject

Destination path resolver



53
54
55
56
57
# File 'lib/middleman-presentation-core/asset.rb', line 53

def destination_path_resolver
  return proc { |_| destination_path } if destination_path

  proc {}
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/middleman-presentation-core/asset.rb', line 65

def eql?(other)
  source_path.eql? other.source_path
end

#hashObject



60
61
62
# File 'lib/middleman-presentation-core/asset.rb', line 60

def hash
  source_path.hash
end

#import_pathObject



40
41
42
# File 'lib/middleman-presentation-core/asset.rb', line 40

def import_path
  relative_source_path.dirname + relative_source_path.basename('.*')
end

#importable?true, false

Is this asset importable?

If it is importable, one can use it in ‘application.js` or `application.scss`.

Returns:

  • (true, false)

    The result of check



81
82
83
# File 'lib/middleman-presentation-core/asset.rb', line 81

def importable?
  importable == true
end

#load_pathObject



44
45
46
# File 'lib/middleman-presentation-core/asset.rb', line 44

def load_path
  relative_source_path
end

#loadable?true, false

Is this asset loadable?

If it is importable, it will be placed in build directory by sprockets.

Returns:

  • (true, false)

    The result of check



91
92
93
# File 'lib/middleman-presentation-core/asset.rb', line 91

def loadable?
  loadable == true
end

#merge!(other) ⇒ Object

Merge data from other asset



96
97
98
99
100
# File 'lib/middleman-presentation-core/asset.rb', line 96

def merge!(other)
  self.importable            = true if other.importable?
  self.loadable              = true if other.loadable?
  self.destination_path = other.destination_path if destination_path.blank?
end