Class: Www::BlogPostCardComponent
- Inherits:
-
ApplicationComponent
- Object
- ViewComponent::Base
- ApplicationComponent
- Www::BlogPostCardComponent
- Defined in:
- app/components/www/blog_post_card_component.rb
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)
9 10 11 12 13 |
# File 'app/components/www/blog_post_card_component.rb', line 9 def initialize(post:, col_size: '') super() @post = post @col_size = col_size end |
Instance Method Details
#author_first_name ⇒ Object
30 31 32 |
# File 'app/components/www/blog_post_card_component.rb', line 30 def @post.&.first_name || 'WarmlyYours' end |
#author_thumbnail? ⇒ Boolean
57 58 59 |
# File 'app/components/www/blog_post_card_component.rb', line 57 def .present? end |
#author_thumbnail_url ⇒ Object
Author thumbnail URL (profile picture or Gravatar fallback)
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/components/www/blog_post_card_component.rb', line 43 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)
35 36 37 38 39 40 |
# File 'app/components/www/blog_post_card_component.rb', line 35 def effective_date date = @post.revised_at.presence || @post.published_at return '' unless date.present? date.strftime('%b %d, %Y') end |
#post_path ⇒ Object
15 16 17 |
# File 'app/components/www/blog_post_card_component.rb', line 15 def post_path helpers.post_path(@post) end |
#preview_image ⇒ Object
Alias for @post#preview_image
19 |
# File 'app/components/www/blog_post_card_component.rb', line 19 delegate :preview_image, :subject, to: :@post |
#reading_time ⇒ Object
25 26 27 28 |
# File 'app/components/www/blog_post_card_component.rb', line 25 def reading_time minutes = @post.reading_time_in_minutes "#{minutes} min" end |
#subject ⇒ Object
Alias for @post#subject
19 |
# File 'app/components/www/blog_post_card_component.rb', line 19 delegate :preview_image, :subject, to: :@post |
#truncated_subject ⇒ Object
21 22 23 |
# File 'app/components/www/blog_post_card_component.rb', line 21 def truncated_subject helpers.truncate(@post.subject, length: 60) end |