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 !
allow way to find themes for a site

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@2217 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Tue Sep 19 07:14:23 -0700 2006
commit  87dc9608d75855ba9c87097940fd379a1f893d5a
tree    179f9d54675387f2cc1cf1019a2ac5c19b74064c
parent  902481b2b1c696f99c73cb0ba555207e0875c90f
...
1
2
3
4
5
...
1
 
2
3
4
0
@@ -1,5 +1,4 @@
0
 class Admin::ThemesController < Admin::BaseController
0
-
0
   def index
0
   end
0
 
...
1
 
 
2
3
4
5
6
7
8
...
95
96
97
 
 
 
 
98
99
 
100
101
102
103
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
105
 
106
107
108
...
1
2
3
4
5
6
 
7
8
9
...
96
97
98
99
100
101
102
103
 
104
105
106
 
 
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
 
123
124
125
126
0
@@ -1,8 +1,9 @@
0
 class Site < ActiveRecord::Base
0
+ @@theme_path = Pathname.new(RAILS_ROOT) + 'themes'
0
+ cattr_reader :theme_path
0
   PERMALINK_OPTIONS = { 'year' => '\d{4}', 'month' => '\d{1,2}', 'day' => '\d{1,2}', 'permalink' => '[a-z0-9-]+', 'id' => '\d+' }
0
   PERMALINK_VAR = /^:([a-z]+)$/
0
 
0
- include Mephisto::Attachments::AttachmentMethods
0
   cattr_accessor :multi_sites_enabled
0
 
0
   has_many :sections do
0
@@ -95,14 +96,31 @@ class Site < ActiveRecord::Base
0
     theme.path
0
   end
0
 
0
+ def theme_path
0
+ @theme_path ||= self.class.theme_path + "site-#{id}"
0
+ end
0
+
0
   def attachment_base_path
0
- @attachment_base_path ||= File.join(RAILS_ROOT, 'themes', "site-#{id}", 'current')
0
+ @attachment_base_path ||= theme_path + 'current'
0
   end
0
   
0
- def site_themes_path
0
- @site_themes_path ||= File.join(RAILS_ROOT, 'themes', "site-#{id}", 'other')
0
+ def other_themes_path
0
+ @other_themes_path ||= theme_path + 'other'
0
+ end
0
+
0
+ def themes
0
+ return @themes unless @themes.nil?
0
+ @themes = []
0
+ FileUtils.mkdir_p other_themes_path
0
+ Dir.foreach other_themes_path do |e|
0
+ next if e.first == '.'
0
+ entry = other_themes_path + e
0
+ next unless entry.directory?
0
+ @themes << Theme.new(entry)
0
+ end
0
+ @themes
0
   end
0
-
0
+
0
   def theme
0
     return @theme unless @theme.nil?
0
     @theme = Theme.new(attachment_base_path)
...
1
2
3
4
5
6
 
 
 
 
 
 
 
 
 
 
 
7
8
9
10
11
12
13
14
15
 
 
16
17
18
...
26
27
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
30
...
1
2
 
3
 
 
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 
 
 
 
 
19
20
21
22
23
...
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
0
@@ -1,18 +1,23 @@
0
 class Theme
0
   attr_reader :path, :base_path
0
-
0
   def initialize(base)
0
- @base_path = base
0
- @path = Pathname.new(@base_path)
0
+ if base.is_a?(Pathname)
0
+ @base_path = base.to_s
0
+ @path = base
0
+ else
0
+ @base_path = base
0
+ @path = Pathname.new(@base_path)
0
+ end
0
+ end
0
+
0
+ def name
0
+ @name ||= @path.basename.to_s
0
   end
0
 
0
   def attachments
0
     return @attachments unless @attachments.nil?
0
- @attachments, @templates, @resources = [], [], []
0
- @attachments.send(:extend, Mephisto::Attachments::AttachmentMethods::InstanceMethods) ; @attachments.theme = self
0
- [@resources, @templates].each { |a| a.send(:extend, Mephisto::Attachments::AttachmentMethods::BaseMethods); a.theme = self }
0
- @resources.send(:extend, Mephisto::Attachments::ResourceMethods)
0
- @templates.send(:extend, Mephisto::Attachments::TemplateMethods)
0
+ @attachments, @templates, @resources = Attachments.new, Templates.new, Resources.new
0
+ [@attachments, @templates, @resources].each { |a| a.theme = self }
0
     Pathname.glob(File.join(base_path, '**/*')).each do |path|
0
       next unless path.file?
0
       @attachments << path
0
@@ -26,4 +31,26 @@ class Theme
0
       attachments && instance_variable_get("@#{attr}")
0
     end
0
   end
0
+
0
+ def export_as_zip(name, options = {})
0
+ path = options[:to] || '.'
0
+ Zip::ZipFile.open(File.join(path, "#{name}.zip"), Zip::ZipFile::CREATE) do |zip|
0
+ %w(templates layouts javascripts stylesheets images).each { |d| zip.dir.mkdir(d) }
0
+ write_theme_files_with zip.file
0
+ end
0
+ end
0
+
0
+ def export(name, options = {})
0
+ path = File.join(options[:to] || '.', name)
0
+ %w(templates layouts javascripts stylesheets images).each { |d| FileUtils.mkdir_p File.join(path, d) }
0
+ write_theme_files_with File, path
0
+ end
0
+
0
+ protected
0
+ def write_theme_files_with(file_class, path = '')
0
+ write_mode = file_class.is_a?(Zip::ZipFileSystem::ZipFsFile) ? 'w' : 'wb'
0
+ attachments.each do |full_path|
0
+ file_class.open((Pathname.new(path) + full_path.relative_path_from(self.path)).to_s, write_mode) { |f| f.write full_path.read }
0
+ end
0
+ end
0
 end
0
\ No newline at end of file
...
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
...
8
9
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
12
13
14
0
@@ -8,73 +8,6 @@
0
 
0
 <div id="themes">
0
   <ul id="themelist">
0
- <li class="theme">
0
- <h3>
0
- A nice theme
0
- <span class="thememeta">
0
- v0.5 | by Dude Yo
0
- </span>
0
- </h3>
0
- <img src="/images/mephisto/preview.png" alt="Theme preview" title="A nice theme (v0.5)" />
0
- <div class="tools" style="display:none">
0
- <ul>
0
- <li><a href="#" title="title">Use this theme</a></li>
0
- <li><a href="#" title="title">Edit source code</a></li>
0
- <li><a href="#" title="title">Change info</a></li>
0
- <li><a href="#" title="title">Export</a></li>
0
- </ul>
0
- </div>
0
- </li>
0
- <li class="theme" id="inuse">
0
- <h3>
0
- A nice theme
0
- <span class="thememeta">
0
- v0.5 | by Dude Yo
0
- </span>
0
- </h3>
0
- <img src="/images/mephisto/preview.png" alt="Theme preview" title="A nice theme (v0.5)" />
0
- <div class="tools" style="display:none">
0
- <ul>
0
- <li><a href="#" title="title">Use this theme</a></li>
0
- <li><a href="#" title="title">Edit source code</a></li>
0
- <li><a href="#" title="title">Change info</a></li>
0
- <li><a href="#" title="title">Export</a></li>
0
- </ul>
0
- </div>
0
- </li>
0
- <li class="theme">
0
- <h3>
0
- A nice theme
0
- <span class="thememeta">
0
- v0.5 | by Dude Yo
0
- </span>
0
- </h3>
0
- <img src="/images/mephisto/preview.png" alt="Theme preview" title="A nice theme (v0.5)" />
0
- <div class="tools" style="display:none">
0
- <ul>
0
- <li><a href="#" title="title">Use this theme</a></li>
0
- <li><a href="#" title="title">Edit source code</a></li>
0
- <li><a href="#" title="title">Change info</a></li>
0
- <li><a href="#" title="title">Export</a></li>
0
- </ul>
0
- </div>
0
- </li>
0
- <li class="theme">
0
- <h3>
0
- A nice theme
0
- <span class="thememeta">
0
- v0.5 | by Dude Yo
0
- </span>
0
- </h3>
0
- <img src="/images/mephisto/preview.png" alt="Theme preview" title="A nice theme (v0.5)" />
0
- <div class="tools" style="display:none">
0
- <ul>
0
- <li><a href="#" title="title">Use this theme</a></li>
0
- <li><a href="#" title="title">Edit source code</a></li>
0
- <li><a href="#" title="title">Change info</a></li>
0
- <li><a href="#" title="title">Export</a></li>
0
- </ul>
0
- </div>
0
- </li>
0
+<%= render :partial => "theme", :collection => site.themes %>
0
   </ul>
0
 </div>
0
\ No newline at end of file
...
 
1
2
3
4
5
6
 
7
8
9
...
37
38
39
40
 
41
42
43
44
...
1
2
3
4
5
6
 
7
8
9
10
...
38
39
40
 
41
42
43
44
45
0
@@ -1,9 +1,10 @@
0
+SITE_DIR = File.join(RAILS_ROOT, 'themes/site-' + (ENV['SITE_ID'] || '1'))
0
 namespace :db do
0
   desc "Loads a schema.rb file into the database and then loads the initial database fixtures."
0
   task :bootstrap do
0
     mkdir_p File.join(RAILS_ROOT, 'log')
0
     %w(environment db:schema:load db:bootstrap:load tmp:create).each { |t| Rake::Task[t].execute }
0
- site_dir = File.join(RAILS_ROOT, 'themes/site-1')
0
+ site_dir = SITE_DIR
0
     if File.exists?(site_dir)
0
       puts "skipping default theme creation..."
0
     else
0
@@ -37,7 +38,7 @@ namespace :db do
0
     
0
     desc "Copy default theme to site theme"
0
     task :copy_default_theme do
0
- FileUtils.cp_r File.join(RAILS_ROOT, 'themes/default'), File.join(RAILS_ROOT, 'themes/site-' + (ENV['SITE_ID'] || '1'), 'current')
0
+ FileUtils.cp_r File.join(RAILS_ROOT, 'themes/default'), File.join(SITE_DIR, 'current')
0
     end
0
   end
0
 end
0
\ No newline at end of file
...
1
2
3
 
4
5
6
7
8
9
10
11
12
13
14
15
...
1
2
3
4
5
 
 
 
 
 
 
 
 
6
7
8
0
@@ -1,15 +1,8 @@
0
 require File.join(RAILS_ROOT, 'app/models/site')
0
 
0
 class Site
0
+ @@theme_path = Pathname.new(RAILS_ROOT) + 'tmp/themes'
0
   attr_reader :recent_template_type, :recent_preferred_template, :recent_layout_template
0
-
0
- def attachment_base_path
0
- @attachment_base_path ||= File.join(RAILS_ROOT, 'tmp/themes', "site-#{id}", 'current')
0
- end
0
-
0
- def site_themes_path
0
- @site_themes_path ||= File.join(RAILS_ROOT, 'tmp/themes', "site-#{id}", 'other')
0
- end
0
   
0
   def set_template_type_for_with_testing(section, template_type)
0
     @recent_template_type = set_template_type_for_without_testing(section, template_type)
...
1
2
3
4
5
...
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
...
1
 
2
3
4
...
162
163
164
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
166
0
@@ -1,5 +1,4 @@
0
 require File.dirname(__FILE__) + '/../test_helper'
0
-
0
 context "Site" do
0
   fixtures :sites, :contents
0
 
0
@@ -163,53 +162,4 @@ context "Site Validations" do
0
     assert_valid @site
0
     assert_equal 'article/:id', @site.permalink_style
0
   end
0
-end
0
-
0
-context "Site Template" do
0
- fixtures :sites, :sections
0
-
0
- def setup
0
- prepare_theme_fixtures
0
- end
0
-
0
- specify "should raise error on missing template" do
0
- sites(:first).templates[:archive].unlink
0
- assert_raise Mephisto::MissingTemplateError do
0
- sites(:first).send(:parse_template, sites(:first).templates[:archive], {}, {})
0
- end
0
- end
0
-
0
- specify "should find preferred for site" do
0
- assert_site_template_name :home, :section
0
- end
0
-
0
- specify "should find fallback for site with preferred template" do
0
- FileUtils.rm File.join(THEME_ROOT, 'site-1', 'current', 'templates', 'home.liquid')
0
- assert_site_template_name :section, :section
0
- end
0
-
0
- specify "should find preferred for site layout" do
0
- FileUtils.cp File.join(THEME_ROOT, 'site-1', 'current', 'layouts', 'layout.liquid'), File.join(THEME_ROOT, 'site-1', 'current', 'layouts', 'custom_layout.liquid')
0
- sites(:first).sections.home.update_attribute :layout, 'custom_layout'
0
- assert_site_layout_name :custom_layout, :layout
0
- end
0
-
0
- specify "should find fallback for site with preferred layout" do
0
- sites(:first).sections.home.update_attribute :layout, 'custom_layout'
0
- assert_site_layout_name :layout
0
- end
0
-
0
- protected
0
- def assert_site_template_name(expected_template_name, template_type = nil, options = {})
0
- template_type ||= expected_template_name
0
- site = options[:site] || sites(:first)
0
- section = options[:section] || site.sections.home
0
- assert_equal(expected_template_name.nil? ? nil : site.templates[expected_template_name], site.send(:set_preferred_template, section, template_type))
0
- end
0
- def assert_site_layout_name(expected_template_name, template_type = nil, options = {})
0
- template_type ||= expected_template_name
0
- site = options[:site] || sites(:first)
0
- section = options[:section] || site.sections.home
0
- assert_equal(expected_template_name.nil? ? nil : site.templates[expected_template_name], site.send(:set_layout_template, section, template_type))
0
- end
0
 end
0
\ No newline at end of file
...
24
25
26
27
 
28
29
30
...
32
33
34
35
 
36
37
38
...
24
25
26
 
27
28
29
30
...
32
33
34
 
35
36
37
38
0
@@ -24,7 +24,7 @@ class ThemeTest < Test::Unit::TestCase
0
   ]
0
 
0
   def test_should_export_files
0
- sites(:first).attachments.export 'foo', :to => THEME_ROOT
0
+ sites(:first).theme.export 'foo', :to => THEME_ROOT
0
     
0
     THEME_FILES.each do |path|
0
       assert File.exists?(File.join(THEME_ROOT, 'foo', path)), "#{path} does not exist"
0
@@ -32,7 +32,7 @@ class ThemeTest < Test::Unit::TestCase
0
   end
0
 
0
   def test_should_export_files_as_zip
0
- sites(:first).attachments.export_as_zip 'foo', :to => THEME_ROOT
0
+ sites(:first).theme.export_as_zip 'foo', :to => THEME_ROOT
0
     
0
     assert File.exists?(File.join(THEME_ROOT, 'foo.zip'))
0
     

Comments

    No one has commented yet.