todo-txt 0.7 → 0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/todo-txt.rb +1 -0
- data/lib/todo-txt/options.rb +41 -0
- data/lib/todo-txt/syntax.rb +15 -1
- data/lib/todo-txt/task.rb +11 -2
- data/spec/todo-txt/options/require_completed_on_spec.rb +42 -0
- data/spec/todo-txt/options_spec.rb +27 -0
- data/spec/todo-txt/syntax_spec.rb +23 -5
- data/todo-txt.gemspec +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61f9189159159b6e65f5f74b988b2e10bce9ebdd
|
4
|
+
data.tar.gz: d4b2af334263168828b8c55907bb7cbd88d5e961
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e21f06a513c28f57ee49574a9cf433d3adaf84bd6ce7de7101263ddd414919cd83b6f2d3d73c7720a85bd3c028e6b22689b7208134d5727bd1ec6d55fa204619
|
7
|
+
data.tar.gz: bec7f7985f84d4d966936f454ebb21d7c820e67488e5fe98c2eceb013a2e5454686084377e4f924a6eaac5d56c47d69a7c50451972ea5d257475a1ff1e720b7d
|
data/.gitignore
CHANGED
data/lib/todo-txt.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
module Todo
|
2
|
+
class << self
|
3
|
+
attr_accessor :options_instance
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.options
|
7
|
+
self.options_instance ||= Options.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.customize
|
11
|
+
self.options_instance ||= Options.new
|
12
|
+
yield(options_instance)
|
13
|
+
end
|
14
|
+
|
15
|
+
class Options
|
16
|
+
# Require all done tasks to have a `completed_on` date. True by default.
|
17
|
+
#
|
18
|
+
# - When `true`, tasks with invalid dates are considered not done.
|
19
|
+
# - When `false`, tasks starting with `x ` are considered done.
|
20
|
+
#
|
21
|
+
# @return [Boolean]
|
22
|
+
attr_accessor :require_completed_on
|
23
|
+
|
24
|
+
# PENDING
|
25
|
+
#
|
26
|
+
# Whether or not to preserve original field order for roundtripping.
|
27
|
+
#
|
28
|
+
# @return [Boolean]
|
29
|
+
attr_accessor :maintain_field_order
|
30
|
+
|
31
|
+
def initialize
|
32
|
+
reset
|
33
|
+
end
|
34
|
+
|
35
|
+
# Reset to defaults.
|
36
|
+
def reset
|
37
|
+
@require_completed_on = true
|
38
|
+
@maintain_field_order = false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/todo-txt/syntax.rb
CHANGED
@@ -52,7 +52,7 @@ module Todo
|
|
52
52
|
#
|
53
53
|
# @param line [String] the todo item to be processed
|
54
54
|
# @return [Date] the completed date of the line
|
55
|
-
def
|
55
|
+
def extract_completed_date(line)
|
56
56
|
date = COMPLETED_ON_PATTERN.match(line)
|
57
57
|
begin
|
58
58
|
Date.parse(date[1]) if date
|
@@ -61,6 +61,20 @@ module Todo
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
+
COMPLETED_FLAG = 'x'.freeze
|
65
|
+
SINGLE_SPACE = ' '.freeze
|
66
|
+
|
67
|
+
# Checks whether the given todo item has a completion flag set.
|
68
|
+
#
|
69
|
+
# This provides support for ad-hoc handwritten lists where the completed flag
|
70
|
+
# is set but there is no completed date.
|
71
|
+
#
|
72
|
+
# @param line [String] the todo item to be processed
|
73
|
+
# @return [Boolean]
|
74
|
+
def check_completed_flag(line)
|
75
|
+
line[0] == COMPLETED_FLAG && line[1] == SINGLE_SPACE
|
76
|
+
end
|
77
|
+
|
64
78
|
# Extracts the completion date for the given todo item.
|
65
79
|
# Returns nil if a valid date is not found.
|
66
80
|
#
|
data/lib/todo-txt/task.rb
CHANGED
@@ -14,11 +14,18 @@ module Todo
|
|
14
14
|
# task = Todo::Task.new("(A) A high priority task!")
|
15
15
|
def initialize task
|
16
16
|
@orig = task
|
17
|
-
@completed_on = get_completed_date(orig)
|
18
17
|
@priority, @created_on = orig_priority(orig), orig_created_on(orig)
|
19
18
|
@due_on = get_due_on_date(orig)
|
20
19
|
@contexts ||= extract_contexts(orig)
|
21
20
|
@projects ||= extract_projects(orig)
|
21
|
+
|
22
|
+
if Todo.options.require_completed_on
|
23
|
+
@completed_on = extract_completed_date(orig)
|
24
|
+
@is_completed = !@completed_on.nil?
|
25
|
+
else
|
26
|
+
@completed_on = extract_completed_date(orig)
|
27
|
+
@is_completed = check_completed_flag(orig)
|
28
|
+
end
|
22
29
|
end
|
23
30
|
|
24
31
|
# Returns the original content of the task.
|
@@ -148,7 +155,7 @@ module Todo
|
|
148
155
|
# task.done?
|
149
156
|
# #=> false
|
150
157
|
def done?
|
151
|
-
|
158
|
+
@is_completed
|
152
159
|
end
|
153
160
|
|
154
161
|
# Completes the task on the current date.
|
@@ -168,6 +175,7 @@ module Todo
|
|
168
175
|
# #=> # the current date
|
169
176
|
def do!
|
170
177
|
@completed_on = Date.today
|
178
|
+
@is_completed = true
|
171
179
|
@priority = nil
|
172
180
|
end
|
173
181
|
|
@@ -188,6 +196,7 @@ module Todo
|
|
188
196
|
# #=> nil
|
189
197
|
def undo!
|
190
198
|
@completed_on = nil
|
199
|
+
@is_completed = false
|
191
200
|
@priority = orig_priority(orig)
|
192
201
|
end
|
193
202
|
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#require_completed_on' do
|
4
|
+
context 'set to true' do
|
5
|
+
it 'should treat tasks without the done flag as not done' do
|
6
|
+
task = Todo::Task.new('this task is treated as incomplete')
|
7
|
+
expect(task.done?).to be false
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should treat tasks with a the done flag and no date as not done' do
|
11
|
+
task = Todo::Task.new('x this task is treated as incomplete')
|
12
|
+
expect(task.done?).to be false
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should treat tasks with a the done flag and a completion date as done' do
|
16
|
+
task = Todo::Task.new('x 2016-04-08 this task is treated as complete')
|
17
|
+
expect(task.done?).to be true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'set to false' do
|
22
|
+
before(:all) do
|
23
|
+
Todo.customize do |options|
|
24
|
+
options.require_completed_on = false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should treat tasks without the done flag as not done' do
|
29
|
+
task = Todo::Task.new('this task is treated as incomplete')
|
30
|
+
expect(task.done?).to be false
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should treat tasks with the done flag as done' do
|
34
|
+
task = Todo::Task.new('x this task is treated as complete')
|
35
|
+
expect(task.done?).to be true
|
36
|
+
end
|
37
|
+
|
38
|
+
after(:all) do
|
39
|
+
Todo.options.reset
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Todo::Options do
|
4
|
+
it 'should be available by default in the top-level module' do
|
5
|
+
expect(Todo.options).to be_a Todo::Options
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should provide require_completed_on as true by default' do
|
9
|
+
expect(Todo.options.require_completed_on).to be true
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should provide maintain_field_order as false by default' do
|
13
|
+
expect(Todo.options.maintain_field_order).to be false
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should support customization' do
|
17
|
+
Todo.customize do |options|
|
18
|
+
options.require_completed_on = false
|
19
|
+
end
|
20
|
+
|
21
|
+
expect(Todo.options.require_completed_on).to be false
|
22
|
+
end
|
23
|
+
|
24
|
+
after(:all) do
|
25
|
+
Todo.options.reset
|
26
|
+
end
|
27
|
+
end
|
@@ -79,21 +79,39 @@ describe Todo::Syntax do
|
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
-
describe '#
|
82
|
+
describe '#extract_completed_date' do
|
83
83
|
specify 'empty task' do
|
84
|
-
expect(
|
84
|
+
expect(extract_completed_date('')).to be nil
|
85
85
|
end
|
86
86
|
|
87
87
|
specify 'uncompleted task' do
|
88
|
-
expect(
|
88
|
+
expect(extract_completed_date('2016-03-29 something to do')).to be nil
|
89
89
|
end
|
90
90
|
|
91
91
|
specify 'completed task without date' do
|
92
|
-
expect(
|
92
|
+
expect(extract_completed_date('2016-03-29 something to do')).to be nil
|
93
93
|
end
|
94
94
|
|
95
95
|
specify 'completed task without date' do
|
96
|
-
expect(
|
96
|
+
expect(extract_completed_date('2016-03-29 something to do')).to be nil
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe '#check_completed_flag' do
|
101
|
+
specify 'empty task' do
|
102
|
+
expect(check_completed_flag('')).to be false
|
103
|
+
end
|
104
|
+
|
105
|
+
specify 'uncompleted task' do
|
106
|
+
expect(check_completed_flag('2016-03-29 something to do')).to be false
|
107
|
+
end
|
108
|
+
|
109
|
+
specify 'completed task without date' do
|
110
|
+
expect(check_completed_flag('x something to do')).to be true
|
111
|
+
end
|
112
|
+
|
113
|
+
specify 'completed task with date' do
|
114
|
+
expect(check_completed_flag('x 2016-03-29 something to do')).to be true
|
97
115
|
end
|
98
116
|
end
|
99
117
|
|
data/todo-txt.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: todo-txt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.8'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Rose
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Allows for simple parsing of todo.txt files, as per Gina Trapani's todo.txt
|
14
14
|
project.
|
@@ -27,11 +27,14 @@ files:
|
|
27
27
|
- lib/todo-txt.rb
|
28
28
|
- lib/todo-txt/list.rb
|
29
29
|
- lib/todo-txt/logger.rb
|
30
|
+
- lib/todo-txt/options.rb
|
30
31
|
- lib/todo-txt/syntax.rb
|
31
32
|
- lib/todo-txt/task.rb
|
32
33
|
- spec/data/todo.txt
|
33
34
|
- spec/spec_helper.rb
|
34
35
|
- spec/todo-txt/list_spec.rb
|
36
|
+
- spec/todo-txt/options/require_completed_on_spec.rb
|
37
|
+
- spec/todo-txt/options_spec.rb
|
35
38
|
- spec/todo-txt/syntax_spec.rb
|
36
39
|
- spec/todo-txt/task_spec.rb
|
37
40
|
- todo-txt.gemspec
|