Class: Breeze::Page

Inherits:
ViewBase show all
Defined in:
app/models/breeze/page.rb

Instance Attribute Summary

Attributes inherited from ActiveYaml

#data

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ViewBase

#add_default_options, #allowed_fields, #get_translation, #has_option?, #header_text, #image_old, #last_update_for, #option, #option_definitions, #safe_options, #set_option, #swap_index_with, #text_text, #type_id, #update, #update_options

Methods inherited from ActiveBase

#add_save, #add_save!, #delete_save!, #edit_save, #edit_save!

Methods inherited from ActiveYaml

all, append, define_access, define_association, delete, fields, find, find_all, find_by, first, full_path, #id, #id=, #initialize, load_file, #persisted?, primary_key, reload, save_all, set_root_path, the_meta_class

Constructor Details

This class inherits a constructor from Breeze::ActiveYaml

Class Method Details

.fix_name(name) ⇒ Object



86
87
88
# File 'app/models/breeze/page.rb', line 86

def self.fix_name(name)
  name.gsub(" ", "_").downcase
end

.new_page(name, type) ⇒ Object



90
91
92
93
94
# File 'app/models/breeze/page.rb', line 90

def self.new_page(name , type)
  data = { name: self.fix_name(name) , updated_at: Time.now , type: type}
  new_id = Page.append(data)
  Page.new(data)
end

Instance Method Details

#change_nameObject



9
10
11
# File 'app/models/breeze/page.rb', line 9

def change_name
  self.name
end

#delete(editor) ⇒ Object



63
64
65
66
# File 'app/models/breeze/page.rb', line 63

def delete(editor)
  sections.each {|section| section.delete(editor) }
  delete_save!(editor)
end

#first_templateObject



54
55
56
57
# File 'app/models/breeze/page.rb', line 54

def first_template
  return "none" unless @content[0]
  @content[0]["template"]
end

#missing_translationsObject



21
22
23
24
25
# File 'app/models/breeze/page.rb', line 21

def missing_translations
  sum = 0
  sections.collect{ |s | sum += s.missing_translations }
  sum
end

#new_section(section_template = nil) ⇒ Object



39
40
41
42
43
# File 'app/models/breeze/page.rb', line 39

def new_section(section_template = nil)
  section_template = "section_spacer" if section_template.blank?
  section = Section.new_section(section_template, self.id , sections.length + 1)
  section
end

#next_pageObject



80
81
82
83
84
# File 'app/models/breeze/page.rb', line 80

def next_page
  all = Page.all
  return all.first if(self.id == all.length)
  all[self.id]
end

#previous_pageObject



75
76
77
78
# File 'app/models/breeze/page.rb', line 75

def previous_page
  return Page.all.last if(self.id == 1)
  Page.all[self.id - 2]
end

#remove_section(section) ⇒ Object



45
46
47
48
49
50
51
52
# File 'app/models/breeze/page.rb', line 45

def remove_section(section)
  from_index = section.index
  @sections.delete_at(from_index)
  @content.delete_at(from_index)
  @sections.each_with_index do |section, index|
    section.set_index(index)
  end
end

#reset_indexObject



59
60
61
# File 'app/models/breeze/page.rb', line 59

def reset_index
  sections.each_with_index{|section, index| section.index = index + 1}
end

#save(editor) ⇒ Object



68
69
70
71
72
73
# File 'app/models/breeze/page.rb', line 68

def save(editor)
  olds = self.redirects.to_s.split(" ")
  olds.delete( self.name.to_s )
  self.redirects = olds.join(" ")
  super
end

#sectionsObject



27
28
29
# File 'app/models/breeze/page.rb', line 27

def sections
  Section.find_all(:page_id, id).sort_by{|obj| obj.index }
end

#sections_updateObject



31
32
33
# File 'app/models/breeze/page.rb', line 31

def sections_update
  last_update_for( sections )
end

#set_name(new_name) ⇒ Object



13
14
15
16
17
18
19
# File 'app/models/breeze/page.rb', line 13

def set_name new_name
  new_name = Page.fix_name(new_name)
  olds = self.redirects.to_s.split(" ")
  olds << self.name unless olds.include?(self.name)
  self.redirects = olds.join(" ")
  self.name = new_name
end

#template_styleObject



35
36
37
# File 'app/models/breeze/page.rb', line 35

def template_style
  PageStyle.find_by_type( type )
end