Class: KramdownParser
- Inherits:
-
Object
- Object
- KramdownParser
- Defined in:
- lib/almanac/MarkdownParser.rb
Instance Method Summary collapse
- #before_save(record) ⇒ Object
- #html_to_kramdown(text) ⇒ Object
-
#initialize(*args) ⇒ KramdownParser
constructor
A new instance of KramdownParser.
- #kramdown_to_html(text) ⇒ Object
Constructor Details
#initialize(*args) ⇒ KramdownParser
Returns a new instance of KramdownParser.
2 3 4 |
# File 'lib/almanac/MarkdownParser.rb', line 2 def initialize(*args) @attribute = *args[0] end |
Instance Method Details
#before_save(record) ⇒ Object
6 7 8 9 |
# File 'lib/almanac/MarkdownParser.rb', line 6 def before_save(record) markdown = Kramdown::Document.new(record.send("#{@attribute}")).to_html record.send("#{@attribute}=", markdown) end |
#html_to_kramdown(text) ⇒ Object
11 12 13 |
# File 'lib/almanac/MarkdownParser.rb', line 11 def html_to_kramdown(text) Kramdown::Document.new(text.html_safe, :input => 'html').to_kramdown end |
#kramdown_to_html(text) ⇒ Object
15 16 17 |
# File 'lib/almanac/MarkdownParser.rb', line 15 def kramdown_to_html(text) Kramdown::Document.new(text.html_safe, :input => 'kramdown').to_html end |