summaryrefslogtreecommitdiff
path: root/app
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
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')
-rw-r--r--app/controllers/content_controller.rb10
-rw-r--r--app/helpers/content_helper.rb4
-rw-r--r--app/helpers/nodes_helper.rb4
-rw-r--r--app/models/page.rb51
-rw-r--r--app/views/custom/page_templates/public/no_date_and_author.html.erb6
-rw-r--r--app/views/custom/page_templates/public/render_page.html.erb (renamed from app/views/content/render_page.html.erb)0
-rw-r--r--app/views/custom/partials/_sidebar_title_only.html.erb (renamed from app/views/custom_templates/partials/_sidebar_title_only.html.erb)0
-rw-r--r--app/views/nodes/edit.html.erb5
8 files changed, 74 insertions, 6 deletions
diff --git a/app/controllers/content_controller.rb b/app/controllers/content_controller.rb
index 0fa9832..706cfcd 100644
--- a/app/controllers/content_controller.rb
+++ b/app/controllers/content_controller.rb
@@ -10,8 +10,14 @@ class ContentController < ApplicationController
10 10
11 @page = Node.find_page(path) 11 @page = Node.find_page(path)
12 12
13 # Replace with real 404 13 if @page
14 unless @page 14 template = @page.valid_template
15
16 render(
17 :file => template,
18 :layout => true
19 )
20 else
15 render( 21 render(
16 :file => File.join(RAILS_ROOT, 'public', '404.html'), 22 :file => File.join(RAILS_ROOT, 'public', '404.html'),
17 :status => 404 23 :status => 404
diff --git a/app/helpers/content_helper.rb b/app/helpers/content_helper.rb
index fba7737..a586142 100644
--- a/app/helpers/content_helper.rb
+++ b/app/helpers/content_helper.rb
@@ -73,7 +73,7 @@ module ContentHelper
73 # partial 73 # partial
74 def select_partial partial 74 def select_partial partial
75 if partial && partial_exists?( partial ) 75 if partial && partial_exists?( partial )
76 return "custom_templates/partials/#{partial}" 76 return "custom/partials/#{partial}"
77 else 77 else
78 return 'content/article' 78 return 'content/article'
79 end 79 end
@@ -83,7 +83,7 @@ module ContentHelper
83 def partial_exists? partial 83 def partial_exists? partial
84 File.exist?( 84 File.exist?(
85 File.join( 85 File.join(
86 RAILS_ROOT, 'app', 'views', 'custom_templates', 'partials', "_#{partial}.html.erb" 86 RAILS_ROOT, 'app', 'views', 'custom', 'partials', "_#{partial}.html.erb"
87 ) 87 )
88 ) 88 )
89 end 89 end
diff --git a/app/helpers/nodes_helper.rb b/app/helpers/nodes_helper.rb
index fc5b0a0..bd54d3d 100644
--- a/app/helpers/nodes_helper.rb
+++ b/app/helpers/nodes_helper.rb
@@ -7,4 +7,8 @@ module NodesHelper
7 truncate(node.draft.title, :length => 50) 7 truncate(node.draft.title, :length => 50)
8 end 8 end
9 end 9 end
10
11 def custom_page_templates
12 Page.custom_templates.map {|x| [x.gsub("_", " ").titlecase, x]}
13 end
10end 14end
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
diff --git a/app/views/custom/page_templates/public/no_date_and_author.html.erb b/app/views/custom/page_templates/public/no_date_and_author.html.erb
new file mode 100644
index 0000000..4eda744
--- /dev/null
+++ b/app/views/custom/page_templates/public/no_date_and_author.html.erb
@@ -0,0 +1,6 @@
1<div class="article">
2 <h2><%= @page.title %></h2>
3 <hr class="subtitle" />
4 <p><em><%= @page.abstract %></em></p>
5 <%= aggregate?(@page.body) %>
6</div> \ No newline at end of file
diff --git a/app/views/content/render_page.html.erb b/app/views/custom/page_templates/public/render_page.html.erb
index 4c21667..4c21667 100644
--- a/app/views/content/render_page.html.erb
+++ b/app/views/custom/page_templates/public/render_page.html.erb
diff --git a/app/views/custom_templates/partials/_sidebar_title_only.html.erb b/app/views/custom/partials/_sidebar_title_only.html.erb
index 819d9ae..819d9ae 100644
--- a/app/views/custom_templates/partials/_sidebar_title_only.html.erb
+++ b/app/views/custom/partials/_sidebar_title_only.html.erb
diff --git a/app/views/nodes/edit.html.erb b/app/views/nodes/edit.html.erb
index 64d4756..929bbf6 100644
--- a/app/views/nodes/edit.html.erb
+++ b/app/views/nodes/edit.html.erb
@@ -13,7 +13,10 @@
13 <%= f.error_messages %> 13 <%= f.error_messages %>
14 14
15 <% fields_for @draft do |d| %> 15 <% fields_for @draft do |d| %>
16 <p></p> 16 <p>
17 <%= d.label :template_name %>
18 <%= d.select :template_name, custom_page_templates %>
19 </p>
17 <p> 20 <p>
18 <%= d.label :title %><br /> 21 <%= d.label :title %><br />
19 <%= d.text_field :title %> 22 <%= d.text_field :title %>