Changeset 370
- Timestamp:
- 2007-03-23 14:33:07 (2 years ago)
- Files:
-
- trunk/app/controllers/application.rb (modified) (3 diffs)
- trunk/app/helpers/application_helper.rb (modified) (4 diffs)
- trunk/app/models/contact.rb (modified) (1 diff)
- trunk/app/models/site.rb (modified) (1 diff)
- trunk/app/models/skin.rb (modified) (3 diffs)
- trunk/app/models/user.rb (modified) (2 diffs)
- trunk/db/init/images.yml (modified) (1 diff)
- trunk/db/init/trans_phrases.yml (modified) (1 diff)
- trunk/lib/parser/lib/parser.rb (modified) (3 diffs)
- trunk/lib/parser/lib/rules/zafu.rb (modified) (12 diffs)
- trunk/lib/parser/lib/rules/zena.rb (modified) (4 diffs)
- trunk/lib/parser/test/parser_test.rb (modified) (1 diff)
- trunk/test/fixtures/links.yml (modified) (1 diff)
- trunk/test/fixtures/trans_phrases.yml (modified) (1 diff)
- trunk/test/fixtures/trans_values.yml (modified) (1 diff)
- trunk/test/fixtures/versions.yml (modified) (1 diff)
- trunk/test/helpers/basic.yml (modified) (4 diffs)
- trunk/test/helpers/relations.yml (modified) (1 diff)
- trunk/test/helpers/test_all.rb (modified) (1 diff)
- trunk/test/helpers/testhelp.rb (modified) (1 diff)
- trunk/test/unit/site_test.rb (modified) (1 diff)
- trunk/test/zena_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/app/controllers/application.rb
r361 r370 192 192 193 193 # TODO: implement 194 def template_url_for_asset(type,url) 194 def template_url_for_asset(opts) 195 195 196 # 1. find in current skin ? 196 # 2. find in corresponding public directory ? 197 case type 198 when :stylesheet 199 when :link 200 when :script 201 end 202 # 3. find in site ? 197 url = opts[:current_template][1..-1].split('/') + opts[:src].split('/') 198 url.compact! 199 skin_name = url.shift 200 if @skin_obj && @skin_obj[:name] == skin_name 201 skin = @skin_obj 202 end 203 skin ||= secure(Skin) { Skin.find_by_name(skin_name) } 204 asset = skin.asset_for_path(url.join('/'), Document) 205 asset ? url_for(data_url(asset).merge(:only_path=>true)) : nil 206 rescue ActiveRecord::RecordNotFound 207 return nil 203 208 end 204 209 … … 231 236 new_lang = nil 232 237 if params[:lang] 233 if visitor.site [:languages].include?(params[:lang])238 if visitor.site.lang_list.include?(params[:lang]) 234 239 new_lang = params[:lang] 235 240 else … … 237 242 end 238 243 elsif params[:prefix] && params[:prefix] != AUTHENTICATED_PREFIX 239 if visitor.site.lang uages.split(',').include?(params[:prefix])244 if visitor.site.lang_list.include?(params[:prefix]) 240 245 session[:lang] = params[:prefix] 241 246 else trunk/app/helpers/application_helper.rb
r361 r370 718 718 actions << version_form_action('propose',version[:id]) 719 719 when Zena::Status[:del] 720 if (version[:user_id] == session[:user][:id])720 if (version[:user_id] == visitor[:id]) 721 721 actions << version_form_action('edit',version[:id]) if @node.can_edit_lang?(version.lang) 722 722 end … … 797 797 798 798 def change_lang(new_lang) 799 if session[:user] 799 if visitor.is_anon? 800 {:overwrite_params => { :prefix => new_lang }} 801 else 800 802 {:overwrite_params => { :lang => new_lang }} 801 else802 {:overwrite_params => { :prefix => new_lang }}803 803 end 804 804 end … … 856 856 [show_link(:home), show_link(:preferences), show_link(:comments), show_link(:users), show_link(:groups), show_link(:translation)].reject {|l| l==''} 857 857 when :home 858 return '' unless session[:user]858 return '' if visitor.is_anon? 859 859 tlink_to_with_state('my home', :controller=>'user', :action=>'home') 860 860 when :preferences 861 return '' unless session[:user]861 return '' if visitor.is_anon? 862 862 tlink_to_with_state('preferences', :controller=>'preferences', :action=>'list') 863 863 when :translation … … 911 911 else 912 912 res = [] 913 visitor.site [:languages].sort.each do |l|913 visitor.site.lang_list.sort.each do |l| 914 914 if l == lang 915 915 res << "<b>#{l}</b>" 916 916 else 917 if session[:user] 917 if visitor.is_anon? 918 res << link_to(l, request.parameters.merge(:prefix=>l)) 919 else 918 920 res << link_to(l, request.parameters.merge(:lang=>l)) 919 else920 res << link_to(l, request.parameters.merge(:prefix=>l))921 921 end 922 922 end trunk/app/models/contact.rb
r245 r370 1 1 class Contact < Page 2 2 link :contact_for, :class_name=>'Project', :as=>'contact', :as_unique=>true 3 link :favorites, :class_name=>'Node' 3 4 4 5 private trunk/app/models/site.rb
r366 r370 191 191 [anon_id, su_id] 192 192 end 193 194 # Return an array with the languages for the site. 195 def lang_list 196 (self[:languages] || "").split(',').map(&:strip) 197 end 193 198 end trunk/app/models/skin.rb
r352 r370 24 24 25 25 def template_for_path(path) 26 asset_for_path(path, Template) 27 end 28 29 30 def asset_for_path(path, klass=Node) 26 31 current = self 27 32 if path == 'any' … … 31 36 while path != [] 32 37 template_name = path.shift 33 current = secure( Template) { Template.find(:first, :conditions=>["parent_id = ? AND name = ?", current[:id], template_name])}38 current = secure(klass) { klass.find(:first, :conditions=>["parent_id = ? AND name = ?", current[:id], template_name])} 34 39 end 35 40 current … … 37 42 rescue ActiveRecord::RecordNotFound 38 43 nil 39 end 44 end 40 45 end trunk/app/models/user.rb
r366 r370 80 80 end 81 81 82 def contact 83 secure(Contact) { Contact.find(self[:contact_id]) } 84 rescue ActiveRecord::RecordNotFound 85 nil 86 end 87 82 88 # Each time a node is found using secure (Zena::Acts::Secure or Zena::Acts::SecureNode), this method is 83 89 # called to set the visitor in the found object. This is also used to keep track of the opened nodes … … 321 327 end 322 328 323 added_site_ids = @defined_site_ids.reject do |id| 324 site_ids.include?(id) 325 end 329 added_site_ids = @defined_site_ids - site_ids 326 330 327 removed_site_ids = site_ids.reject do |id| 328 @defined_site_ids.include?(id) 329 end 331 removed_site_ids = site_ids - @defined_site_ids 330 332 331 333 # make sure visitor is an admin in all the modified site ids: trunk/db/init/images.yml
r355 r370 179 179 lang: en 180 180 value: "<img src='/images/layers.png' alt='diff'/>" 181 182 - phrase_id: 102 183 lang: en 184 value: "<img src='/images/heart.png' alt='favorite'/>" trunk/db/init/trans_phrases.yml
r355 r370 302 302 - id: 101 303 303 phrase: 'btn_diff' 304 305 - id: 102 306 phrase: 'favorite' trunk/lib/parser/lib/parser.rb
r340 r370 19 19 end 20 20 21 def template_url_for_asset( type,url)22 "/test_#{ type}/#{url}"21 def template_url_for_asset(opts) 22 "/test_#{opts[:type]}/#{opts[:src]}" 23 23 end 24 24 … … 43 43 44 44 class Parser 45 attr_accessor :text, :method 46 attr_accessor :pass 45 attr_accessor :text, :method, :pass, :options 47 46 48 47 class << self … … 311 310 # puts "MADE #{new_obj.inspect}" 312 311 # puts "TEXT #{@text.inspect}" 312 new_obj 313 313 end 314 314 trunk/lib/parser/lib/rules/zafu.rb
r315 r370 20 20 res = super 21 21 if (@context[:parts] || {})[@context[:name]] 22 res22 (@space_before || '') + res + (@space_after || '') 23 23 else 24 24 render_html_tag(res) … … 49 49 50 50 def render_html_tag(text) 51 return text unless @html_tag && !@html_tag_done 52 res = "<#{@html_tag}#{params_to_html(@html_tag_params || {})}" 53 if text != '' 54 res << ">#{text}</#{@html_tag}>" 55 else 56 res << "/>" 51 return text if @html_tag_done 52 if @html_tag 53 res = "<#{@html_tag}#{params_to_html(@html_tag_params || {})}" 54 if text != '' 55 res << ">#{text}</#{@html_tag}>" 56 else 57 res << "/>" 58 end 59 else 60 res = text 57 61 end 58 62 @html_tag_done = true 59 res63 (@space_before || '') + res + (@space_after || '') 60 64 end 61 65 … … 63 67 return expand_with unless @html_tag 64 68 unless @params[:src][0..0] == '/' 69 opts = {:src => @params[:src]} 65 70 case @html_tag 66 71 when 'link' 67 72 if @params[:rel].downcase == 'stylesheet' 68 @params[:src] = @options[:helper].send(:template_url_for_asset, :stylesheet , @params[:src])73 opts[:type] = :stylesheet 69 74 else 70 @params[:src] = @options[:helper].send(:template_url_for_asset, :link, @params[:src]) 71 end 72 else 73 @params[:src] = @options[:helper].send(:template_url_for_asset, @html_tag.to_sym , @params[:src]) 74 end 75 opts[:type] = :link 76 end 77 else 78 opts[:type] = @html_tag.to_sym 79 end 80 opts[:current_template] = @options[:included_history].last 81 @params[:src] = @options[:helper].send(:template_url_for_asset, opts) 75 82 end 76 83 res = "<#{@html_tag}#{params_to_html(@params)}" … … 100 107 @end_tag_count = 1 101 108 109 # code indentation 110 @space_before = @options[:space_before] 111 @options.delete(:space_before) 112 113 # puts "[#{@space_before}(#{@method})#{@space_after}]" 102 114 if @params =~ /\A([^>]*?)do\s*=('|")([^\2]*?[^\\])\2([^>]*)\Z/ 103 115 # we have a sub 'do' … … 108 120 opts[:end_do] = @end_tag 109 121 110 make(:void, opts) 122 sub = make(:void, opts) 123 @space_after = sub.instance_variable_get(:@space_after) 124 sub.instance_variable_set(:@space_after,"") 111 125 if @method == 'include' 112 126 include_template … … 122 136 end 123 137 end 124 125 138 if !@html_tag && (@html_tag = @params[:tag]) 126 139 @params.delete(:tag) … … 142 155 def scan 143 156 # puts "SCAN(#{@method}): [#{@text}]" 144 if @text =~ /\A([^<]* )</157 if @text =~ /\A([^<]*?)(^ *|)</m 145 158 flush $1 159 eat $2 146 160 if @text[1..1] == '/' 161 store $2 147 162 scan_close_tag 148 163 elsif @text[0..3] == '<!--' 149 scan_html_comment 150 else 151 scan_tag 164 scan_html_comment(:space_before=> $2) 165 else 166 scan_tag(:space_before=> $2) 152 167 end 153 168 else … … 158 173 159 174 def scan_close_tag 160 if @text =~ /\A<\/([^>]+)> /175 if @text =~ /\A<\/([^>]+)>( *\n+|)/m 161 176 # puts "CLOSE:[#{$&}]}" # ztag 162 177 # closing tag … … 165 180 if @end_tag_count == 0 166 181 eat $& 182 @space_after = $2 167 183 leave 168 184 else … … 188 204 end 189 205 190 def scan_html_comment 206 def scan_html_comment(opts={}) 191 207 if @text =~ /<!--\|(.*?)-->/m 192 208 # zafu html escaped 193 209 eat $& 194 @text = $1 + @text210 @text = opts[:space_before] + $1 + @text 195 211 elsif @text =~ /<!--.*?-->/m 196 212 # html comment … … 202 218 end 203 219 204 def scan_tag 220 def scan_tag(opts={}) 205 221 # puts "TAG(#{@method}): [#{@text}]" 206 222 if @text =~ /\A<z:(\w+)([^>]*?)(\/?)>/ 207 223 # puts "ZTAG:[#{$&}]}" # ztag 208 224 eat $& 209 opts = {:method=>$1, :params=>$2}225 opts.merge!(:method=>$1, :params=>$2) 210 226 opts.merge!(:text=>'') if $3 != '' 211 227 make(:void, opts) … … 213 229 # puts "DO:[#{$&}]}" # do tag 214 230 eat $& 215 opts = {:method=>$4, :html_tag=>$1, :html_tag_params=>$2, :params=>$5}231 opts.merge!(:method=>$4, :html_tag=>$1, :html_tag_params=>$2, :params=>$5) 216 232 opts.merge!(:text=>'') if $6 != '' 217 233 make(:void, opts) trunk/lib/parser/lib/rules/zena.rb
r326 r370 56 56 elsif @params[:attr] 57 57 "<%= #{node}#{get_attribute(attribute)} %>" 58 elsif @params[:date] 59 # date can be any attribute v_created_at or updated_at etc. 60 # TODO format with @params[:format] and @params[:tformat] << translated format 61 else 62 # error 63 end 64 end 65 66 def r_zazen 67 attribute = @params[:attr] || @params[:tattr] 68 if @context[:trans] 69 # TODO: what do we do here with dates ? 70 "#{node}#{get_attribute(attribute)}" 71 elsif @params[:tattr] 72 "<%= zazen(trans(#{node}#{get_attribute(attribute)})) %>" 73 elsif @params[:attr] 74 "<%= zazen(#{node}#{get_attribute(attribute)}) %>" 58 75 elsif @params[:date] 59 76 # date can be any attribute v_created_at or updated_at etc. … … 432 449 "<span class='parser_error'>No stored nodes in the current context</span>" 433 450 end 451 elsif select == 'visitor' 452 do_var("visitor.contact") 434 453 elsif select =~ /^\d+$/ 435 454 do_var("secure(Node) { Node.find_by_id(#{select.inspect})} rescue nil") … … 782 801 end 783 802 803 784 804 def render_html_tag(text) 805 return text if @html_tag_done 806 if @html_tag 807 res = "<#{@html_tag}#{params_to_html(@html_tag_params || {})}" 808 if text != '' 809 res << ">#{text}</#{@html_tag}>" 810 else 811 res << "/>" 812 end 813 else 814 res = text 815 end 816 @html_tag_done = true 817 (@options[:space_before] || '') + res + (@options[:space_after] || '') 818 end 819 820 def render_html_tag(text) 821 return text if @html_tag_done 785 822 set_params = {} 786 823 @params.each do |k,v| … … 790 827 @html_tag = 'div' if !@html_tag && set_params != {} 791 828 792 return text unless @html_tag && !@html_tag_done793 829 @html_tag_params ||= {} 794 830 bak = @html_tag_params.dup trunk/lib/parser/test/parser_test.rb
r359 r370 33 33 testfile :zafu, :zafu_asset, :zafu_insight, :zazen 34 34 def test_single 35 do_test('za zen', 'wiki_link_partial_url')35 do_test('zafu', 'tada') 36 36 end 37 37 def test_zazen_image_no_image trunk/test/fixtures/links.yml
r307 r370 34 34 target_id: 12 35 35 role: hot 36 37 nature_favorite_for_ant: 38 id: 7 39 source_id: 3 40 target_id: 29 41 role: favorite trunk/test/fixtures/trans_phrases.yml
r350 r370 402 402 id: 101 403 403 phrase: 'btn_diff' 404 405 102: 406 id: 102 407 phrase: 'favorite' trunk/test/fixtures/trans_values.yml
r350 r370 934 934 lang: en 935 935 value: "<img src='/images/layers.png' alt='diff'/>" 936 937 174: 938 id: 174 939 phrase_id: 102 940 lang: en 941 value: "<img src='/images/heart.png' alt='favorite'/>" trunk/test/fixtures/versions.yml
r360 r370 409 409 title: parc opening 410 410 summary: no summary yet 411 text: nothing written yet 411 text: | 412 We are glad to announce the opening of our new project ! 413 414 You are all invited to *Romanel* for a great party this weekend. 412 415 lang: en 413 416 number: 2 trunk/test/helpers/basic.yml
r326 r370 30 30 tem: "include: this <% puts \"could be\" %> nasty" 31 31 32 rename_asset:33 src: "< link rel='stylesheet' src='water' type='text/css'/>"34 tem: "< link rel='stylesheet' src='/data/pdf/15/water.pdf' type='text/css'/>"32 wiki: 33 src: "<img src='bird' alt='bird'/>" 34 tem: "<img alt='bird' src='/data/jpg/20/bird.jpg'/>" 35 35 36 36 show_title: … … 180 180 src: "<div id='lang' do='lang_links'><a>en</a> | <b>fr</b></div>" 181 181 tem: "<div id='lang'><%= lang_links(:node=>@node) %></div>" 182 res: "/<div id='lang'><b>en.* test_render.*lang=es.*\|.*test_render.*=en.*fr/"182 res: "/<div id='lang'><b>en.*\|.*test_render.*=fr/" 183 183 184 184 show_path: … … 365 365 src: "<z:show_comments/>" 366 366 tem: "<%= show_comments(:node=>@node) %>" 367 res: "/<div class='comment ' id='comments_list'>.*reply.*add/"367 res: "/<div class='comments' id='comments'>.*reply.*add/" 368 368 369 369 content_for_layout: … … 376 376 tem: "<% if @title_for_layout -%><%= @title_for_layout %><% else -%>blah blih<% end -%>" 377 377 res: "blah blih" 378 379 tada: 380 context: 381 node: 'opening' 382 src: | 383 <h1 id='main_title' do='show' attr='v_title'>Super project</h1> 384 385 <ul do='tags'> 386 <li do='each' do='link'>art</li> 387 <li do='ignore'>life</li> 388 <li do='ignore'>ruby</li> 389 </ul> 390 391 <div id='text' do='zazen' attr='v_text'> 392 <p>Lorem ipsum dolor sit amet, consectetuer elit....</p> 393 <h3>some title</h3> 394 </div> 395 res: | 396 <h1 id='main_title'>parc opening</h1> 397 398 <ul> 399 <li><a href="/oo/tag23.html">Art</a></li> 400 <li><a href="/oo/tag24.html">News list</a></li> 401 </ul> 402 403 <div id='text'><p>We are glad to announce the opening of our new project !</p> 404 405 406 <p>You are all invited to <strong>Romanel</strong> for a great party this weekend.</p></div> trunk/test/helpers/relations.yml
r326 r370 187 187 188 188 menu_with_favorites: 189 src: "<ul><z:root do='pages' only='public' cache='true' name='menu'><li do='each'><z:link/><ul do='pages'><li do='each' do='link'/></ul></li></z:root><z:node select='visitor' do='favorites'><li do='trans'>favorites<ul><li do='each' do='link'/></ul></li></ul>" 190 res: "" 189 src: "<ul><z:root do='pages' only='public' cache='true' name='menu'><li do='each'><z:link/><ul do='pages'><li do='each' do='link'/></ul></li></z:root><z:node select='visitor' do='favorites'><li class='favorites'><z:trans>favorites</z:trans><ul><li do='each' do='link'/></ul></li></ul>" 190 res: "/.*tag23.*tag25.*Clean Water.*favorites.*Nature/" 191 192 visitor_favorites: 193 src: "<z:node select='visitor'><ul do='favorites'><li do='each' do='link'/></ul></z:node>" 194 res: "<ul><li><a href=\"/oo/page29.html\">Nature</a></li></ul>" trunk/test/helpers/test_all.rb
r352 r370 4 4 testfile :relations, :basic 5 5 Project # make sure we load Project links before trying relations 6 6 7 def test_single 7 do_test('basic', 'link_version') 8 do_test('basic', 'show_title') 9 end 10 11 # test rename asset (has to be called wiki to find the proper skin) 12 def test_basic_wiki 13 Node.connection.execute "UPDATE nodes SET parent_id = 33 WHERE id = 20;" # status, art 14 do_test('basic', 'wiki') 8 15 end 9 16 trunk/test/helpers/testhelp.rb
r352 r370 37 37 38 38 def set_context 39 session[:user] = User.find(@params[:user_id])[:id] # make sure the user exists 40 session[:lang] = visitor.lang = @params[:prefix] 39 @visitor = User.find(@params[:user_id]) 40 @visitor.lang = @params[:prefix] 41 @visitor.site = Site.find(:first, :select=>"sites.*", :from=>"sites, sites_users", 42 :conditions=>["sites_users.site_id = sites.id AND sites_users.user_id = ?", visitor[:id]]) 43 @visitor.visit(@visitor) 41 44 @node = secure(Node) { Node.find(@params[:node_id])} 42 45 @text = @params[:text] 43 46 @test_url = @params[:url] 44 47 @params.delete(:user_id) 48 @params.delete(:prefix) 45 49 @params.delete(:node_id) 46 50 @params.delete(:text) trunk/test/unit/site_test.rb
r363 r370 116 116 assert_equal 'test.host', site[:host] 117 117 end 118 119 def test_lang_list 120 site = sites(:zena) 121 site.languages = "en,fr" 122 assert_equal ['en', 'fr'], site.lang_list 123 site.languages = "en,fr, ru , es" 124 assert_equal ['en', 'fr', 'ru', 'es'], site.lang_list 125 end 118 126 end trunk/test/zena_test.rb
r362 r370 170 170 @visitor.site = Site.find(:first, :select=>"sites.*", :from=>"sites, sites_users", 171 171 :conditions=>["sites_users.site_id = sites.id AND sites_users.user_id = ?", @visitor[:id]]) 172 @visitor.visit(@visitor) 172 173 @lang = @visitor.lang 173 174 end
