Changeset 700
- Timestamp:
- 2007-08-14 17:21:29 (1 year ago)
- Files:
-
- trunk/lib/parser/lib/parser.rb (modified) (2 diffs)
- trunk/lib/parser/lib/rules/zena.rb (modified) (2 diffs)
- trunk/lib/parser/test/parser_test.rb (modified) (1 diff)
- trunk/lib/parser/test/zafu.yml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/parser/lib/parser.rb
r648 r700 363 363 end 364 364 365 # Parse parameters into a hash. This parsing supports multiple values for one key by creating additional keys: 366 # <tag do='hello' or='goodbye' or='gotohell'> creates the hash {:do=>'hello', :or=>'goodbye', :or1=>'gotohell'} 365 367 def parse_params(text) 366 368 return {} unless text … … 374 376 if rest =~ /('|")([^\1]*?[^\\]|)\1/ 375 377 rest = rest[$&.length..-1].strip 378 key_counter = 1 379 while params[key] 380 key = "#{key}#{key_counter}".to_sym 381 key_counter += 1 382 end 383 376 384 if $1 == "'" 377 385 params[key] = $2.gsub("\\'", "'") trunk/lib/parser/lib/rules/zena.rb
r699 r700 1020 1020 end 1021 1021 1022 # <r:pages from='site' project='stored' limit='5'> 1023 # is the same as 1024 # <div do='pages from site' project='stored' limit='5'> 1025 # <div do='references' or='references_for'> 1022 1026 def get_list_finder(rel,params=@params) 1023 1027 # FIXME: could SQL injection be possible here ? (all params are passed to the 'find') 1024 erb_params = {} 1028 relations = [rel] 1029 conditions = [] 1030 query_params = {} 1031 1032 if params[:from] 1033 relations[0] << " from #{params[:from]}" 1034 end 1035 1036 if params[:or] 1037 relations << params[:or] 1038 key_counter = 1 1039 while or_value = params["or#{key_counter}".to_sym] 1040 key_counter += 1 1041 finders << or_value 1042 end 1043 end 1044 1025 1045 if order = params[:order] 1026 1046 if order == 'random' 1027 erb_params[:order] = 'RAND()'1047 query_params[:order] = 'RAND()' 1028 1048 elsif order =~ /\A(\w+)( ASC| DESC|)\Z/ 1029 erb_params[:order] = order1049 query_params[:order] = order 1030 1050 else 1031 1051 # ignore 1032 1052 end 1033 1053 end 1034 erb_params[:from] = params[:from] if params[:from]1054 1035 1055 [:limit, :offset].each do |k| 1036 1056 next unless params[k] 1037 erb_params[k] = params[k].to_i.to_s 1038 end 1039 [:from, :direction, :or].each do |k| 1040 next unless params[k] 1041 erb_params[k] = params[k] 1042 end 1043 conditions = [] 1057 query_params[k] = params[k].to_i.to_s 1058 end 1059 1044 1060 1045 1061 # FIXME: stored should be clarified and managed in a single way through links and contexts. … … 1094 1110 end 1095 1111 1096 res_params = params_to_erb(erb_params) 1097 if conditions != [] 1098 conditions = conditions.join(' AND ') 1099 if res_params != '' 1100 res_params << ", :conditions=>\"#{conditions}\"" 1101 else 1102 res_params = ":conditions=>\"#{conditions}\"" 1103 end 1104 end 1105 "#{node}.relation(#{rel.inspect}#{res_params})" 1106 end 1112 query_params[:conditions] = conditions.join(' AND ') if conditions != [] 1113 query_params[:relations ] = relations 1114 query_params[:node_name ] = node 1115 1116 sql_query = Node.build_find(node, query_params) 1117 1118 "#{node}.do_find(\"#{sql_query}\")" 1119 end 1120 1107 1121 # <r:hot else='project'/> 1108 1122 # <r:relation role='hot,project'> = get relation if empty get project trunk/lib/parser/test/parser_test.rb
r679 r700 56 56 testfile :zafu, :zafu_asset, :zafu_insight, :zazen 57 57 def test_single 58 do_test('zafu', ' include_replace_same_with')58 do_test('zafu', 'multiple_param') 59 59 end 60 60 trunk/lib/parser/test/zafu.yml
r679 r700 249 249 res: "[test][hello]a thing [hello/] here[/hello][/test]" 250 250 251 multiple_param: 252 src: "<r:test do='hello' param='1' param='2'>a thing <r:hello/> here</r:test>" 253 res: "[test][hello {= :param1=>'2', :param=>'1'}]a thing [hello/] here[/hello][/test]" 254 251 255 ztag_tag: 252 256 src: "<r:hello tag='p'/>"
