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 !
add theme toolbox

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@2260 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Sun Sep 24 19:15:05 -0700 2006
commit  6022c851dd7c4f2c0970f077f9d393dbfc814806
tree    d0cdf43fbf838491c67dc13209afc23926697dd6
parent  01edc37c3577841a035289fb086beb2c05764a2d
...
2
3
4
5
 
6
7
8
...
46
47
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
50
51
 
52
53
54
...
2
3
4
 
5
6
7
8
...
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
 
65
66
67
68
0
@@ -2,7 +2,7 @@ class Admin::ThemesController < Admin::BaseController
0
   @@theme_export_path = RAILS_PATH + 'tmp/export'
0
   cattr_accessor :theme_export_path
0
   
0
- before_filter :find_theme, :only => [:preview_for, :export, :change_to]
0
+ before_filter :find_theme, :only => [:preview_for, :export, :change_to, :show, :destroy]
0
 
0
   def preview_for
0
     send_file((@theme.preview.exist? ? @theme.preview : RAILS_PATH + 'public/images/mephisto/preview.png').to_s, :type => 'image/png', :disposition => 'inline')
0
@@ -46,9 +46,23 @@ class Admin::ThemesController < Admin::BaseController
0
     end
0
   end
0
 
0
+ def destroy
0
+ if @theme.current?
0
+ flash[:error] = "Cannot delete the current theme"
0
+ else
0
+ @index = site.themes.index(@theme)
0
+ @theme.path.rmtree
0
+ flash[:notice] = "The '#{params[:id]}' theme was deleted."
0
+ end
0
+ respond_to do |format|
0
+ format.html { redirect_to :action => 'index' }
0
+ format.js
0
+ end
0
+ end
0
+
0
   protected
0
     def find_theme
0
- show_404 unless @theme = site.themes[params[:id]]
0
+ show_404 unless @theme = params[:id] == 'current' ? site.theme : site.themes[params[:id]]
0
     end
0
 
0
     def temp_theme_path_for(prefix)
...
114
115
116
117
 
118
119
120
...
255
256
257
258
 
259
260
261
...
114
115
116
 
117
118
119
120
...
255
256
257
 
258
259
260
261
0
@@ -114,7 +114,7 @@ class Site < ActiveRecord::Base
0
       entry = other_themes_path + e
0
       next unless entry.directory?
0
       @themes << Theme.new(entry)
0
- @themes.pop if @themes.last == theme
0
+ @themes.pop if @themes.last.similar_to?(theme)
0
     end
0
     def @themes.[](key) key = key.to_s ; detect { |t| t.name == key } ; end
0
     @themes
0
@@ -255,7 +255,7 @@ class Site < ActiveRecord::Base
0
     def find_preferred_template(template_type, custom_template)
0
       preferred = templates.find_preferred(template_type, custom_template)
0
       return preferred if preferred && preferred.file?
0
- raise Mephisto::MissingTemplateError.new(template_type, templates.collect_templates(template_type, custom_template))
0
+ raise MissingTemplateError.new(template_type, templates.collect_templates(template_type, custom_template).collect(&:basename))
0
     end
0
     
0
     def parse_template(template, assigns, controller)
...
132
133
134
135
136
137
138
139
140
 
 
 
 
 
141
142
143
...
132
133
134
 
 
 
 
 
 
135
136
137
138
139
140
141
142
0
@@ -132,12 +132,11 @@ class Theme
0
   end
0
   
0
   def ==(comparison_object)
0
- case comparison_object
0
- when Theme
0
- title == comparison_object.title && version == comparison_object.version
0
- else
0
- base_path == comparison_object.to_s
0
- end
0
+ base_path == (comparison_object.is_a?(Theme) ? comparison_object.base_path : comparison_object.to_s)
0
+ end
0
+
0
+ def similar_to?(theme)
0
+ title == theme.title && version == theme.version
0
   end
0
 
0
   protected
...
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
10
11
12
 
 
 
 
 
 
 
 
 
 
13
14
0
@@ -10,14 +10,4 @@
0
       <a id="theme_dialog_<%= theme_counter %>" class="theme_dialog">
0
       <img src="<%= url_for(:controller => '/admin/themes', :action => 'preview_for', :id => theme) %>" alt="Theme preview" title="<%=h theme.title %> (v<%=h theme.version %>)" />
0
       </a>
0
- <div class="tools" id="theme_tools_<%= theme_counter %>" style="display:none">
0
- <ul>
0
- <% unless theme.current? -%>
0
- <li><%= link_to 'Use this theme', :action => 'change_to', :id => theme %></li>
0
- <li><%= link_to 'Edit', :controller => 'design', :action => 'index', :theme => theme %></li>
0
- <% end -%>
0
- <!--li><a href="#" title="title">Change info</a></li-->
0
- <li><%= link_to 'Export', :action => 'export', :id => theme %></li>
0
- </ul>
0
- </div>
0
     </li>
0
\ No newline at end of file
...
120
121
122
123
124
125
126
127
128
129
130
 
 
 
 
 
 
131
132
133
...
120
121
122
 
 
 
 
 
 
 
 
123
124
125
126
127
128
129
130
131
0
@@ -120,13 +120,11 @@ Pathname.class_eval do
0
   end
0
 end
0
 
0
-module Mephisto
0
- class MissingTemplateError < StandardError
0
- attr_reader :template_type, :templates
0
- def initialize(template_type, templates)
0
- @template_type = template_type
0
- @templates = templates
0
- super "No template found for #{template_type}, checked #{templates.to_sentence}."
0
- end
0
+class MissingTemplateError < StandardError
0
+ attr_reader :template_type, :templates
0
+ def initialize(template_type, templates)
0
+ @template_type = template_type
0
+ @templates = templates
0
+ super "No template found for #{template_type}, checked #{templates.to_sentence}."
0
   end
0
 end
0
\ No newline at end of file
...
555
556
557
 
 
558
 
559
560
561
...
555
556
557
558
559
560
561
562
563
564
0
@@ -555,7 +555,10 @@ Event.addBehavior({
0
   },
0
   
0
   'a.theme_dialog:click': function() {
0
+ var img = this.down('img');
0
+ var pieces = img.src.split('/');
0
     new Dialog.Rjs();
0
+ new Ajax.Request('/admin/themes/show/' + pieces[pieces.length-1]);
0
   }
0
   
0
   //'.theme': function() {
...
11
12
13
 
14
15
16
...
51
52
53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
...
11
12
13
14
15
16
17
...
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
0
@@ -11,6 +11,7 @@ class Admin::ThemesControllerTest < Test::Unit::TestCase
0
     @request = ActionController::TestRequest.new
0
     @response = ActionController::TestResponse.new
0
     login_as :quentin
0
+ prepare_theme_fixtures
0
   end
0
 
0
   def test_should_allow_site_admin
0
@@ -51,4 +52,34 @@ class Admin::ThemesControllerTest < Test::Unit::TestCase
0
     assert_equal %w(current empty encytemedia hemingway), sites(:first).themes.collect(&:name)
0
     assert_equal 'Hemingway', sites(:first).themes[:hemingway].title
0
   end
0
+
0
+ def test_should_delete_theme
0
+ delete :destroy, :id => 'encytemedia'
0
+ assert_equal 2, assigns(:index)
0
+ assert_redirected_to :action => 'index'
0
+ assert_match /deleted/, flash[:notice]
0
+ assert_equal %w(current empty), sites(:first).themes.collect(&:name)
0
+ end
0
+
0
+ def test_should_not_delete_current_theme
0
+ delete :destroy, :id => 'current'
0
+ assert_redirected_to :action => 'index'
0
+ assert_match /current/, flash[:error]
0
+ assert_equal %w(current empty encytemedia), sites(:first).themes.collect(&:name)
0
+ end
0
+
0
+ def test_should_delete_theme_with_ajax
0
+ xhr :delete, :destroy, :id => 'empty'
0
+ assert_equal 1, assigns(:index)
0
+ assert_response :success
0
+ assert_match /deleted/, flash[:notice]
0
+ assert_equal %w(current encytemedia), sites(:first).themes.collect(&:name)
0
+ end
0
+
0
+ def test_should_not_delete_current_theme_with_ajax
0
+ xhr :delete, :destroy, :id => 'current'
0
+ assert_response :success
0
+ assert_match /current/, flash[:error]
0
+ assert_equal %w(current empty encytemedia), sites(:first).themes.collect(&:name)
0
+ end
0
 end
...
97
98
99
100
 
101
102
103
...
97
98
99
 
100
101
102
103
0
@@ -97,7 +97,7 @@ context "Site Template" do
0
   specify "should raise error on missing template" do
0
     sites(:first).templates[:archive].unlink
0
     sites(:first).templates[:index].unlink
0
- assert_raise Mephisto::MissingTemplateError do
0
+ assert_raise MissingTemplateError do
0
       sites(:first).send(:set_content_template, sites(:first).sections.home, :archive)
0
     end
0
   end

Comments

    No one has commented yet.