module Roda::RodaPlugins::Assets::InstanceMethods
def assets(type, attrs = OPTS)
tag for each asset file. When the assets are compiled, this will
When the assets are not compiled, this will result in a separate
as the attrs argument.
You can specify custom attributes for the tag by passing a hash
the type, such as [:css, :frontend].
To return the tags for a specific asset group, use an array for
the :css type.
This will use a script tag for the :js type and a link tag for
Return a string containing html tags for the given asset type.
def assets(type, attrs = OPTS) ltype = type.is_a?(Array) ? type[0] : type o = self.class.assets_opts if o[:compiled] && (algo = o[:sri]) && (hash = _compiled_assets_hash(type)) attrs = Hash[attrs] attrs[:integrity] = "#{algo}-#{h([[hash].pack('H*')].pack('m').tr("\n", ''))}" end attributes = attrs.map{|k,v| "#{k}=\"#{h(v)}\""}.join(' ') if ltype == :js tag_start = "<script#{' type="text/javascript"' unless attrs[:type]} #{attributes} src=\"" tag_end = "\"></script>" else tag_start = "<link rel=\"stylesheet\" #{attributes} href=\"" tag_end = "\" />" end paths = assets_paths(type) if o[:early_hints] early_hint_as = ltype == :js ? 'script' : 'style' send_early_hints('Link'=>paths.map{|p| "<#{p}>; rel=preload; as=#{early_hint_as}"}.join("\n")) end paths.map{|p| "#{tag_start}#{h(p)}#{tag_end}"}.join("\n") end