Changeset 1206

Show
Ignore:
Timestamp:
2008-10-02 10:36:32 (3 months ago)
Author:
gaspard
Message:

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

Enhanced [date] to enable params in value parsing ("[param:year]-01-01").

Files:

Legend:

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

    r1197 r1206  
    779779    end 
    780780     
    781     def format_date(thedate, format, tz_name=nil, lang=visitor.lang) 
     781    def format_date(thedate, theformat = nil, tz_name=nil, lang=visitor.lang) 
     782      format = theformat || '%Y-%m-%d %H:%M:%S' 
    782783      return "" unless thedate 
    783784      if tz_name 
     
    797798          adate = Date.parse(thedate) 
    798799        rescue 
    799           return "<span class='parser_error'>invalid date #{thedate.inspect}</span>" 
     800          # only return error if there is a format (without = used in sql query) 
     801          return theformat ? "<span class='parser_error'>invalid date #{thedate.inspect}</span>" : Time.now.strftime('%Y-%m-%d %H:%M:%S') 
    800802        end 
    801803      else 
  • trunk/lib/parser/lib/rules/zena.rb

    r1202 r1206  
    16421642            expand_with(:date=>select) 
    16431643          end 
    1644         elsif select =~ /^\[(.*)\]$/ 
    1645           expand_with(:date=>"(#{node_attribute($1)} || main_date)") 
     1644        elsif select =~ /\[(.*)\]/ 
     1645          date, static = parse_attributes_in_value(select, :erb => false) 
     1646          expand_with(:date => "\"#{date}\"") 
    16461647        else 
    16471648          parser_error("bad parameter '#{select}'") 
     
    33263327        elsif ref_date =~ /(\d{4}-\d{1,2}-\d{1,2}( \d{1,2}:\d{1,2}(:\d{1,2})?)?)/ 
    33273328          ref_date = "'#{$1}'" 
     3329        elsif ref_date =~ /\A"/ 
     3330          ref_date = "'\#{format_date(#{ref_date})}'" 
    33283331        else 
    33293332          ref_date = "'\#{#{ref_date}.strftime('%Y-%m-%d %H:%M:%S')}'" 
  • trunk/test/helpers/zena_parser/basic.yml

    r1198 r1206  
    11051105  res: "Sunday 02.03.2008" 
    11061106 
     1107date_from_params: 
     1108  context: 
     1109    year: 1975 
     1110  src: "<r:date select='[param:year]-01-01'><r:show date='current_date' format='%A %d.%m.%Y'/></r:date>" 
     1111  tem: "<%= format_date(\"#{params[:year]}-01-01\", \"%A %d.%m.%Y\") %>" 
     1112  res: "Wednesday 01.01.1975" 
     1113 
     1114date_from_params_in_query: 
     1115  context: 
     1116    year: 2006 
     1117  src: "<r:date select='[param:year]-01-01'><r:nodes in='site' log='year' do='each' join=', ' do='[name]'/></r:date>" 
     1118  tem: "/date_format.*format_date.*params\[:year\].*%Y/" 
     1119  res: "letter, opening, proposition" 
     1120 
    11071121paginate: 
    11081122  context: