Class: Pulitzer::ContentElement
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Pulitzer::ContentElement
- Defined in:
- app/models/pulitzer/content_element.rb
Instance Attribute Summary collapse
-
#ensure_unique ⇒ Object
Returns the value of attribute ensure_unique.
-
#version_unavailable ⇒ Object
Returns the value of attribute version_unavailable.
Instance Method Summary collapse
- #clickable_kind ⇒ Object
- #clone_image(clone_attrs) ⇒ Object
- #clone_me ⇒ Object
- #content ⇒ Object
- #content_display ⇒ Object
- #custom_content ⇒ Object
- #custom_display ⇒ Object
- #custom_type? ⇒ Boolean
- #empty_body? ⇒ Boolean
- #has_content? ⇒ Boolean
- #html ⇒ Object
- #style_display ⇒ Object
- #style_options ⇒ Object
-
#video_link ⇒ Object
def reprocess_versions! self.photo.recreate_versions! self.broadcast_change end.
Instance Attribute Details
#ensure_unique ⇒ Object
Returns the value of attribute ensure_unique.
18 19 20 |
# File 'app/models/pulitzer/content_element.rb', line 18 def ensure_unique @ensure_unique end |
#version_unavailable ⇒ Object
Returns the value of attribute version_unavailable.
18 19 20 |
# File 'app/models/pulitzer/content_element.rb', line 18 def version_unavailable @version_unavailable end |
Instance Method Details
#clickable_kind ⇒ Object
91 92 93 94 95 96 97 98 99 |
# File 'app/models/pulitzer/content_element.rb', line 91 def clickable_kind if custom_type? custom_option.custom_option_list elsif body.present? Pulitzer::PostTypeContentElementType::URL_clickable else Pulitzer::PostTypeContentElementType::Any_clickable end end |
#clone_image(clone_attrs) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'app/models/pulitzer/content_element.rb', line 124 def clone_image(clone_attrs) clone_attrs.delete 'image' my_clone = Pulitzer::ContentElement.new(clone_attrs) if image.file && image.file.exists? my_clone.remote_image_url = image.url # If there is an error getting the image, don't bail out, # create the content element clone without the image so the user can reupload later if !my_clone.valid? if my_clone.errors.get(:image) my_clone = Pulitzer::ContentElement.new(clone_attrs) end end end my_clone.save! my_clone end |
#clone_me ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'app/models/pulitzer/content_element.rb', line 109 def clone_me clone_attrs = self.attributes.dup clone_attrs.delete 'id' clone_attrs.delete 'version_id' type_clone_method = 'clone_' + type.to_s if respond_to? type_clone_method my_clone = send type_clone_method, clone_attrs else my_clone = Pulitzer::ContentElement.create!(clone_attrs) end my_clone end |
#content ⇒ Object
71 72 73 74 75 76 77 |
# File 'app/models/pulitzer/content_element.rb', line 71 def content if custom_type? custom_content else body end end |
#content_display ⇒ Object
79 80 81 82 83 84 85 |
# File 'app/models/pulitzer/content_element.rb', line 79 def content_display if custom_type? custom_display else body end end |
#custom_content ⇒ Object
63 64 65 |
# File 'app/models/pulitzer/content_element.rb', line 63 def custom_content custom_option.value end |
#custom_display ⇒ Object
67 68 69 |
# File 'app/models/pulitzer/content_element.rb', line 67 def custom_display "#{custom_option.display} #{custom_option.custom_option_list.name.singularize}" end |
#custom_type? ⇒ Boolean
87 88 89 |
# File 'app/models/pulitzer/content_element.rb', line 87 def custom_type? custom_option.present? end |
#empty_body? ⇒ Boolean
49 50 51 |
# File 'app/models/pulitzer/content_element.rb', line 49 def empty_body? !has_content? end |
#has_content? ⇒ Boolean
53 54 55 56 57 58 59 60 61 |
# File 'app/models/pulitzer/content_element.rb', line 53 def has_content? if image_type? image? elsif custom_type? custom_content.present? else body.present? end end |
#html ⇒ Object
45 46 47 |
# File 'app/models/pulitzer/content_element.rb', line 45 def html body.blank? ? "" : body.html_safe end |
#style_display ⇒ Object
105 106 107 |
# File 'app/models/pulitzer/content_element.rb', line 105 def style_display style&.display_name end |
#style_options ⇒ Object
101 102 103 |
# File 'app/models/pulitzer/content_element.rb', line 101 def post_type_content_element_type.styles end |
#video_link ⇒ Object
def reprocess_versions!
self.photo.recreate_versions!
self.broadcast_change
end
39 40 41 42 43 |
# File 'app/models/pulitzer/content_element.rb', line 39 def video_link if video_type? && !body.nil? vimeo_video(body) || youtube_video(body) end end |