Module: Sinatra::Chicago::Helpers
- Defined in:
- lib/chicago/helpers.rb
Instance Method Summary collapse
-
#anchor(name, url, options = {}) ⇒ Object
A basic anchor (link_to) tag.
-
#javascript_include(name, options = {}) ⇒ Object
A helper to include javascript source tags.
-
#stylesheet_include(name, options = {}) ⇒ Object
A helper to include stylesheet links.
Instance Method Details
#anchor(name, url, options = {}) ⇒ Object
A basic anchor (link_to) tag
Exmaples:
anchor('GusGus', 'http://gusg.us')
=> <a href="http://gusg.us">GusG.us</a>
anchor('GusGus', 'http://gusg.us', :title => 'You know who!')
=> <a href="http://gusg.us" title="You know who!">GusG.us</a>
13 14 15 16 17 |
# File 'lib/chicago/helpers.rb', line 13 def anchor(name, url, ={}) defaults = {:href => url} = hash_to_attributes(defaults.merge()) %Q[<a #{}>#{name}</a>] end |
#javascript_include(name, options = {}) ⇒ Object
A helper to include javascript source tags. Currently defaults everything to load from a /javascripts directory.
Exmaples:
javascript_include('foo')
=> <javascript src="/javascripts/foo.js" type="text/javascript"></script>
javascript_include('foo/bar')
=> <javascript src="/javascripts/foo/bar.js" type="text/javascript"></script>
javascript_include('foo', :something => "great")
=> <javascript src="/javascripts/foo.js" type="text/javascript" something="great"></script>
javascript_include('http://example.com/foo.js')
=> <javascript src="http://example.com/foo.js" type="text/javascript"></script>
59 60 61 62 63 64 |
# File 'lib/chicago/helpers.rb', line 59 def javascript_include(name, ={}) name = "/javascripts/#{name}.js" unless remote_asset?(name) defaults = {:src => name, :type => "text/javascript"} = hash_to_attributes(defaults.merge()) %Q[<script #{}></script>] end |
#stylesheet_include(name, options = {}) ⇒ Object
A helper to include stylesheet links. Currently defaults everything to load from a /stylesheets directory.
Exmaples:
stylesheet_include('foo')
=> <link href="/stylsheets/foo.css" media="screen" rel="stylesheet" type="text/css" />
stylesheet_include('foo/bar')
=> <link href="/stylsheets/foo/bar.css" media="screen" rel="stylesheet" type="text/css" />
stylesheet_include('foo', :media => "print")
=> <link href="/stylsheets/foo.css" media="print" rel="stylesheet" type="text/css" />
stylesheet_include('http://example.com/foo.css')
=> <link href="http://example.com/foo.css" media="print" rel="stylesheet" type="text/css" />
35 36 37 38 39 40 41 |
# File 'lib/chicago/helpers.rb', line 35 def stylesheet_include(name, ={}) name = "/stylesheets/#{name}.css" unless remote_asset?(name) defaults = {:href => name, :media => "screen", :rel => "stylesheet", :type => "text/css"} = hash_to_attributes(defaults.merge()) %Q[<link #{}/>] end |