public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
template admin stuff

git-svn-id: http://svn.techno-weenie.net/projects/mephisto@547 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Sun Jan 01 11:58:28 -0800 2006
commit  088ed38fbc10555eb45629e37e659c3855a8aa27
tree    872305269f0cfcaa579f1b6fa1dab6647ee13738
parent  649c989a7c00c76b2a9e82e076e66cfaae2a1ac5
...
1
2
 
3
4
5
...
10
11
12
13
 
14
15
16
17
18
19
20
21
22
 
 
23
24
...
1
 
2
3
4
5
...
10
11
12
 
13
14
15
16
17
18
19
 
 
 
20
21
22
23
0
@@ -1,5 +1,5 @@
0
 class Admin::TemplatesController < ApplicationController
0
- before_filter :select_templates
0
+ before_filter :select_template, :except => :index
0
   verify :params => :id, :only => [:edit, :update],
0
          :add_flash => { :error => 'Template required' },
0
          :redirect_to => { :action => 'index' }
0
@@ -10,15 +10,14 @@ class Admin::TemplatesController < ApplicationController
0
   def update
0
     if @tmpl.update_attributes(params[:template])
0
       flash[:notice] = "#{@tmpl.name} updated."
0
- redirect_to :action => 'edit'
0
+ redirect_to :action => 'edit', :id => @tmpl
0
     else
0
       render :action => 'edit'
0
     end
0
   end
0
 
0
   protected
0
- def select_templates
0
- @templates = Template.find :all
0
- @tmpl = @templates.find { |t| t.id.to_s == params[:id] } if params[:id]
0
+ def select_template
0
+ @tmpl = Template.find_by_name(params[:id])
0
   end
0
 end
...
3
4
5
6
7
 
 
8
9
 
10
11
 
 
12
13
14
...
16
17
18
19
 
 
 
20
21
22
...
25
26
27
 
 
 
 
28
29
...
3
4
5
 
 
6
7
8
 
9
10
 
11
12
13
14
15
...
17
18
19
 
20
21
22
23
24
25
...
28
29
30
31
32
33
34
35
36
0
@@ -3,12 +3,13 @@ class Template < ActiveRecord::Base
0
     :main => [:home, :index],
0
     :single => [:single, :index],
0
     :tag => [:tag, :archive, :index],
0
- :page => [:page, :index],
0
- :author => [:author, :archive, :index],
0
+ #:page => [:page, :index],
0
+ #:author => [:author, :archive, :index],
0
     :search => [:search, :index],
0
- :error => [:error, :index]
0
+ #:error => [:error, :index]
0
   }
0
- cattr_reader :hierarchy
0
+ @@template_types = @@hierarchy.values.flatten.uniq
0
+ cattr_reader :hierarchy, :template_types
0
 
0
   class << self
0
     def find_all_by_name(template_type)
0
@@ -16,7 +17,9 @@ class Template < ActiveRecord::Base
0
     end
0
 
0
     def templates_for(template_type)
0
- find_all_by_name(template_type).inject({}) { |templates, template| templates.merge(template.name => template.data) }
0
+ find_all_by_name(template_type).inject({}) do |templates, template|
0
+ template.data.blank? ? templates : templates.merge(template.name => template.data)
0
+ end
0
     end
0
 
0
     def find_preferred(template_type, templates = nil)
0
@@ -25,4 +28,8 @@ class Template < ActiveRecord::Base
0
       nil
0
     end
0
   end
0
+
0
+ def to_param
0
+ name
0
+ end
0
 end
0
\ No newline at end of file
...
1
 
 
 
2
3
 
4
5
6
7
8
9
10
 
11
...
1
2
3
4
5
 
6
7
8
9
 
 
 
10
11
12
0
@@ -1,9 +1,10 @@
0
 <div id="content">
0
+
0
+<%= render :partial => 'templates' %>
0
+
0
 <% form_for :template, @tmpl, :url => { :action => 'update' } do |f| -%>
0
- <p><%= f.text_field :name %></p>
0
+ <h1><%=h @tmpl.name %></h1>
0
   <p><%= f.text_area :data %></p>
0
   <p><%= submit_tag 'Save' %></p>
0
 <% end -%>
0
-</div>
0
-
0
-<%= render :partial => 'side' %>
0
\ No newline at end of file
0
+</div>
0
\ No newline at end of file
...
1
 
2
3
4
5
 
 
 
6
...
1
2
3
4
 
5
6
7
8
9
0
@@ -1,4 +1,7 @@
0
 <div id="content">
0
+<%= render :partial => 'templates' %>
0
 </div>
0
 
0
-<%= render :partial => 'side' %>
0
\ No newline at end of file
0
+<div id="side">
0
+ <p>Please choose a template to edit</p>
0
+</div>
0
\ No newline at end of file
...
6
7
8
 
 
 
 
 
 
 
9
10
11
...
6
7
8
9
10
11
12
13
14
15
16
17
18
0
@@ -6,6 +6,13 @@ Form.clear_default_text = function(input, remove_class) {
0
   }
0
 }
0
 
0
+var Template = {
0
+ navigate_to: function(select) {
0
+ var template = select.options[select.selectedIndex].value;
0
+ if(template) location.href = "/admin/templates/edit/" + template;
0
+ }
0
+};
0
+
0
 Ajax.Responders.register({
0
   // log the beginning of the requests
0
   onCreate: function(request, transport) {
...
60
61
62
 
 
 
 
 
63
64
65
...
60
61
62
63
64
65
66
67
68
69
70
0
@@ -60,6 +60,11 @@ input.default {
0
   list-style: square;
0
 }
0
 
0
+#template_data {
0
+ width:100%;
0
+ height:600px;
0
+}
0
+
0
 #header {
0
   border-bottom:10px solid #DDE0E9;
0
   font-size:24px;
...
19
20
21
22
 
23
24
25
...
37
38
39
40
 
41
42
43
44
 
45
46
47
48
49
50
 
51
52
53
...
19
20
21
 
22
23
24
25
...
37
38
39
 
40
41
42
43
 
44
45
46
47
48
49
 
50
51
52
53
0
@@ -19,7 +19,7 @@ class Admin::TemplatesControllerTest < Test::Unit::TestCase
0
   end
0
 
0
   def test_should_show_edit_template_form
0
- get :edit, :id => templates(:layout).id
0
+ get :edit, :id => templates(:layout).name
0
     assert_equal 10, assigns(:templates).length
0
     assert_tag :tag => 'form'
0
     assert_tag :tag => 'input', :attributes => { :id => 'template_name' }
0
@@ -37,17 +37,17 @@ class Admin::TemplatesControllerTest < Test::Unit::TestCase
0
   end
0
 
0
   def test_should_require_posted_template
0
- get :update, :id => templates(:layout).id, :template => { :name => 'foo' }
0
+ get :update, :id => templates(:layout).name, :template => { :name => 'foo' }
0
     assert_redirected_to :action => 'edit'
0
     assert flash[:error]
0
     
0
- post :update, :id => templates(:layout).id
0
+ post :update, :id => templates(:layout).name
0
     assert_redirected_to :action => 'edit'
0
     assert flash[:error]
0
   end
0
 
0
   def test_should_save_template
0
- post :update, :id => templates(:layout).id, :template => { :name => 'foo' }
0
+ post :update, :id => templates(:layout).name, :template => { :name => 'foo' }
0
     assert_redirected_to :action => 'edit'
0
     assert flash[:notice]
0
     templates(:layout).reload

Comments

    No one has commented yet.