Sha256: 2bbc40dd11d1fdadafe68e5ca6f3e0d276d9b0d125449848bd9f10b21e5f1a22
Contents?: true
Size: 1.67 KB
Versions: 2
Compression:
Stored size: 1.67 KB
Contents
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(',') @context += revision.page.categories @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 @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
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
Pimki-1.8.092 | app/models/chunks/todo.rb |
Pimki-1.8.200 | app/models/chunks/todo.rb |