Changeset 615

Show
Ignore:
Timestamp:
2007-06-07 17:23:38 (2 years ago)
Author:
gaspard
Message:

[new] added sharp options for zazen links ("hello":23#) ("hello":23#[parent/name]) ("hello":23#[parent/])

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/app/controllers/application.rb

    r612 r615  
    453453    # /////// The following methods are common to controllers and views //////////// # 
    454454   
    455     def data_path(obj, opts={}) 
    456       format = obj.kind_of?(Document) ? obj.c_ext : nil 
    457       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)) 
    458458    end 
    459459   
    460460     
    461461    # 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       
    464478      opts   = options.dup 
    465479      format = opts.delete(:format) || 'html' 
     
    470484      params = (opts == {}) ? '' : ('?' + opts.map{ |k,v| "#{k}=#{v}"}.join('&')) 
    471485       
    472       if obj[:id] == current_site[:root_id] && mode.nil? 
     486      if node[:id] == current_site[:root_id] && mode.nil? 
    473487        "/#{pre}" # index page 
    474       elsif obj[:custom_base] 
     488      elsif node[:custom_base] 
    475489        "/#{pre}/" + 
    476         obj.basepath + 
     490        node.basepath + 
    477491        (mode         ? "_#{mode}" : '') + 
    478492        ".#{format}" 
    479493      else 
    480494        "/#{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                        ) + 
    484498        (mode          ? "_#{mode}" : '') + 
    485499        ".#{format}" 
     
    487501    end 
    488502   
    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? } 
    491505      prefix = path.shift 
    492506 
  • trunk/app/helpers/application_helper.rb

    r612 r615  
    214214  def make_link(opts) 
    215215    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 
    216224    if opts[:id] =~ /(\d+)(_\w+|)(\.\w+|)/ 
    217225      opts[:id]     = $1 
     
    903911      attributes += options[:id] ? " id='#{options.delete(:id)}'" : '' 
    904912    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>" 
    923914  end 
    924915   
  • trunk/app/models/project.rb

    r585 r615  
    1717   
    1818  def relation_methods 
    19     super + ['notes_all'
     19    super + ['notes_all', 'posts'
    2020  end 
    2121   
     
    3333  end 
    3434   
    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)) } 
    4938  end 
    50 =end 
    51  
     39     
    5240  # All events related to this project (new/modified pages, notes) 
    5341  def timeline 
  • trunk/db/init/base/skins/default/default.css

    r613 r615  
    8282ul ul, ul ol, ol ol, ol ul { margin-bottom:0; } 
    8383 
    84 .zazen b, .zazen strong { font-weight:bold;  } 
     84b, strong { font-weight:bold;  } 
     85i, em     { font-style:italic; } 
    8586.zazen i, .zazen em     { font-style:italic; } 
    8687/* inline forms */ 
     
    113114#nav_main a { color:white; } 
    114115 
    115 #lang em { font-weight:normal; color:white;} 
     116#lang em { font-style:normal; color:white;} 
    116117#path, #lang, #lang a, #path a { color:#A27C6E;} 
    117118#path a.current { color:white;} 
  • trunk/lib/parser/lib/rules/zazen.rb

    r612 r615  
    9595        # link inside the cms "":34 
    9696        title, id = $1, $2 
    97         if id =~ /(.*)#(.*)/ 
    98           id, sharp = $1, $2 
     97        if id =~ /(.*?)#(.*)/ 
     98          id, sharp = *id.split('#') 
    9999          sharp = title if sharp.blank? 
    100100        end 
  • trunk/lib/parser/lib/rules/zena.rb

    r613 r615  
    10221022      if value = params[:project] 
    10231023        if value == 'stored' && stored = @context[:stored_project] 
    1024           conditions << "project_id = '\#{#{stored}[:project_id]}'" 
     1024          conditions << "project_id = '\#{#{stored}.get_project_id}'" 
    10251025        elsif value == 'current' 
    1026           conditions << "project_id = '\#{#{node}[:project_id]}'" 
     1026          conditions << "project_id = '\#{#{node}.get_project_id}'" 
    10271027        elsif value =~ /\A\d+\Z/ 
    10281028          conditions << "project_id = '#{value.to_i}'" 
     
    10341034      if value = params[:section] 
    10351035        if value == 'stored' && stored = @context[:stored_section] 
    1036           conditions << "section_id = '\#{#{stored}[:section_id]}'" 
     1036          conditions << "section_id = '\#{#{stored}.get_section_id}'" 
    10371037        elsif value == 'current' 
    1038           conditions << "section_id = '\#{#{node}[:section_id]}'" 
     1038          conditions << "section_id = '\#{#{node}.get_section_id}'" 
    10391039        elsif value =~ /\A\d+\Z/ 
    10401040          conditions << "section_id = '#{value.to_i}'" 
     
    10471047        if value = params[k] 
    10481048          # current, same are synonym for 'today' 
    1049           value = 'today' if ['current', 'same'].include?(value) 
    10501049          conditions << Node.connection.date_condition(value,"#{k}_at",current_date) 
    10511050        end 
     
    15031502    class MysqlAdapter 
    15041503      def date_condition(date_cond, field, ref_date='today') 
    1505         if ref_date == 'today' 
     1504        if date_cond == 'today' || ref_date == 'today' 
    15061505          ref_date = 'now()' 
    15071506        else 
     
    15091508        end 
    15101509        case date_cond 
    1511         when 'today' 
     1510        when 'today', 'current', 'same' 
    15121511          "DATE(#{field}) = DATE(#{ref_date})" 
    15131512        when 'week' 
  • trunk/lib/parser/test/parser_test.rb

    r612 r615  
    5656  testfile :zafu, :zafu_asset, :zafu_insight, :zazen 
    5757  def test_single 
    58     do_test('zazen', 'link_sharp') 
     58    do_test('zazen', 'link_sharp_attribute') 
    5959  end 
    6060   
  • trunk/lib/parser/test/zazen.yml

    r612 r615  
    126126link_sharp: 
    127127  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>" 
    129129 
    130130link_sharp_same_as_title: 
    131131  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 
     134link_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>" 
    133137 
    134138wiki_link: 
  • trunk/test/helpers/zena_parser_test.rb

    r614 r615  
    55 
    66class ZenaParserTest < ZenaHelperTest 
    7   testfile :relations, :basic, :zafu_ajax 
     7  testfile :relations, :basic, :zafu_ajax, :zazen 
    88  Section # make sure we load Section links before trying relations 
    99   
    1010  def test_single 
    11     do_test('relations', 'checkbox') 
     11    do_test('zazen', 'link_sharp_in_name') 
    1212  end 
    1313