summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorhukl <contact@smyck.org>2009-03-02 20:29:25 +0100
committerhukl <contact@smyck.org>2009-03-03 19:47:18 +0100
commit82f16e71d49350c1ad4aa48773db5d0f45a55c6c (patch)
tree72a341b68e2b1f35772e11add0bef7208e9b90b6 /app/models
parentc9183349c2fbacf24fca5cd7767190d069ce8873 (diff)
introducing page templates - need to add edit capabilities
renamed the custom template folder forgot one fix for the new custom template path page templates refined renamed page attribute template to template_name as i suspected it to be a reserved word. it still didn't work until i discovered that simon defined the accessible attributes! That costed me 40 minutes of lifetime. But he apologized ;) tests for public and custom page templates
Diffstat (limited to 'app/models')
-rw-r--r--app/models/page.rb51
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 @@
1class Page < ActiveRecord::Base 1class 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
66end \ No newline at end of file 115end \ No newline at end of file