Changeset 1165

Show
Ignore:
Timestamp:
2008-09-18 17:16:57 (4 months ago)
Author:
gaspard
Message:

commit a0c317a905b8816c939c64bf9a768244bdb6a47d
Author: Gaspard Bucher <gaspard@teti.ch>

Enhanced color highlighting for pseudo_sql syntax.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/app/models/comment.rb

    r1078 r1165  
    77=end 
    88class Comment < ActiveRecord::Base 
    9   zafu_readable      :title, :text, :author_name, :created_at, :updated_at, :status 
     9  zafu_readable      :title, :text, :author_name, :created_at, :updated_at, :status, :user_id, :user_zip 
    1010  zafu_context       :replies => ["Comment"] 
    1111  attr_accessible    :title, :text, :author_name, :discussion_id, :reply_to, :status 
     
    2323  def author_name 
    2424    self[:author_name] || (self[:user_id] ? author.fullname : nil) 
     25  end 
     26   
     27  def user_zip 
     28    user_id 
    2529  end 
    2630   
  • trunk/app/models/node.rb

    r1147 r1165  
    132132                     :section_zip, :skin, :ref_lang, :fullpath, :rootpath, :position, :publish_from, :max_status, :rgroup_id,  
    133133                     :wgroup_id, :pgroup_id, :basepath, :custom_base, :klass, :zip, :score, :comments_count, :l_status, :l_comment, 
    134                      :custom_a, :custom_b, :title, :text, 
     134                     :custom_a, :custom_b, :title, :text, :user_id, 
    135135                     :m_text, :m_title, :m_author    
    136136  zafu_context       :author => "Contact", :parent => "Node",  
  • trunk/app/models/version.rb

    r1096 r1165  
    3131 
    3232  zafu_readable      :title, :text, :summary, :comment, :created_at, :updated_at, :publish_from, :status,  
    33                      :wgroup_id, :pgroup_id, :zip, :lang, :user_zip 
     33                     :wgroup_id, :pgroup_id, :zip, :lang, :user_zip, :user_id 
    3434                      
    3535  zafu_context       :author => "Contact", :user => "User", :node => "Node" 
  • trunk/lib/node_query.rb

    r1122 r1165  
    163163        case $2 
    164164        when 'visitor' 
    165           value = "\#{Node.connection.quote(\#{#{val_start}Node.zafu_attribute(visitor.contact, #{$3.inspect})#{val_end}})}" 
     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 
    166170        when 'param' 
    167171          value = "\#{Node.connection.quote(#{val_start}params[:#{$3}].to_s#{val_end})}" 
     
    343347      #   * VCLASS: a virtual class created by the user ('posts', 'houses', ...) 
    344348      #   * RELATION: a relation defined by the user ('icon_for', 'news', 'calendar', ...) 
    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'. 
     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'. 
    346350      # 
    347351      # Examples: 'todos in section where d_priority = high and d_assigned = [visitor:name]' 
  • trunk/lib/parser/lib/rules/code_syntax.rb

    r996 r1165  
    239239Syntax::SYNTAX['sh'] = ShTokenizer 
    240240 
    241  
     241class PseudoSqlTokenizer < Syntax::Tokenizer 
     242  def step 
     243    if @state.nil? and method = scan(/\w+/) 
     244      start_group :method, method 
     245      @state = :method 
     246    elsif @state == :in and context = scan(/\w+/) 
     247      start_group :context, context 
     248      @state = :context 
     249    elsif keyword = scan(/\bin\b/) 
     250      start_group :context, keyword 
     251      @state = :in 
     252    elsif keyword = scan(/\bfrom\b/) 
     253      start_group :sub, keyword 
     254      @state = nil 
     255    elsif keyword = scan(/\bwhere|order\b/) 
     256      start_group :keyword, keyword 
     257    elsif punct  = scan(/\b>=|<=|<>|<|=|>|not\s+like|like|lt|le|eq|ne|ge|gt\b/) 
     258      start_group :punct, punct 
     259    elsif string = scan(/("|')[^'"]*\1/) 
     260      string =~ /("|')([^'"]*)\1/ 
     261      start_group :punct, $1 
     262      start_group :string, $2 
     263      start_group :punct, $1 
     264    else 
     265      start_group :normal, scan(/./m) 
     266    end 
     267  end 
     268end 
     269Syntax::SYNTAX['pseudo_sql'] = PseudoSqlTokenizer 
     270 
     271 
  • trunk/public/stylesheets/code.css

    r1144 r1165  
    5151.css .class { color:orange;} 
    5252 
     53.pseudo_sql .string { color: #361; } 
     54.pseudo_sql .keyword { color: #622;} 
     55.pseudo_sql .sub { color:#622; font-weight:bold;} 
     56.pseudo_sql .punct {color: #622;} 
     57.pseudo_sql .method {color: #944;} 
     58.pseudo_sql .context {color: #07b;} 
    5359 
    5460.zazen pre { 
  • trunk/test/helpers/node_query/filters.yml

    r1084 r1165  
    9191  src: "nodes in site group by log_at:year order by log_at:year asc, name asc" 
    9292  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 
     94nodes_author: 
     95  context: 
     96    visitor: ant 
     97  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: "."