Class: Lcms::Engine::SocialMediaPresenter
- Inherits:
-
Object
- Object
- Lcms::Engine::SocialMediaPresenter
- Defined in:
- app/presenters/lcms/engine/social_media_presenter.rb
Instance Attribute Summary collapse
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#view ⇒ Object
readonly
Returns the value of attribute view.
Instance Method Summary collapse
- #clean(str) ⇒ Object
- #default ⇒ Object
- #description ⇒ Object
- #facebook ⇒ Object
-
#initialize(target:, view:) ⇒ SocialMediaPresenter
constructor
A new instance of SocialMediaPresenter.
- #pinterest ⇒ Object
- #quick_reference_guide? ⇒ Boolean
- #thumbnails ⇒ Object
- #title ⇒ Object
- #twitter ⇒ Object
Constructor Details
#initialize(target:, view:) ⇒ SocialMediaPresenter
Returns a new instance of SocialMediaPresenter.
8 9 10 11 |
# File 'app/presenters/lcms/engine/social_media_presenter.rb', line 8 def initialize(target:, view:) @target = target @view = view end |
Instance Attribute Details
#target ⇒ Object (readonly)
Returns the value of attribute target.
6 7 8 |
# File 'app/presenters/lcms/engine/social_media_presenter.rb', line 6 def target @target end |
#view ⇒ Object (readonly)
Returns the value of attribute view.
6 7 8 |
# File 'app/presenters/lcms/engine/social_media_presenter.rb', line 6 def view @view end |
Instance Method Details
#clean(str) ⇒ Object
68 69 70 |
# File 'app/presenters/lcms/engine/social_media_presenter.rb', line 68 def clean(str) view.(str) end |
#default ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'app/presenters/lcms/engine/social_media_presenter.rb', line 23 def default OpenStruct.new( # use facebook image as default image: thumbnails[:facebook] || view.page_og_image, title: title, description: description ) end |
#description ⇒ Object
18 19 20 21 |
# File 'app/presenters/lcms/engine/social_media_presenter.rb', line 18 def description desc = target.try(:teaser).try(:html_safe) clean(desc) || clean(view.content_for(:og_description)) || view.page_description end |
#facebook ⇒ Object
32 33 34 35 36 |
# File 'app/presenters/lcms/engine/social_media_presenter.rb', line 32 def facebook @facebook ||= extend_with_default( image: thumbnails[:facebook] || view.page_og_image ) end |
#pinterest ⇒ Object
45 46 47 48 49 |
# File 'app/presenters/lcms/engine/social_media_presenter.rb', line 45 def pinterest @pinterest ||= extend_with_default( image: thumbnails[:pinterest] || view.page_og_image ) end |
#quick_reference_guide? ⇒ Boolean
72 73 74 |
# File 'app/presenters/lcms/engine/social_media_presenter.rb', line 72 def quick_reference_guide? (target.is_a?(Resource) || target.is_a?(ResourcePresenter)) && target.quick_reference_guide? end |
#thumbnails ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/presenters/lcms/engine/social_media_presenter.rb', line 51 def thumbnails # @thumbnails ||= begin # if target # target.social_thumbnails.reduce({}) do |dict, thumb| # dict[thumb.media] = thumb.image.url + "?ts=#{Time.now.to_i}#{Random.rand(1_000_000)}" # dict # end.with_indifferent_access # else # {} # end # end # According to issue 140 (https://github.com/learningtapestry/unbounded/issues/140) # we are commenting out social_thumbnails for now, until we can fix the titles and reparse the images. {} end |
#title ⇒ Object
13 14 15 16 |
# File 'app/presenters/lcms/engine/social_media_presenter.rb', line 13 def title title_ = target.try(:title).try(:html_safe) clean(title_) || clean(view.content_for(:og_title)) || view.page_title end |
#twitter ⇒ Object
38 39 40 41 42 43 |
# File 'app/presenters/lcms/engine/social_media_presenter.rb', line 38 def twitter @twitter ||= extend_with_default( # use same image as facebook for twitter image: thumbnails[:facebook] || view.page_og_image ) end |