Module: Sinatra::Cigars::Helpers
- Defined in:
- lib/sinatra/cigars/helpers.rb
Instance Method Summary collapse
- #css(href = '/style') ⇒ Object
- #development? ⇒ Boolean
- #favicon(src = nil) ⇒ Object
- #home? ⇒ Boolean
- #js(src) ⇒ Object
- #livereload ⇒ Object
- #meta(arg) ⇒ Object
- #production? ⇒ Boolean
- #staging? ⇒ Boolean
- #test? ⇒ Boolean
- #title(str, prefix = "", suffix = false) ⇒ Object
- #typekit(id) ⇒ Object
Instance Method Details
#css(href = '/style') ⇒ Object
31 32 33 |
# File 'lib/sinatra/cigars/helpers.rb', line 31 def css href = '/style' render_haml "%link{rel: 'stylesheet', href: '#{render_tag(href, '.css')}'}" end |
#development? ⇒ Boolean
7 8 9 |
# File 'lib/sinatra/cigars/helpers.rb', line 7 def development? ENV['RACK_ENV'] == 'development' end |
#favicon(src = nil) ⇒ Object
39 40 41 |
# File 'lib/sinatra/cigars/helpers.rb', line 39 def favicon src = nil render_haml "%link{rel: 'shortcut icon', href: '#{render_tag((src ? src : '/favicon'), (src ? '.png' : '.ico'))}'}" end |
#home? ⇒ Boolean
23 24 25 |
# File 'lib/sinatra/cigars/helpers.rb', line 23 def home? request.path == '/' end |
#js(src) ⇒ Object
35 36 37 |
# File 'lib/sinatra/cigars/helpers.rb', line 35 def js src render_haml "%script{src: '#{render_tag(src, '.js')}'}" end |
#livereload ⇒ Object
47 48 49 |
# File 'lib/sinatra/cigars/helpers.rb', line 47 def livereload haml "%script{src: 'http://#{request.host}:35729/livereload.js'}" if development? or test? end |
#meta(arg) ⇒ Object
27 28 29 |
# File 'lib/sinatra/cigars/helpers.rb', line 27 def arg arg.is_a?(Hash) ? (arg) : (arg) end |
#production? ⇒ Boolean
19 20 21 |
# File 'lib/sinatra/cigars/helpers.rb', line 19 def production? ENV['RACK_ENV'] == 'production' end |
#staging? ⇒ Boolean
15 16 17 |
# File 'lib/sinatra/cigars/helpers.rb', line 15 def staging? ENV['RACK_ENV'] == 'staging' end |
#test? ⇒ Boolean
11 12 13 |
# File 'lib/sinatra/cigars/helpers.rb', line 11 def test? ENV['RACK_ENV'] == 'test' end |
#title(str, prefix = "", suffix = false) ⇒ Object
43 44 45 |
# File 'lib/sinatra/cigars/helpers.rb', line 43 def title str, prefix = "", suffix = false home? ? render_haml("%title= '#{str}'") : render_haml("%title= '#{suffix ? str + prefix : prefix + str}'") end |
#typekit(id) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/sinatra/cigars/helpers.rb', line 51 def typekit id src = <<-EOF.gsub(/^ {8}/, '') <script src="//use.typekit.net/#{id}.js"></script> <script>try{Typekit.load();}catch(e){}</script> EOF end |