Class: RubberRing::Page
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- RubberRing::Page
- Defined in:
- app/models/rubber_ring/page.rb
Instance Attribute Summary collapse
-
#edit_mode ⇒ Object
Returns the value of attribute edit_mode.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
- .add_template(options) ⇒ Object
- .remove(options, key_to_remove) ⇒ Object
- .remove_template(options) ⇒ Object
- .save_or_update(options) ⇒ Object
- .save_or_update_templates(options) ⇒ Object
Instance Method Summary collapse
-
#content ⇒ Object
all page_contents as one hash.
- #edit_mode? ⇒ Boolean
- #group_keys(group_key) ⇒ Object
Instance Attribute Details
#edit_mode ⇒ Object
Returns the value of attribute edit_mode.
3 4 5 |
# File 'app/models/rubber_ring/page.rb', line 3 def edit_mode @edit_mode end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'app/models/rubber_ring/page.rb', line 3 def title @title end |
Class Method Details
.add_template(options) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/models/rubber_ring/page.rb', line 55 def self.add_template() page, content = get_page_and_content(, :content) last = RubberRing::PageTemplate.all.order(:sort).last pt = RubberRing::PageTemplate.where('id = ?', content['index']).first_or_initialize() new_pt = pt.id.nil? ? last.dup : pt.dup new_pt.sort = last.sort + 1 new_pt.save return page, new_pt end |
.remove(options, key_to_remove) ⇒ Object
74 75 76 77 78 79 80 |
# File 'app/models/rubber_ring/page.rb', line 74 def self.remove(, key_to_remove) page = load_first_page() RubberRing::PageContent .where('page_id = ? AND key = ?', page.id, key_to_remove) .delete_all page end |
.remove_template(options) ⇒ Object
68 69 70 71 72 |
# File 'app/models/rubber_ring/page.rb', line 68 def self.remove_template() page, content = get_page_and_content(, :content) RubberRing::PageTemplate.where('id = ?', content['index']).delete_all page end |
.save_or_update(options) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/models/rubber_ring/page.rb', line 7 def self.save_or_update() page, page_content = get_page_and_content(, :content) page_content.keys.each do |key| pc = RubberRing::PageContent.where('page_id = ? AND key = ?', page.id, key) .first_or_initialize() pc.update_attributes( key: key, value: page_content[key], page: page ) pc.save end page end |
.save_or_update_templates(options) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/models/rubber_ring/page.rb', line 26 def self.save_or_update_templates() page, templates = get_page_and_content(, :content) templates.keys.each do |key| template = templates[key] pt = RubberRing::PageTemplate.where('id = ?', template['index']).first_or_initialize() if pt.id.nil? pt.update_attributes( key: template['key'], template: template['template'], sort: template['sort'], tclass: template['tclass'], element: template['element'], page: page ) else # when updating, only sort is allowed to change pt.update_attributes( sort: template['sort'] ) end pt.save end page end |
Instance Method Details
#content ⇒ Object
all page_contents as one hash
92 93 94 95 96 97 98 |
# File 'app/models/rubber_ring/page.rb', line 92 def content result = {} page_contents.each do |page_content| result[page_content.key] = page_content.value end result end |
#edit_mode? ⇒ Boolean
87 88 89 |
# File 'app/models/rubber_ring/page.rb', line 87 def edit_mode? @edit_mode end |
#group_keys(group_key) ⇒ Object
82 83 84 85 |
# File 'app/models/rubber_ring/page.rb', line 82 def group_keys(group_key) return [] if content.nil? (content.select { |key, _| key.match(group_key) }).keys end |