Module: Sinatra::SinatraHelpers::Erb::Links
- Defined in:
- lib/useful/sinatra_helpers/erb/links.rb
Instance Method Summary collapse
-
#image_tag(src, options = {}) ⇒ Object
helper to emulate ‘image_tag’ EX : image_tag ‘logo.jpg’ => <img src=“images/logo.jpg” />.
-
#javascript_include_tag(srcs, options = {}) ⇒ Object
helper to emulate ‘javascript_include_tag’ EX : javascript_include_tag ‘app’ => <script src=“/js/app.js” type=“text/javascript” /> EX : javascript_include_tag [‘app’, ‘jquery’] => <script src=“/js/app.js” type=“text/javascript” /> => <script src=“/js/jquery.js” type=“text/javascript” />.
-
#javascript_tag(options = {}) ⇒ Object
helper to emulate ‘javascript_tag’.
-
#link_to(content, href, options = {}) ⇒ Object
helper to emulate action view’s ‘link_to’ EX : link_to “google”, “google.com” => <a href=“google.com”>google</a>.
- #link_to_function(content, function, opts = {}) ⇒ Object
- #mail_link_to(email, options = {}) ⇒ Object
- #open_link_to(content, href, options = {}) ⇒ Object
-
#stylesheet_link_tag(srcs, options = {}) ⇒ Object
helper to emulate ‘stylesheet_link_tag’ EX : stylesheet_link_tag ‘default’ => <link rel=“stylesheet” href=“/stylesheets/default.css” type=“text/css” media=“all” title=“no title” charset=“utf-8”>.
Instance Method Details
#image_tag(src, options = {}) ⇒ Object
helper to emulate ‘image_tag’ EX : image_tag ‘logo.jpg’
=> <img src="images/logo.jpg" />
36 37 38 39 |
# File 'lib/useful/sinatra_helpers/erb/links.rb', line 36 def image_tag(src,={}) [:src] = ['/'].include?(src[0..0]) ? src : "/images/#{src}" tag(:img, ) end |
#javascript_include_tag(srcs, options = {}) ⇒ Object
helper to emulate ‘javascript_include_tag’ EX : javascript_include_tag ‘app’
=> <script src="/js/app.js" type="text/javascript" />
EX : javascript_include_tag [‘app’, ‘jquery’]
=> <script src="/js/app.js" type="text/javascript" />
=> <script src="/js/jquery.js" type="text/javascript" />
60 61 62 63 64 65 66 |
# File 'lib/useful/sinatra_helpers/erb/links.rb', line 60 def javascript_include_tag(srcs,={}) [:type] ||= "text/javascript" srcs.to_a.collect do |src| [:src] = "/javascripts/#{src}.js#{"?#{Time.now.to_i}" if Sinatra::Application.environment.to_s == 'development'}" tag(:script, ) { '' } end.join("\n") end |
#javascript_tag(options = {}) ⇒ Object
helper to emulate ‘javascript_tag’
69 70 71 72 |
# File 'lib/useful/sinatra_helpers/erb/links.rb', line 69 def javascript_tag(={}) [:type] ||= "text/javascript" tag(:script, ) { yield } end |
#link_to(content, href, options = {}) ⇒ Object
helper to emulate action view’s ‘link_to’ EX : link_to “google”, “google.com”
> <a href=“google.com”>google</a>
12 13 14 15 |
# File 'lib/useful/sinatra_helpers/erb/links.rb', line 12 def link_to(content,href,={}) .update :href => href tag(:a, ) { content } end |
#link_to_function(content, function, opts = {}) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/useful/sinatra_helpers/erb/links.rb', line 26 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_link_to(email, options = {}) ⇒ Object
22 23 24 |
# File 'lib/useful/sinatra_helpers/erb/links.rb', line 22 def mail_link_to(email, ={}) link_to [:label] || email, "mailto: #{email}" end |
#open_link_to(content, href, options = {}) ⇒ Object
17 18 19 20 |
# File 'lib/useful/sinatra_helpers/erb/links.rb', line 17 def open_link_to(content, href, ={}) [:onclick] = "javascript: window.open('#{href}'); return false;" link_to(content, href, ) end |
#stylesheet_link_tag(srcs, options = {}) ⇒ Object
helper to emulate ‘stylesheet_link_tag’ EX : stylesheet_link_tag ‘default’
=> <link rel="stylesheet" href="/stylesheets/default.css" type="text/css" media="all" title="no title" charset="utf-8">
44 45 46 47 48 49 50 51 52 |
# File 'lib/useful/sinatra_helpers/erb/links.rb', line 44 def stylesheet_link_tag(srcs,={}) [:media] ||= "screen" [:type] ||= "text/css" [:rel] ||= "stylesheet" srcs.to_a.collect do |src| [:href] = "/stylesheets/#{src}.css#{"?#{Time.now.to_i}" if Sinatra::Application.environment.to_s == 'development'}" tag(:link, ) end.join("\n") end |