Class: Pulitzer::Partial

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

Instance Method Summary collapse

Instance Method Details

#available_layoutsObject



24
25
26
# File 'app/models/pulitzer/partial.rb', line 24

def available_layouts
  post_type.layouts
end

#clone_meObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/pulitzer/partial.rb', line 36

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



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

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

#folder_pathObject



28
29
30
# File 'app/models/pulitzer/partial.rb', line 28

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

#full_view_pathObject



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

def full_view_path
  Pulitzer.partial_folder + '/' + folder_path + '/' + template_path
end

#handle_sort_orderObject



18
19
20
21
22
# File 'app/models/pulitzer/partial.rb', line 18

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