Class: Www::BlogPostCardComponent
- Inherits:
-
ApplicationComponent
- Object
- ViewComponent::Base
- ApplicationComponent
- Www::BlogPostCardComponent
- Defined in:
- app/components/www/blog_post_card_component.rb
Overview
ViewComponent: renders the blog post card block.
Delegated Instance Attributes collapse
-
#preview_image ⇒ Object
Alias for @post#preview_image.
-
#subject ⇒ Object
Alias for @post#subject.
Methods inherited from ApplicationComponent
#cms_link, #image_asset_tag, #image_tag, #number_to_currency, #number_with_delimiter, #post_url, #strip_tags
Instance Method Summary collapse
- #author_first_name ⇒ Object
- #author_thumbnail? ⇒ Boolean
-
#author_thumbnail_url ⇒ Object
Author thumbnail URL (profile picture or Gravatar fallback).
-
#effective_date ⇒ Object
Returns the effective date: revised_at if present, otherwise published_at (short format).
-
#initialize(post:, col_size: '') ⇒ BlogPostCardComponent
constructor
NOTE: To avoid N+1 queries, ensure posts are loaded with: Post.includes(original_author: :profile_image).
- #post_path ⇒ Object
- #reading_time ⇒ Object
- #truncated_subject ⇒ Object
Methods inherited from ApplicationComponent
Constructor Details
#initialize(post:, col_size: '') ⇒ BlogPostCardComponent
NOTE: To avoid N+1 queries, ensure posts are loaded with:
Post.includes(original_author: :profile_image)
10 11 12 13 14 |
# File 'app/components/www/blog_post_card_component.rb', line 10 def initialize(post:, col_size: '') super() @post = post @col_size = col_size end |
Instance Method Details
#author_first_name ⇒ Object
31 32 33 |
# File 'app/components/www/blog_post_card_component.rb', line 31 def @post.&.first_name || 'WarmlyYours' end |
#author_thumbnail? ⇒ Boolean
58 59 60 |
# File 'app/components/www/blog_post_card_component.rb', line 58 def .present? end |
#author_thumbnail_url ⇒ Object
Author thumbnail URL (profile picture or Gravatar fallback)
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/components/www/blog_post_card_component.rb', line 44 def return nil unless @post. # Try profile image first (consolidated storage for all party types) if (pp = @post..profile_image) pp.image_url(size: '40x40>') elsif (email = @post..email&.presence) # Gravatar fallback require 'digest/md5' hash = Digest::MD5.hexdigest(email.downcase) "https://www.gravatar.com/avatar/#{hash}.jpg?s=40" end end |
#effective_date ⇒ Object
Returns the effective date: revised_at if present, otherwise published_at (short format)
36 37 38 39 40 41 |
# File 'app/components/www/blog_post_card_component.rb', line 36 def effective_date date = @post.revised_at.presence || @post.published_at return '' if date.blank? date.strftime('%b %d, %Y') end |
#post_path ⇒ Object
16 17 18 |
# File 'app/components/www/blog_post_card_component.rb', line 16 def post_path helpers.post_path(@post) end |
#preview_image ⇒ Object
Alias for @post#preview_image
20 |
# File 'app/components/www/blog_post_card_component.rb', line 20 delegate :preview_image, :subject, to: :@post |
#reading_time ⇒ Object
26 27 28 29 |
# File 'app/components/www/blog_post_card_component.rb', line 26 def reading_time minutes = @post.reading_time_in_minutes "#{minutes} min" end |
#subject ⇒ Object
Alias for @post#subject
20 |
# File 'app/components/www/blog_post_card_component.rb', line 20 delegate :preview_image, :subject, to: :@post |
#truncated_subject ⇒ Object
22 23 24 |
# File 'app/components/www/blog_post_card_component.rb', line 22 def truncated_subject helpers.truncate(@post.subject, length: 60) end |