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.



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

def ensure_unique
  @ensure_unique
end

#version_unavailableObject

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

Class Method Details

.export_configObject

def reprocess_versions!

self.photo.recreate_versions!
self.broadcast_change

end



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

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



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

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



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

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



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

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



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

def content
  if custom_type?
    custom_content
  else
    body
  end
end

#content_displayObject



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

def content_display
  if custom_type?
    custom_display
  else
    body
  end
end

#custom_contentObject



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

def custom_content
  custom_option.value
end

#custom_displayObject



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

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

#custom_type?Boolean

Returns:

  • (Boolean)


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

def custom_type?
  custom_option.present?
end

#empty_body?Boolean

Returns:

  • (Boolean)


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

def empty_body?
  !has_content?
end

#has_content?Boolean

Returns:

  • (Boolean)


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

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

#htmlObject



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

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

#style_displayObject



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

def style_display
  style&.display_name
end

#style_optionsObject



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

def style_options
  post_type_content_element_type.styles
end


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

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