Class: Liquid::PostDrop

Inherits:
Drop
  • Object
show all
Includes:
Memery
Defined in:
app/models/liquid/post_drop.rb

Overview

Exposes a safe, explicit subset of Post attributes to Liquid templates
rendered inside blog post content (solution / description fields).

Pass a PostDrop into the Liquid render context as the 'post' variable:

Liquid::ParseEnvironment.parse(content).render('post' => Liquid::PostDrop.new(post), ...)

This enables blog authors to reference post metadata inside content, e.g.:

post.subject } → article title
post.slug } → URL slug
post.reading_time_minutes } → estimated reading time
post.tags | join: ", " } → comma-joined tag list
post.author } → author full name
post.published_at } → ISO-8601 publish date
if post.tags contains "snow-melting" %…endif % → tag conditionals

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(post) ⇒ PostDrop

Returns a new instance of PostDrop.



25
26
27
28
# File 'app/models/liquid/post_drop.rb', line 25

def initialize(post)
  super()
  @post = post
end

Instance Attribute Details

#postObject (readonly)

Returns the value of attribute post.



23
24
25
# File 'app/models/liquid/post_drop.rb', line 23

def post
  @post
end

Instance Method Details

#authorObject

Author full name



67
68
69
# File 'app/models/liquid/post_drop.rb', line 67

def author
  post.author&.full_name
end

Breadcrumb paths array (bare paths, e.g. ["/floor-heating"])



92
93
94
# File 'app/models/liquid/post_drop.rb', line 92

def breadcrumbs
  post.breadcrumbs || []
end

#descriptionObject

Short description / excerpt shown on index pages



87
88
89
# File 'app/models/liquid/post_drop.rb', line 87

def description
  post.description
end

#idObject

Unique article ID (integer)



31
32
33
# File 'app/models/liquid/post_drop.rb', line 31

def id
  post.id
end

#primary_tagObject

Primary (first) tag slug



62
63
64
# File 'app/models/liquid/post_drop.rb', line 62

def primary_tag
  post.primary_tag
end

#published_atObject

ISO-8601 publish date string (nil if unpublished)



72
73
74
# File 'app/models/liquid/post_drop.rb', line 72

def published_at
  post.published_at&.iso8601
end

#reading_time_minutesObject

Estimated reading time in minutes



82
83
84
# File 'app/models/liquid/post_drop.rb', line 82

def reading_time_minutes
  post.reading_time_minutes
end

#revised_atObject

ISO-8601 revised date string (nil if never revised)



77
78
79
# File 'app/models/liquid/post_drop.rb', line 77

def revised_at
  post.revised_at&.iso8601
end

#slugObject

URL slug (used in warmlyyours.com/{locale}/posts/SLUG)



46
47
48
# File 'app/models/liquid/post_drop.rb', line 46

def slug
  post.slug
end

#subjectObject

Article title — the H1 rendered above the body on the public page



36
37
38
# File 'app/models/liquid/post_drop.rb', line 36

def subject
  post.subject
end

#tagsObject

Array of tag slugs (e.g. ["radiant-floor-heating", "snow-melting"])



56
57
58
# File 'app/models/liquid/post_drop.rb', line 56

def tags
  post.tags || []
end

#titleObject

SEO title override (may differ from subject); falls back to subject



41
42
43
# File 'app/models/liquid/post_drop.rb', line 41

def title
  post.title.presence || post.subject
end

#urlObject

Canonical public URL with {locale} placeholder so it works for any locale



51
52
53
# File 'app/models/liquid/post_drop.rb', line 51

def url
  "https://www.warmlyyours.com/{{locale}}/posts/#{post.slug}"
end