module Sinatra::Exstatic::Private
The private instance methods. @api private
Constants
- DEFAULT_CSS
The default options passed with a stylesheet asset.
- DEFAULT_JS
Default options for the javascript script tags.
Private Instance Methods
Make's sure the options don't get mixed up with the other args.
# File lib/sinatra/exstatic_assets.rb, line 222 def sss_extract_options(a) opts = a.last.respond_to?(:keys) ? a.pop || {} : {} url_opts = opts.empty? ? {} : { absolute: opts.delete(:absolute), script_name: opts.delete(:script_name), }.reject{|k,v| v.nil? } a = [nil] if a == [] [a, opts, url_opts] end
@param [String] source @param [Hash] options @option options [TrueClass] :script_name whether to append the script_name environment variable or not @example
favicon_tag # => <link href="/favicon.ico" rel="icon">
# File lib/sinatra/exstatic_assets.rb, line 251 def sss_favicon_tag(source, options, url_opts) source = "/favicon.ico" if source.nil? or source.empty? # xhtml style like <link rel="shortcut icon" href="http://example.com/myicon.ico" /> options[:rel] ||= settings.xhtml ? "shortcut icon" : "icon" asset = Asset.new source, options.delete(:asset_dir), options.delete(:timestamp_format) options[:href] = sss_url_for asset, options.merge(timestamp: false), url_opts Tag.new "link", options end
@see sss_stylesheet_tag
# File lib/sinatra/exstatic_assets.rb, line 239 def sss_image_tag(source, options, url_opts) options[:src] = sss_url_for Asset.new( source, options.delete(:asset_dir), options.delete(:timestamp_format) ), options, url_opts Tag.new "img", options end
Produce a javascript script tag. @see sss_stylesheet_tag
but there is no `closed` option here.
# File lib/sinatra/exstatic_assets.rb, line 212 def sss_javascript_tag(source, options, url_opts) asset = Asset.new source, options.delete(:asset_dir), options.delete(:timestamp_format) href = sss_url_for asset, options, url_opts Tag.new("script", DEFAULT_JS.merge(:src => href) .merge(options) ) {} end
Produce a stylesheet link tag. @param [String] source The file or HTML resource. @param [Hash] options @option options [String] :asset_dir The directory the asset is held. Defaults to Sinatra's `public_folder` setting. @option options [Hash] :url_options Options for devising the URL. @option options [TrueClass] :script_name Whether to prepend the SCRIPT_NAME env variable. @return [Tag]
# File lib/sinatra/exstatic_assets.rb, line 195 def sss_stylesheet_tag(source, options, url_opts) asset = Asset.new source, options.delete(:asset_dir), options.delete(:timestamp_format) href = sss_url_for asset, options, url_opts Tag.new "link", DEFAULT_CSS.merge(:href => href) .merge(options) end
Wraps around Sinatra::Helpers#uri. Appends a querystring if passed an Asset
object. @param [String,#querystring] addr @param [Hash] options @option options [TrueClass] :absolute see Sinatra::Helpers#uri @option options [TrueClass] :script_name Whether to prepend the SCRIPT_NAME env variable. @return [String] @see Sinatra::Helpers#uri
# File lib/sinatra/exstatic_assets.rb, line 141 def sss_url_for(addr, options, url_opts) absolute = url_opts.delete :absolute absolute = false if absolute.nil? scr = url_opts.delete(:script_name) script_name = if addr.is_uri? false elsif addr.start_with?("/") scr.nil? ? true : scr else false end href = uri addr, absolute, script_name timestamp = if scr == false false else # timestamp | # nil t # f | f # t | t if options[:timestamp] && options[:timestamp] == false false else true end end opts = {timestamp: timestamp}.merge options addr.respond_to?(:querystring) && opts[:timestamp] ? "#{href}#{addr.querystring}" : href end