Module: Sinatra::Mars::Helpers
- Defined in:
- lib/mars/helpers.rb
Constant Summary collapse
- SASS =
'sass'
- JS =
'js'
- MDOWN =
'md'
- COFFEE =
'coffee'
- CSS =
'css'
- SCSS =
'scss'
- RUBY =
'rb'
Instance Method Summary collapse
-
#coffee(coffeefile) ⇒ Object
renders coffee files.
-
#css(cssfile, mediatype = "all") ⇒ Object
renders css files.
-
#find_file(filename, ext) ⇒ Object
finds file.
-
#javascript(jsfile) ⇒ Object
renders javascript files.
-
#markdown(mdfile) ⇒ Object
renders markdown files.
-
#render_script(text, file_type) ⇒ Object
renders script tag based on file type.
-
#render_style(text, mediatype = "all") ⇒ Object
renders style tag based on media type.
-
#ruby(rubyfile) ⇒ Object
parses and evals ruby partials.
-
#sass(sassfile, mediatype = "all") ⇒ Object
renders sass files.
-
#scss(scssfile, mediatype = "all") ⇒ Object
renders scss files.
Instance Method Details
#coffee(coffeefile) ⇒ Object
renders coffee files
48 49 50 |
# File 'lib/mars/helpers.rb', line 48 def coffee(coffeefile) render_script open_file(find_file(coffeefile, COFFEE)), 'coffeescript' end |
#css(cssfile, mediatype = "all") ⇒ Object
renders css files
23 24 25 |
# File 'lib/mars/helpers.rb', line 23 def css(cssfile, mediatype="all") render_style open_file(find_file(cssfile, CSS)), mediatype end |
#find_file(filename, ext) ⇒ Object
finds file
70 71 72 |
# File 'lib/mars/helpers.rb', line 70 def find_file(filename, ext) Dir.glob(File.join(.views, "**/*.#{ext}")).select { |extfile| extfile.downcase =~ /\/#{filename.to_s.downcase}.#{ext}$/ }.first end |
#javascript(jsfile) ⇒ Object
renders javascript files
38 39 40 |
# File 'lib/mars/helpers.rb', line 38 def javascript(jsfile) render_script open_file(find_file(jsfile, JS)), 'javascript' end |
#markdown(mdfile) ⇒ Object
renders markdown files
43 44 45 |
# File 'lib/mars/helpers.rb', line 43 def markdown(mdfile) Maruku.new(open_file(find_file(mdfile, MDOWN))).to_html end |
#render_script(text, file_type) ⇒ Object
renders script tag based on file type
55 56 57 58 59 |
# File 'lib/mars/helpers.rb', line 55 def render_script(text, file_type) ["<script type='text/#{file_type}'>", text, "</script>\n"].join("\n") end |
#render_style(text, mediatype = "all") ⇒ Object
renders style tag based on media type
62 63 64 65 66 |
# File 'lib/mars/helpers.rb', line 62 def render_style(text, mediatype="all") ["<style type='text/css' media='#{mediatype}' >", text, "</style>\n"].join("\n") end |
#ruby(rubyfile) ⇒ Object
parses and evals ruby partials
18 19 20 |
# File 'lib/mars/helpers.rb', line 18 def ruby(rubyfile) instance_eval(open_file(find_file(rubyfile, RUBY))) end |
#sass(sassfile, mediatype = "all") ⇒ Object
renders sass files
28 29 30 |
# File 'lib/mars/helpers.rb', line 28 def sass(sassfile, mediatype="all") render_style Sass::Engine.new(open_file(find_file(sassfile, SASS))).render, mediatype end |
#scss(scssfile, mediatype = "all") ⇒ Object
renders scss files
33 34 35 |
# File 'lib/mars/helpers.rb', line 33 def scss(scssfile, mediatype="all") render_style Sass::Engine.new(open_file(find_file(scssfile, SCSS)), :syntax => :scss).render, mediatype end |