Module: Sinatra::Exstatic::Helpers

Includes:
Private
Defined in:
lib/sinatra/exstatic_assets.rb

Overview

These are the helpers available to a Sinatra app using the extension.

Examples:

# For a classic app
require 'sinatra/exstatic'
# That's all for a classic app, the helpers
# are now available.

# For a modular app
require 'sinatra/base'
require 'sinatra/exstatic'
class MyApp < Sinatra::Base
  helpers Sinatra::Exstatic

Instance Method Summary collapse

Instance Method Details

#favicon_tag(*args) ⇒ Object Also known as: link_favicon_tag, favicon

Examples:

favicon_tag
# => <link href="/favicon.ico" rel="icon">

Parameters:

  • source (String)
  • options (Hash)


283
284
285
286
287
288
289
290
291
292
293
294
# File 'lib/sinatra/exstatic_assets.rb', line 283

def favicon_tag(*args)
  source, options = sss_extract_options args
  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"

  url_options = options.delete(:url_options) || {}
  options[:href] = sss_url_for(Asset.new(source), url_options.merge(timestamp: false))
  
  Tag.new "link", options
end

#image_tag(*sources) ⇒ #to_s Also known as: img_tag

Produce an HTML img tag.

Examples:

image_tag "/images/big-fish.jpg", width: "500", height: "250", alt: "The biggest fish in the world!"
# => <img alt="The biggest fish in the world!" height="250" src="/images/big-fish.jpg?ts=1367933468" width="500" />

Parameters:

  • sources (String)

    The file or HTML resource.

  • options (Hash)

Returns:

  • (#to_s)


# File 'lib/sinatra/exstatic_assets.rb', line 228

#javascript_tag(*sources) ⇒ #to_s Also known as: javascript_include_tag, js_tag, script_tag

Produce an HTML script tag.

Examples:

javascript_tag "http://code.jquery.com/jquery-1.9.1.min.js"
# => <script charset="utf-8" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>

Parameters:

  • sources (String)

    The file or HTML resource.

  • options (Hash)

Returns:

  • (#to_s)


260
261
262
263
264
265
266
267
# File 'lib/sinatra/exstatic_assets.rb', line 260

%w{image_tag stylesheet_tag javascript_tag}.each do |method_name|
  define_method method_name do |*sources|
    list, options = sss_extract_options sources
    list.map {|source|
      send "sss_#{method_name}", source, options
    }.join "\n"
  end
end

#stylesheet_tag(*sources) ⇒ #to_s Also known as: css_tag, stylesheet

Produce an HTML link tag to a stylesheet.

Examples:

stylesheet_tag "/css/screen.css"
# => <link charset="utf-8" href="/css/screen.css?ts=1367678587" media="screen" rel="stylesheet">

Parameters:

  • sources (String)

    The file or HTML resource.

  • options (Hash)

Returns:

  • (#to_s)


# File 'lib/sinatra/exstatic_assets.rb', line 239