W3cubDocs

/Padrino

Module: Padrino::Helpers::AssetTagHelpers

Overview

Helpers related to producing assets (images, stylesheets, js, etc) within templates.

Constant Summary collapse

APPEND_ASSET_EXTENSIONS =
["js", "css"]
ABSOLUTE_URL_PATTERN =
%r{^(https?://)}
ASSET_FOLDERS =
{
  :js => 'javascripts',
  :css => 'stylesheets',
}

Instance Method Summary

Instance Method Details

#asset_path(kind, source = nil) ⇒ String

Returns the path to the specified asset (css or javascript).

Examples:

# Generates: /javascripts/application.js?1269008689
asset_path :js, :application

# Generates: /stylesheets/application.css?1269008689
asset_path :css, :application

# Generates: /images/example.jpg?1269008689
asset_path :images, 'example.jpg'

# Generates: /uploads/file.ext?1269008689
asset_path 'uploads/file.ext'

Parameters:

  • kind (String) — The kind of asset (i.e :images, :js, :css).
  • source (String) (defaults to: nil) — The path to the asset (relative or absolute).

Returns:

  • (String) — Path for the asset given the kind and source.

#favicon_tag(source, options = {}) ⇒ String

Generates a favicon link. Looks inside images folder

Examples:

favicon_tag 'favicon.png'
favicon_tag 'icons/favicon.png'
# or override some options
favicon_tag 'favicon.png', :type => 'image/ico'

Parameters:

  • source (String) — The source image path for the favicon link tag.
  • options (Hash) (defaults to: {}) — The html options for the favicon link tag.

Returns:

  • (String) — The favicon link html tag with specified options.

#feed_tag(mime, url, options = {}) ⇒ String

Creates a link tag that browsers and news readers can use to auto-detect an RSS or ATOM feed.

@param options

The options for the feed tag.

Examples:

feed_tag :atom, url(:blog, :posts, :format => :atom), :title => "ATOM"
# Generates: <link type="application/atom+xml" rel="alternate" href="/blog/posts.atom" title="ATOM" />
feed_tag :rss, url(:blog, :posts, :format => :rss)
# Generates: <link type="application/rss+xml" rel="alternate" href="/blog/posts.rss" title="rss" />

Parameters:

  • mime (Symbol) — The mime type of the feed (i.e :atom or :rss).
  • url (String) — The url for the feed tag to reference.
  • options (Hash) (defaults to: {}) — a customizable set of options

Options Hash (options):

  • :rel (String) — default: "alternate" — Specify the relation of this link.
  • :type (String) — Override the auto-generated mime type.
  • :title (String) — Specify the title of the link, defaults to the type.

Returns:

  • (String) — Feed link html tag with specified options.

#flash_tag(*args) ⇒ String

Creates a div to display the flash of given type if it exists.

Examples:

flash_tag(:notice, :id => 'flash-notice')
# Generates: <div class="notice" id="flash-notice">flash-notice</div>
flash_tag(:error, :success)
# Generates: <div class="error">flash-error</div>
# <div class="success">flash-success</div>

Parameters:

  • kind (Symbol) — The type of flash to display in the tag.
  • options (Hash) — The html options for this section. use :bootstrap => true to support Twitter's bootstrap dismiss alert button.

Returns:

  • (String) — Flash tag html with specified options.

#image_alt(src) ⇒ String

Returns a string suitable for an alt attribute of img element.

Parameters:

  • src (String) — The source path for the image tag.

Returns:

  • (String) — The alt attribute value.

#image_path(src) ⇒ String

Returns the path to the image, either relative or absolute. We search it in your appname.public_folder like app/public/images for inclusion. You can provide also a full path.

Examples:

# Generates: /images/foo.jpg?1269008689
image_path("foo.jpg")

Parameters:

  • src (String) — The path to the image file (relative or absolute).

Returns:

  • (String) — Path to an image given the kind and source.

#image_tag(url, options = {}) ⇒ String

Creates an image element with given url and options.

Examples:

image_tag('icons/avatar.png')

Parameters:

  • url (String) — The source path for the image tag.
  • options (Hash) (defaults to: {}) — The html options for the image tag.

Returns:

  • (String) — Image html tag with url and specified options.

#javascript_include_tag(*sources, options = {}) ⇒ String

Returns a html script tag for each of the sources provided. You can pass in the filename without extension or a symbol and we search it in your appname.public_folder like app/public/javascript for inclusion. You can provide also a full path.

Examples:

javascript_include_tag 'application', :extjs

Parameters:

  • sources (Array<String>) — Splat of js source paths
  • options (Hash) (defaults to: {}) — The html options for the script tag

Returns:

  • (String) — Script tag for sources with specified options.

Creates a link element with given name, url and options.

Note that you can pass :if or :unless conditions, but if you provide :current as condition padrino return true/false if the request.path_info match the given url.

Examples:

link_to('click me', '/dashboard', :class => 'linky')
# Generates <a class="linky" href="/dashboard">click me</a>

link_to('click me', '/dashboard', :remote => true)
# Generates <a href="/dashboard" data-remote="true">click me</a>

link_to('click me', '/dashboard', :method => :delete)
# Generates <a href="/dashboard" data-method="delete" rel="nofollow">click me</a>

link_to('/dashboard', :class => 'blocky') { 'click me' }
# Generates <a class="blocky" href="/dashboard">click me</a>

Overloads:

  • #link_to(caption, url, options = {}) ⇒ String

    Parameters:

    • caption (String) — The text caption.
    • url (String) — The url href.
    • options (Hash) (defaults to: {}) — The html options.
  • #link_to(url, options = {}, &block) ⇒ String

    Parameters:

    • url (String) — The url href.
    • options (Hash) (defaults to: {}) — The html options.
    • block (Proc) — The link content.

Parameters:

  • options (Hash) — a customizable set of options

Returns:

  • (String) — Link tag html with specified options.

#mail_to(email, caption = nil, mail_options = {}) ⇒ String

Creates a mail link element with given name and caption.

Examples:

mail_to "[email protected]"
# Generates: <a href="mailto:[email protected]">[email protected]</a>

mail_to "[email protected]", "My Email"
# Generates: <a href="mailto:[email protected]">My Email</a>

Parameters:

  • email (String) — The email address for the link.
  • caption (String) (defaults to: nil) — The caption for the link.
  • mail_options (Hash) (defaults to: {}) — The options for the mail link. Accepts html options.

Options Hash (mail_options):

  • cc (String) — The cc recipients.
  • bcc (String) — The bcc recipients.
  • subject (String) — The subject line.
  • body (String) — The email body.

Returns:

  • (String) — Mail link html tag with specified options.

#meta_tag(content, options = {}) ⇒ String

Creates a meta element with the content and given options.

Examples:

meta_tag "weblog,news", :name => "keywords"
# Generates: <meta name="keywords" content="weblog,news" />

meta_tag "text/html; charset=UTF-8", 'http-equiv' => "Content-Type"
# Generates: <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

Parameters:

  • content (String) — The content for the meta tag.
  • options (Hash) (defaults to: {}) — The html options for the meta tag.

Returns:

  • (String) — Meta html tag with specified options.

Returns a html link tag for each of the sources provided. You can pass in the filename without extension or a symbol and we search it in your appname.public_folder like app/public/stylesheets for inclusion. You can provide also a full path.

Examples:

stylesheet_link_tag 'style', 'application', 'layout'

Parameters:

  • sources (Array<String>) — Splat of css source paths
  • options (Hash) (defaults to: {}) — The html options for the link tag

Returns:

  • (String) — Stylesheet link html tag for sources with specified options.