diff options
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/page.rb | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/app/models/page.rb b/app/models/page.rb index 7ac8f35..7ac0b60 100644 --- a/app/models/page.rb +++ b/app/models/page.rb | |||
| @@ -1,5 +1,8 @@ | |||
| 1 | class Page < ActiveRecord::Base | 1 | class Page < ActiveRecord::Base |
| 2 | 2 | ||
| 3 | PUBLIC_TEMPLATE_PATH = File.join(%w(custom page_templates public)) | ||
| 4 | FULL_PUBLIC_TEMPLATE_PATH = File.join(RAILS_ROOT, 'app', 'views', PUBLIC_TEMPLATE_PATH) | ||
| 5 | |||
| 3 | # Mixins and Plugins | 6 | # Mixins and Plugins |
| 4 | acts_as_taggable | 7 | acts_as_taggable |
| 5 | acts_as_list :column => :revision, :scope => :node_id | 8 | acts_as_list :column => :revision, :scope => :node_id |
| @@ -11,7 +14,7 @@ class Page < ActiveRecord::Base | |||
| 11 | belongs_to :user | 14 | belongs_to :user |
| 12 | 15 | ||
| 13 | # Security | 16 | # Security |
| 14 | attr_accessible :title, :abstract, :body | 17 | attr_accessible :title, :abstract, :body, :template_name |
| 15 | 18 | ||
| 16 | # Class Methods | 19 | # Class Methods |
| 17 | 20 | ||
| @@ -44,6 +47,12 @@ class Page < ActiveRecord::Base | |||
| 44 | 47 | ||
| 45 | end | 48 | end |
| 46 | 49 | ||
| 50 | def self.custom_templates | ||
| 51 | files = Dir.entries(FULL_PUBLIC_TEMPLATE_PATH).select do |x| | ||
| 52 | x if x.gsub!(".html.erb", "") | ||
| 53 | end | ||
| 54 | end | ||
| 55 | |||
| 47 | # Instance Methods | 56 | # Instance Methods |
| 48 | 57 | ||
| 49 | def clone_attributes_from page | 58 | def clone_attributes_from page |
| @@ -63,4 +72,44 @@ class Page < ActiveRecord::Base | |||
| 63 | 72 | ||
| 64 | I18n.locale = locale_before | 73 | I18n.locale = locale_before |
| 65 | end | 74 | end |
| 75 | |||
| 76 | def public_template_path | ||
| 77 | File.join(PUBLIC_TEMPLATE_PATH, template_name) | ||
| 78 | end | ||
| 79 | |||
| 80 | def full_public_template_path | ||
| 81 | File.join(FULL_PUBLIC_TEMPLATE_PATH, template_name) | ||
| 82 | end | ||
| 83 | |||
| 84 | def template_exists? | ||
| 85 | File.exists? "#{full_public_template_path}.html.erb" | ||
| 86 | end | ||
| 87 | |||
| 88 | def valid_template | ||
| 89 | |||
| 90 | if template_name && template_exists? | ||
| 91 | public_template_path | ||
| 92 | else | ||
| 93 | File.join(PUBLIC_TEMPLATE_PATH, 'render_page') | ||
| 94 | end | ||
| 95 | end | ||
| 96 | |||
| 97 | def clone_attributes_from page | ||
| 98 | return nil unless page | ||
| 99 | |||
| 100 | self.tag_list = page.tag_list.join(", ") | ||
| 101 | self.template_name = page.template_name | ||
| 102 | |||
| 103 | locale_before = I18n.locale | ||
| 104 | |||
| 105 | I18n.available_locales.each do |l| | ||
| 106 | next if l == :root | ||
| 107 | I18n.locale = l | ||
| 108 | self.title = page.title | ||
| 109 | self.abstract = page.abstract | ||
| 110 | self.body = page.body | ||
| 111 | end | ||
| 112 | |||
| 113 | I18n.locale = locale_before | ||
| 114 | end | ||
| 66 | end \ No newline at end of file | 115 | end \ No newline at end of file |
