Module: Sinatra::FancyHelpers
- Defined in:
- lib/sinatra/fancyviews.rb
Instance Method Summary collapse
- #fancyviews ⇒ Object
- #haml_format ⇒ Object
-
#page(name, options = {}) ⇒ Object
same as ‘view` but has layout by default.
- #script_tag(scripts) ⇒ Object
-
#scripts ⇒ Object
renders all the scripts captured by the :script filter.
- #style_tag(styles, media = nil) ⇒ Object
-
#styles(options = {}) ⇒ Object
renders all the styles captured by the :style filter.
-
#view(name, options = {}) ⇒ Object
use this instead of ‘haml` when rendering a template, unlike the haml method, layout is false by default.
Instance Method Details
#fancyviews ⇒ Object
110 111 112 |
# File 'lib/sinatra/fancyviews.rb', line 110 def fancyviews @fancyviews ||= FancyViews.new(self) end |
#haml_format ⇒ Object
106 107 108 |
# File 'lib/sinatra/fancyviews.rb', line 106 def haml_format (.member?(:haml) && .haml[:format]) || :xhtml end |
#page(name, options = {}) ⇒ Object
same as ‘view` but has layout by default
66 67 68 69 |
# File 'lib/sinatra/fancyviews.rb', line 66 def page(name, = {}) [:layout] = true unless .has_key?(:layout) view(name, ) end |
#script_tag(scripts) ⇒ Object
100 101 102 103 104 |
# File 'lib/sinatra/fancyviews.rb', line 100 def script_tag(scripts) capture_haml do haml_tag(:script, scripts, :type => ("text/javascript" if haml_format != :html5)) end.strip end |
#scripts ⇒ Object
renders all the scripts captured by the :script filter
94 95 96 97 98 |
# File 'lib/sinatra/fancyviews.rb', line 94 def scripts script_tag(fancyviews.included_scripts.map do |name, js| "\n/* -- #{name} -- */\n" + js end.join) end |
#style_tag(styles, media = nil) ⇒ Object
87 88 89 90 91 |
# File 'lib/sinatra/fancyviews.rb', line 87 def style_tag(styles, media=nil) capture_haml do haml_tag(:style, styles, :type => ("text/css" if haml_format != :html5), :media => media) end.strip end |
#styles(options = {}) ⇒ Object
renders all the styles captured by the :style filter
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/sinatra/fancyviews.rb', line 72 def styles( = {}) imported = if [:import] [*[:import]].map { |name| File.read("#{self..views}/#{name}.sass") }.join("\n") end rendered_styles = fancyviews.included_styles.map do |name, sass| # would be nice if construction took an :offest to go along with the :filename eng = Sass::Engine.new((imported || '') + "\n" + sass, :load_paths => [self..views]) "\n/* -- #{name} -- */\n" + eng.render end.join style_tag(rendered_styles, [:media]) end |
#view(name, options = {}) ⇒ Object
use this instead of ‘haml` when rendering a template, unlike the haml method, layout is false by default
56 57 58 59 60 61 62 63 |
# File 'lib/sinatra/fancyviews.rb', line 56 def view(name, = {}) parent_view = fancyviews.view_name.to_s fancyviews.view_name = name.to_s [:layout] = false unless .has_key?(:layout) rendered = haml(name, ) fancyviews.view_name = parent_view rendered end |