Class: Hightouch::BlogPosting
- Inherits:
-
Object
- Object
- Hightouch::BlogPosting
- Includes:
- Virtus
- Defined in:
- lib/hightouch/blog_posting.rb
Constant Summary collapse
- DESC_SEPARATOR =
/READMORE/
Instance Attribute Summary collapse
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
Instance Method Summary collapse
- #article_body ⇒ Object
- #description ⇒ Object
-
#initialize(page, blog) ⇒ BlogPosting
constructor
A new instance of BlogPosting.
- #update ⇒ Object
Constructor Details
#initialize(page, blog) ⇒ BlogPosting
Returns a new instance of BlogPosting.
20 21 22 23 24 25 |
# File 'lib/hightouch/blog_posting.rb', line 20 def initialize(page, blog) @blog = blog @page = page update end |
Instance Attribute Details
#page ⇒ Object (readonly)
Returns the value of attribute page.
18 19 20 |
# File 'lib/hightouch/blog_posting.rb', line 18 def page @page end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
18 19 20 |
# File 'lib/hightouch/blog_posting.rb', line 18 def raw @raw end |
Instance Method Details
#article_body ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/hightouch/blog_posting.rb', line 46 def article_body @body ||= begin body = page.render(layout: false) if body =~ DESC_SEPARATOR body.sub!(DESC_SEPARATOR, '') else body end end end |
#description ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/hightouch/blog_posting.rb', line 58 def description @description ||= begin desc = if raw =~ DESC_SEPARATOR raw.split(DESC_SEPARATOR).first else raw.match(/(.{1,200}.*?)(\n|\Z)/m).to_s end engine = ::Tilt[page.source_file].new { desc } engine.render end end |
#update ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/hightouch/blog_posting.rb', line 27 def update app = page.store.app path = page.source_file.sub(app.source_dir, '') @name = page.data.title @date_created = Date.strptime(page.data.date_created, '%Y/%m/%d') if page.data.date_created @author = page.data. @url = '/' + page.path @raw = app.frontmatter(path).last update_association(Category, page.data.categories) if page.data.categories update_association(Tag, page.data.) if page.data. update_archive(@date_created) @description = nil @body = nil end |