Module: Templette::Helpers
- Included in:
- DataAccessors
- Defined in:
- lib/templette/helpers.rb
Overview
Standard tag helpers to attempt to make life a little easier. Tag methods will not modify full paths (with an http protocol). If a tag is just a local path, it will heed the configurable site_root, and prepend the necessary directories to build the anticipated path.
Instance Method Summary collapse
-
#image_tag(path, options = {}) ⇒ Object
image_tag(‘’, :alt => ‘lol!’) => “<img src=‘’ alt=‘lol!’ />”.
-
#script_tag(path) ⇒ Object
Genrates a javascript scrip tag.
-
#stylesheet_tag(path, options = {}) ⇒ Object
Generates a link to a stylesheet.
Instance Method Details
#image_tag(path, options = {}) ⇒ Object
image_tag(‘’, :alt => ‘lol!’)
=> "<img src='http://flickr.com/hilarious-picture.jpg' alt='lol!' />"
19 20 21 22 |
# File 'lib/templette/helpers.rb', line 19 def image_tag(path, = {}) = {:alt => path}.merge() "<img src='#{tag_path(path, 'images')}' #{params_to_attributes()}/>" end |
#script_tag(path) ⇒ Object
Genrates a javascript scrip tag.
Ex.
script_tag('slider')
=> <script src='/javascripts/slider.js' type='text/javascript'></script>
41 42 43 |
# File 'lib/templette/helpers.rb', line 41 def script_tag(path) "<script src='#{tag_path(path, 'javascripts', 'js')}' type='text/javascript'></script>" end |
#stylesheet_tag(path, options = {}) ⇒ Object
Generates a link to a stylesheet. Default options => ‘text/css’, :rel => ‘stylesheet’
Ex.
stylesheet_tag('print', :media => 'print')
=> "<link href='/stylesheets/print.css' media='print' type='text/css' />"
30 31 32 33 |
# File 'lib/templette/helpers.rb', line 30 def stylesheet_tag(path, = {}) = {:type => 'text/css', :rel => 'stylesheet', :media => 'screen'}.merge() "<link href='#{tag_path(path, 'stylesheets', 'css')}' #{params_to_attributes()}/>" end |