Class: ActiveAdmin::Cms::Content

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
ActsAsMarkup::ActiveRecordExtension::ClassMethods
Includes:
ActionView::Helpers, Haml::Helpers
Defined in:
lib/active_admin/cms/content.rb

Instance Method Summary collapse

Instance Method Details

#content_typeObject

process_in_background :image process_in_background :file



26
27
28
# File 'lib/active_admin/cms/content.rb', line 26

def content_type
  content_type_class.constantize if content_type_class
end

#content_type=(type) ⇒ Object



34
35
36
# File 'lib/active_admin/cms/content.rb', line 34

def content_type=(type)
  update_attribute :content_type_class, type.to_s
end

#content_type_classObject



30
31
32
# File 'lib/active_admin/cms/content.rb', line 30

def content_type_class
  super || 'ActiveAdmin::Cms::ContentTypes::String'
end

#image_uploaderObject



38
39
40
# File 'lib/active_admin/cms/content.rb', line 38

def image_uploader
  content_type.image_uploader
end

#set_content(value) ⇒ Object



42
43
44
# File 'lib/active_admin/cms/content.rb', line 42

def set_content(value)
  self.send("#{self.content_type.input_field}=", value)
end

#to_html(options = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/active_admin/cms/content.rb', line 46

def to_html(options = {})
  #debugger
  html = ''

  if content_type.text_allowed?
    if content_type.markdown_allowed?
      html += text.to_html
    else
      html += text.to_s
    end
  end

  if content_type.image_allowed?
    if image
      tag_options = options[:tag]
      tag_options ||= {}
      tag_options[:src] ||= image.url(options[:version])
      html += tag(:img, tag_options) if tag_options[:src] != 'missing.png'
    end
  end

  html
end