Changeset 1168
- Timestamp:
- 2008-09-19 16:27:18 (4 months ago)
- Files:
-
- trunk/app/models/comment.rb (modified) (2 diffs)
- trunk/app/models/node.rb (modified) (1 diff)
- trunk/app/models/version.rb (modified) (1 diff)
- trunk/db/migrate/000_zena/021_create_relations.rb (modified) (1 diff)
- trunk/lib/node_query.rb (modified) (2 diffs)
- trunk/lib/parser/lib/rules/zena.rb (modified) (2 diffs)
- trunk/test/helpers/node_query/comments.yml (added)
- trunk/test/helpers/node_query/filters.yml (modified) (1 diff)
- trunk/test/helpers/node_query/relations.yml (modified) (1 diff)
- trunk/test/helpers/zena_parser/basic.yml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/app/models/comment.rb
r1165 r1168 7 7 =end 8 8 class Comment < ActiveRecord::Base 9 zafu_readable :title, :text, :author_name, :created_at, :updated_at, :status , :user_id, :user_zip9 zafu_readable :title, :text, :author_name, :created_at, :updated_at, :status 10 10 zafu_context :replies => ["Comment"] 11 11 attr_accessible :title, :text, :author_name, :discussion_id, :reply_to, :status … … 23 23 def author_name 24 24 self[:author_name] || (self[:user_id] ? author.fullname : nil) 25 end26 27 def user_zip28 user_id29 25 end 30 26 trunk/app/models/node.rb
r1165 r1168 132 132 :section_zip, :skin, :ref_lang, :fullpath, :rootpath, :position, :publish_from, :max_status, :rgroup_id, 133 133 :wgroup_id, :pgroup_id, :basepath, :custom_base, :klass, :zip, :score, :comments_count, :l_status, :l_comment, 134 :custom_a, :custom_b, :title, :text, :user_id,134 :custom_a, :custom_b, :title, :text, 135 135 :m_text, :m_title, :m_author 136 136 zafu_context :author => "Contact", :parent => "Node", trunk/app/models/version.rb
r1165 r1168 31 31 32 32 zafu_readable :title, :text, :summary, :comment, :created_at, :updated_at, :publish_from, :status, 33 :wgroup_id, :pgroup_id, :zip, :lang, :user_zip , :user_id33 :wgroup_id, :pgroup_id, :zip, :lang, :user_zip 34 34 35 35 zafu_context :author => "Contact", :user => "User", :node => "Node" trunk/db/migrate/000_zena/021_create_relations.rb
r1067 r1168 15 15 end 16 16 add_column :links, 'relation_id', :integer 17 # load relations fixtures18 source_rel = {}19 target_rel = {}20 relations = []21 YAML::load_documents( File.open( File.join(RAILS_ROOT, 'test', 'fixtures', 'relations.yml') ) ) do |entries|22 entries.each do |key,value|23 relation = []24 ['source_role', 'source_kpath', 'source_icon', 'target_role', 'target_kpath', 'target_icon'].each do |sym|25 relation << quote(value[sym])26 end27 relations << relation28 end29 end30 # create relations for each site31 Site.find(:all).each do |site|32 insert = relations.map do |rel|33 "(#{(rel + [site[:id]]).join(',')})"34 end35 execute "INSERT INTO relations (`source_role`,`source_kpath`,`source_icon`,`target_role`,`target_kpath`,`target_icon`,`site_id`) VALUES #{insert.join(', ')}"36 execute "UPDATE links,nodes SET relation_id = (SELECT id FROM relations WHERE source_role = links.role OR target_role = links.role AND site_id = #{site[:id]} LIMIT 1) WHERE links.source_id = nodes.id AND nodes.site_id = #{site[:id]}"37 end38 17 end 39 18 trunk/lib/node_query.rb
r1165 r1168 163 163 case $2 164 164 when 'visitor' 165 if $3 == 'author_id' # FIXME: this is a bit hackish. If anyone has a better idea.. 166 value = "\#{visitor.id}" 167 else 168 value = "\#{Node.connection.quote(\#{#{val_start}Node.zafu_attribute(visitor.contact, #{$3.inspect})#{val_end}})}" 169 end 165 value = "\#{Node.connection.quote(\#{#{val_start}Node.zafu_attribute(visitor.contact, #{$3.inspect})#{val_end}})}" 170 166 when 'param' 171 167 value = "\#{Node.connection.quote(#{val_start}params[:#{$3}].to_s#{val_end})}" … … 347 343 # * VCLASS: a virtual class created by the user ('posts', 'houses', ...) 348 344 # * RELATION: a relation defined by the user ('icon_for', 'news', 'calendar', ...) 349 # * CLAUSE: field = value ('log_at:year = 2005'). You can use parameters, visitor data in clause: 'log_at:year = [param:year]', 'd_assigned = [visitor:name]'. You can use version and/or dynamic attributes : 'v_comment = super', 'd_priority = low'.345 # * CLAUSE: field = value ('log_at:year = 2005'). You can use parameters, visitor data in clause: 'log_at:year = [param:year]', 'd_assigned = [visitor:name]'. You can only use 'and' in clauses. 'or' is not supported. You can use version and/or dynamic attributes : 'v_comment = super', 'd_priority = low'. 350 346 # 351 347 # Examples: 'todos in section where d_priority = high and d_assigned = [visitor:name]' trunk/lib/parser/lib/rules/zena.rb
r1163 r1168 2557 2557 end 2558 2558 when :test 2559 if value =~ /("[^"]*"|'[^']*'|[\w:\. ]+)\s*(>=|<=|<>|<|=|>|lt|le|eq|ne|ge|gt)\s*("[^"]*"|'[^']*'|[\w\.]+)/2559 if value =~ /("[^"]*"|'[^']*'|[\w:\.\-]+)\s*(>=|<=|<>|<|=|>|lt|le|eq|ne|ge|gt)\s*("[^"]*"|'[^']*'|[\w\.\-]+)/ 2560 2560 parts = [$1,$3] 2561 2561 op = {'lt' => '<','le' => '<=','eq' => '==', '=' => '==','ne' => '!=','ge' => '>=','gt' => '>'}[$2] || $2 2562 toi = ( op =~ /(>|<)/ || (parts[0] =~ /^ \d+$/ || parts[1] =~ /^\d+$/) )2562 toi = ( op =~ /(>|<)/ || (parts[0] =~ /^-?\d+$/ || parts[1] =~ /^-?\d+$/) ) 2563 2563 parts.map! do |part| 2564 2564 if ['"',"'"].include?(part[0..0]) … … 2566 2566 elsif part == 'NOW' 2567 2567 "Time.now.to_i" 2568 elsif part =~ /^ \d+$/2568 elsif part =~ /^-?\d+$/ 2569 2569 part 2570 2570 else trunk/test/helpers/node_query/filters.yml
r1165 r1168 91 91 src: "nodes in site group by log_at:year order by log_at:year asc, name asc" 92 92 sql: "SELECT nodes.* FROM nodes WHERE (#{@node.secure_scope('nodes')}) GROUP BY year(nodes.log_at) ORDER BY year(nodes.log_at) ASC, nodes.name ASC" 93 94 nodes_author:95 context:96 visitor: ant97 src: "nodes where user_id eq \"[visitor:author_id]\" in site"98 sql: "SELECT nodes.* FROM nodes WHERE nodes.user_id = \#{visitor.id} AND (\#{@node.secure_scope('nodes')}) ORDER BY nodes.position ASC, nodes.name ASC"99 res: "."trunk/test/helpers/node_query/relations.yml
r1123 r1168 29 29 projects_in_site: 30 30 sql: "SELECT nodes.* FROM nodes WHERE nodes.kpath LIKE 'NPP%' AND (#{@node.secure_scope('nodes')}) ORDER BY nodes.position ASC, nodes.name ASC" 31 32 comments_order:33 src: "comments order by created_at desc"34 sql: "Comment: SELECT comments.* FROM comments WHERE comments.discussion_id = #{@node.get_discussion_id} ORDER BY comments.created_at DESC"trunk/test/helpers/zena_parser/basic.yml
r1164 r1168 630 630 src: "<div do='project' on_if='name eq \"cleanWater\"' do='[name]'/>" 631 631 res: "<div class='on'>cleanWater</div>" 632 633 test_negative_value: 634 src: "<div do='void' off_if='custom_a eq -10'>...</div>" 635 tem: "<div<%= @node.custom_a.to_i == -10 ? \" class='off'\" : \"\" %>>...</div>" 632 636 633 637 simple_each:
