Class: Pulitzer::Partial

Inherits:
ApplicationRecord show all
Includes:
ForeignOffice::Broadcaster
Defined in:
app/models/pulitzer/partial.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

Instance Attribute Details

#reload_showObject

Returns the value of attribute reload_show.



17
18
19
# File 'app/models/pulitzer/partial.rb', line 17

def reload_show
  @reload_show
end

#remove_showObject

Returns the value of attribute remove_show.



17
18
19
# File 'app/models/pulitzer/partial.rb', line 17

def remove_show
  @remove_show
end

Class Method Details

.convert_nested_assoc(json_hash) ⇒ Object



34
35
36
37
38
39
# File 'app/models/pulitzer/partial.rb', line 34

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

.export_configObject



25
26
27
28
29
30
31
32
# File 'app/models/pulitzer/partial.rb', line 25

def self.export_config
  {
    except: [:id, :free_form_section_id],
    include: {
      content_elements: Pulitzer::ContentElement.export_config
    }
  }
end

Instance Method Details

#available_arrangementsObject



75
76
77
# File 'app/models/pulitzer/partial.rb', line 75

def available_arrangements
  post_type_version.arrangement_styles
end

#available_backgroundsObject



63
64
65
# File 'app/models/pulitzer/partial.rb', line 63

def available_backgrounds
  post_type_version.background_styles
end

#available_justificationsObject



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

def available_justifications
  post_type_version.justification_styles
end

#available_sequence_flowsObject



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

def available_sequence_flows
  post_type_version.sequence_flow_styles
end

#background_css_classObject



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

def background_css_class
  background_style&.css_class_name
end

#clone_meObject



99
100
101
102
103
104
105
106
107
108
109
110
# File 'app/models/pulitzer/partial.rb', line 99

def clone_me
  clone_attrs = self.attributes.dup
  clone_attrs.delete 'id'
  clone_attrs.delete 'free_form_section_id'

  my_clone = Pulitzer::Partial.create!(clone_attrs)
  content_elements.each do |ce|
    cloned_content_element = ce.clone_me
    my_clone.content_elements << cloned_content_element
  end
  my_clone
end

#content_element(label) ⇒ Object



41
42
43
# File 'app/models/pulitzer/partial.rb', line 41

def content_element(label)
  self.content_elements.find_by(label: label)
end

#folder_pathObject



79
80
81
# File 'app/models/pulitzer/partial.rb', line 79

def folder_path
  name.downcase.gsub(/ /,'_').gsub(/\W/,'')
end

#full_view_pathObject



95
96
97
# File 'app/models/pulitzer/partial.rb', line 95

def full_view_path
  File.join Pulitzer.partial_folder, folder_path, version_folder, template_path
end

#handle_sort_orderObject



57
58
59
60
61
# File 'app/models/pulitzer/partial.rb', line 57

def handle_sort_order
  if new_record? && sort_order.nil?
    self.sort_order = free_form_section.partials.maximum(:sort_order).to_i + 1
  end
end

#justification_css_classObject



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

def justification_css_class
  justification_style&.css_class_name
end

#sequence_flow_css_classObject



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

def sequence_flow_css_class
  sequence_flow_style&.css_class_name
end

#serializeObject



116
117
118
119
# File 'app/models/pulitzer/partial.rb', line 116

def serialize
  self.attributes.merge \
    reload_show: self.reload_show
end

#template_pathObject



87
88
89
90
91
92
93
# File 'app/models/pulitzer/partial.rb', line 87

def template_path
  if arrangement_style.present?
    arrangement_style.view_file_name
  else
    'default'
  end
end

#upgradable?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'app/models/pulitzer/partial.rb', line 112

def upgradable?
  version_number < (post_type_version&.post_type&.post_type_versions&.published&.maximum(:version_number) || 0)
end

#version_folderObject



83
84
85
# File 'app/models/pulitzer/partial.rb', line 83

def version_folder
  "v_#{version_number}"
end