Module: ActionView::Helpers::AssetTagHelper

Defined in:
lib/ezcript/application_helper_extension.rb

Instance Method Summary collapse

Instance Method Details



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/ezcript/application_helper_extension.rb', line 137

def complete_link_to(*args, &block)
  if block_given?
    options      = args.first || {}
    html_options = args.second
    link_to(capture(&block), options, html_options)
  else
    name         = args[0]
    options      = args[1] || {}
    html_options = args[2]

    html_options = convert_options_to_data_attributes(options, html_options)
    url = url_for(options)
    url = File.join(Compass::Info.app_host, url).to_s unless url.downcase.starts_with?("http")

    if html_options
      html_options = html_options.stringify_keys
      href = html_options['href']
      tag_options = tag_options(html_options)
    else
      tag_options = nil
    end

    href_attr = "href=\"#{html_escape(url)}\"" unless href
    "<a #{href_attr}#{tag_options}>#{(name || url)}</a>".html_safe
  end
end

#image_tag(source, options = {}) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/ezcript/application_helper_extension.rb', line 116

def image_tag(source, options = {})
  options.symbolize_keys!

  src = options[:src] = "#{Compass::Info.asset_dir}#{path_to_image(source)}"

  unless src =~ /^cid:/
    options[:alt] = options.fetch(:alt){ File.basename(src, '.*').capitalize }
  end

  if size = options.delete(:size)
    options[:width], options[:height] = size.split("x") if size =~ %r{^\d+x\d+$}
  end

  if mouseover = options.delete(:mouseover)
    options[:onmouseover] = "this.src='#{path_to_image(mouseover)}'"
    options[:onmouseout]  = "this.src='#{src}'"
  end

  tag("img", options)
end

#javascript_src_tag(source, options) ⇒ Object



110
111
112
113
114
# File 'lib/ezcript/application_helper_extension.rb', line 110

def javascript_src_tag(source, options)
  s= "#{Compass::Info.asset_dir}/javascripts/#{source}"
  s << ".js" unless s.end_with?(".js")
  ("script", "", { "type" => Mime::JS, "src" => path_to_javascript(s) }.merge(options))
end

#stylesheet_tag(source, options) ⇒ Object



105
106
107
108
# File 'lib/ezcript/application_helper_extension.rb', line 105

def stylesheet_tag(source, options)
  s= "#{Compass::Info.asset_dir}/stylesheets/#{source}"
  tag("link", { "rel" => "stylesheet", "type" => Mime::CSS, "media" => "screen", "href" => html_escape(path_to_stylesheet(s)) }.merge(options), false, false)
end