<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>app/models/attachments.rb</filename>
    </added>
    <added>
      <filename>app/models/resources.rb</filename>
    </added>
    <added>
      <filename>app/models/templates.rb</filename>
    </added>
    <added>
      <filename>app/views/admin/themes/_theme.rhtml</filename>
    </added>
    <added>
      <filename>test/fixtures/themes/site-1/other/encytemedia/about.yml</filename>
    </added>
    <added>
      <filename>test/fixtures/themes/site-1/other/encytemedia/preview.png</filename>
    </added>
    <added>
      <filename>test/unit/site_template_test.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,5 +1,4 @@
 class Admin::ThemesController &lt; Admin::BaseController
-
   def index
   end
 </diff>
      <filename>app/controllers/admin/themes_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,8 +1,9 @@
 class Site &lt; ActiveRecord::Base
+  @@theme_path = Pathname.new(RAILS_ROOT) + 'themes'
+  cattr_reader :theme_path
   PERMALINK_OPTIONS = { 'year' =&gt; '\d{4}', 'month' =&gt; '\d{1,2}', 'day' =&gt; '\d{1,2}', 'permalink' =&gt; '[a-z0-9-]+', 'id' =&gt; '\d+' }
   PERMALINK_VAR     = /^:([a-z]+)$/
 
-  include Mephisto::Attachments::AttachmentMethods
   cattr_accessor :multi_sites_enabled
 
   has_many  :sections do
@@ -95,14 +96,31 @@ class Site &lt; ActiveRecord::Base
     theme.path
   end
 
+  def theme_path
+    @theme_path ||= self.class.theme_path + &quot;site-#{id}&quot;
+  end
+
   def attachment_base_path
-    @attachment_base_path ||= File.join(RAILS_ROOT, 'themes', &quot;site-#{id}&quot;, 'current')
+    @attachment_base_path ||= theme_path + 'current'
   end
   
-  def site_themes_path
-    @site_themes_path ||= File.join(RAILS_ROOT, 'themes', &quot;site-#{id}&quot;, 'other')
+  def other_themes_path
+    @other_themes_path ||= theme_path + 'other'
+  end
+
+  def themes
+    return @themes unless @themes.nil?
+    @themes = []
+    FileUtils.mkdir_p other_themes_path
+    Dir.foreach other_themes_path do |e|
+      next if e.first == '.'
+      entry = other_themes_path + e
+      next unless entry.directory?
+      @themes &lt;&lt; Theme.new(entry)
+    end
+    @themes
   end
-  
+
   def theme
     return @theme unless @theme.nil?
     @theme = Theme.new(attachment_base_path)</diff>
      <filename>app/models/site.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,18 +1,23 @@
 class Theme
   attr_reader :path, :base_path
-  
   def initialize(base)
-    @base_path = base
-    @path      = Pathname.new(@base_path)
+    if base.is_a?(Pathname)
+      @base_path = base.to_s
+      @path      = base
+    else
+      @base_path = base
+      @path      = Pathname.new(@base_path)
+    end
+  end
+
+  def name
+    @name ||= @path.basename.to_s
   end
 
   def attachments
     return @attachments unless @attachments.nil?
-    @attachments, @templates, @resources = [], [], []
-    @attachments.send(:extend, Mephisto::Attachments::AttachmentMethods::InstanceMethods) ; @attachments.theme = self
-    [@resources, @templates].each { |a| a.send(:extend, Mephisto::Attachments::AttachmentMethods::BaseMethods); a.theme = self }
-    @resources.send(:extend, Mephisto::Attachments::ResourceMethods)
-    @templates.send(:extend, Mephisto::Attachments::TemplateMethods)
+    @attachments, @templates, @resources = Attachments.new, Templates.new, Resources.new
+    [@attachments, @templates, @resources].each { |a| a.theme = self }
     Pathname.glob(File.join(base_path, '**/*')).each do |path|
       next unless path.file?
       @attachments &lt;&lt; path
@@ -26,4 +31,26 @@ class Theme
       attachments &amp;&amp; instance_variable_get(&quot;@#{attr}&quot;)
     end
   end
+
+  def export_as_zip(name, options = {})
+    path = options[:to] || '.'
+    Zip::ZipFile.open(File.join(path, &quot;#{name}.zip&quot;), Zip::ZipFile::CREATE) do |zip|
+      %w(templates layouts javascripts stylesheets images).each { |d| zip.dir.mkdir(d) }
+      write_theme_files_with zip.file
+    end
+  end
+
+  def export(name, options = {})
+    path = File.join(options[:to] || '.', name)
+    %w(templates layouts javascripts stylesheets images).each { |d| FileUtils.mkdir_p File.join(path, d) }
+    write_theme_files_with File, path
+  end
+
+  protected
+    def write_theme_files_with(file_class, path = '')
+      write_mode = file_class.is_a?(Zip::ZipFileSystem::ZipFsFile) ? 'w' : 'wb'
+      attachments.each do |full_path| 
+        file_class.open((Pathname.new(path) + full_path.relative_path_from(self.path)).to_s, write_mode) { |f| f.write full_path.read }
+      end
+    end
 end
\ No newline at end of file</diff>
      <filename>app/models/theme.rb</filename>
    </modified>
    <modified>
      <diff>@@ -8,73 +8,6 @@
 
 &lt;div id=&quot;themes&quot;&gt;
   &lt;ul id=&quot;themelist&quot;&gt;
-    &lt;li class=&quot;theme&quot;&gt;
-      &lt;h3&gt;
-        A nice theme
-        &lt;span class=&quot;thememeta&quot;&gt;
-          v0.5 | by Dude Yo
-        &lt;/span&gt;
-      &lt;/h3&gt;
-      &lt;img src=&quot;/images/mephisto/preview.png&quot; alt=&quot;Theme preview&quot; title=&quot;A nice theme (v0.5)&quot; /&gt;
-      &lt;div class=&quot;tools&quot; style=&quot;display:none&quot;&gt;
-        &lt;ul&gt;
-          &lt;li&gt;&lt;a href=&quot;#&quot; title=&quot;title&quot;&gt;Use this theme&lt;/a&gt;&lt;/li&gt;
-          &lt;li&gt;&lt;a href=&quot;#&quot; title=&quot;title&quot;&gt;Edit source code&lt;/a&gt;&lt;/li&gt;
-          &lt;li&gt;&lt;a href=&quot;#&quot; title=&quot;title&quot;&gt;Change info&lt;/a&gt;&lt;/li&gt;
-          &lt;li&gt;&lt;a href=&quot;#&quot; title=&quot;title&quot;&gt;Export&lt;/a&gt;&lt;/li&gt;
-        &lt;/ul&gt;
-      &lt;/div&gt;
-    &lt;/li&gt;
-    &lt;li class=&quot;theme&quot; id=&quot;inuse&quot;&gt;
-      &lt;h3&gt;
-        A nice theme
-        &lt;span class=&quot;thememeta&quot;&gt;
-          v0.5 | by Dude Yo
-        &lt;/span&gt;
-      &lt;/h3&gt;
-      &lt;img src=&quot;/images/mephisto/preview.png&quot; alt=&quot;Theme preview&quot; title=&quot;A nice theme (v0.5)&quot; /&gt;
-      &lt;div class=&quot;tools&quot; style=&quot;display:none&quot;&gt;
-        &lt;ul&gt;
-          &lt;li&gt;&lt;a href=&quot;#&quot; title=&quot;title&quot;&gt;Use this theme&lt;/a&gt;&lt;/li&gt;
-          &lt;li&gt;&lt;a href=&quot;#&quot; title=&quot;title&quot;&gt;Edit source code&lt;/a&gt;&lt;/li&gt;
-          &lt;li&gt;&lt;a href=&quot;#&quot; title=&quot;title&quot;&gt;Change info&lt;/a&gt;&lt;/li&gt;
-          &lt;li&gt;&lt;a href=&quot;#&quot; title=&quot;title&quot;&gt;Export&lt;/a&gt;&lt;/li&gt;
-        &lt;/ul&gt;
-      &lt;/div&gt;
-    &lt;/li&gt;
-    &lt;li class=&quot;theme&quot;&gt;
-      &lt;h3&gt;
-        A nice theme
-        &lt;span class=&quot;thememeta&quot;&gt;
-          v0.5 | by Dude Yo
-        &lt;/span&gt;
-      &lt;/h3&gt;
-      &lt;img src=&quot;/images/mephisto/preview.png&quot; alt=&quot;Theme preview&quot; title=&quot;A nice theme (v0.5)&quot; /&gt;
-      &lt;div class=&quot;tools&quot; style=&quot;display:none&quot;&gt;
-        &lt;ul&gt;
-          &lt;li&gt;&lt;a href=&quot;#&quot; title=&quot;title&quot;&gt;Use this theme&lt;/a&gt;&lt;/li&gt;
-          &lt;li&gt;&lt;a href=&quot;#&quot; title=&quot;title&quot;&gt;Edit source code&lt;/a&gt;&lt;/li&gt;
-          &lt;li&gt;&lt;a href=&quot;#&quot; title=&quot;title&quot;&gt;Change info&lt;/a&gt;&lt;/li&gt;
-          &lt;li&gt;&lt;a href=&quot;#&quot; title=&quot;title&quot;&gt;Export&lt;/a&gt;&lt;/li&gt;
-        &lt;/ul&gt;
-      &lt;/div&gt;
-    &lt;/li&gt;
-    &lt;li class=&quot;theme&quot;&gt;
-      &lt;h3&gt;
-        A nice theme
-        &lt;span class=&quot;thememeta&quot;&gt;
-          v0.5 | by Dude Yo
-        &lt;/span&gt;
-      &lt;/h3&gt;
-      &lt;img src=&quot;/images/mephisto/preview.png&quot; alt=&quot;Theme preview&quot; title=&quot;A nice theme (v0.5)&quot; /&gt;
-      &lt;div class=&quot;tools&quot; style=&quot;display:none&quot;&gt;
-        &lt;ul&gt;
-          &lt;li&gt;&lt;a href=&quot;#&quot; title=&quot;title&quot;&gt;Use this theme&lt;/a&gt;&lt;/li&gt;
-          &lt;li&gt;&lt;a href=&quot;#&quot; title=&quot;title&quot;&gt;Edit source code&lt;/a&gt;&lt;/li&gt;
-          &lt;li&gt;&lt;a href=&quot;#&quot; title=&quot;title&quot;&gt;Change info&lt;/a&gt;&lt;/li&gt;
-          &lt;li&gt;&lt;a href=&quot;#&quot; title=&quot;title&quot;&gt;Export&lt;/a&gt;&lt;/li&gt;
-        &lt;/ul&gt;
-      &lt;/div&gt;
-    &lt;/li&gt;
+&lt;%= render :partial =&gt; &quot;theme&quot;, :collection =&gt; site.themes %&gt;
   &lt;/ul&gt;
 &lt;/div&gt;
\ No newline at end of file</diff>
      <filename>app/views/admin/themes/index.rhtml</filename>
    </modified>
    <modified>
      <diff>@@ -1,9 +1,10 @@
+SITE_DIR = File.join(RAILS_ROOT, 'themes/site-' + (ENV['SITE_ID'] || '1'))
 namespace :db do
   desc &quot;Loads a schema.rb file into the database and then loads the initial database fixtures.&quot;
   task :bootstrap do
     mkdir_p File.join(RAILS_ROOT, 'log')
     %w(environment db:schema:load db:bootstrap:load tmp:create).each { |t| Rake::Task[t].execute }
-    site_dir = File.join(RAILS_ROOT, 'themes/site-1')
+    site_dir = SITE_DIR
     if File.exists?(site_dir)
       puts &quot;skipping default theme creation...&quot;
     else
@@ -37,7 +38,7 @@ namespace :db do
     
     desc &quot;Copy default theme to site theme&quot;
     task :copy_default_theme do
-      FileUtils.cp_r File.join(RAILS_ROOT, 'themes/default'), File.join(RAILS_ROOT, 'themes/site-' + (ENV['SITE_ID'] || '1'), 'current')
+      FileUtils.cp_r File.join(RAILS_ROOT, 'themes/default'), File.join(SITE_DIR, 'current')
     end
   end
 end
\ No newline at end of file</diff>
      <filename>lib/tasks/bootstrap.rake</filename>
    </modified>
    <modified>
      <diff>@@ -1,15 +1,8 @@
 require File.join(RAILS_ROOT, 'app/models/site')
 
 class Site
+  @@theme_path = Pathname.new(RAILS_ROOT) + 'tmp/themes'
   attr_reader :recent_template_type, :recent_preferred_template, :recent_layout_template
-
-  def attachment_base_path
-    @attachment_base_path ||= File.join(RAILS_ROOT, 'tmp/themes', &quot;site-#{id}&quot;, 'current')
-  end
-
-  def site_themes_path
-    @site_themes_path ||= File.join(RAILS_ROOT, 'tmp/themes', &quot;site-#{id}&quot;, 'other')
-  end
   
   def set_template_type_for_with_testing(section, template_type)
     @recent_template_type = set_template_type_for_without_testing(section, template_type)</diff>
      <filename>test/mocks/test/site.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,4 @@
 require File.dirname(__FILE__) + '/../test_helper'
-
 context &quot;Site&quot; do
   fixtures :sites, :contents
 
@@ -163,53 +162,4 @@ context &quot;Site Validations&quot; do
     assert_valid @site
     assert_equal 'article/:id', @site.permalink_style
   end
-end
-
-context &quot;Site Template&quot; do
-  fixtures :sites, :sections
-
-  def setup
-    prepare_theme_fixtures
-  end
-
-  specify &quot;should raise error on missing template&quot; do
-    sites(:first).templates[:archive].unlink
-    assert_raise Mephisto::MissingTemplateError do
-      sites(:first).send(:parse_template, sites(:first).templates[:archive], {}, {})
-    end
-  end
-
-  specify &quot;should find preferred for site&quot; do
-    assert_site_template_name :home, :section
-  end
-
-  specify &quot;should find fallback for site with preferred template&quot; do
-    FileUtils.rm File.join(THEME_ROOT, 'site-1', 'current', 'templates', 'home.liquid')
-    assert_site_template_name :section, :section
-  end
-
-  specify &quot;should find preferred for site layout&quot; do
-    FileUtils.cp File.join(THEME_ROOT, 'site-1', 'current', 'layouts', 'layout.liquid'), File.join(THEME_ROOT, 'site-1', 'current', 'layouts', 'custom_layout.liquid')
-    sites(:first).sections.home.update_attribute :layout, 'custom_layout'
-    assert_site_layout_name :custom_layout, :layout
-  end
-
-  specify &quot;should find fallback for site with preferred layout&quot; do
-    sites(:first).sections.home.update_attribute :layout, 'custom_layout'
-    assert_site_layout_name :layout
-  end
-
-  protected
-    def assert_site_template_name(expected_template_name, template_type = nil, options = {})
-      template_type ||= expected_template_name
-      site            = options[:site] || sites(:first)
-      section         = options[:section] || site.sections.home
-      assert_equal(expected_template_name.nil? ? nil : site.templates[expected_template_name], site.send(:set_preferred_template, section, template_type))
-    end
-    def assert_site_layout_name(expected_template_name, template_type = nil, options = {})
-      template_type ||= expected_template_name
-      site            = options[:site] || sites(:first)
-      section         = options[:section] || site.sections.home
-      assert_equal(expected_template_name.nil? ? nil : site.templates[expected_template_name], site.send(:set_layout_template, section, template_type))
-    end
 end
\ No newline at end of file</diff>
      <filename>test/unit/site_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -24,7 +24,7 @@ class ThemeTest &lt; Test::Unit::TestCase
   ]
 
   def test_should_export_files
-    sites(:first).attachments.export 'foo', :to =&gt; THEME_ROOT
+    sites(:first).theme.export 'foo', :to =&gt; THEME_ROOT
     
     THEME_FILES.each do |path|
       assert File.exists?(File.join(THEME_ROOT, 'foo', path)), &quot;#{path} does not exist&quot;
@@ -32,7 +32,7 @@ class ThemeTest &lt; Test::Unit::TestCase
   end
 
   def test_should_export_files_as_zip
-    sites(:first).attachments.export_as_zip 'foo', :to =&gt; THEME_ROOT
+    sites(:first).theme.export_as_zip 'foo', :to =&gt; THEME_ROOT
     
     assert File.exists?(File.join(THEME_ROOT, 'foo.zip'))
     </diff>
      <filename>test/unit/theme_test.rb</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>lib/mephisto/attachments/attachment_methods.rb</filename>
    </removed>
    <removed>
      <filename>lib/mephisto/attachments/resource_methods.rb</filename>
    </removed>
    <removed>
      <filename>lib/mephisto/attachments/template_methods.rb</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>902481b2b1c696f99c73cb0ba555207e0875c90f</id>
    </parent>
  </parents>
  <author>
    <name>technoweenie</name>
    <email>technoweenie@567b1171-46fb-0310-a4c9-b4bef9110e78</email>
  </author>
  <url>http://github.com/francois/mephisto/commit/87dc9608d75855ba9c87097940fd379a1f893d5a</url>
  <id>87dc9608d75855ba9c87097940fd379a1f893d5a</id>
  <committed-date>2006-09-19T07:14:23-07:00</committed-date>
  <authored-date>2006-09-19T07:14:23-07:00</authored-date>
  <message>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</message>
  <tree>179f9d54675387f2cc1cf1019a2ac5c19b74064c</tree>
  <committer>
    <name>technoweenie</name>
    <email>technoweenie@567b1171-46fb-0310-a4c9-b4bef9110e78</email>
  </committer>
</commit>
