app/models/chunks/todo.rb in Pimki-1.3.092 vs app/models/chunks/todo.rb in Pimki-1.4.092

- old
+ new

@@ -1,23 +1,44 @@ -require 'chunks/wiki' -require 'date' -require 'parsedate' - -# ToDo items. -class Todo < Chunk::Abstract - def self.pattern() /todo: (.*?)(?=<br|\r|\n|\z)/i end - - def initialize(match_data, revision) - super(match_data, revision) - @text = match_data[1] - end - - def escaped_text() nil end - - def unmask(content) - return self if content.gsub!( Regexp.new(mask(content)), - # the style 'todo' is bright-red to be eye catching. It is not expected that - # there will be too many items on one page, but each is supposed to stand out. - # The ToDo special page differentiates between the 'todo' and 'todoFuture' styles. - "<span class=\"todo\"><strong>TODO:</strong> #{@text}</span>" ) - end -end +require 'chunks/wiki' +require 'date' +require 'parsedate' + +# ToDo items. +class Todo < Chunk::Abstract + def self.pattern() /todo(@[\w,]+)?: (.*?)(?=<br|\r|\n|\z)/i end + + attr_accessor :context, :due_date + + def initialize(match_data, revision) + super(match_data, revision) + @context = match_data[1] + @context = @context.nil? || @context.empty? ? [] : @context.delete('@').split(',') + @text = match_data[2] + begin + d = ParseDate.parsedate(@text) + # see if there's a date in the todo: + if not d.all? { |x| x.nil? } + d = d[0..2] + # sanity check the order retured from ParseDate: stuff like 'Jan 2005' + # will be returned in inverse order to '12 Jan 2005'. (ie. no automatic bounds checking) + d.reverse! if d[2] > 31 + # get the [year,month,date] with sane values if you miss the day/year. + # this should allow users to specify stuff like 'Dec 2005' or 'Dec 21'. + d = [ d[0] || Date.today.year, d[1], d[2] || 1 ] + @due_date = Date.new(*d) + end + rescue => detail + p ['==>', detail, @text] + @due_date = nil + end + end + + def escaped_text() nil end + + def unmask(content) + return self if content.gsub!( Regexp.new(mask(content)), + # the style 'todo' is bright-red to be eye catching. It is not expected that + # there will be too many items on one page, but each is supposed to stand out. + # The ToDo special page differentiates between the 'todo' and 'todoFuture' styles. + "<todo-tag context='#{@context.join(',')}' due_date='#{@due_date}'><span class=\"todo\"><strong>TODO#{ " @ #{@context.join(', ')}" unless @context.empty?}:</strong> #{@text}</span></todo-tag>" ) + end +end