Module: Yarrow::HTML::AssetTags

Includes:
Configurable
Included in:
Output::Context
Defined in:
lib/yarrow/html/asset_tags.rb

Instance Method Summary collapse

Methods included from Configurable

#config

Instance Method Details

#base_url_pathObject

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
  if config.assets.nil? || config.output_dir.nil?
    raise Yarrow::ConfigurationError
  end

  # TODO: prepend configurable CDN URL for host path
  # TODO: dev/production mode switch

  config.assets.output_dir.gsub(config.output_dir, '')
end


38
39
40
41
42
43
44
45
46
# File 'lib/yarrow/html/asset_tags.rb', line 38

def link_tag(options)
  href_path = if asset_in_manifest?(options)
     digest_path(options[:asset])
  else
    options[:href]
  end

  "<link href=\"#{href_path}\" rel=\"stylesheet\" type=\"text/css\">"
end

#manifestObject

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



28
29
30
31
32
33
34
35
36
# File 'lib/yarrow/html/asset_tags.rb', line 28

def script_tag(options)
  src_path = if asset_in_manifest?(options)
    digest_path(options[:asset])
  else
    options[:src]
  end

  "<script src=\"#{src_path}\"></script>"
end

#script_tagsObject



24
25
26
# File 'lib/yarrow/html/asset_tags.rb', line 24

def script_tags
  manifest.js_logical_paths.map { |path| script_tag(asset: path) }.join("\n")
end