Module: Brandish::Processors::Common::Asset::Paths
- Included in:
- Brandish::Processors::Common::Asset
- Defined in:
- lib/brandish/processors/common/asset/paths.rb
Overview
Common path operations used for asset processors. This assumes a css-like dependency structure similar to HTML's. These are not required to be used.
Instance Method Summary collapse
-
#asset_kind_extension ⇒ ::String
abstract
The extension for this kind of asset.
-
#asset_kind_path ⇒ ::String
abstract
The asset path for this kind of asset.
-
#asset_load_paths ⇒ Object
The load paths for this asset type.
-
#load_file_paths ⇒ {::Symbol => ::Pathname}
The file paths.
-
#output_assets_path ⇒ ::String
The default output assets path.
-
#uri_path(uri) ⇒ ::Pathname
Converts the given uri into a pathname, using the host, the path, the query, and the fragment all as directories.
Instance Method Details
#asset_kind_extension ⇒ ::String
The extension for this kind of asset. This defaults to no extension.
25 26 27 |
# File 'lib/brandish/processors/common/asset/paths.rb', line 25 def asset_kind_extension "" end |
#asset_kind_path ⇒ ::String
The asset path for this kind of asset.
16 17 18 |
# File 'lib/brandish/processors/common/asset/paths.rb', line 16 def asset_kind_path nil end |
#asset_load_paths ⇒ Object
The load paths for this asset type. This defaults to a pathset
containing all of the sources, all of the sources' appended with
#asset_kind_path, and all of the paths given by the
:asset_load_paths
option value.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/brandish/processors/common/asset/paths.rb', line 33 def asset_load_paths return @asset_load_paths if @asset_load_paths paths = PathSet.new @context.configure.sources .each { |p| paths << p } .each { |p| paths << p / asset_kind_path } @options.fetch(:asset_load_paths, []).each { |p| paths << p } @asset_load_paths = paths end |
#load_file_paths ⇒ {::Symbol => ::Pathname}
The file paths. This returns a hash with three elements:
:file
, which is the given file name from the element;
:out
, which is the full output directory for outputting the
asset file; and :src
, which is similar to what the HTML src
or href value would be for the asset.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/brandish/processors/common/asset/paths.rb', line 73 def load_file_paths file = load_asset_file # The full path to the file itself. path = asset_load_paths.find(file, @options) output_path = @context.configure.output # The relative path from the source asset directory. asset_path = asset_load_paths.resolve(file) # The "raw" output path. raw_output_path = @pairs.fetch("output") { asset_path.sub_ext(asset_kind_extension) } # The actual output path of the file. file_output_path = output_assets_path / raw_output_path src_output_path = file_output_path.relative_path_from(output_path) { file: path, out: file_output_path, src: src_output_path } end |
#output_assets_path ⇒ ::String
The default output assets path.
47 48 49 |
# File 'lib/brandish/processors/common/asset/paths.rb', line 47 def output_assets_path @context.configure.output / asset_kind_path end |
#uri_path(uri) ⇒ ::Pathname
Converts the given uri into a pathname, using the host, the path,
the query, and the fragment all as directories. This turns the
uri https://example.com/some-path?waffles#test
into the path
example.com/some-path/waffles/test.<asset_kind_extension>
.
58 59 60 61 62 63 64 |
# File 'lib/brandish/processors/common/asset/paths.rb', line 58 def uri_path(uri) base = [uri.host, (uri.path unless uri.path.empty?), (uri.query if uri.query), (uri.fragment if uri.fragment)].compact ::Pathname.new(::File.join(*base)).sub_ext(asset_kind_extension) end |