Class: Pulitzer::Partial

Inherits:
ApplicationRecord show all
Defined in:
app/models/pulitzer/partial.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

assoc_name, attrs_name, convert_hash_to_nested

Class Method Details

.convert_nested_assoc(json_hash) ⇒ Object



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

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



20
21
22
23
24
25
26
27
# File 'app/models/pulitzer/partial.rb', line 20

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

Instance Method Details

#available_arrangementsObject



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

def available_arrangements
  post_type_version.arrangement_styles
end

#available_backgroundsObject



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

def available_backgrounds
  post_type_version.background_styles
end

#available_justificationsObject



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

def available_justifications
  post_type_version.justification_styles
end

#available_sequence_flowsObject



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

def available_sequence_flows
  post_type_version.sequence_flow_styles
end

#background_css_classObject



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

def background_css_class
  background_style&.css_class_name
end

#clone_meObject



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

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



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

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

#folder_pathObject



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

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

#full_view_pathObject



90
91
92
# File 'app/models/pulitzer/partial.rb', line 90

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

#handle_sort_orderObject



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

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



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

def justification_css_class
  justification_style&.css_class_name
end

#sequence_flow_css_classObject



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

def sequence_flow_css_class
  sequence_flow_style&.css_class_name
end

#template_pathObject



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

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

#upgradable?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'app/models/pulitzer/partial.rb', line 107

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

#version_folderObject



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

def version_folder
  "v_#{version_number}"
end