Class: Pulitzer::ContentElement

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/pulitzer/content_element.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ensure_uniqueObject

Returns the value of attribute ensure_unique.



14
15
16
# File 'app/models/pulitzer/content_element.rb', line 14

def ensure_unique
  @ensure_unique
end

#version_unavailableObject

Returns the value of attribute version_unavailable.



14
15
16
# File 'app/models/pulitzer/content_element.rb', line 14

def version_unavailable
  @version_unavailable
end

Instance Method Details

#clone_image(clone_attrs) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/models/pulitzer/content_element.rb', line 69

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



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

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

#empty_body?Boolean

Returns:

  • (Boolean)


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

def empty_body?
  image_type? ? !image? : body.blank?
end

#has_content?Boolean

Returns:

  • (Boolean)


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

def has_content?
  image_type? ? image? : body.present?
end

#htmlObject



42
43
44
# File 'app/models/pulitzer/content_element.rb', line 42

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

def reprocess_versions!

self.photo.recreate_versions!
self.broadcast_change

end



36
37
38
39
40
# File 'app/models/pulitzer/content_element.rb', line 36

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