Class: Pulitzer::PostTypeContentElementType

Inherits:
ApplicationRecord show all
Includes:
PostTypeElement
Defined in:
app/models/pulitzer/post_type_content_element_type.rb

Constant Summary collapse

Any_clickable =
OpenStruct.new
URL_clickable =
OpenStruct.new

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PostTypeElement

#handle_sort_order, #highest_sibling_sort, included

Methods inherited from ApplicationRecord

assoc_name, attrs_name, convert_hash_to_nested

Class Method Details

.clickable_kindsObject



45
46
47
# File 'app/models/pulitzer/post_type_content_element_type.rb', line 45

def self.clickable_kinds
  [Any_clickable] + Pulitzer::CustomOptionList.all.to_a + [URL_clickable]
end

.convert_nested_assoc(json_hash) ⇒ Object



38
39
40
41
42
43
# File 'app/models/pulitzer/post_type_content_element_type.rb', line 38

def self.convert_nested_assoc(json_hash)
  json_hash[attrs_name].map!{|ptcet_attrs|
    new_attrs = Pulitzer::Style.convert_hash_to_nested ptcet_attrs
  }
  json_hash      
end

.export_configObject



29
30
31
32
33
34
35
36
# File 'app/models/pulitzer/post_type_content_element_type.rb', line 29

def self.export_config
  {
    except: [:id, :post_type_version_id],
    include: {
      styles: { except: :id }
    }
  }
end

Instance Method Details

#any_clickable_kind?Boolean

Returns:

  • (Boolean)


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

def any_clickable_kind?
  'any' == clickable_kind
end

#clickable_kind_displayObject



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

def clickable_kind_display
  GlobalID::Locator.locate(clickable_kind)&.name || clickable_kind.humanize
end

#clickable_kindsObject



61
62
63
# File 'app/models/pulitzer/post_type_content_element_type.rb', line 61

def clickable_kinds
  Pulitzer::CustomOptionList.all.to_a + [URL_clickable]
end

#clone_meObject



103
104
105
106
107
108
# File 'app/models/pulitzer/post_type_content_element_type.rb', line 103

def clone_me
  clone_attrs = self.attributes.dup
  clone_attrs.delete 'id'
  clone_attrs.delete 'post_type_version_id'
  Pulitzer::PostTypeContentElementType.new(clone_attrs)
end

#custom_clickable_kindsObject



65
66
67
# File 'app/models/pulitzer/post_type_content_element_type.rb', line 65

def custom_clickable_kinds
  Pulitzer::CustomOptionList.all.to_a
end

#custom_option_listObject



69
70
71
# File 'app/models/pulitzer/post_type_content_element_type.rb', line 69

def custom_option_list
  GlobalID::Locator.locate(clickable_kind)
end

#custom_optionsObject



73
74
75
# File 'app/models/pulitzer/post_type_content_element_type.rb', line 73

def custom_options
  custom_option_list&.custom_options
end

#first_styleObject



99
100
101
# File 'app/models/pulitzer/post_type_content_element_type.rb', line 99

def first_style
  styles.first
end

#text_editor_displayObject



90
91
92
93
94
95
96
97
# File 'app/models/pulitzer/post_type_content_element_type.rb', line 90

def text_editor_display
  case text_editor
  when 'None'
    'no editor'
  else
    text_editor
  end
end

#type_specific_displayObject



77
78
79
80
81
82
83
84
85
86
87
88
# File 'app/models/pulitzer/post_type_content_element_type.rb', line 77

def type_specific_display
  case type
  when :image
    "#{height}x#{width}"
  when :text
    text_editor_display
  when :clickable
    clickable_kind_display
  else
    ''
  end
end

#url_clickable_kind?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'app/models/pulitzer/post_type_content_element_type.rb', line 57

def url_clickable_kind?
  'url' == clickable_kind
end