Class: Todo

Inherits:
Chunk::Abstract show all
Defined in:
app/models/chunks/todo.rb

Overview

ToDo items.

Instance Attribute Summary collapse

Attributes inherited from Chunk::Abstract

#revision, #text

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Chunk::Abstract

#mask, #post_mask, #pre_mask, #revert

Constructor Details

#initialize(match_data, revision) ⇒ Todo

Returns a new instance of Todo.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/models/chunks/todo.rb', line 11

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

Instance Attribute Details

#contextObject

Returns the value of attribute context.



9
10
11
# File 'app/models/chunks/todo.rb', line 9

def context
  @context
end

#due_dateObject

Returns the value of attribute due_date.



9
10
11
# File 'app/models/chunks/todo.rb', line 9

def due_date
  @due_date
end

Class Method Details

.patternObject



7
# File 'app/models/chunks/todo.rb', line 7

def self.pattern() /todo(@[\w,]+)?: (.*?)(?=<br|\r|\n|\z)/i end

Instance Method Details

#escaped_textObject



35
# File 'app/models/chunks/todo.rb', line 35

def escaped_text() nil end

#unmask(content) ⇒ Object



37
38
39
40
41
42
43
# File 'app/models/chunks/todo.rb', line 37

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