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 !
dont use custom section template/layout if it doesn't exist

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@2213 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Mon Sep 18 18:16:58 -0700 2006
commit  dc4e8f4e6aa541cb24daeb3084e08ce15e8ae6b0
tree    a53ef319334f08957103ec0ad46608689a22c53d
parent  48e513d377de973535538a9a4163a2eb0be642e5
...
192
193
194
195
 
196
197
198
...
205
206
207
208
209
 
210
211
212
...
192
193
194
 
195
196
197
198
...
205
206
207
 
 
208
209
210
211
0
@@ -192,7 +192,7 @@ class Site < ActiveRecord::Base
0
     
0
     def set_preferred_template(section, template_type)
0
       preferred_template = section.template if [:page, :section].include?(template_type)
0
- preferred_template.blank? ? templates.find_preferred(template_type) : templates[preferred_template]
0
+ templates.find_preferred(template_type, preferred_template)
0
     end
0
     
0
     def set_layout_template(section, template_type)
0
@@ -205,8 +205,7 @@ class Site < ActiveRecord::Base
0
             when :search then search_layout
0
           end
0
         end
0
-
0
- templates[layout_template.blank? ? 'layout' : layout_template]
0
+ templates.find_preferred(:layout, layout_template)
0
     end
0
     
0
     def parse_template(template, assigns, controller)
...
8
9
10
11
 
 
12
13
14
...
8
9
10
 
11
12
13
14
15
0
@@ -8,7 +8,8 @@ module Mephisto
0
         :archive => [:archive, :index],
0
         :search => [:search, :archive, :index],
0
         :error => [:error, :index],
0
- :tag => [:tag, :archive, :index]
0
+ :tag => [:tag, :archive, :index],
0
+ :layout => [:layout]
0
       }
0
     
0
       @@template_types = (@@hierarchy.values.flatten.uniq << :layout).collect! { |f| "#{f}.liquid" }
...
54
55
56
 
 
57
58
59
...
200
201
202
203
204
205
206
...
54
55
56
57
58
59
60
61
...
202
203
204
 
205
206
207
0
@@ -54,6 +54,8 @@ Fixtures.class_eval do
0
   end
0
 end
0
 
0
+THEME_ROOT = File.join(RAILS_ROOT, 'tmp/themes')
0
+
0
 class Test::Unit::TestCase
0
   self.use_transactional_fixtures = true
0
   self.use_instantiated_fixtures = false
0
@@ -200,7 +202,6 @@ class Test::Unit::TestCase
0
     end
0
   end
0
 
0
- THEME_ROOT = File.join(RAILS_ROOT, 'tmp/themes')
0
   def prepare_theme_fixtures
0
     FileUtils.rm_rf THEME_ROOT
0
     FileUtils.mkdir_p THEME_ROOT
...
1
2
3
 
4
5
6
...
73
74
75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
 
3
4
5
6
...
73
74
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
109
110
111
112
113
114
115
116
117
0
@@ -1,6 +1,6 @@
0
 require File.dirname(__FILE__) + '/../test_helper'
0
 
0
-class TemplateTest < Test::Unit::TestCase
0
+context "Template" do
0
   fixtures :sites
0
 
0
   def setup
0
@@ -73,3 +73,45 @@ class TemplateTest < Test::Unit::TestCase
0
       assert_equal(expected_template_name.nil? ? nil : site.templates[expected_template_name], site.templates.find_preferred(template_type, options[:custom]))
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 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', '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', 'layouts', 'layout.liquid'), File.join(THEME_ROOT, 'site-1', '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

Comments

    No one has commented yet.