Class: Glue::Template::Helper
- Inherits:
-
Object
- Object
- Glue::Template::Helper
- Defined in:
- lib/glue/template/helper.rb
Instance Method Summary collapse
- #config ⇒ Object
- #haml(text) ⇒ Object
- #markdown(text) ⇒ Object
- #render(path) ⇒ Object
- #textile(text) ⇒ Object
- #url_for(path) ⇒ Object
Instance Method Details
#config ⇒ Object
4 5 6 |
# File 'lib/glue/template/helper.rb', line 4 def config @config ||= YAML.load_file(GLUE_ROOT + "/config/glue.yml") end |
#haml(text) ⇒ Object
25 26 27 |
# File 'lib/glue/template/helper.rb', line 25 def haml(text) Haml::Engine.new(text).to_html(self, .data) end |
#markdown(text) ⇒ Object
17 18 19 |
# File 'lib/glue/template/helper.rb', line 17 def markdown(text) RDiscount.new(text).to_html end |
#render(path) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/glue/template/helper.rb', line 29 def render(path) parts = [GLUE_ROOT, "views", File.dirname(path), "_" + File.basename(path)] parts.reject! {|p| p == "." } path = File.join(*parts) if File.exists?(file = "#{path}.haml") haml File.read(file) elsif File.exists?(file = "#{path}.markdown") markdown File.read(file) elsif File.exists?(file = "#{path}.textile") textile File.read(file) else "Missing partial at <strong>#{path}</strong>" end end |
#textile(text) ⇒ Object
21 22 23 |
# File 'lib/glue/template/helper.rb', line 21 def textile(text) RedCloth.new(text).to_html end |
#url_for(path) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/glue/template/helper.rb', line 8 def url_for(path) uri = URI.parse(config["base_url"]) base_path = uri.path.chomp("/") path = File.join(base_path, path) path << ".html" if config["use_extension"] && base_path !~ /\.html$/ path end |