Changeset 615
- Timestamp:
- 2007-06-07 17:23:38 (2 years ago)
- Files:
-
- trunk/app/controllers/application.rb (modified) (3 diffs)
- trunk/app/helpers/application_helper.rb (modified) (2 diffs)
- trunk/app/models/project.rb (modified) (2 diffs)
- trunk/db/init/base/skins/default/default.css (modified) (2 diffs)
- trunk/lib/parser/lib/rules/zazen.rb (modified) (1 diff)
- trunk/lib/parser/lib/rules/zena.rb (modified) (5 diffs)
- trunk/lib/parser/test/parser_test.rb (modified) (1 diff)
- trunk/lib/parser/test/zazen.yml (modified) (1 diff)
- trunk/test/helpers/zena_parser_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/app/controllers/application.rb
r612 r615 453 453 # /////// The following methods are common to controllers and views //////////// # 454 454 455 def data_path( obj, opts={})456 format = obj.kind_of?(Document) ? obj.c_ext : nil457 zen_path( obj, {:format => format}.merge(opts))455 def data_path(node, opts={}) 456 format = node.kind_of?(Document) ? node.c_ext : nil 457 zen_path(node, {:format => format}.merge(opts)) 458 458 end 459 459 460 460 461 461 # Path for the node (as string). Options can be :format and :mode. 462 def zen_path(obj, options={}) 463 return '#' unless obj 462 def zen_path(node, options={}) 463 return '#' unless node 464 if sharp = options.delete(:sharp) 465 if sharp =~ /\[(.+)\]/ 466 sharp_value = node.zafu_read($1) 467 else 468 sharp_value = "node#{node[:zip]}" 469 end 470 if sharp_in = options.delete(:sharp_in) 471 sharp_node = node.relation(sharp_in) || node 472 return "#{zen_path(sharp_node, options)}##{sharp_value}" 473 else 474 return "##{sharp_value}" 475 end 476 end 477 464 478 opts = options.dup 465 479 format = opts.delete(:format) || 'html' … … 470 484 params = (opts == {}) ? '' : ('?' + opts.map{ |k,v| "#{k}=#{v}"}.join('&')) 471 485 472 if obj[:id] == current_site[:root_id] && mode.nil?486 if node[:id] == current_site[:root_id] && mode.nil? 473 487 "/#{pre}" # index page 474 elsif obj[:custom_base]488 elsif node[:custom_base] 475 489 "/#{pre}/" + 476 obj.basepath +490 node.basepath + 477 491 (mode ? "_#{mode}" : '') + 478 492 ".#{format}" 479 493 else 480 494 "/#{pre}/" + 481 ( obj.basepath != '' ? "#{obj.basepath}/" : '') +482 ( obj.class.to_s.downcase ) +483 ( obj[:zip].to_s ) +495 (node.basepath != '' ? "#{node.basepath}/" : '') + 496 (node.class.to_s.downcase ) + 497 (node[:zip].to_s ) + 484 498 (mode ? "_#{mode}" : '') + 485 499 ".#{format}" … … 487 501 end 488 502 489 def zen_url( obj, opts={})490 path = zen_path( obj,opts).split('/').reject { |p| p.blank? }503 def zen_url(node, opts={}) 504 path = zen_path(node,opts).split('/').reject { |p| p.blank? } 491 505 prefix = path.shift 492 506 trunk/app/helpers/application_helper.rb
r612 r615 214 214 def make_link(opts) 215 215 link_opts = {} 216 if sharp = opts[:sharp] 217 if sharp =~ /\[(.+)\/(.*)\]/ 218 sharp_in, sharp = $1, $2 219 sharp = "[#{sharp}]" if sharp != '' 220 link_opts[:sharp_in] = sharp_in 221 end 222 link_opts[:sharp] = sharp 223 end 216 224 if opts[:id] =~ /(\d+)(_\w+|)(\.\w+|)/ 217 225 opts[:id] = $1 … … 903 911 attributes += options[:id] ? " id='#{options.delete(:id)}'" : '' 904 912 end 905 906 url = if sharp = options.delete(:sharp) 907 if sharp =~ /\[(.+)\]/ 908 sharp_value = node.zafu_read($1) 909 else 910 sharp_value = "node#{node[:zip]}" 911 end 912 if sharp_in = options.delete(:sharp_in) 913 sharp_node = node.relation(sharp_in) || node 914 "#{zen_path(sharp_node, options)}##{sharp_value}" 915 else 916 "##{sharp_value}" 917 end 918 else 919 zen_path(node, options) 920 end 921 922 url_only ? url : "<a#{attributes} href='#{url}'>#{text}</a>" 913 url_only ? zen_path(node, options) : "<a#{attributes} href='#{zen_path(node, options)}'>#{text}</a>" 923 914 end 924 915 trunk/app/models/project.rb
r585 r615 17 17 18 18 def relation_methods 19 super + ['notes_all' ]19 super + ['notes_all', 'posts'] 20 20 end 21 21 … … 33 33 end 34 34 35 =begin 36 conditions = options[:conditions] 37 options.delete(:conditions) 38 options.merge!( :select => "#{Note.table_name}.*, links.id AS link_id, links.role", 39 :joins => "LEFT JOIN links ON #{Note.table_name}.id=links.source_id", 40 :conditions => ["(section_id = ?) OR (links.role='project' AND links.target_id = ? AND links.id IS NOT NULL)", self[:id], self[:id] ] 41 ) 42 if conditions 43 Note.with_scope(:find=>{:conditions=>conditions}) do 44 secure(Note) { Note.find(:all, options ) } 45 end 46 else 47 secure(Note) { Note.find(:all, options ) } 48 end 35 def posts(opts={}) 36 options = {:order=>'log_at DESC'}.merge(opts) 37 secure(Note) { Post.find(:all, relation_options(options)) } 49 38 end 50 =end 51 39 52 40 # All events related to this project (new/modified pages, notes) 53 41 def timeline trunk/db/init/base/skins/default/default.css
r613 r615 82 82 ul ul, ul ol, ol ol, ol ul { margin-bottom:0; } 83 83 84 .zazen b, .zazen strong { font-weight:bold; } 84 b, strong { font-weight:bold; } 85 i, em { font-style:italic; } 85 86 .zazen i, .zazen em { font-style:italic; } 86 87 /* inline forms */ … … 113 114 #nav_main a { color:white; } 114 115 115 #lang em { font- weight:normal; color:white;}116 #lang em { font-style:normal; color:white;} 116 117 #path, #lang, #lang a, #path a { color:#A27C6E;} 117 118 #path a.current { color:white;} trunk/lib/parser/lib/rules/zazen.rb
r612 r615 95 95 # link inside the cms "":34 96 96 title, id = $1, $2 97 if id =~ /(.* )#(.*)/98 id, sharp = $1, $297 if id =~ /(.*?)#(.*)/ 98 id, sharp = *id.split('#') 99 99 sharp = title if sharp.blank? 100 100 end trunk/lib/parser/lib/rules/zena.rb
r613 r615 1022 1022 if value = params[:project] 1023 1023 if value == 'stored' && stored = @context[:stored_project] 1024 conditions << "project_id = '\#{#{stored} [:project_id]}'"1024 conditions << "project_id = '\#{#{stored}.get_project_id}'" 1025 1025 elsif value == 'current' 1026 conditions << "project_id = '\#{#{node} [:project_id]}'"1026 conditions << "project_id = '\#{#{node}.get_project_id}'" 1027 1027 elsif value =~ /\A\d+\Z/ 1028 1028 conditions << "project_id = '#{value.to_i}'" … … 1034 1034 if value = params[:section] 1035 1035 if value == 'stored' && stored = @context[:stored_section] 1036 conditions << "section_id = '\#{#{stored} [:section_id]}'"1036 conditions << "section_id = '\#{#{stored}.get_section_id}'" 1037 1037 elsif value == 'current' 1038 conditions << "section_id = '\#{#{node} [:section_id]}'"1038 conditions << "section_id = '\#{#{node}.get_section_id}'" 1039 1039 elsif value =~ /\A\d+\Z/ 1040 1040 conditions << "section_id = '#{value.to_i}'" … … 1047 1047 if value = params[k] 1048 1048 # current, same are synonym for 'today' 1049 value = 'today' if ['current', 'same'].include?(value)1050 1049 conditions << Node.connection.date_condition(value,"#{k}_at",current_date) 1051 1050 end … … 1503 1502 class MysqlAdapter 1504 1503 def date_condition(date_cond, field, ref_date='today') 1505 if ref_date == 'today'1504 if date_cond == 'today' || ref_date == 'today' 1506 1505 ref_date = 'now()' 1507 1506 else … … 1509 1508 end 1510 1509 case date_cond 1511 when 'today' 1510 when 'today', 'current', 'same' 1512 1511 "DATE(#{field}) = DATE(#{ref_date})" 1513 1512 when 'week' trunk/lib/parser/test/parser_test.rb
r612 r615 56 56 testfile :zafu, :zafu_asset, :zafu_insight, :zazen 57 57 def test_single 58 do_test('zazen', 'link_sharp ')58 do_test('zazen', 'link_sharp_attribute') 59 59 end 60 60 trunk/lib/parser/test/zazen.yml
r612 r615 126 126 link_sharp: 127 127 src: '"hello":23#world of fame' 128 res: "<p>[make_link sharp:|world| id:|23| title:|hello|] of fame</p>"128 res: "<p>[make_link id:|23| sharp:|world| title:|hello|] of fame</p>" 129 129 130 130 link_sharp_same_as_title: 131 131 src: '"hello":23# I love you' 132 res: "<p>[make_link sharp:|hello| id:|23| title:|hello|] I love you</p>" 132 res: "<p>[make_link id:|23| sharp:|hello| title:|hello|] I love you</p>" 133 134 link_sharp_attribute: 135 src: '"hello":23#[name] I love you' 136 res: "<p>[make_link id:|23| sharp:|[name]| title:|hello|] I love you</p>" 133 137 134 138 wiki_link: trunk/test/helpers/zena_parser_test.rb
r614 r615 5 5 6 6 class ZenaParserTest < ZenaHelperTest 7 testfile :relations, :basic, :zafu_ajax 7 testfile :relations, :basic, :zafu_ajax, :zazen 8 8 Section # make sure we load Section links before trying relations 9 9 10 10 def test_single 11 do_test(' relations', 'checkbox')11 do_test('zazen', 'link_sharp_in_name') 12 12 end 13 13
