todotxt 0.0.3 → 0.1.0

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.
Files changed (49) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +2 -0
  3. data/README.md +1 -0
  4. data/bin/todotxt +3 -3
  5. data/conf/todotxt.cfg +13 -1
  6. data/cucumber.yml +3 -0
  7. data/features/add.feature +24 -0
  8. data/features/append.feature +28 -0
  9. data/features/backwards.feature +28 -0
  10. data/features/colors.feature +51 -0
  11. data/features/del.feature +52 -0
  12. data/features/depri.feature +38 -0
  13. data/features/do.feature +47 -0
  14. data/features/due.feature +49 -0
  15. data/features/edit.feature +31 -0
  16. data/features/generate_config.feature +19 -0
  17. data/features/generate_txt.feature +20 -0
  18. data/features/initialize.feature +73 -0
  19. data/features/list.feature +132 -0
  20. data/features/move.feature +33 -0
  21. data/features/prepend.feature +28 -0
  22. data/features/pri.feature +40 -0
  23. data/features/replace.feature +28 -0
  24. data/features/step_definitions/environment_steps.rb +47 -0
  25. data/features/step_definitions/list_steps.rb +34 -0
  26. data/features/support/ansi.rb +5 -0
  27. data/features/support/aruba.rb +9 -0
  28. data/features/support/debugger.rb +1 -0
  29. data/features/undo.feature +54 -0
  30. data/lib/todotxt/cli.rb +131 -45
  31. data/lib/todotxt/clihelpers.rb +4 -1
  32. data/lib/todotxt/config.rb +58 -0
  33. data/lib/todotxt/regex.rb +1 -0
  34. data/lib/todotxt/todo.rb +5 -0
  35. data/lib/todotxt/todofile.rb +40 -0
  36. data/lib/todotxt/todolist.rb +20 -2
  37. data/lib/todotxt/version.rb +1 -1
  38. data/lib/todotxt.rb +2 -0
  39. data/spec/cli_spec.rb +6 -0
  40. data/spec/config_spec.rb +52 -0
  41. data/spec/fixtures/config_both.cfg +4 -0
  42. data/spec/fixtures/config_new.cfg +2 -0
  43. data/spec/fixtures/config_old.cfg +1 -0
  44. data/spec/spec_helper.rb +3 -0
  45. data/spec/todo_spec.rb +12 -0
  46. data/spec/todofile_spec.rb +31 -0
  47. data/spec/todolist_spec.rb +20 -2
  48. data/todotxt.gemspec +4 -0
  49. metadata +154 -28
@@ -1,6 +1,7 @@
1
1
  require "todotxt/todo"
2
2
 
3
3
  module Todotxt
4
+ #@TODO merge with TodoFile, both overlap too much
4
5
  class TodoList
5
6
  include Enumerable
6
7
 
@@ -10,7 +11,7 @@ module Todotxt
10
11
  @todos = []
11
12
  @file = file
12
13
 
13
- File.open(file).read.each_line do |l|
14
+ File.open(file.path).read.each_line do |l|
14
15
  add l.strip unless l.empty?
15
16
  end
16
17
  end
@@ -27,6 +28,11 @@ module Todotxt
27
28
  @todos.reject! { |t| t.line.to_s == line.to_s }
28
29
  end
29
30
 
31
+ def move line, other_list
32
+ other_list.add find_by_line(line).to_s
33
+ remove line
34
+ end
35
+
30
36
  def projects
31
37
  map { |t| t.projects }.flatten.uniq.sort
32
38
  end
@@ -40,7 +46,7 @@ module Todotxt
40
46
  end
41
47
 
42
48
  def save
43
- File.open(@file, "w") { |f| f.write to_txt }
49
+ File.open(@file.path, "w") { |f| f.write to_txt }
44
50
  end
45
51
 
46
52
  def each &block
@@ -71,10 +77,22 @@ module Todotxt
71
77
  self
72
78
  end
73
79
 
80
+ def on_date date
81
+ @todos.select { |t| t.due == date }
82
+ end
83
+
84
+ def before_date date
85
+ @todos.reject { |t| t.due.nil? || t.due >= date }
86
+ end
87
+
74
88
  def to_txt
75
89
  @todos.sort { |a,b| a.line <=> b.line }.map { |t| t.to_s.strip }.join("\n")
76
90
  end
77
91
 
92
+ def to_s
93
+ @file.basename
94
+ end
95
+
78
96
  def to_a
79
97
  map { |t| ["#{t.line}. ", t.to_s] }
80
98
  end
@@ -1,3 +1,3 @@
1
1
  module Todotxt
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/todotxt.rb CHANGED
@@ -5,8 +5,10 @@ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
5
5
  module Todotxt
6
6
  autoload :Todo, "todotxt/todo"
7
7
  autoload :TodoList, "todotxt/todolist"
8
+ autoload :TodoFile, "todotxt/todofile"
8
9
  autoload :CLI, "todotxt/cli"
9
10
  autoload :CLIHelpers, "todotxt/clihelpers"
11
+ autoload :Config, "todotxt/config"
10
12
  end
11
13
 
12
14
  require "todotxt/regex"
data/spec/cli_spec.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "spec_helper"
2
+ require "todotxt/clihelpers"
3
+ require "todotxt/cli"
4
+
5
+ describe Todotxt::CLI do
6
+ end
@@ -0,0 +1,52 @@
1
+ require "spec_helper"
2
+ require "todotxt/config"
3
+
4
+ describe Todotxt::Config do
5
+ before(:each) do
6
+ ENV["HOME"] = File.join "/", "tmp"
7
+ @config_file = File.join ENV["HOME"], ".todotxt.cfg"
8
+ end
9
+
10
+ context "valid config" do
11
+ before(:each) do
12
+ @cfg = Todotxt::Config.new "spec/fixtures/config_new.cfg"
13
+ end
14
+
15
+ it 'should have a "files"' do
16
+ @cfg.files.keys.should include "todo"
17
+ end
18
+
19
+ it 'should not be deprecated' do
20
+ @cfg.should_not be_deprecated
21
+ end
22
+ end
23
+
24
+ context "old style config" do
25
+ before(:each) do
26
+ @cfg = Todotxt::Config.new "spec/fixtures/config_old.cfg"
27
+ end
28
+
29
+ it 'should place "todo_txt_path" under files' do
30
+ @cfg.files.keys.should include "todo"
31
+ end
32
+
33
+ it 'should be deprecated' do
34
+ @cfg.should be_deprecated
35
+ end
36
+ end
37
+
38
+ it 'not allow both "files" and "todo_txt_path"' do
39
+ expect do
40
+ Todotxt::Config.new "spec/fixtures/config_both.cfg"
41
+ end.to raise_error "Bad configuration file: use either files or todo_txt_path"
42
+ end
43
+
44
+ context "#generate!" do
45
+ it 'should create a template' do
46
+ File.delete @config_file if File.exists? @config_file
47
+ todo = Todotxt::Config.new
48
+ todo.generate!
49
+ File.exists?(@config_file).should be_true
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,4 @@
1
+ todo_txt_path = "/tmp/todo.txt"
2
+
3
+ [files]
4
+ todo = "/tmp/todo.txt"
@@ -0,0 +1,2 @@
1
+ [files]
2
+ todo = "/tmp/todo.txt"
@@ -0,0 +1 @@
1
+ todo_txt_path = "/tmp/todo.txt"
@@ -0,0 +1,3 @@
1
+ require 'chronic'
2
+ require 'simplecov'
3
+ SimpleCov.start
data/spec/todo_spec.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require "spec_helper"
1
2
  require "todotxt/todo"
2
3
 
3
4
  describe Todotxt::Todo do
@@ -27,6 +28,17 @@ describe Todotxt::Todo do
27
28
  todo.done.should eql true
28
29
  end
29
30
 
31
+ it "parses a due date" do
32
+ todo = Todotxt::Todo.new "(A) x 2012-12-12 an item +project1 +project2 @context1 @context2"
33
+ todo.due.should eql Chronic.parse("12 December 2012").to_date
34
+
35
+ todo = Todotxt::Todo.new "2012-1-2 an item +project1 +project2 @context1 @context2"
36
+ todo.due.should eql Chronic.parse("2 January 2012").to_date
37
+
38
+ todo = Todotxt::Todo.new "42 folders"
39
+ todo.due.should be_nil
40
+ end
41
+
30
42
  it "stores line number when creating an item" do
31
43
  todo = Todotxt::Todo.new "an item", "2"
32
44
 
@@ -0,0 +1,31 @@
1
+ require "spec_helper"
2
+ require "todotxt/config"
3
+ require "todotxt/todofile"
4
+
5
+ describe Todotxt::TodoFile do
6
+ before(:each) do
7
+ @todo_path = "/tmp/todo.txt"
8
+ Todotxt::Config.any_instance.stub(:files) do
9
+ {todo:@todo_path}
10
+ end
11
+ end
12
+ after(:each) do
13
+ File.delete @todo_path if File.exists? @todo_path
14
+ end
15
+
16
+ it 'should create a new file when initializing' do
17
+ file = Todotxt::TodoFile.new(@todo_path)
18
+ file.class.should == Todotxt::TodoFile
19
+ end
20
+
21
+ it 'should create a new file via the key in config' do
22
+ file = Todotxt::TodoFile.from_key(:todo)
23
+ file.class.should == Todotxt::TodoFile
24
+ end
25
+
26
+ it 'should throw an error for undefined keys' do
27
+ expect {
28
+ Todotxt::TodoFile.from_key(:does_not_exist)
29
+ }.to raise_error "Key not found in config"
30
+ end
31
+ end
@@ -1,10 +1,13 @@
1
+ require "spec_helper"
1
2
  require "todotxt/todolist"
3
+ require "todotxt/todofile"
2
4
 
3
5
  describe Todotxt::TodoList do
4
6
 
5
7
  describe "with simple list" do
6
8
  before :each do
7
- @list = Todotxt::TodoList.new File.join(File.dirname(__FILE__), "fixtures", "simple_todo.txt")
9
+ @file = Todotxt::TodoFile.new File.join(File.dirname(__FILE__), "fixtures", "simple_todo.txt")
10
+ @list = Todotxt::TodoList.new @file
8
11
  end
9
12
 
10
13
  it "parses a file on creation" do
@@ -50,6 +53,20 @@ describe Todotxt::TodoList do
50
53
  @list.todos.count.should eql 1
51
54
  end
52
55
 
56
+ it "fetches items for a certain date" do
57
+ @list.add "2012-12-12 item"
58
+ date = DateTime.parse("2012-12-12")
59
+ @list.on_date(date).count.should eql 1
60
+ @list.on_date(date).should eql [@list.todos.last]
61
+ end
62
+
63
+ it "fetchs items before a cereain date" do
64
+ @list.add "2012-11-11 item"
65
+ @list.add "2012-12-12 item"
66
+ date = DateTime.parse("2012-12-12")
67
+ @list.before_date(date).count.should eql 1
68
+ end
69
+
53
70
  it "includes done items in search when told to do so" do
54
71
  @list.filter "first", :with_done => true
55
72
 
@@ -75,7 +92,8 @@ EOF
75
92
 
76
93
  describe "with complex list" do
77
94
  before :each do
78
- @list = Todotxt::TodoList.new File.join(File.dirname(__FILE__), "fixtures", "complex_todo.txt")
95
+ @file = Todotxt::TodoFile.new File.join(File.dirname(__FILE__), "fixtures", "complex_todo.txt")
96
+ @list = Todotxt::TodoList.new @file
79
97
  end
80
98
 
81
99
  it "sorts itself automatically on parse" do
data/todotxt.gemspec CHANGED
@@ -21,7 +21,11 @@ Gem::Specification.new do |s|
21
21
  s.add_dependency "thor", "~> 0.15.4"
22
22
  s.add_dependency "rainbow", "~> 1.1.4"
23
23
  s.add_dependency "parseconfig", "~> 1.0.2"
24
+ s.add_dependency "chronic", "~> 0.9.1"
24
25
 
25
26
  s.add_development_dependency "rake"
26
27
  s.add_development_dependency "rspec", "~> 2.11.0"
28
+ s.add_development_dependency "simplecov"
29
+ s.add_development_dependency "aruba", "~> 0.5.1"
30
+ s.add_development_dependency "debugger"
27
31
  end
metadata CHANGED
@@ -1,71 +1,141 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: todotxt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
5
- prerelease:
4
+ version: 0.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Johan Sahlén
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-07-17 00:00:00.000000000Z
11
+ date: 2013-03-15 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: thor
16
- requirement: &70177769396400 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
21
19
  version: 0.15.4
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *70177769396400
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.15.4
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: rainbow
27
- requirement: &70177769395640 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
31
  - - ~>
31
32
  - !ruby/object:Gem::Version
32
33
  version: 1.1.4
33
34
  type: :runtime
34
35
  prerelease: false
35
- version_requirements: *70177769395640
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 1.1.4
36
41
  - !ruby/object:Gem::Dependency
37
42
  name: parseconfig
38
- requirement: &70177769394860 !ruby/object:Gem::Requirement
39
- none: false
43
+ requirement: !ruby/object:Gem::Requirement
40
44
  requirements:
41
45
  - - ~>
42
46
  - !ruby/object:Gem::Version
43
47
  version: 1.0.2
44
48
  type: :runtime
45
49
  prerelease: false
46
- version_requirements: *70177769394860
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: chronic
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 0.9.1
47
69
  - !ruby/object:Gem::Dependency
48
70
  name: rake
49
- requirement: &70177769394140 !ruby/object:Gem::Requirement
50
- none: false
71
+ requirement: !ruby/object:Gem::Requirement
51
72
  requirements:
52
73
  - - ! '>='
53
74
  - !ruby/object:Gem::Version
54
75
  version: '0'
55
76
  type: :development
56
77
  prerelease: false
57
- version_requirements: *70177769394140
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
58
83
  - !ruby/object:Gem::Dependency
59
84
  name: rspec
60
- requirement: &70177769393240 !ruby/object:Gem::Requirement
61
- none: false
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 2.11.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
62
93
  requirements:
63
94
  - - ~>
64
95
  - !ruby/object:Gem::Version
65
96
  version: 2.11.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: aruba
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 0.5.1
66
118
  type: :development
67
119
  prerelease: false
68
- version_requirements: *70177769393240
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: 0.5.1
125
+ - !ruby/object:Gem::Dependency
126
+ name: debugger
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
69
139
  description: Interact with your todo.txt using a Ruby-base command-line tool
70
140
  email:
71
141
  - johan@monospace.se
@@ -82,50 +152,106 @@ files:
82
152
  - bin/todotxt
83
153
  - conf/todo.txt
84
154
  - conf/todotxt.cfg
155
+ - cucumber.yml
156
+ - features/add.feature
157
+ - features/append.feature
158
+ - features/backwards.feature
159
+ - features/colors.feature
160
+ - features/del.feature
161
+ - features/depri.feature
162
+ - features/do.feature
163
+ - features/due.feature
164
+ - features/edit.feature
165
+ - features/generate_config.feature
166
+ - features/generate_txt.feature
167
+ - features/initialize.feature
168
+ - features/list.feature
169
+ - features/move.feature
170
+ - features/prepend.feature
171
+ - features/pri.feature
172
+ - features/replace.feature
173
+ - features/step_definitions/environment_steps.rb
174
+ - features/step_definitions/list_steps.rb
175
+ - features/support/ansi.rb
176
+ - features/support/aruba.rb
177
+ - features/support/debugger.rb
178
+ - features/undo.feature
85
179
  - lib/todotxt.rb
86
180
  - lib/todotxt/cli.rb
87
181
  - lib/todotxt/clihelpers.rb
182
+ - lib/todotxt/config.rb
88
183
  - lib/todotxt/regex.rb
89
184
  - lib/todotxt/todo.rb
185
+ - lib/todotxt/todofile.rb
90
186
  - lib/todotxt/todolist.rb
91
187
  - lib/todotxt/version.rb
188
+ - spec/cli_spec.rb
189
+ - spec/config_spec.rb
92
190
  - spec/fixtures/complex_todo.txt
191
+ - spec/fixtures/config_both.cfg
192
+ - spec/fixtures/config_new.cfg
193
+ - spec/fixtures/config_old.cfg
93
194
  - spec/fixtures/simple_todo.txt
195
+ - spec/spec_helper.rb
94
196
  - spec/todo_spec.rb
197
+ - spec/todofile_spec.rb
95
198
  - spec/todolist_spec.rb
96
199
  - todotxt.gemspec
97
200
  homepage: http://github.com/jsahlen/todotxt
98
201
  licenses: []
202
+ metadata: {}
99
203
  post_install_message:
100
204
  rdoc_options: []
101
205
  require_paths:
102
206
  - lib
103
207
  required_ruby_version: !ruby/object:Gem::Requirement
104
- none: false
105
208
  requirements:
106
209
  - - ! '>='
107
210
  - !ruby/object:Gem::Version
108
211
  version: '0'
109
- segments:
110
- - 0
111
- hash: -265984123705521099
112
212
  required_rubygems_version: !ruby/object:Gem::Requirement
113
- none: false
114
213
  requirements:
115
214
  - - ! '>='
116
215
  - !ruby/object:Gem::Version
117
216
  version: '0'
118
- segments:
119
- - 0
120
- hash: -265984123705521099
121
217
  requirements: []
122
218
  rubyforge_project: todotxt
123
- rubygems_version: 1.8.10
219
+ rubygems_version: 2.0.0
124
220
  signing_key:
125
- specification_version: 3
221
+ specification_version: 4
126
222
  summary: todo.txt with a Ruby flair
127
223
  test_files:
224
+ - features/add.feature
225
+ - features/append.feature
226
+ - features/backwards.feature
227
+ - features/colors.feature
228
+ - features/del.feature
229
+ - features/depri.feature
230
+ - features/do.feature
231
+ - features/due.feature
232
+ - features/edit.feature
233
+ - features/generate_config.feature
234
+ - features/generate_txt.feature
235
+ - features/initialize.feature
236
+ - features/list.feature
237
+ - features/move.feature
238
+ - features/prepend.feature
239
+ - features/pri.feature
240
+ - features/replace.feature
241
+ - features/step_definitions/environment_steps.rb
242
+ - features/step_definitions/list_steps.rb
243
+ - features/support/ansi.rb
244
+ - features/support/aruba.rb
245
+ - features/support/debugger.rb
246
+ - features/undo.feature
247
+ - spec/cli_spec.rb
248
+ - spec/config_spec.rb
128
249
  - spec/fixtures/complex_todo.txt
250
+ - spec/fixtures/config_both.cfg
251
+ - spec/fixtures/config_new.cfg
252
+ - spec/fixtures/config_old.cfg
129
253
  - spec/fixtures/simple_todo.txt
254
+ - spec/spec_helper.rb
130
255
  - spec/todo_spec.rb
256
+ - spec/todofile_spec.rb
131
257
  - spec/todolist_spec.rb