Class: Pulitzer::ContentElement

Inherits:
ApplicationRecord show all
Defined in:
app/models/pulitzer/content_element.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

assoc_name, attrs_name, convert_hash_to_nested, convert_nested_assoc

Instance Attribute Details

#ensure_uniqueObject

Returns the value of attribute ensure_unique.



19
20
21
# File 'app/models/pulitzer/content_element.rb', line 19

def ensure_unique
  @ensure_unique
end

#version_unavailableObject

Returns the value of attribute version_unavailable.



19
20
21
# File 'app/models/pulitzer/content_element.rb', line 19

def version_unavailable
  @version_unavailable
end

Class Method Details

.export_configObject

def reprocess_versions!

self.photo.recreate_versions!
self.broadcast_change

end



40
41
42
# File 'app/models/pulitzer/content_element.rb', line 40

def self.export_config
  { except: [:id, :image, :post_type_content_element_type_id, :version_id, :style_id, :partial_id, :custom_option_id, :created_at, :updated_at]}
end

Instance Method Details

#clickable_kindObject



96
97
98
99
100
101
102
103
104
# File 'app/models/pulitzer/content_element.rb', line 96

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



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'app/models/pulitzer/content_element.rb', line 129

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_meObject



114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'app/models/pulitzer/content_element.rb', line 114

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

#contentObject



76
77
78
79
80
81
82
# File 'app/models/pulitzer/content_element.rb', line 76

def content
  if custom_type?
    custom_content
  else
    body
  end
end

#content_displayObject



84
85
86
87
88
89
90
# File 'app/models/pulitzer/content_element.rb', line 84

def content_display
  if custom_type?
    custom_display
  else
    body
  end
end

#custom_contentObject



68
69
70
# File 'app/models/pulitzer/content_element.rb', line 68

def custom_content
  custom_option.value
end

#custom_displayObject



72
73
74
# File 'app/models/pulitzer/content_element.rb', line 72

def custom_display
  "#{custom_option.display} #{custom_option.custom_option_list.name.singularize}"
end

#custom_type?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'app/models/pulitzer/content_element.rb', line 92

def custom_type?
  custom_option.present?
end

#empty_body?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'app/models/pulitzer/content_element.rb', line 54

def empty_body?
  !has_content?
end

#has_content?Boolean

Returns:

  • (Boolean)


58
59
60
61
62
63
64
65
66
# File 'app/models/pulitzer/content_element.rb', line 58

def has_content?
  if image_type?
    image?
  elsif custom_type?
    custom_content.present?
  else
    body.present?
  end
end

#htmlObject



50
51
52
# File 'app/models/pulitzer/content_element.rb', line 50

def html
  body.blank? ? "" : body.html_safe
end

#style_displayObject



110
111
112
# File 'app/models/pulitzer/content_element.rb', line 110

def style_display
  style&.display_name
end

#style_optionsObject



106
107
108
# File 'app/models/pulitzer/content_element.rb', line 106

def style_options
  post_type_content_element_type.styles
end


44
45
46
47
48
# File 'app/models/pulitzer/content_element.rb', line 44

def video_link
  if video_type? && !body.nil?
    vimeo_video(body) || youtube_video(body)
  end
end