Changeset 313
- Timestamp:
- 2007-02-25 22:52:24 (2 years ago)
- Files:
-
- trunk/app/controllers/application.rb (modified) (2 diffs)
- trunk/app/helpers/application_helper.rb (modified) (5 diffs)
- trunk/app/helpers/version_helper.rb (modified) (1 diff)
- trunk/app/models/skin.rb (modified) (1 diff)
- trunk/app/models/template.rb (modified) (1 diff)
- trunk/app/models/text_document_version.rb (modified) (1 diff)
- trunk/app/views/contact/_title.rhtml (modified) (1 diff)
- trunk/app/views/document/_title.rhtml (modified) (1 diff)
- trunk/app/views/image/_title.rhtml (modified) (1 diff)
- trunk/app/views/main/_branch_title.rhtml (modified) (1 diff)
- trunk/app/views/main/_content_title.rhtml (modified) (1 diff)
- trunk/app/views/node/_groups.rhtml (modified) (1 diff)
- trunk/app/views/node/_title.rhtml (modified) (1 diff)
- trunk/app/views/note/_li.rhtml (modified) (1 diff)
- trunk/db/initialize/zena/base.yml (modified) (3 diffs)
- trunk/db/schema.rb (modified) (1 diff)
- trunk/lib/parser/lib/parser.rb (modified) (3 diffs)
- trunk/lib/parser/lib/rules/zena.rb (modified) (5 diffs)
- trunk/lib/parser/test/parser_test.rb (modified) (2 diffs)
- trunk/lib/parser/test/testhelp.rb (modified) (1 diff)
- trunk/lib/parser/test/zafu.yml (modified) (1 diff)
- trunk/lib/secure.rb (modified) (7 diffs)
- trunk/test/fixtures/document_contents.yml (modified) (1 diff)
- trunk/test/fixtures/nodes.yml (modified) (13 diffs)
- trunk/test/fixtures/versions.yml (modified) (1 diff)
- trunk/test/functional/application_controller_test.rb (modified) (2 diffs)
- trunk/test/functional/main_controller_test.rb (modified) (3 diffs)
- trunk/test/helpers/basic.yml (modified) (1 diff)
- trunk/test/helpers/relations.yml (modified) (1 diff)
- trunk/test/helpers/test_all.rb (modified) (1 diff)
- trunk/test/unit/h_main_test.rb (modified) (4 diffs)
- trunk/test/unit/secure_test.rb (modified) (1 diff)
- trunk/test/unit/template_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/app/controllers/application.rb
r285 r313 12 12 private 13 13 def render_and_cache(opts={}) 14 opts = {:template=>opts} if opts.kind_of?(String)15 opts = {:template=>@node[:template], :cache=>true}.merge(opts)16 14 @node ||= secure(Node) { Node.find(ZENA_ENV[:root_id]) } 15 opts = {:mode=>opts} if opts.kind_of?(String) 16 opts = {:skin=>@node[:skin], :cache=>true}.merge(opts) 17 17 18 18 @project = @node.project 19 @date ||= params[:date] ? parse_date(params[:date]) : Time.now 19 20 render :template=>template_url(opts), :layout=>false 20 21 … … 26 27 27 28 def template_url(opts={}) 28 template_name = opts[:template] || 'default' 29 return '/templates/default' if template_name == 'default' # while testing 30 template = secure(Template) { Template.best_match(:template=>template_name, :class=>@node.class, :mode=>opts[:mode]) } 31 return '/templates/default' unless template 32 sess = @session 33 response.template.instance_eval { @session = sess } 34 template.template_url(response.template) 29 skin = opts[:skin] || 'default' 30 skin_obj = nil 31 skin_helper = nil 32 # find best match 33 mode = opts[:mode] 34 mode = nil if (mode.nil? || mode == '') 35 klass = @node.class.to_s.downcase 36 template = nil 37 choices = [] 38 39 if skin == 'default' 40 # 3. default_class_mode (101) 41 choices << ["default","any_#{klass}_#{mode}"] if mode && klass 42 # 4. default__mode (100) 43 choices << ["default","any__#{mode}"] if mode 44 # 7. default_class ( 1) 45 choices << ["default","any_#{klass}"] if klass 46 # 8. default ( 0) 47 choices << ["default","any"] 48 else 49 # (mode / template / class) 50 # 1. template_class_mode (111) 51 choices << [skin,"any_#{klass}_#{mode}"] if mode && skin && klass 52 # 2. template__mode (110) 53 choices << [skin,"any__#{mode}"] if mode && skin 54 # 3. default_class_mode (101) 55 choices << ["default","any_#{klass}_#{mode}"] if mode && klass 56 # 4. default__mode (100) 57 choices << ["default","any__#{mode}"] if mode 58 # 5. template_class ( 11) 59 choices << [skin,"any_#{klass}"] if skin && klass 60 # 6. template ( 10) 61 choices << [skin,"any"] if skin 62 # 7. default_class ( 1) 63 choices << ["default","any_#{klass}"] if klass 64 # 8. default ( 0) 65 choices << ["default","any"] 66 end 67 if skin 68 begin 69 skin_obj = secure(Skin) { Skin.find_by_name(skin) } 70 sess = @session 71 response.template.instance_eval { @session = sess } 72 skin_helper = response.template 73 rescue 74 skin_obj = nil 75 end 76 end 77 choices.each do |skin, template_name| 78 # find the fixed template 79 template = "/templates/fixed/#{skin}/#{template_name}" 80 break if File.exist?("#{RAILS_ROOT}/app/views#{template}.rhtml") 81 # find the compiled version 82 template = "/templates/compiled/#{skin}/#{template_name}_#{lang}.rhtml" 83 break if File.exist?("#{RAILS_ROOT}/app/views#{template}") 84 # search in the skin_obj 85 if skin_obj 86 break if template = skin_obj.template_url_for_name(template_name, skin_helper) 87 end 88 # continue search 89 end 90 return template 91 rescue ActiveRecord::RecordNotFound 92 # skin name was bad 93 return '/templates/fixed/default/any' 35 94 end 36 95 trunk/app/helpers/application_helper.rb
r309 r313 571 571 #TODO: test 572 572 # Return the list of possible templates 573 def form_templates 574 return @form_templates if @form_templates 575 @form_templates = [] 576 Dir.foreach(File.join(RAILS_ROOT, 'app', 'views', 'templates')) do |file| 577 next unless file =~ /^([a-zA-Z0-9]+)\.rhtml$/ 578 next if ['index', 'not_found'].include?($1) 579 @form_templates << $1 580 end 581 @form_templates 573 def form_skins 574 return @form_skins if @form_skins 575 @form_skins = secure(Skin) { Skin.find(:all, :order=>'name ASC') }.map {|r| r[:name]} 576 Dir.foreach(File.join(RAILS_ROOT, 'app', 'views', 'templates', 'fixed')) do |file| 577 next unless file =~ /^([a-zA-Z0-9_]+)$/ 578 @form_skins << $1 unless @form_skins.include?($1) 579 end 580 @form_skins 582 581 end 583 582 … … 620 619 621 620 622 # Used by edit_buttons621 # Used by node_actions 623 622 def form_action(action, version_id=nil, link_text=nil) 624 623 version_id ||= @node.v_id … … 664 663 res << form_action('drive',version_id, opts[:text]) 665 664 end 666 "<ul class='actions'><li>#{res.join("</li>\n<li>")}</li></ul>" 665 if res != [] 666 "<ul class='actions'><li>#{res.join("</li>\n<li>")}</li></ul>" 667 else 668 "" 669 end 667 670 end 668 671 … … 793 796 # size can be either :small or :large, options are 794 797 # :node=>object 795 def author(opts={})798 def show_author(opts={}) 796 799 obj = opts[:node] || @node 797 800 res = [] … … 826 829 if options[:href] 827 830 node = node.relation(options[:href]) || node 828 end 829 url = node_url(node) 831 end 830 832 text = options[:text] || node.version.title 831 link_to(text,url.merge(options[:url])) 833 if opts[:dash] 834 "<a href='##{opts[:dash]}'>#{text}</a>" 835 else 836 url = node_url(node) 837 link_to(text,url.merge(options[:url])) 838 end 832 839 end 833 840 trunk/app/helpers/version_helper.rb
r213 r313 1 1 module VersionHelper 2 2 def form_tabs 3 tmplt = @node. template|| 'default'3 tmplt = @node.skin || 'default' 4 4 tabs = [['text','text'],['title','title'],['help','help']] 5 5 ["#{tmplt}_#{@node.class.to_s.downcase}", "any_#{@node.class.to_s.downcase}"].each do |filename| trunk/app/models/skin.rb
r280 r313 2 2 # of a site. 3 3 class Skin < Template 4 # opts can be :mode and :klass 5 def template_url_for_name(template_name, helper) 6 if template_name == 'any' 7 template = self 8 else 9 template = secure(Template) { Template.find(:conditions=>["parent_id = ? AND name = ?", self[:id], template_name])} 10 end 11 tmpl_name = "#{template_name}_#{visitor_lang}.rhtml" 12 tmpl_dir = "/templates/compiled/#{self[:name]}" 13 FileUtils::mkpath("#{RAILS_ROOT}/app/views#{tmpl_dir}") 14 # render for the current lang 15 res = ZafuParser.new(template.version.text, :helper=>helper).render 16 File.open("#{RAILS_ROOT}/app/views#{tmpl_dir}/#{tmpl_name}", "wb") { |f| f.syswrite(res) } 17 return "#{tmpl_dir}/#{tmpl_name}" 18 rescue ActiveRecord::RecordNotFound 19 nil 20 end 4 21 end trunk/app/models/template.rb
r280 r313 1 1 class Template < TextDocument 2 class << self 3 # Return the best template for the current :mode, :class and :template. Must be used within 'secure' scope. 4 def best_match(opts={}) 5 mode = opts[:mode] 6 mode = nil if (mode.nil? || mode == '') 7 klass = opts[:class] ? opts[:class].to_s.downcase : nil 8 tmpl = opts[:template] 9 template = nil 10 choices = [] 11 # (mode / template / class) 12 # 1. template_class_mode (111) 13 choices << "#{tmpl}_#{klass}_#{mode}" if mode && tmpl && klass 14 # 2. template__mode (110) 15 choices << "#{tmpl}__#{mode}" if mode && tmpl 16 # 3. default_class_mode (101) 17 choices << "default_#{klass}_#{mode}" if mode && klass 18 # 4. default__mode (100) 19 choices << "default__#{mode}" if mode 20 # 5. template_class ( 11) 21 choices << "#{tmpl}_#{klass}" if tmpl && klass 22 # 6. template ( 10) 23 choices << tmpl if tmpl 24 # 7. default_class ( 1) 25 choices << "default_#{klass}" if klass 26 # 8. default ( 0) 27 choices << "default" 28 choices.each do |template_name| 29 # we are in secure scope already 30 break if template = Template.find_by_name(template_name) 2 3 # TODO: test 4 def sweep_cache 5 super 6 if self.kind_of?(Skin) 7 tmpl = "#{name}/any" 8 else 9 tmpl = "#{parent[:name]}/#{name}" 10 end 11 ZENA_ENV[:languages].each do |lang| 12 filepath = File.join(RAILS_ROOT,'app', 'views', 'templates', 'compiled') 13 filepath = "#{filepath}/#{tmpl}_#{lang}.rhtml" 14 if File.exist?(filepath) 15 File.delete(filepath) 31 16 end 32 return template33 17 end 34 end35 36 # opts can be :mode and :klass37 def template_url(helper)38 temp_url = "#{self[:name]}_#{visitor_lang}"39 40 # 2. does the file for the current lang exist ?41 path = File.join(RAILS_ROOT, 'app', 'views', 'templates', "#{temp_url}.rhtml")42 if File.exist?(path) && (File.stat(path).mtime > version.updated_at)43 # we are done44 return "/templates/#{temp_url}"45 end46 # render for the current lang47 res = ZafuParser.new(version.text, :helper=>helper).render48 File.open(path, "wb") { |f| f.syswrite(res) }49 return "/templates/#{temp_url}"50 18 end 51 19 end trunk/app/models/text_document_version.rb
r266 r313 3 3 TextDocumentContent 4 4 end 5 6 5 private 7 6 end trunk/app/views/contact/_title.rhtml
r182 r313 3 3 <div class='title'> 4 4 <h1 class="s<%= @node.v_status %>"><%= show_title %><br/> 5 <ul class='node_actions'><%= edit_button(:all) %></ul>5 <ul class='node_actions'><%= node_actions(:actions=>:all) %></ul> 6 6 </h1> 7 7 <%= author(:large) %> trunk/app/views/document/_title.rhtml
r182 r313 7 7 <td class='subtitle'> 8 8 <h1 class="s<%= @node.v_status %>"><%= show_title %><br/> 9 <ul class='node_actions'><%= edit_button(:all) %></ul>9 <ul class='node_actions'><%= node_actions(:actions=>:all) %></ul> 10 10 </h1> 11 11 <%= author(:large) %><%#= plug :links %> trunk/app/views/image/_title.rhtml
r182 r313 2 2 <div class='header'> 3 3 <h1 class='s<%= @node.v_status %>'><%= show_title %> 4 <ul class='node_actions'><%= edit_button(:all) %></ul>4 <ul class='node_actions'><%= node_actions(:actions=>:all) %></ul> 5 5 </h1> 6 6 <div class='subtitle'><%= author(:large) %><%#= plug :links %></div> trunk/app/views/main/_branch_title.rhtml
r199 r313 1 1 <div class='s<%= branch.class.to_s.downcase %>' ><%= link_to branch.name, :prefix => prefix, :controller => 'main', :action=>'site_tree', :id=>branch[:id], :prefix=>prefix %> 2 <% if session[:user] %><span class='readers'><%= edit_button(:drive, :node => branch, :text=>readers_for(branch)) %></span><% end %>2 <% if session[:user] %><span class='readers'><%= node_actions(:actions=>:drive, :node => branch, :text=>readers_for(branch)) %></span><% end %> 3 3 <span class='class'><%= link_to(branch.class.to_s.downcase, node_url(branch)) %></span></div> trunk/app/views/main/_content_title.rhtml
r132 r313 6 6 <td class='subtitle'> 7 7 <h1 class="s<%= @node.v_status %>"><span id='v_title<%= @node.v_id %>'><%= @node.v_title %></span><br/> 8 <ul class='node_actions'><%= edit_button(:all) %></ul>8 <ul class='node_actions'><%= node_actions(:actions=>:all) %></ul> 9 9 </h1> 10 10 <%= author(:large) %><%#= plug :links %> trunk/app/views/node/_groups.rhtml
r299 r313 14 14 <% if inherit_modes %> 15 15 <%= form_remote_tag(:with=>'groups', :url=>{:controller=>'node', :action=>'update', :id=>@node[:id], :rnd=>rnd}) %> 16 <li><label><%= trans('mode') %></label><%= select('node', 'inherit', inherit_modes, {}, {:onchange=>"Zena.update_rwp(this.value,'#{groups_list.index(@node.ref[:rgroup_id])}','#{groups_list.index(@node.ref[:wgroup_id])}','#{groups_list.index(@node.ref[:pgroup_id])}', '#{form_ templates.index(@node.ref[:template])}'); return false;"}) %></li>16 <li><label><%= trans('mode') %></label><%= select('node', 'inherit', inherit_modes, {}, {:onchange=>"Zena.update_rwp(this.value,'#{groups_list.index(@node.ref[:rgroup_id])}','#{groups_list.index(@node.ref[:wgroup_id])}','#{groups_list.index(@node.ref[:pgroup_id])}', '#{form_skins.index(@node.ref[:skin])}'); return false;"}) %></li> 17 17 <li><label><%= trans('publishers') %></label><%= select('node', 'pgroup_id', form_groups, { :include_blank => true }, {:disabled=>(@node[:inherit] != 0)}) %></li> 18 18 <li><label><%= trans('writers') %></label><%= select('node', 'wgroup_id', form_groups, { :include_blank => true }, {:disabled=>(@node[:inherit] != 0)}) %></li> 19 19 <li><label><%= trans('readers') %></label><%= select('node', 'rgroup_id', form_groups, { :include_blank => true }, {:disabled=>(@node[:inherit] != 0)}) %></li> 20 <li><label><%= trans(' template') %></label><%= select('node', 'template', form_templates,{}, {:disabled=>(@node[:inherit] != 0)}) %></li>20 <li><label><%= trans('skin') %></label><%= select('node', 'skin', form_skins,{}, {:disabled=>(@node[:inherit] != 0)}) %></li> 21 21 <li class='submit'><%= submit_tag transb('change') %></li> 22 22 <%= end_form_tag %> trunk/app/views/node/_title.rhtml
r182 r313 2 2 <div class='header'> 3 3 <h1 class='s<%= @node.v_status %>'><%= show_title %> 4 <ul class='node_actions'><%= edit_button(:all) %></ul>4 <ul class='node_actions'><%= node_actions(:actions=>:all) %></ul> 5 5 </h1> 6 6 <div class='subtitle'><%= author(:large) %><%#= plug :links %></div> trunk/app/views/note/_li.rhtml
r240 r313 3 3 <div class='li_s<%= li.v_status %>'> 4 4 <p class='log_at'><%= @note_date ? short_time(li.event_at) : short_date(li.log_at) %></p> 5 <p class='title'><%= show_title( li, :project=>(li.project != @node.project)) %></p>5 <p class='title'><%= show_title(:node=>li, :project=>(li.project != @node.project)) %></p> 6 6 <p class='sign'><%= li.v_author.initials %></p> 7 <ul class='node_actions'><%= edit_button(:all, :node=>li) %></ul>7 <ul class='node_actions'><%= node_actions(:actions=>:all, :node=>li) %></ul> 8 8 </div> 9 9 </div> trunk/db/initialize/zena/base.yml
r302 r313 45 45 max_status: 50 46 46 inherit: 0 47 template:default47 skin: default 48 48 rgroup_id: 1 49 49 wgroup_id: 2 … … 62 62 max_status: 50 63 63 inherit: 1 64 template:default64 skin: default 65 65 rgroup_id: 1 66 66 wgroup_id: 2 … … 78 78 max_status: 50 79 79 inherit: 1 80 template:default80 skin: default 81 81 rgroup_id: 1 82 82 wgroup_id: 2 trunk/db/schema.rb
r297 r313 120 120 t.column "basepath", :text 121 121 t.column "dgroup_id", :integer 122 t.column " template", :string122 t.column "skin", :string 123 123 end 124 124 trunk/lib/parser/lib/parser.rb
r311 r313 85 85 @context = context 86 86 # name param is propagated into children (used to label parts of a large template) 87 if name = @params[:name]87 if @params && name = @params[:name] 88 88 @params.delete(:name) 89 89 if @context[:name] … … 111 111 res = @method 112 112 end 113 res + @text113 after_render(res + @text) 114 114 end 115 115 … … 165 165 def before_render 166 166 true 167 end 168 169 def after_render(text) 170 text 167 171 end 168 172 trunk/lib/parser/lib/rules/zena.rb
r312 r313 32 32 @params.delete(:store) 33 33 end 34 if @params[:anchor] && !@context[:preflight] 35 @anchor = r_anchor 36 @params.delete(:anchor) 37 end 34 38 true 39 end 40 41 def after_render(text) 42 if @anchor 43 @anchor + text 44 else 45 text 46 end 35 47 end 36 48 … … 82 94 "<%= trans(#{text}) %>" 83 95 end 96 end 97 98 def r_anchor(obj=node) 99 "<a name='#{node_class.to_s.downcase}<%= #{obj}[:id] %>'/>" 84 100 end 85 101 … … 289 305 out "<% #{list}.each do |#{var}| -%>" 290 306 end 307 out r_anchor(var) if @anchor # insert anchor inside the each loop 308 @anchor = nil 291 309 res = expand_with(:node=>var) 292 310 if @context[:template_url] && @pass[:edit] … … 469 487 def r_link 470 488 # text 489 @blocks = [] # do not use block content for link. 471 490 text = get_text_for_erb 472 491 if text … … 488 507 url = '' 489 508 end 509 if @params[:dash] == 'true' 510 dash = ", :dash=>\"#{node_class.to_s.downcase}\#{#{node}[:id]}\"" 511 else 512 dash = '' 513 end 490 514 # link 491 "<%= node_link(:node=>#{lnode}#{text}#{href}#{url} ) %>"515 "<%= node_link(:node=>#{lnode}#{text}#{href}#{url}#{dash}) %>" 492 516 end 493 517 trunk/lib/parser/test/parser_test.rb
r311 r313 8 8 def r_text 9 9 @params[:text] 10 end 11 12 def r_repeat 13 count = @params[:count] || 2 14 count.to_i.times do 15 out expand_with 16 end 10 17 end 11 18 … … 24 31 end 25 32 class ZazenTest < Test::Unit::TestCase 26 testfile :zafu, :zafu_asset, :zafu_insight 33 testfile :zafu, :zafu_asset, :zafu_insight, :zazen 27 34 def test_single 28 do_test('zafu_insight', 'simple') 35 do_test('zafu', 'preserve_newlines') 36 end 37 def test_zazen_image_no_image 38 file = 'zazen' 39 test = 'image_no_image' 40 res = @@test_parsers[file].new_with_url("/#{test.gsub('_', '/')}", :helper=>DummyHelper.new(@@test_strings[file])).render(:images=>false) 41 assert_equal @@test_strings[file][test]['res'], res 29 42 end 30 43 make_tests trunk/lib/parser/test/testhelp.rb
r279 r313 90 90 def do_test(file, test) 91 91 res = @@test_parsers[file].new_with_url("/#{test.gsub('_', '/')}", :helper=>DummyHelper.new(@@test_strings[file])).render 92 if @@test_strings[file][test]['res'][0..0] == "/" 93 assert_match %r{@@test_strings[file][test]['res'][1..-2]}, res 94 else 95 assert_equal @@test_strings[file][test]['res'], res 92 if @@test_strings[file][test]['res'] 93 if @@test_strings[file][test]['res'][0..0] == "/" 94 assert_match %r{#{@@test_strings[file][test]['res'][1..-2]}}m, res 95 else 96 assert_equal @@test_strings[file][test]['res'], res 97 end 96 98 end 97 99 end trunk/lib/parser/test/zafu.yml
r311 r313 219 219 src: "include_with: <z:include template='/name/title'><h1 do='with' part='title' do='hello'/></z:include>" 220 220 res: "include_with: title: <h1>hello world!</h1>" 221 222 preserve_newlines: 223 src: | 224 <z:repeat><p do='test'>blah</p> 225 </z:repeat>ok 226 227 res: | 228 [test]<p>blah</p>[/test] 229 [test]<p>blah</p>[/test] 230 ok 231 trunk/lib/secure.rb
r299 r313 336 336 return false 337 337 end 338 [:rgroup_id, :wgroup_id, :pgroup_id, : template].each do |sym|338 [:rgroup_id, :wgroup_id, :pgroup_id, :skin].each do |sym| 339 339 # not defined = inherit 340 340 self[sym] ||= ref[sym] … … 354 354 self[:wgroup_id] = ref.wgroup_id 355 355 self[:pgroup_id] = ref.pgroup_id 356 self[: template ] = ref.template356 self[:skin ] = ref.skin 357 357 when -1 358 358 # private … … 376 376 errors.add('wgroup_id', "you cannot change this") unless wgroup_id == ref.wgroup_id 377 377 errors.add('pgroup_id', "you cannot change this") unless pgroup_id == ref.pgroup_id 378 errors.add(' template' , "you cannot change this") unless template == ref.template378 errors.add('skin' , "you cannot change this") unless skin == ref.skin 379 379 end 380 380 else 381 381 errors.add('inherit', "bad inheritance mode") 382 end 383 errors.add('template', "unknown template '#{template}.rhtml'") unless File.exist?(File.join(RAILS_ROOT, 'app','views', 'templates', "#{template}.rhtml")) 382 end 384 383 385 384 # publish_from can only be set by the object itself by setting @publish_from … … 498 497 unless inherit == old.inherit 499 498 if old.can_visible? || ( old.can_manage? && (old.max_status_with_heirs < Zena::Status[:pub]) ) 500 [:rgroup_id, :wgroup_id, :pgroup_id, : template].each do |sym|499 [:rgroup_id, :wgroup_id, :pgroup_id, :skin].each do |sym| 501 500 self[sym] = ref[sym] 502 501 end … … 539 538 errors.add('wgroup_id', "you cannot change this") unless wgroup_id == old.wgroup_id 540 539 errors.add('pgroup_id', "you cannot change this") unless pgroup_id == old.pgroup_id 541 # but you can change templates and name540 # but you can change skins and name 542 541 end 543 542 else … … 547 546 errors.add('wgroup_id', "you cannot change this") unless wgroup_id == old.wgroup_id 548 547 errors.add('pgroup_id', "you cannot change this") unless pgroup_id == old.pgroup_id 549 errors.add(' template', "you cannot change this") unless template == old.template548 errors.add('skin', "you cannot change this") unless skin == old.skin 550 549 end 551 550 else 552 551 errors.add('inherit', "bad inheritance mode") 553 end 554 errors.add('template', "unknown template") unless template == old[:template] || File.exist?(File.join(RAILS_ROOT, 'app', 'views', 'templates', "#{template}.rhtml")) 555 @needs_inheritance_spread = (rgroup_id != old.rgroup_id || wgroup_id != old.wgroup_id || pgroup_id != old.pgroup_id || template != old.template) 552 end 553 @needs_inheritance_spread = (rgroup_id != old.rgroup_id || wgroup_id != old.wgroup_id || pgroup_id != old.pgroup_id || skin != old.skin) 556 554 return errors.empty? 557 555 end … … 617 615 h[:wgroup_id] = wgroup_id 618 616 h[:pgroup_id] = pgroup_id 619 h[: template ] = template617 h[:skin ] = skin 620 618 # there should never be errors here (if we had the correct rights to change 621 619 # the current node, we can change it's children), so we skip validation trunk/test/fixtures/document_contents.yml
r61 r313 56 56 ext: 'pdf' 57 57 size: 63569 58 59 wiki_skin: 60 id: 7 61 version_id: 38 62 type: TextDocumentContent 63 content_type: "text/html" 64 name: "wiki" 65 ext: 'zafu' 66 size: trunk/test/fixtures/nodes.yml
r301 r313 1 1 <% @dates = " created_at: 2006-03-10\n updated_at: 2006-04-11\n publish_from: 2006-03-10" %> 2 <% @defaults = "#@dates\n ref_lang: en\n max_status: 50\n template:default" %>2 <% @defaults = "#@dates\n ref_lang: en\n max_status: 50\n skin: default" %> 3 3 <% @rights = " rgroup_id: 1\n wgroup_id: 3\n pgroup_id: 4" %> 4 4 zena: … … 16 16 max_status: 50 17 17 inherit: 0 18 template:default18 skin: default 19 19 <%= @rights %> 20 20 … … 213 213 max_status: 30 214 214 inherit: 1 215 template:default215 skin: default 216 216 <%= @rights %> 217 217 … … 228 228 max_status: 50 229 229 log_at: 2006-03-15 230 template:default230 skin: default 231 231 <%= @dates %> 232 232 <%= @rights %> … … 258 258 ref_lang: en 259 259 max_status: 50 260 template:wiki260 skin: wiki 261 261 rgroup_id: 1 262 262 wgroup_id: 1 … … 275 275 ref_lang: en 276 276 max_status: 50 277 template:wiki277 skin: wiki 278 278 rgroup_id: 1 279 279 wgroup_id: 1 … … 292 292 ref_lang: en 293 293 max_status: 50 294 template:wiki294 skin: wiki 295 295 rgroup_id: 1 296 296 wgroup_id: 1 … … 354 354 user_id: 5 355 355 inherit: 0 356 template:default356 skin: default 357 357 <%= @dates %> 358 358 ref_lang: en … … 383 383 user_id: 4 384 384 inherit: 0 385 template:default385 skin: default 386 386 <%= @dates %> 387 387 ref_lang: en … … 405 405 ref_lang: en 406 406 max_status: 30 407 template:default407 skin: default 408 408 rgroup_id: 1 409 409 wgroup_id: 3 … … 424 424 ref_lang: en 425 425 max_status: 30 426 template:default426 skin: default 427 427 rgroup_id: 1 428 428 wgroup_id: 3 … … 443 443 ref_lang: en 444 444 max_status: 30 445 template:default445 skin: default 446 446 rgroup_id: 1 447 447 wgroup_id: 3 … … 460 460 <%= @defaults %> 461 461 <%= @rights %> 462 463 wiki_skin: 464 id: 33 465 type: Skin 466 kpath: NPDTTS 467 name: wiki 468 project_id: 1 469 parent_id: 5 470 user_id: 4 471 inherit: 1 472 log_at: 2006-10-03 473 <%= @defaults %> 474 <%= @rights %> trunk/test/fixtures/versions.yml
r302 r313 517 517 number: 1 518 518 <%= @defaults %> 519 520 wiki_template_en: 521 type: TextDocumentVersion 522 id: 38 523 node_id: 33 524 user_id: 4 525 comment: very simple template for wiki 526 title: wiki template 527 summary: This page is a *Letter*. 528 text: | 529 <html> 530 <head> 531 <title do='show' attr='v_title'>some title</title> 532 </head> 533 <body> 534 <h1 do='show_title'>super title</h1> 535 <h2><a name='contents'/>contents</h2> 536 <ul do='pages'> 537 <li do='each' do='link' dash='true'>some link</li> 538 </ul> 539 540 <z:pages do='each'> 541 <h3><z:title anchor='true' actions='all'/> <a href='#contents'>top</a></h3> 542 <z:text/> 543 </z:pages> 544 </body> 545 </html> 546 lang: en 547 number: 1 548 <%= @defaults %> trunk/test/functional/application_controller_test.rb
r219 r313 20 20 # render_and_cache and authorize tested in MainControllerTest 21 21 22 def test_ template22 def test_skin 23 23 wiki = @controller.send(:secure,Node) { Node.find(nodes_id(:wiki)) } 24 assert_equal 'wiki', wiki. template24 assert_equal 'wiki', wiki.skin 25 25 @controller.instance_eval{ @node = wiki } 26 assert_equal 'wiki', @controller.send(: template)26 assert_equal 'wiki', @controller.send(:skin) 27 27 end 28 28 29 def test_class_ template29 def test_class_skin 30 30 proj = @controller.send(:secure,Node) { Node.find(nodes_id(:cleanWater)) } 31 assert_equal 'default', proj. template31 assert_equal 'default', proj.skin 32 32 @controller.instance_eval{ @node = proj } 33 assert_equal 'default_project', @controller.send(: template)34 proj. template= 'truc'35 assert_equal 'truc', proj. template36 assert_equal 'default', @controller.send(: template)33 assert_equal 'default_project', @controller.send(:skin) 34 proj.skin = 'truc' 35 assert_equal 'truc', proj.skin 36 assert_equal 'default', @controller.send(:skin) 37 37 end 38 38 39 def test_general_class_ template39 def test_general_class_skin 40 40 letter = @controller.send(:secure, Node) { Node.find(nodes_id(:letter)) } 41 assert_equal 'default', letter. template41 assert_equal 'default', letter.skin 42 42 @controller.instance_eval{ @node = letter } 43 assert_equal 'any_letter', @controller.send(: template)43 assert_equal 'any_letter', @controller.send(:skin) 44 44 end 45 45 46 def test_custom_ template47 assert_equal 'index', @controller.send(: template,'index')46 def test_custom_skin 47 assert_equal 'index', @controller.send(:skin,'index') 48 48 end 49 49 50 def test_mode_ template50 def test_mode_skin 51 51 @controller.instance_eval { @params = {:mode=>'wiki'} } 52 52 proj = @controller.send(:secure,Node) { Node.find(nodes_id(:cleanWater)) } 53 53 @controller.instance_eval { @node = proj } 54 assert_equal 'wiki', @controller.send(: template)54 assert_equal 'wiki', @controller.send(:skin) 55 55 end 56 56 … … 59 59 doc = @controller.send(:secure, Node) { Node.find(nodes_id(:water_pdf)) } 60 60 @controller.instance_eval{ @node = page } 61 assert_equal 'forms/default', @controller.send(:form_ template)61 assert_equal 'forms/default', @controller.send(:form_skin) 62 62 @controller.instance_eval{ @node = doc } 63 assert_equal 'forms/any_document', @controller.send(:form_ template)63 assert_equal 'forms/any_document', @controller.send(:form_skin) 64 64 end 65 65 trunk/test/functional/main_controller_test.rb
r219 r313 14 14 end 15 15 16 def test_index17 assert_routing '/en', {:controller=>'main', :action=>'index', :prefix=>'en'}18 assert_routing '/', {:controller=>'main', :action=>'redirect'}19 get 'index', :prefix=>'en'20 assert_response :success21 assert_template 'index'22 end23 24 16 def test_render_and_cache 25 17 get 'index'
