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
Search Repo:
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
update tests for big theme change

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@2413 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Sun Oct 29 18:07:11 -0800 2006
commit  dca28fdafa70598c1568656569d8718cddcfd9af
tree    ca081149f0d9f5da86c1c3bedc188a50b7cb6e48
parent  57bfdce6df620ff51c3b0c00dbfc04840d08cb8b
...
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
 
 
 
124
125
 
126
127
128
 
129
130
131
132
133
134
135
...
133
134
135
136
 
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
 
 
160
161
162
163
164
 
165
166
167
168
169
170
 
171
172
173
...
300
301
302
303
 
304
305
306
...
104
105
106
 
 
 
 
 
 
 
 
107
108
109
110
111
112
 
 
 
113
114
115
116
 
117
118
 
 
119
120
121
122
123
124
125
126
...
124
125
126
 
127
128
129
 
 
 
 
 
 
 
 
 
 
 
 
130
131
 
 
 
 
 
 
 
132
133
134
135
136
137
 
138
139
140
141
142
143
 
144
145
146
147
...
274
275
276
 
277
278
279
280
0
@@ -104,28 +104,19 @@
0
     @theme_path ||= self.class.theme_path + "site-#{id}"
0
   end
0
 
0
- {:attachment_base => :current, :rollback => :rollback, :other_themes => :other}.each do |key, value|
0
- define_method "#{key}_path" do
0
- inst_var = :"@#{key}_path"
0
- instance_variable_set(inst_var, theme_path + value.to_s) if instance_variable_get(inst_var).nil?
0
- instance_variable_get(inst_var)
0
- end
0
- end
0
-
0
   def attachment_path
0
     theme.path
0
   end
0
 
0
   def themes
0
     return @themes unless @themes.nil?
0
- @themes = [theme]
0
- FileUtils.mkdir_p other_themes_path
0
- Dir.foreach other_themes_path do |e|
0
+ @themes = []
0
+ FileUtils.mkdir_p theme_path
0
+ Dir.foreach theme_path do |e|
0
       next if e.first == '.'
0
- entry = other_themes_path + e
0
+ entry = theme_path + e
0
       next unless entry.directory?
0
- @themes << Theme.new(entry)
0
- @themes.pop if @themes.last.similar_to?(theme)
0
+ @themes << Theme.new(entry, self)
0
     end
0
     def @themes.[](key) key = key.to_s ; detect { |t| t.name == key } ; end
0
     @themes.sort! {|a,b| a.name <=> b.name}
0
0
0
0
0
@@ -133,41 +124,24 @@
0
 
0
   def theme
0
     return @theme unless @theme.nil?
0
- @theme = Theme.current(attachment_base_path)
0
+ @theme = themes[current_theme_path]
0
   end
0
 
0
- def rollback_theme
0
- return @rollback_theme unless @rollback_theme.nil?
0
- @rollback_theme = Theme.new(rollback_path)
0
- end
0
-
0
- def rollback
0
- tmp = other_themes_path + '_tmp'
0
- FileUtils.cp_r rollback_path, tmp
0
- change_theme_to themes['_tmp']
0
- tmp.rmtree
0
- end
0
-
0
   def change_theme_to(new_theme_path)
0
     new_theme = (new_theme_path.is_a?(Theme) ? new_theme_path : themes[new_theme_path]) || raise("No theme '#{new_theme_path}' found")
0
- rollback_path.rmtree if rollback_path.exist?
0
- if attachment_path.exist?
0
- FileUtils.cp_r attachment_path, rollback_path
0
- attachment_path.rmtree
0
- end
0
- FileUtils.cp_r new_theme.base_path, attachment_base_path
0
- @theme = @themes = @rollback_theme = nil
0
+ update_attribute :current_theme_path, new_theme.path.basename.to_s
0
+ @theme = nil
0
     theme
0
   end
0
 
0
   def import_theme(zip_file, name)
0
- imported_name = Theme.import zip_file, :to => other_themes_path + name
0
+ imported_name = Theme.import zip_file, :to => theme_path + name
0
     @theme = @themes = @rollback_theme = nil
0
     themes[imported_name]
0
   end
0
 
0
   def move_theme(theme, new_name)
0
- FileUtils.move theme.base_path, other_themes_path + new_name
0
+ FileUtils.move theme.base_path, theme_path + new_name
0
   end
0
 
0
   [:attachments, :templates, :resources].each { |m| delegate m, :to => :theme }
0
@@ -300,7 +274,7 @@
0
     
0
     def parse_template(template, assigns, controller)
0
       # give the include tag access to files in the site's fragments directory
0
- Liquid::Template.file_system = Liquid::LocalFileSystem.new(File.join(attachment_base_path, 'templates'))
0
+ Liquid::Template.file_system = Liquid::LocalFileSystem.new(File.join(theme.path, 'templates'))
0
       tmpl = Liquid::Template.parse(template.read.to_s)
0
       returning tmpl.render(assigns, :registers => {:controller => controller}) do |result|
0
         yield tmpl, result if block_given?
...
4
5
6
7
8
9
10
11
12
13
14
...
43
44
45
46
 
 
47
48
49
...
54
55
56
57
 
 
58
59
60
...
4
5
6
 
 
 
 
 
7
8
9
...
38
39
40
 
41
42
43
44
45
...
50
51
52
 
53
54
55
56
57
0
@@ -4,11 +4,6 @@
0
   @@allowed_extensions = %w(.js .css .liquid .png .gif .jpg .swf)
0
   cattr_reader :root_theme_files, :theme_directories, :allowed_extensions
0
   attr_reader :path, :base_path
0
- attr_writer :current
0
-
0
- def self.current(base)
0
- returning(new(base)) { |theme| theme.current = true }
0
- end
0
 
0
   def self.import(zip_file, options = {})
0
     dest = options[:to].is_a?(Pathname) ? options[:to] : Pathname.new(options[:to] || '.')
0
@@ -43,7 +38,8 @@
0
     raise ThemeError.new(dest, $!.message)
0
   end
0
 
0
- def initialize(base)
0
+ def initialize(base, site = nil)
0
+ @site = site
0
     if base.is_a?(Pathname)
0
       @base_path = base.to_s
0
       @path = base
0
@@ -54,7 +50,8 @@
0
   end
0
 
0
   def current?
0
- @current == true
0
+ @current ||= (@site && @site.current_theme_path == @path.basename.to_s) || :false
0
+ @current != :false
0
   end
0
 
0
   def name
...
18
19
20
21
 
22
23
24
...
18
19
20
 
21
22
23
24
0
@@ -18,7 +18,7 @@
0
       <li><%= link_to 'Download theme', :action => 'export', :id => @theme %></li>
0
     <% unless @theme.current? -%>
0
       <li><%= link_to_remote 'Delete theme', :url => {:action => 'destroy', :id => @theme}, :method => :delete,
0
- :confirm => "Are you sure you wish to delete this theme stored at 'others/#{@theme.path.relative_path_from(site.other_themes_path).to_s}'?" %></li>
0
+ :confirm => "Are you sure you wish to delete this theme stored at 'others/#{@theme.path.relative_path_from(site.theme_path).to_s}'?" %></li>
0
     <% end -%>
0
     </ul>
0
   </div>
...
2
3
4
5
6
7
8
9
10
11
12
13
14
15
...
2
3
4
 
 
 
 
 
 
 
 
5
6
7
0
@@ -2,14 +2,6 @@
0
 <%= javascript_include_tag 'mephisto/dialog' %>
0
 <% end -%>
0
 
0
-<% content_for :sidebar do -%>
0
-<% if site.rollback_path.exist? -%>
0
-<h3>Rollback Available</h3>
0
-<p>You can rollback to the previous theme before the current theme was applied on <%= site.rollback_path.mtime.to_date.to_s :long %>.</p>
0
-<p><%= link_to 'Rollback', :action => 'rollback' %></p>
0
-<% end -%>
0
-<% end -%>
0
-
0
 <% content_for :action_nav do -%>
0
   <div id="page-nav">
0
     <ul id="act-nav" class="clear">
...
10
11
12
 
...
10
11
12
13
0
@@ -10,4 +10,5 @@
0
   permalink_style: ":year/:month/:day/:permalink"
0
   tag_path: tags
0
   search_path: search
0
+ current_theme_path: simpla
...
2
3
4
5
 
6
7
8
...
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
153
154
...
2
3
4
 
5
6
7
8
...
132
133
134
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
0
@@ -2,7 +2,7 @@
0
 # migrations feature of ActiveRecord to incrementally modify your database, and
0
 # then regenerate this schema definition.
0
 
0
-ActiveRecord::Schema.define(:version => 66) do
0
+ActiveRecord::Schema.define(:version => 67) do
0
 
0
   create_table "assets", :force => true do |t|
0
     t.column "content_type", :string
0
@@ -132,23 +132,24 @@
0
   add_index "sessions", ["session_id"], :name => "sessions_session_id_index"
0
 
0
   create_table "sites", :force => true do |t|
0
- t.column "title", :string
0
- t.column "subtitle", :string
0
- t.column "email", :string
0
- t.column "ping_urls", :text
0
- t.column "articles_per_page", :integer, :default => 15
0
- t.column "host", :string
0
- t.column "akismet_key", :string, :limit => 100
0
- t.column "akismet_url", :string
0
- t.column "approve_comments", :boolean
0
- t.column "comment_age", :integer
0
- t.column "timezone", :string
0
- t.column "filter", :string
0
- t.column "permalink_style", :string
0
- t.column "search_path", :string
0
- t.column "tag_path", :string
0
- t.column "search_layout", :string
0
- t.column "tag_layout", :string
0
+ t.column "title", :string
0
+ t.column "subtitle", :string
0
+ t.column "email", :string
0
+ t.column "ping_urls", :text
0
+ t.column "articles_per_page", :integer, :default => 15
0
+ t.column "host", :string
0
+ t.column "akismet_key", :string, :limit => 100
0
+ t.column "akismet_url", :string
0
+ t.column "approve_comments", :boolean
0
+ t.column "comment_age", :integer
0
+ t.column "timezone", :string
0
+ t.column "filter", :string
0
+ t.column "permalink_style", :string
0
+ t.column "search_path", :string
0
+ t.column "tag_path", :string
0
+ t.column "search_layout", :string
0
+ t.column "tag_layout", :string
0
+ t.column "current_theme_path", :string
0
   end
0
 
0
   add_index "sites", ["host"], :name => "index_sites_on_host"
...
60
61
62
63
64
 
 
 
65
66
67
...
60
61
62
 
 
63
64
65
66
67
68
0
@@ -60,8 +60,9 @@
0
     desc "Copy default theme to site theme"
0
     task :copy_default_theme do
0
       FileUtils.mkdir_p SITE_DIR
0
- FileUtils.cp_r File.join(RAILS_ROOT, 'themes/default'), File.join(SITE_DIR, 'current')
0
- Dir[File.join(RAILS_ROOT, 'themes/site-1/current/**/.svn')].each do |dir|
0
+ theme_path = File.join(SITE_DIR, 'simpla')
0
+ FileUtils.cp_r File.join(RAILS_ROOT, 'themes/default'), theme_path
0
+ Dir[File.join(theme_path, '**/.svn')].each do |dir|
0
         FileUtils.rm_rf dir
0
       end
0
     end
...
16
17
18
 
19
20
21
...
29
30
31
 
32
33
34
...
38
39
40
 
...
16
17
18
19
20
21
22
...
30
31
32
33
34
35
36
...
40
41
42
43
0
@@ -16,6 +16,7 @@
0
   permalink_style: ":year/:month/:day/:permalink"
0
   tag_path: tags
0
   search_path: search
0
+ current_theme_path: current
0
 hostess:
0
   id: 2
0
   title: Cupcake
0
@@ -29,6 +30,7 @@
0
   permalink_style: ":year/:month/:day/:permalink"
0
   tag_path: tags
0
   search_path: search
0
+ current_theme_path: current
0
 garden:
0
   id: 3
0
   title: walled garden
0
@@ -38,4 +40,5 @@
0
   permalink_style: ":year/:month/:day/:permalink"
0
   tag_path: tags
0
   search_path: search
0
+ current_theme_path: current
...
 
 
 
 
 
...
1
2
3
4
5
0
@@ -1 +1,6 @@
0
+title: Encytemedia
0
+author: Justin Palmer
0
+version: 0.5
0
+homepage: http://encytemedia.com/blog/
0
+summary: cool stuff
...
1
2
3
4
5
...
 
 
 
 
 
0
@@ -1,6 +1 @@
0
-title: Encytemedia
0
-author: Justin Palmer
0
-version: 0.5
0
-homepage: http://encytemedia.com/blog/
0
-summary: cool stuff
...
1
...
 
0
@@ -1,2 +1 @@
0
-title: Rollback
...
75
76
77
78
79
80
81
82
83
84
85
86
87
88
 
89
90
 
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
...
75
76
77
 
 
 
 
 
 
 
78
79
80
 
81
82
 
83
84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
86
0
@@ -75,35 +75,13 @@
0
     assert_match /deleted/, flash[:notice]
0
     assert_equal %w(current encytemedia), sites(:first).themes.collect(&:name)
0
   end
0
-
0
- specify "should not delete current theme with ajax" do
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
 
0
   specify "should change theme" do
0
     post :change_to, :id => 'encytemedia'
0
- assert sites(:first).theme.current?
0
+ assert_equal 'encytemedia', sites(:first).reload.current_theme_path
0
     assert sites(:first).theme.path.exist?, "#{sites(:first).theme.path.to_s} does not exist"
0
- assert_equal 'current', sites(:first).theme.name
0
+ assert_equal 'encytemedia', sites(:first).theme.name
0
     assert_equal 'Encytemedia', sites(:first).theme.title
0
- end
0
-
0
- specify "should change theme and create rollback" do
0
- post :change_to, :id => 'encytemedia'
0
- assert sites(:first).rollback_theme.path.exist?, "#{sites(:first).rollback_theme.path.to_s} does not exist"
0
- assert_equal 'rollback', sites(:first).rollback_theme.name
0
- assert_equal 'Hemingway', sites(:first).rollback_theme.title
0
- end
0
-
0
- specify "should rollback theme" do
0
- post :rollback
0
- assert_equal 'Rollback', sites(:first).theme.title
0
- assert_equal 'Hemingway', sites(:first).rollback_theme.title
0
- assert_match /rolled back/, flash[:notice]
0
- assert_redirected_to :controller => 'design', :action => 'index'
0
   end
0
 end
...
11
12
13
14
 
15
16
17
18
19
20
21
22
23
24
25
26
27
28
...
50
51
52
53
 
 
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
...
11
12
13
 
14
15
 
 
 
 
16
 
 
 
 
17
18
19
20
...
42
43
44
 
45
46
47
48
49
 
 
 
 
 
 
 
 
 
 
 
 
 
50
51
52
0
@@ -11,17 +11,9 @@
0
   end
0
   
0
   specify "should set attachment base path" do
0
- assert_equal Site.theme_path + 'site-1' + 'current', sites(:first).attachment_base_path
0
+ assert_equal Site.theme_path + 'site-1' + 'current', sites(:first).theme.path
0
   end
0
-
0
- specify "should set other themes path" do
0
- assert_equal Site.theme_path + 'site-1' + 'other', sites(:first).other_themes_path
0
- end
0
 
0
- specify "should set rollback themes path" do
0
- assert_equal Site.theme_path + 'site-1' + 'rollback', sites(:first).rollback_path
0
- end
0
-
0
   specify "should set current theme" do
0
     assert_kind_of Theme, sites(:first).theme
0
     assert_equal Site.theme_path + 'site-1' + 'current', sites(:first).theme.path
0
0
@@ -50,23 +42,11 @@
0
     theme = sites(:first).change_theme_to :encytemedia
0
     assert theme.current?
0
     assert theme.path.exist?, "#{theme.path.to_s} does not exist"
0
- assert_equal 'current', theme.name
0
+ assert_equal 'encytemedia', sites(:first).reload.current_theme_path
0
+ assert_equal 'encytemedia', theme.name
0
     assert_equal 'Encytemedia', theme.title
0
   end
0
 
0
- specify "should change theme and create rollback" do
0
- theme = sites(:first).change_theme_to :encytemedia
0
- assert sites(:first).rollback_theme.path.exist?, "#{sites(:first).rollback_theme.path.to_s} does not exist"
0
- assert_equal 'rollback', sites(:first).rollback_theme.name
0
- assert_equal 'Hemingway', sites(:first).rollback_theme.title
0
- end
0
-
0
- specify "should rollback theme" do
0
- sites(:first).rollback
0
- assert_equal 'Rollback', sites(:first).theme.title
0
- assert_equal 'Hemingway', sites(:first).rollback_theme.title
0
- end
0
-
0
   specify "should import theme" do
0
     sites(:first).import_theme sites(:first).theme_path + 'hemingway.zip', 'hemingway'
0
     assert_equal %w(current empty encytemedia hemingway), sites(:first).themes.collect(&:name)

Comments

    No one has commented yet.