Class: Middleman::Presentation::Asset
- Inherits:
-
Object
- Object
- Middleman::Presentation::Asset
- 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
-
#destination_path ⇒ Object
Returns the value of attribute destination_path.
-
#importable ⇒ Object
writeonly
Sets the attribute importable.
-
#loadable ⇒ Object
writeonly
Sets the attribute loadable.
-
#relative_source_path ⇒ Object
readonly
Returns the value of attribute relative_source_path.
-
#source_path ⇒ Object
readonly
Returns the value of attribute source_path.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#destination_path_resolver ⇒ Object
Destination path resolver.
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
- #import_path ⇒ Object
-
#importable? ⇒ true, false
Is this asset importable?.
-
#initialize(source_path:, relative_source_path:, destination_path:, importable: false, loadable: false) ⇒ Asset
constructor
Create instance.
- #load_path ⇒ Object
-
#loadable? ⇒ true, false
Is this asset loadable?.
-
#merge!(other) ⇒ Object
Merge data from other asset.
Constructor Details
#initialize(source_path:, relative_source_path:, destination_path:, importable: false, loadable: false) ⇒ Asset
Create instance
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_path ⇒ Object
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
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
21 22 23 |
# File 'lib/middleman-presentation-core/asset.rb', line 21 def loadable=(value) @loadable = value end |
#relative_source_path ⇒ Object (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_path ⇒ Object (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_resolver ⇒ Object
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
65 66 67 |
# File 'lib/middleman-presentation-core/asset.rb', line 65 def eql?(other) source_path.eql? other.source_path end |
#hash ⇒ Object
60 61 62 |
# File 'lib/middleman-presentation-core/asset.rb', line 60 def hash source_path.hash end |
#import_path ⇒ Object
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`.
81 82 83 |
# File 'lib/middleman-presentation-core/asset.rb', line 81 def importable? importable == true end |
#load_path ⇒ Object
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.
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 |