Class: Twirly::Post
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Twirly::Post
- Includes:
- Serializers::Post
- Defined in:
- lib/twirly/post.rb
Class Method Summary collapse
Instance Method Summary collapse
- #authors ⇒ Object
- #body ⇒ Object
- #category ⇒ Object
- #existing_front_matter ⇒ Object
- #front_matter ⇒ Object
- #processed_front_matter ⇒ Object
- #published? ⇒ Boolean
- #short_published_at ⇒ Object
- #slug ⇒ Object
- #tags ⇒ Object
- #to_md ⇒ Object
Methods included from Serializers::Post
Class Method Details
Instance Method Details
#authors ⇒ Object
56 57 58 |
# File 'lib/twirly/post.rb', line 56 def members.map { |member| Twirly::User.new(member) } end |
#body ⇒ Object
40 41 42 |
# File 'lib/twirly/post.rb', line 40 def body @body ||= Liquid::Template.parse(card.desc.sub(/---.*---/mi, '').strip).render end |
#category ⇒ Object
15 |
# File 'lib/twirly/post.rb', line 15 def category; card.list.name end |
#existing_front_matter ⇒ Object
21 22 23 |
# File 'lib/twirly/post.rb', line 21 def existing_front_matter @existing_front_matter ||= card.desc.scan(/(---.*---)/mi).flatten.first end |
#front_matter ⇒ Object
60 61 62 |
# File 'lib/twirly/post.rb', line 60 def front_matter "#{processed_front_matter.to_yaml}\n---" end |
#processed_front_matter ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/twirly/post.rb', line 25 def processed_front_matter @processed_front_matter = begin matter = YAML::load(existing_front_matter || '{}') matter[:title] = title matter[:slug] = slug matter[:category] = category matter[:date] = short_published_at matter[:tags] = .join(', ') matter[:authors] = .map(&:username).join(', ') matter[:attachments] = .map(&:url).join(', ') if card..any? matter end end |
#published? ⇒ Boolean
48 49 50 |
# File 'lib/twirly/post.rb', line 48 def published? published_at && card.labels.any? { |label| label.name == 'published' } end |
#short_published_at ⇒ Object
44 45 46 |
# File 'lib/twirly/post.rb', line 44 def short_published_at published_at.strftime('%Y-%m-%d') end |
#slug ⇒ Object
52 53 54 |
# File 'lib/twirly/post.rb', line 52 def slug "#{short_published_at}-#{title.parameterize}-#{card_id}" end |
#tags ⇒ Object
17 18 19 |
# File 'lib/twirly/post.rb', line 17 def labels.map(&:name).reject { |label| label == 'published' } end |
#to_md ⇒ Object
64 65 66 |
# File 'lib/twirly/post.rb', line 64 def to_md "#{front_matter}\n\n#{body}" end |