Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add Haml 'support' #46

Merged
merged 2 commits into from

3 participants

@stubbornella
  • If Haml is available and the user specifies 'haml_example' in the code block, convert haml to html for display purposes but render a haml example.
stubbornella added some commits
@stubbornella stubbornella Add Haml 'support'
- If Haml is available and the user specifies 'haml_example' in the code
  block, convert haml to html for display purposes but render a haml
  example.
335de1e
@stubbornella stubbornella Support syntax highlighting for Haml.
- Was necessary to 'hint' the lexer for pygments.
d5259f4
@jdcantrell
Owner

I'm really glad to see this!

@aflanagan aflanagan merged commit 7c171e4 into trulia:master
@jdcantrell
Owner

We just updated the gem on rubygems.org with this change, and a couple of other minor changes. Thanks again!

@stubbornella
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 12, 2013
  1. @stubbornella

    Add Haml 'support'

    stubbornella authored Nicole Sullivan committed
    - If Haml is available and the user specifies 'haml_example' in the code
      block, convert haml to html for display purposes but render a haml
      example.
  2. @stubbornella

    Support syntax highlighting for Haml.

    stubbornella authored Nicole Sullivan and Rajan Agaskar committed
    - Was necessary to 'hint' the lexer for pygments.
This page is out of date. Refresh to see the latest.
Showing with 28 additions and 2 deletions.
  1. +28 −2 lib/hologram_markdown_renderer.rb
View
30 lib/hologram_markdown_renderer.rb
@@ -32,10 +32,36 @@ def block_code(code, language)
'<script>' + code + '</script>
<div class="codeBlock jsExample">' + Pygments.highlight(code) + '</div>'
else
- '<div class="codeExample">' + '<div class="exampleOutput">' + code + '</div>' + '<div class="codeBlock">' + Pygments.highlight(code) + '</div>' + '</div>'
+ '<div class="codeExample">' + '<div class="exampleOutput">' + render_html(code, language) + '</div>' + '<div class="codeBlock">' + Pygments.highlight(code, lexer: get_lexer(language)) + '</div>' + '</div>'
end
else
'<div class="codeBlock">' + Pygments.highlight(code) + '</div>'
- end
+ end
+ end
+
+ private
+ def render_html(code, language)
+ case language
+ when 'haml_example'
+ safe_require 'haml', language
+ return Haml::Engine.new(code.strip).render(Object.new, {})
+ else
+ code
+ end
+ end
+
+ def get_lexer(language)
+ case language
+ when 'haml_example'
+ 'haml'
+ else
+ 'html'
+ end
+ end
+
+ def safe_require(templating_library, language)
+ require templating_library
+ rescue LoadError
+ raise "#{templating_library} must be present for you to use #{language}"
end
end
Something went wrong with that request. Please try again.