Class: Trahald::MarkdownBody
- Inherits:
-
Object
- Object
- Trahald::MarkdownBody
- Defined in:
- lib/trahald/markdown-body.rb
Defined Under Namespace
Classes: Summary
Constant Summary collapse
- MAX_TEXT_SIZE =
160
Instance Method Summary collapse
- #img_src ⇒ Object
-
#initialize(name, body, date) ⇒ MarkdownBody
constructor
A new instance of MarkdownBody.
- #pre ⇒ Object
- #summary ⇒ Object
Constructor Details
#initialize(name, body, date) ⇒ MarkdownBody
Returns a new instance of MarkdownBody.
11 12 13 14 15 |
# File 'lib/trahald/markdown-body.rb', line 11 def initialize(name, body, date) @name = name @body = body @date = date end |
Instance Method Details
#img_src ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/trahald/markdown-body.rb', line 26 def img_src pattern = Regexp.new '!\[.+\]\((.+)\)' raw = @body.split('\n') raw.map{|r| $1 if pattern =~ r }.select{|i| i} end |
#pre ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/trahald/markdown-body.rb', line 17 def pre raw = Sanitize.clean Kramdown::Document.new(@body).to_html if raw.size > MAX_TEXT_SIZE raw[0, MAX_TEXT_SIZE] + "..." else raw end end |