Module: Yarrow::HTML::AssetTags
Instance Method Summary collapse
-
#base_url_path ⇒ Object
Computes the base URL path to assets in the public web directory.
-
#link_tag(options) ⇒ Object
TODO: support asset path option?.
-
#manifest ⇒ Object
TODO: make sprockets manifest optional/pluggable.
-
#script_tag(options) ⇒ Object
TODO: support asset path option?.
- #script_tags ⇒ Object
Methods included from Configurable
Instance Method Details
#base_url_path ⇒ Object
Computes the base URL path to assets in the public web directory.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/yarrow/html/asset_tags.rb', line 13 def base_url_path raise Yarrow::ConfigurationError if config.assets.nil? raise Yarrow::ConfigurationError if config.output_dir.nil? # TODO: prepend configurable CDN URL for host path # TODO: dev/production mode switch assets_path = config.assets.output_dir assets_path.gsub(config.output_dir, '') end |
#link_tag(options) ⇒ Object
TODO: support asset path option?
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/yarrow/html/asset_tags.rb', line 41 def link_tag() if .has_key? :asset and manifest.exists? [:asset] stylesheet_path = manifest.digest_path([:asset]) href_path = "#{base_url_path}/#{stylesheet_path}" else href_path = [:href] end "<link href=\"#{href_path}\" rel=\"stylesheet\" type=\"text/css\">" end |
#manifest ⇒ Object
TODO: make sprockets manifest optional/pluggable
7 8 9 |
# File 'lib/yarrow/html/asset_tags.rb', line 7 def manifest Yarrow::Assets::Manifest.new(config) end |
#script_tag(options) ⇒ Object
TODO: support asset path option?
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/yarrow/html/asset_tags.rb', line 29 def script_tag() if .has_key? :asset and manifest.exists? [:asset] script_path = manifest.digest_path([:asset]) src_path = "#{base_url_path}/#{script_path}" else src_path = [:src] end "<script src=\"#{src_path}\"></script>" end |
#script_tags ⇒ Object
24 25 26 |
# File 'lib/yarrow/html/asset_tags.rb', line 24 def manifest.js_logical_paths.map { |asset_path| script_tag(asset: asset_path) }.join("\n") end |