Changeset 315
- Timestamp:
- 2007-02-26 23:07:02 (2 years ago)
- Files:
-
- trunk/app/controllers/application.rb (modified) (4 diffs)
- trunk/app/models/skin.rb (modified) (1 diff)
- trunk/app/views/version/preview.rjs (modified) (1 diff)
- trunk/config/environments/development.rb (modified) (1 diff)
- trunk/doc/README_FOR_APP (modified) (1 diff)
- trunk/lib/parser/lib/parser.rb (modified) (4 diffs)
- trunk/lib/parser/lib/rules/zafu.rb (modified) (1 diff)
- trunk/lib/parser/lib/rules/zena.rb (modified) (4 diffs)
- trunk/lib/parser/test/parser_test.rb (modified) (1 diff)
- trunk/lib/parser/test/zafu.yml (modified) (1 diff)
- trunk/public/stylesheets/zen.css (modified) (2 diffs)
- trunk/test/fixtures/document_contents.yml (modified) (1 diff)
- trunk/test/fixtures/nodes.yml (modified) (1 diff)
- trunk/test/fixtures/versions.yml (modified) (1 diff)
- trunk/test/helpers/basic.yml (modified) (3 diffs)
- trunk/test/helpers/relations.yml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/app/controllers/application.rb
r313 r315 28 28 def template_url(opts={}) 29 29 skin = opts[:skin] || 'default' 30 skin_obj = nil30 @skin_obj = nil 31 31 skin_helper = nil 32 32 # find best match … … 67 67 if skin 68 68 begin 69 skin_obj = secure(Skin) { Skin.find_by_name(skin) }69 @skin_obj = secure(Skin) { Skin.find_by_name(skin) } 70 70 sess = @session 71 71 response.template.instance_eval { @session = sess } 72 72 skin_helper = response.template 73 73 rescue 74 skin_obj = nil74 @skin_obj = nil 75 75 end 76 76 end … … 82 82 template = "/templates/compiled/#{skin}/#{template_name}_#{lang}.rhtml" 83 83 break if File.exist?("#{RAILS_ROOT}/app/views#{template}") 84 # search in the skin_obj85 if skin_obj86 break if template = skin_obj.template_url_for_name(template_name, skin_helper)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 87 end 88 88 # continue search … … 94 94 end 95 95 96 # TODO...97 96 def template_text_for_url(url) 98 return "NOT IMPLEMENTED YET (#{url})"99 97 url = url[1..-1] # strip leading '/' 100 98 url = url.split('/') 101 template = secure(Skin) { Skin.find_by_path(url) } 99 skin_name = url.shift 100 if @skin_obj[:name] == skin_name 101 skin = @skin_obj 102 end 103 skin ||= secure(Skin) { Skin.find_by_name(skin_name) } 104 template = skin.template_for_path(url) 102 105 template.version.text 103 rescue ActiveRecord::RecordNotFound106 rescue 104 107 return nil 105 108 end trunk/app/models/skin.rb
r313 r315 6 6 if template_name == 'any' 7 7 template = self 8 zafu_url = "/#{self[:name]}/any" 8 9 else 9 template = secure(Template) { Template.find(:conditions=>["parent_id = ? AND name = ?", self[:id], template_name])} 10 template = secure(Template) { Template.find(:first, :conditions=>["parent_id = ? AND name = ?", self[:id], template_name])} 11 zafu_url = "/#{self[:name]}/#{template_name}" 10 12 end 11 tmpl_name = "#{template_name}_#{visitor_lang} .rhtml"13 tmpl_name = "#{template_name}_#{visitor_lang}" 12 14 tmpl_dir = "/templates/compiled/#{self[:name]}" 13 15 FileUtils::mkpath("#{RAILS_ROOT}/app/views#{tmpl_dir}") 14 16 # render for the current lang 15 res = ZafuParser.new (template.version.text, :helper=>helper).render16 File.open("#{RAILS_ROOT}/app/views#{tmpl_dir}/#{tmpl_name} ", "wb") { |f| f.syswrite(res) }17 res = ZafuParser.new_with_url(zafu_url, :helper=>helper).render 18 File.open("#{RAILS_ROOT}/app/views#{tmpl_dir}/#{tmpl_name}.rhtml", "wb") { |f| f.syswrite(res) } 17 19 return "#{tmpl_dir}/#{tmpl_name}" 18 20 rescue ActiveRecord::RecordNotFound 19 21 nil 20 22 end 23 24 def template_for_path(path) 25 Skin.logger.info "[#{name}] GET (#{path.inspect})" 26 current = self 27 if path == ['any'] 28 return current 29 else 30 while path != [] 31 template_name = path.shift 32 Skin.logger.info "[#{name}] GET ('parent_id = #{current[:id]} AND name = '#{template_name}')" 33 begin 34 current = secure(Template) { Template.find(:first, :conditions=>["parent_id = ? AND name = ?", current[:id], template_name])} 35 Skin.logger.info "OK" 36 rescue ActiveRecord::RecordNotFound 37 Skin.logger.info "NOT FOUND" 38 break 39 end 40 end 41 if path == [] 42 current 43 else 44 nil 45 end 46 end 47 rescue ActiveRecord::RecordNotFound 48 nil 49 end 21 50 end trunk/app/views/version/preview.rjs
r279 r315 1 1 # page.replace_html "template", @html 2 2 3 page << "try {" 3 4 page.replace_html "v_title#{@preview_id}", @v_title 5 page << "} catch(err) {}" 6 page << "try {" 4 7 page.replace_html "v_summary#{@preview_id}", zazen(@v_summary, :pretty_code=>true) unless @node.kind_of?(Note) 8 page << "} catch(err) {}" 9 page << "try {" 5 10 page.replace_html "v_text#{@preview_id}", zazen(@v_text, :pretty_code=>true) 11 page << "} catch(err) {}" 6 12 # trunk/config/environments/development.rb
r175 r315 16 16 config.action_controller.perform_caching = false 17 17 config.action_view.cache_template_extensions = false 18 config.action_view.debug_rjs = true18 #config.action_view.debug_rjs = true 19 19 20 20 # Don't care if the mailer can't send trunk/doc/README_FOR_APP
r286 r315 27 27 We should use attr_protected instead of filtering forms. 28 28 * Remove all .utc (now using ENV['TZ']) 29 * Provide a 'grows with zena' // 'runs with zena' logo and link 30 * Provide a link from zena to teti.ch 29 31 === Optimization & Cache 30 32 * sweep public page cache : trunk/lib/parser/lib/parser.rb
r313 r315 24 24 # Retrieve the template text in the current folder or as an absolute path. 25 25 # This method is used when 'including' text 26 def find_template_text(url, helper, current_folder='/') 26 def find_template_text(url, helper, current_folder=nil) 27 current_folder ||= '/' 27 28 # remove trailing '/' 28 29 if current_folder[-1..-1] == '/' … … 88 89 @params.delete(:name) 89 90 if @context[:name] 90 @context[:name] <<"/#{name}"91 @context[:name] += "/#{name}" 91 92 else 92 93 @context[:name] = name … … 182 183 # fetch text 183 184 text = @text 185 @options[:included_history] ||= [] 186 @options[:current_folder] ||= '/' 184 187 @text, absolute_url = self.class.find_template_text(@params[:template], @options[:helper], @options[:current_folder]) 185 188 if absolute_url … … 365 368 res << b 366 369 else 367 res << b.render(new_context )370 res << b.render(new_context.dup) 368 371 if pass = b.pass 369 372 if pass[:part] trunk/lib/parser/lib/rules/zafu.rb
r311 r315 7 7 @context = context 8 8 @html_tag_done = false 9 unless @html_tag 10 if @params[:id] || @params[:class] 11 @html_tag = @params[:tag] || 'div' 12 @params.delete(:tag) 13 @html_tag_params = {} 14 [:id, :class].each do |k| 15 @html_tag_params[k] = @params[k] if @params[k] 16 @params.delete(k) 17 end 18 end 19 end 9 20 res = super 10 21 if (@context[:parts] || {})[@context[:name]] trunk/lib/parser/lib/rules/zena.rb
r313 r315 24 24 end 25 25 end 26 inline_methods :login_link, :visitor_link, :search_box, : menu, :path_links, :lang_links26 inline_methods :login_link, :visitor_link, :search_box, :show_menu, :path_links, :lang_links 27 27 direct_methods :uses_calendar 28 28 … … 97 97 98 98 def r_anchor(obj=node) 99 "<a name='#{node_class.to_s.downcase}<%= #{obj}[:id] %>' />"99 "<a name='#{node_class.to_s.downcase}<%= #{obj}[:id] %>'></a>" 100 100 end 101 101 … … 113 113 end 114 114 res << "%>" 115 if @params[:status] 115 if @params[:status] == 'true' || (@params[:status].nil? && @params[:actions]) 116 116 res = "<div class='s<%= #{node}.version.status %>'>#{res}</div>" 117 117 end … … 362 362 begin Module::const_get(klass) rescue "NilClass" end 363 363 cond = "#{node}.kind_of?(#{klass})" 364 elsif klass = (@params[:klass] || @params[:class])364 elsif klass = @params[:klass] 365 365 begin Module::const_get(klass) rescue "NilClass" end 366 366 cond = "#{node}.class == #{klass}" trunk/lib/parser/test/parser_test.rb
r313 r315 33 33 testfile :zafu, :zafu_asset, :zafu_insight, :zazen 34 34 def test_single 35 do_test('zafu', ' preserve_newlines')35 do_test('zafu', 'names') 36 36 end 37 37 def test_zazen_image_no_image trunk/lib/parser/test/zafu.yml
r313 r315 229 229 [test]<p>blah</p>[/test] 230 230 ok 231 231 232 names: 233 src: "<p do='void' name='root'><p do='inspect' name='first'/><p do='inspect' name='second'/></p>" 234 res: "<p>[inspect {> :name=>'root/first'}]<p/>[/inspect][inspect {> :name=>'root/second'}]<p/>[/inspect]</p>" 235 236 default_tag: 237 src: "<z:void class='test'>blah</z:void>" 238 res: "<div class='test'>blah</div>" 239 240 set_tag_param: 241 src: "<z:void class='test' tag='p'>blah</z:void>" 242 res: "<p class='test'>blah</p>" trunk/public/stylesheets/zen.css
r277 r315 97 97 .actions li:hover a { border-bottom:5px solid orange; } 98 98 99 .node_actions:hover { visibility:visible; }100 101 99 /* INLINE FORMS */ 102 100 .inline_form { margin:2px; padding:3px; background:#9FA6AC; border:1px dotted grey;} … … 158 156 /* NOTES */ 159 157 #left { position:absolute; top:125px; left:20px; width:220px; } 158 #left ul { margin:0 0 1em 1em;} 159 #left li { padding:2px;} 160 160 #add_note, #add_note_form { margin-left:1em } 161 161 #add_note { padding:10px 3px;} trunk/test/fixtures/document_contents.yml
r314 r315 65 65 ext: 'html' 66 66 size: 67 68 wiki_layout: 69 id: 8 70 version_id: 39 71 type: TextDocumentContent 72 content_type: "text/html" 73 name: "layout" 74 ext: 'html' 75 size: trunk/test/fixtures/nodes.yml
r313 r315 470 470 user_id: 4 471 471 inherit: 1 472 log_at: 2006-10-03 473 <%= @defaults %> 474 <%= @rights %> 472 <%= @defaults %> 473 <%= @rights %> 474 475 wiki_layout: 476 id: 34 477 type: Template 478 kpath: NPDTT 479 name: layout 480 project_id: 1 481 parent_id: 33 482 user_id: 4 483 inherit: 1 484 <%= @defaults %> 485 <%= @rights %> trunk/test/fixtures/versions.yml
r313 r315 523 523 node_id: 33 524 524 user_id: 4 525 comment: very simple templatefor wiki525 comment: very simple skin for wiki 526 526 title: wiki template 527 summary: This page is a *Letter*.527 summary: Very simple skin. 528 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> 529 <z:include template='layout'> 530 <z:with id='left' part='body/left'> 531 <a name='contents'></a><h2 do='trans'>Contents</h2> 536 532 <ul do='pages'> 537 <li do='each' do='link' dash='true'>some link</li> 533 <li do='each'><z:link dash='true'>some link</z:link> 534 <ul do='pages'> 535 <li do='each' do='link' dash='true'>sub link</li> 536 </ul> 537 </li> 538 538 </ul> 539 539 </z:with> 540 <z:with id='content' class='content' part='body/main/content'> 540 541 <z:pages do='each'> 541 <h 3><z:title anchor='true' actions='all'/> <a href='#contents'>top</a></h3>542 <h2><z:title anchor='true' actions='all'/></h2> 542 543 <z:text/> 544 <z:pages do='each'> 545 <h3><z:title anchor='true' actions='all'/></h3> 546 <z:text/> 547 </z:pages> 543 548 </z:pages> 544 </body> 549 </z:with> 550 lang: en 551 number: 1 552 <%= @defaults %> 553 554 layout_template_en: 555 type: TextDocumentVersion 556 id: 39 557 node_id: 34 558 user_id: 4 559 comment: layout for wiki 560 title: wiki template 561 summary: Layout for the wiki skin. 562 text: | 563 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 564 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 565 566 <html xmlns="http://www.w3.org/1999/xhtml" do='void' lang="en" set_lang='[v_lang]' xml:lang='en'> 567 <head> 568 <title do='show' attr='v_title' name='title'>node title</title> 569 <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> 570 <meta http-equiv="Content-Language" do='void' content="fr-fr" tset_content='[v_lang]_content' /> 571 572 <link href="/stylesheets/zen.css" rel="Stylesheet" type="text/css" /> 573 <link href="/stylesheets/comment.css" rel="Stylesheet" type="text/css" /> 574 <link href="/stylesheets/search.css" rel="Stylesheet" type="text/css" /> 575 <link href="/stylesheets/code.css" rel="Stylesheet" type="text/css" /> 576 <z:javascripts list='prototype,effects,zena'/> 577 <z:uses_calendar/> 578 </head> 579 580 <body do='void' name='body'> 581 <div class="navbar"> 582 <div id='lang' do='lang_links'><a>en</a> | <b>fr</b></div> 583 <div id='path' do='path_links'><ul><li><a href='#'>first</a></li> / <li><a href='#'>second</a></li> / <li><a href='#' class='current'>here</a></li></ul></div> 584 <div id='login' do='login_link'><a href='#'>login</a></div> 585 <div id='visitor' do='visitor_link'><a href='#'>visitor name</a></div> 586 <div id='search' do='search_box'><div class='search'><form><input type='text' id='search' name='search'/></form></div></div> 587 </div> 588 589 <div id='menu' do='show_menu'> 590 <ul class='menu'><li><a>first</a></li> 591 <li><a>second</a><ul><li><a>sub</a></li><li><a>sub</a><ul><li><a>subsub</a></li></ul></li></ul></li> 592 </ul> 593 </div> 594 595 <div id='logo' do='link' href='root'><img src='img/logo.png' width='220' height='100'/></div> 596 597 <z:flash_messages/> 598 599 <div id="left" do='void' name='left'> 600 </div> 601 <div id="main" do='void' name='main'> 602 603 <div class='content' id='content' do='void' name='content'> 604 dummy content 605 </div> 606 607 <div id="right" do='void' name='right'> 608 </div> 609 </div> 610 </body> 545 611 </html> 546 612 lang: en trunk/test/helpers/basic.yml
r313 r315 114 114 anchor: 115 115 src: "<z:anchor/>" 116 res: "<a name='node12' />"116 res: "<a name='node12'></a>" 117 117 118 118 show_title_anchor: 119 119 src: "<z:title anchor='true'/>" 120 res: "<a name='node12' /><span id='v_title12'>status title</span>"120 res: "<a name='node12'></a><span id='v_title12'>status title</span>" 121 121 122 122 show_attr_anchor: 123 123 src: "<z:show attr='name' anchor='true'/>" 124 res: "<a name='node12' />status"124 res: "<a name='node12'></a>status" 125 125 126 126 link_version: … … 134 134 node: 'opening' 135 135 src: "<z:traductions><z:each join=', '><z:link tattr='lang' dash='true' anchor='true'/></z:each></z:traductions>" 136 res: "<a name='version17' /><a href='#version17'>french</a>"136 res: "<a name='version17'></a><a href='#version17'>french</a>" 137 137 138 138 title: … … 222 222 223 223 case_when: 224 src: "<z:case><z:when kind_of='Document'>this is a document</z:when><z:when class='Page'>Page</z:when><z:when status='pub'>Pub</z:when>"224 src: "<z:case><z:when kind_of='Document'>this is a document</z:when><z:when klass='Page'>Page</z:when><z:when status='pub'>Pub</z:when>" 225 225 tem: "<% if false -%><% elsif @node.kind_of?(Document) -%>this is a document<% elsif @node.class == Page -%>Page<% elsif @node.version[:status] == 50 -%>Pub<% end -%>" 226 226 res: "Page" trunk/test/helpers/relations.yml
r313 r315 176 176 pages_anchor: 177 177 src: "<z:project><z:pages do='each' join=', '><z:show attr='name' anchor='true'/></z:pages></z:project>" 178 res: "<a name='node13' />lake, <a name='node12'/>status, <a name='node27'/>track"178 res: "<a name='node13'></a>lake, <a name='node12'></a>status, <a name='node27'></a>track"
