Module: Useful::ErbHelpers::Links
- Includes:
- Common
- Defined in:
- lib/useful/erb_helpers/links.rb
Constant Summary collapse
- ABSOLUTE_LINK_PATH =
/\Ahttp[s]*:\/\//
Constants included from Common
Class Method Summary collapse
Instance Method Summary collapse
-
#image_tag(source, options = {}) ⇒ Object
helper to emulate 'image_tag' EX : image_tag 'logo.jpg' =>
EX : image_tag '/better/logo.jpg' =>
. -
#javascript_include_tag(*args) ⇒ Object
helper to emulate 'javascript_include_tag' EX : javascript_include_tag 'app' => EX : javascript_include_tag ['app', 'jquery'] => => .
-
#javascript_tag(options = {}) ⇒ Object
helper to emulate 'javascript_tag'.
-
#link_to(*args) ⇒ Object
helper to emulate action view's 'link_to' EX : link_to "http://google.com" => http://google.com EX : link_to "google", "http://google.com" => google EX : link_to "google", "http://google.com", :class => "awesome" => google EX : link_to "http://google.com", :popup => true => http://google.com EX : link_to "http://google.com", :popup => ['new_window_name', 'height=300,width=600'] => http://google.com EX : link_to "http://google.com", :confirm => "Are you sure?" => http://google.com EX : link_to "http://google.com", :confirm => "Are you sure?", :popup => true => http://google.com.
- #link_to_function(content, function, opts = {}) ⇒ Object
-
#mail_to(*args) ⇒ Object
helper for generating a mailto: EX: mail_to "me@domain.com" # => me@domain.com EX: mail_to "me@domain.com", nil, :replace_at => "at", :replace_dot => "dot", :class => "email" # => me_at_domain_dot_com EX: mail_to "me@domain.com", nil, :replace_at => " [at]", :replace_dot => " [dot] ", :disabled => true # => me [at] domain [dot] com EX: mail_to "me@domain.com", "My email", :cc => "ccaddress@domain.com", :subject => "This is an example email" # => My email.
-
#stylesheet_link_tag(*args) ⇒ Object
helper to emulate activesupport's 'stylesheet_link_tag' EX : stylesheet_link_tag 'default' => EX : stylesheet_link_tag 'default', :timestamp => true => EX : stylesheet_link_tag 'default', :media => 'screen' => EX : stylesheet_link_tag 'default', 'test', :media => 'screen' => => EX : stylesheet_link_tag ['default', 'test'], :media => 'screen' => => EX : stylesheet_link_tag 'default', '/other_sheets/other', '/other_sheets/another.css' => => => .
Methods included from Common
#erb_helper_clear_output_buffer
Class Method Details
.included(receiver) ⇒ Object
131 132 133 |
# File 'lib/useful/erb_helpers/links.rb', line 131 def self.included(receiver) receiver.send :include, Useful::ErbHelpers::Tags end |
Instance Method Details
#image_tag(source, options = {}) ⇒ Object
helper to emulate 'image_tag'
EX : image_tag 'logo.jpg'
=>
EX : image_tag '/better/logo.jpg'
=> 
69 70 71 72 73 74 75 76 |
# File 'lib/useful/erb_helpers/links.rb', line 69 def image_tag(source,={}) [:src] = if source =~ ABSOLUTE_LINK_PATH source else ['/'].include?(source[0..0]) ? source : "/images/#{source}" end tag(:img, ) end |
#javascript_include_tag(*args) ⇒ Object
helper to emulate 'javascript_include_tag'
EX : javascript_include_tag 'app'
=>
EX : javascript_include_tag ['app', 'jquery']
=>
=>
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/useful/erb_helpers/links.rb', line 120 def javascript_include_tag(*args) srcs, = (args) [:type] ||= "text/javascript" = .delete(:timestamp) Array(srcs).collect do |src| #TODO: write sinatra helper to auto set env with Sinatra::Application.environment.to_s [:src] = build_src_href(src, :default_path => "javascripts", :extension => ".js", :timestamp => ) tag(:script, ) { '' } end.join("\n") end |
#javascript_tag(options = {}) ⇒ Object
helper to emulate 'javascript_tag'
109 110 111 112 |
# File 'lib/useful/erb_helpers/links.rb', line 109 def javascript_tag(={}) [:type] ||= "text/javascript" tag(:script, ) { yield } end |
#link_to(*args) ⇒ Object
helper to emulate action view's 'link_to' EX : link_to "http://google.com" => http://google.com EX : link_to "google", "http://google.com" => google EX : link_to "google", "http://google.com", :class => "awesome" => google EX : link_to "http://google.com", :popup => true => http://google.com EX : link_to "http://google.com", :popup => ['new_window_name', 'height=300,width=600'] => http://google.com EX : link_to "http://google.com", :confirm => "Are you sure?" => http://google.com EX : link_to "http://google.com", :confirm => "Are you sure?", :popup => true => http://google.com
30 31 32 33 34 35 |
# File 'lib/useful/erb_helpers/links.rb', line 30 def link_to(*args) content, href, = link_content_href_opts(args) .update :href => href () tag(:a, ) { content } end |
#link_to_function(content, function, opts = {}) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/useful/erb_helpers/links.rb', line 57 def link_to_function(content, function, opts={}) opts ||= {} opts[:href] ||= 'javascript: void(0);' opts[:onclick] = "javascript: #{function}; return false;" link_to content, opts[:href], opts end |
#mail_to(*args) ⇒ Object
helper for generating a mailto: EX: mail_to "[email protected]"
=> [email protected]
EX: mail_to "[email protected]", nil, :replace_at => "at", :replace_dot => "dot", :class => "email"
=> me_at_domain_dot_com
EX: mail_to "[email protected]", nil, :replace_at => " [at]", :replace_dot => " [dot] ", :disabled => true
=> me [at] domain [dot] com
EX: mail_to "[email protected]", "My email", :cc => "[email protected]", :subject => "This is an example email"
=> My email
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/useful/erb_helpers/links.rb', line 46 def mail_to(*args) content, email, = link_content_href_opts(args) email_args = [:cc, :bcc, :subject, :body].inject({}) do |args, arg| args[arg] = .delete(arg) if .has_key?(arg) args end content.gsub!(/@/, .delete(:replace_at)) if .has_key?(:replace_at) content.gsub!(/\./, .delete(:replace_dot)) if .has_key?(:replace_dot) .delete(:disabled) ? content : link_to(content, "mailto: #{email}#{email_args.to_http_query_str}", ) end |
#stylesheet_link_tag(*args) ⇒ Object
helper to emulate activesupport's 'stylesheet_link_tag' EX : stylesheet_link_tag 'default' => EX : stylesheet_link_tag 'default', :timestamp => true => EX : stylesheet_link_tag 'default', :media => 'screen' => EX : stylesheet_link_tag 'default', 'test', :media => 'screen' => => EX : stylesheet_link_tag ['default', 'test'], :media => 'screen' => => EX : stylesheet_link_tag 'default', '/other_sheets/other', '/other_sheets/another.css' => => =>
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/useful/erb_helpers/links.rb', line 95 def stylesheet_link_tag(*args) srcs, = (args) [:rel] ||= "stylesheet" [:type] ||= "text/css" [:media] ||= "all" = .delete(:timestamp) Array(srcs).collect do |src| #TODO: write sinatra helper to auto set env with Sinatra::Application.environment.to_s [:href] = build_src_href(src, :default_path => "stylesheets", :extension => ".css", :timestamp => ) tag(:link, ) end.join("\n") end |