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.
Delegated Instance Attributes collapse
-
#description ⇒ Object
Alias for Post#description.
-
#id ⇒ Object
Alias for Post#id.
-
#primary_tag ⇒ Object
Alias for Post#primary_tag.
-
#reading_time_minutes ⇒ Object
Alias for Post#reading_time_minutes.
-
#slug ⇒ Object
Alias for Post#slug.
-
#subject ⇒ Object
Alias for Post#subject.
Instance Method Summary collapse
-
#author ⇒ Object
Author full name.
-
#breadcrumbs ⇒ Object
Breadcrumb paths array (bare paths, e.g. ["/floor-heating"]).
-
#initialize(post) ⇒ PostDrop
constructor
A new instance of PostDrop.
-
#published_at ⇒ Object
ISO-8601 publish date string (nil if unpublished).
-
#revised_at ⇒ Object
ISO-8601 revised date string (nil if never revised).
-
#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
59 60 61 |
# File 'app/models/liquid/post_drop.rb', line 59 def post.&.full_name end |
#breadcrumbs ⇒ Object
Breadcrumb paths array (bare paths, e.g. ["/floor-heating"])
80 81 82 |
# File 'app/models/liquid/post_drop.rb', line 80 def post. || [] end |
#description ⇒ Object
Alias for Post#description
77 |
# File 'app/models/liquid/post_drop.rb', line 77 delegate :description, to: :post |
#id ⇒ Object
Alias for Post#id
31 |
# File 'app/models/liquid/post_drop.rb', line 31 delegate :id, to: :post |
#primary_tag ⇒ Object
Alias for Post#primary_tag
56 |
# File 'app/models/liquid/post_drop.rb', line 56 delegate :primary_tag, to: :post |
#published_at ⇒ Object
ISO-8601 publish date string (nil if unpublished)
64 65 66 |
# File 'app/models/liquid/post_drop.rb', line 64 def published_at post.published_at&.iso8601 end |
#reading_time_minutes ⇒ Object
Alias for Post#reading_time_minutes
74 |
# File 'app/models/liquid/post_drop.rb', line 74 delegate :reading_time_minutes, to: :post |
#revised_at ⇒ Object
ISO-8601 revised date string (nil if never revised)
69 70 71 |
# File 'app/models/liquid/post_drop.rb', line 69 def revised_at post.revised_at&.iso8601 end |
#slug ⇒ Object
Alias for Post#slug
42 |
# File 'app/models/liquid/post_drop.rb', line 42 delegate :slug, to: :post |
#subject ⇒ Object
Alias for Post#subject
34 |
# File 'app/models/liquid/post_drop.rb', line 34 delegate :subject, to: :post |
#tags ⇒ Object
Array of tag slugs (e.g. ["radiant-floor-heating", "snow-melting"])
50 51 52 |
# File 'app/models/liquid/post_drop.rb', line 50 def post. || [] end |
#title ⇒ Object
SEO title override (may differ from subject); falls back to subject
37 38 39 |
# File 'app/models/liquid/post_drop.rb', line 37 def title post.title.presence || post.subject end |
#url ⇒ Object
Canonical public URL with {locale} placeholder so it works for any locale
45 46 47 |
# File 'app/models/liquid/post_drop.rb', line 45 def url "https://www.warmlyyours.com/{{locale}}/posts/#{post.slug}" end |