Class: Middleman::Sprockets::Asset
- Inherits:
-
Object
- Object
- Middleman::Sprockets::Asset
- Defined in:
- lib/middleman-sprockets/asset.rb
Overview
Asset
Instance Attribute Summary collapse
-
#destination_directory ⇒ Object
writeonly
Set destination directory @param [String] path The path to the destination directory.
-
#source_path ⇒ Object
readonly
Returns the value of attribute source_path.
Instance Method Summary collapse
-
#destination_path ⇒ Pathname
Path where the asset should be stored.
-
#destination_path=(path) ⇒ Object
Sets the destination_path.
-
#has_type?(t) ⇒ true, false
Check on file type.
-
#import? ⇒ true, false
Should the asset imported?.
-
#import_it ⇒ Object
Tell asset that it is importable.
-
#initialize(source_path, options) ⇒ Asset
constructor
Create instance.
-
#match?(path) ⇒ true, false
Check if given path matches source_path.
Constructor Details
#initialize(source_path, options) ⇒ Asset
Create instance
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/middleman-sprockets/asset.rb', line 22 def initialize(source_path, ) source_directory = .fetch(:source_directory, nil) fail ArgumentError, 'Missing argument source_directory' unless source_directory @source_directory = source_directory @source_path = Pathname.new(source_path) @relative_source_path = @source_path.relative_path_from(Pathname.new(source_directory)) @base_name = @source_path.basename @import_it = false end |
Instance Attribute Details
#destination_directory=(path) ⇒ Object
Set destination directory
@param [String] path
The path to the destination directory
@return [Pathname]
The path as pathname
82 83 84 |
# File 'lib/middleman-sprockets/asset.rb', line 82 def destination_directory=(path) @destination_directory = Pathname.new path end |
#source_path ⇒ Object (readonly)
Returns the value of attribute source_path.
13 14 15 |
# File 'lib/middleman-sprockets/asset.rb', line 13 def source_path @source_path end |
Instance Method Details
#destination_path ⇒ Pathname
Path where the asset should be stored
58 59 60 61 62 63 64 |
# File 'lib/middleman-sprockets/asset.rb', line 58 def destination_path return @destination_path if @destination_path fail ::Sprockets::FileNotFound, "Couldn't find an appropriate output directory for '#{destination_directory}' - halting because it was explicitly requested via 'import_asset'" unless destination_directory destination_directory + relative_source_path end |
#destination_path=(path) ⇒ Object
Sets the destination_path
71 72 73 |
# File 'lib/middleman-sprockets/asset.rb', line 71 def destination_path=(path) @destination_path = Pathname.new path end |
#has_type?(t) ⇒ true, false
Check on file type
47 48 49 |
# File 'lib/middleman-sprockets/asset.rb', line 47 def has_type?(t) type == t end |
#import? ⇒ true, false
Should the asset imported?
39 40 41 |
# File 'lib/middleman-sprockets/asset.rb', line 39 def import? valid? && (in_trusted_source_directory? || import_it?) end |
#import_it ⇒ Object
Tell asset that it is importable
97 98 99 |
# File 'lib/middleman-sprockets/asset.rb', line 97 def import_it @import_it = true # single = end |
#match?(path) ⇒ true, false
Check if given path matches source_path
92 93 94 |
# File 'lib/middleman-sprockets/asset.rb', line 92 def match?(path) source_path == Pathname.new(path) end |