Class: Liquid::PostDrop
- Inherits:
-
Drop
- Object
- Drop
- Liquid::PostDrop
- 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
-
#post ⇒ Object
readonly
Returns the value of attribute post.
Instance Method Summary collapse
-
#author ⇒ Object
Author full name.
-
#breadcrumbs ⇒ Object
Breadcrumb paths array (bare paths, e.g. ["/floor-heating"]).
-
#description ⇒ Object
Short description / excerpt shown on index pages.
-
#id ⇒ Object
Unique article ID (integer).
-
#initialize(post) ⇒ PostDrop
constructor
A new instance of PostDrop.
-
#primary_tag ⇒ Object
Primary (first) tag slug.
-
#published_at ⇒ Object
ISO-8601 publish date string (nil if unpublished).
-
#reading_time_minutes ⇒ Object
Estimated reading time in minutes.
-
#revised_at ⇒ Object
ISO-8601 revised date string (nil if never revised).
-
#slug ⇒ Object
URL slug (used in warmlyyours.com/{locale}/posts/SLUG).
-
#subject ⇒ Object
Article title — the H1 rendered above the body on the public page.
-
#tags ⇒ Object
Array of tag slugs (e.g. ["radiant-floor-heating", "snow-melting"]).
-
#title ⇒ Object
SEO title override (may differ from subject); falls back to subject.
-
#url ⇒ Object
Canonical public URL with {locale} placeholder so it works for any locale.
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
#post ⇒ Object (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
#author ⇒ Object
Author full name
67 68 69 |
# File 'app/models/liquid/post_drop.rb', line 67 def post.&.full_name end |
#breadcrumbs ⇒ Object
Breadcrumb paths array (bare paths, e.g. ["/floor-heating"])
92 93 94 |
# File 'app/models/liquid/post_drop.rb', line 92 def post. || [] end |
#description ⇒ Object
Short description / excerpt shown on index pages
87 88 89 |
# File 'app/models/liquid/post_drop.rb', line 87 def description post.description end |
#id ⇒ Object
Unique article ID (integer)
31 32 33 |
# File 'app/models/liquid/post_drop.rb', line 31 def id post.id end |
#primary_tag ⇒ Object
Primary (first) tag slug
62 63 64 |
# File 'app/models/liquid/post_drop.rb', line 62 def primary_tag post.primary_tag end |
#published_at ⇒ Object
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_minutes ⇒ Object
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_at ⇒ Object
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 |
#slug ⇒ Object
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 |
#subject ⇒ Object
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 |
#tags ⇒ Object
Array of tag slugs (e.g. ["radiant-floor-heating", "snow-melting"])
56 57 58 |
# File 'app/models/liquid/post_drop.rb', line 56 def post. || [] end |
#title ⇒ Object
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 |
#url ⇒ Object
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 |