Class: Www::MagazineBlogCardComponent
- Inherits:
-
ApplicationComponent
show all
- Includes:
- ActionView::Helpers::TagHelper, ActionView::Helpers::UrlHelper
- Defined in:
- app/components/www/magazine_blog_card_component.rb
Delegated Instance Attributes
collapse
#cms_link, #image_asset_tag, #image_tag, #number_to_currency, #number_with_delimiter, #post_url, #strip_tags
Instance Method Summary
collapse
#fetch_or_fallback
Constructor Details
#initialize(post:, variant: :default, show_reading_time: true, show_author: true, heading_level: :h3) ⇒ MagazineBlogCardComponent
Returns a new instance of MagazineBlogCardComponent.
12
13
14
15
16
17
18
19
|
# File 'app/components/www/magazine_blog_card_component.rb', line 12
def initialize(post:, variant: :default, show_reading_time: true, show_author: true, heading_level: :h3)
super()
@post = post
@variant = variant
@show_reading_time = show_reading_time
@show_author = show_author
@heading_level = heading_level
end
|
Instance Method Details
#author_first_name ⇒ Object
48
49
50
|
# File 'app/components/www/magazine_blog_card_component.rb', line 48
def author_first_name
@post.author&.first_name || 'WarmlyYours'
end
|
#author_full_name ⇒ Object
52
53
54
|
# File 'app/components/www/magazine_blog_card_component.rb', line 52
def author_full_name
@post.author&.name || 'WarmlyYours Team'
end
|
#author_thumbnail? ⇒ Boolean
71
72
73
|
# File 'app/components/www/magazine_blog_card_component.rb', line 71
def author_thumbnail?
author_thumbnail_url.present?
end
|
#author_thumbnail_url ⇒ Object
Author thumbnail URL (profile picture or Gravatar fallback)
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'app/components/www/magazine_blog_card_component.rb', line 57
def author_thumbnail_url
return nil unless @post.author
if (pp = @post.author.profile_image)
pp.image_url(size: '48x48>')
elsif (email = @post.author.email&.presence)
require 'digest/md5'
hash = Digest::MD5.hexdigest(email.downcase)
"https://www.gravatar.com/avatar/#{hash}.jpg?s=48"
end
end
|
#card_classes ⇒ Object
79
80
81
82
83
|
# File 'app/components/www/magazine_blog_card_component.rb', line 79
def card_classes
base = 'magazine-blog-card'
base += ' magazine-blog-card--hero' if hero?
base
end
|
#description_excerpt ⇒ Object
96
97
98
99
100
|
# File 'app/components/www/magazine_blog_card_component.rb', line 96
def description_excerpt
return nil unless hero? && @post.description.present?
helpers.truncate(helpers.strip_tags(@post.description), length: 200)
end
|
#display_date ⇒ Object
32
33
34
|
# File 'app/components/www/magazine_blog_card_component.rb', line 32
def display_date
@post.effective_revised_date
end
|
36
37
38
39
40
41
42
43
44
45
46
|
# File 'app/components/www/magazine_blog_card_component.rb', line 36
def formatted_date
date = display_date
return '' unless date
if hero?
date.strftime('%B %Y')
else
date.strftime('%B %Y').upcase
end
end
|
#hero? ⇒ Boolean
75
76
77
|
# File 'app/components/www/magazine_blog_card_component.rb', line 75
def hero?
@variant == :hero
end
|
#image_dimensions ⇒ Object
85
86
87
88
89
90
91
92
93
94
|
# File 'app/components/www/magazine_blog_card_component.rb', line 85
def image_dimensions
if hero?
{ width: 1200, height: 600, crop_mode: :none, thumbnail: true }
else
{ width: 600, height: 400, crop_mode: :none, thumbnail: true }
end
end
|
#post_path ⇒ Object
21
22
23
|
# File 'app/components/www/magazine_blog_card_component.rb', line 21
def post_path
helpers.post_path(@post)
end
|
#preview_image ⇒ Object
Alias for @post#preview_image
25
|
# File 'app/components/www/magazine_blog_card_component.rb', line 25
delegate :preview_image, :subject, :published_at, to: :@post
|
#published_at ⇒ Object
Alias for @post#published_at
25
|
# File 'app/components/www/magazine_blog_card_component.rb', line 25
delegate :preview_image, :subject, :published_at, to: :@post
|
#reading_time ⇒ Object
27
28
29
30
|
# File 'app/components/www/magazine_blog_card_component.rb', line 27
def reading_time
minutes = @post.reading_time_in_minutes
"#{minutes} min read"
end
|
#subject ⇒ Object
25
|
# File 'app/components/www/magazine_blog_card_component.rb', line 25
delegate :preview_image, :subject, :published_at, to: :@post
|