all_todo 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e614f169caa9cf9299694cbae2877a94a5bea86
4
- data.tar.gz: 18c546ba19151dc0728c091583c907bce8ccecc7
3
+ metadata.gz: 14a238fd842c1ed5bc0895777821fd9c55475f8f
4
+ data.tar.gz: 94883c7db7611aaf8d9b81437f4aa7792425e68c
5
5
  SHA512:
6
- metadata.gz: 6b0ffae932f9e7521ce2bc53540628ee6b776c1ecbd92789f27545a97321400eb8b179ceeb6dafdabf6482222d00c4a53e3313045d95a7b4226e07a7644207b1
7
- data.tar.gz: b92a0306c04b622aa19bdd664b22b07a82c3698dbbbbd5d1f5f02892612395b237c5f14916ab22752c7c411d2a51a064ce4e84167127277b0c1225ecff1680e1
6
+ metadata.gz: 5d644983654f354f63ab409e03264b12dc15c7164cebfab9f1ee2aa9a78399f0776f44cb8103ca1d372ad4284ab8b0c9fe23338e13e9084b25cc5fc04fc25669
7
+ data.tar.gz: eea0a4e9fc9e82949dfa4b2b7b805ed0dcb790636978ef8c1e8bad97e7992652efc77a7131c6676e3656f54c68372b198e4bb0c74208fc6af35b5cba8925b7df
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/all_todo.rb CHANGED
@@ -9,29 +9,35 @@ require 'rexle-diff'
9
9
 
10
10
  class AllTodo < PxTodo
11
11
 
12
- def initialize(raw_s, filepath: '.')
12
+ def initialize(raw_s=nil, filepath: '.')
13
13
 
14
- super(raw_s, filepath: filepath) do |x|
14
+ if raw_s then
15
15
 
16
- todo = x.title
17
-
18
- # is the to-do item selected for action today?
19
- today_item = todo.slice!(/^\*\s+/)
20
- x.when = 'today' if today_item
21
-
22
- x.title = todo
23
-
24
- end
16
+ super(raw_s, filepath: filepath) do |x|
17
+
18
+ todo = x.title
25
19
 
20
+ # is the to-do item selected for action today?
21
+ today_item = todo.slice!(/^\*\s+/)
22
+ x.when = 'today' if today_item
23
+
24
+ x.title = todo
25
+
26
+ end
27
+ end
28
+
26
29
  end
27
30
 
31
+ # generates the all_todo_detail.txt file contents
32
+ #
28
33
  def detail()
29
34
 
30
35
  lines = []
31
36
 
32
37
  @px.each_recursive do |item, parent, level, i|
33
38
 
34
- lines << item.to_h.map {|k,v| "%s%s: %s" % [' ' * level, k, v]}.join("\n")
39
+ lines << item.to_h.map \
40
+ {|k,v| "%s%s: %s" % [' ' * level, k, v]}.join("\n")
35
41
  lines << ['']
36
42
 
37
43
  end
@@ -69,12 +75,83 @@ class AllTodo < PxTodo
69
75
  pr = PxRowX.new(lines.join)
70
76
  pr.to_xml pretty: true
71
77
 
78
+ end
79
+
80
+ # parses the all_todo_detail.txt file and updates the all_todo_detail.xml file
81
+
82
+ def update_detail()
83
+
84
+ s = File.read File.join(@filepath, 'all_todo_detail.txt')
85
+
86
+ px = Polyrex.new parse_detail(s)
87
+ results = []
88
+
89
+ px.each_recursive do |x, parent|
90
+
91
+ if x.when.length > 0 then
92
+
93
+ basic_xpath = x.node.backtrack.to_xpath
94
+
95
+ a = basic_xpath.split('/')
96
+ a.shift # removes the root node reference
97
+
98
+ s = if parent.heading.length > 0 then
99
+ "heading='%s'" % parent.heading
100
+ else
101
+ "title='%s'" % parent.title
102
+ end
103
+
104
+ a[-3] << "[summary/#{s}]"
105
+ a.last << "[summary/title='#{x.title}']"
106
+ xpath = a.join('/')
107
+
108
+ results << [xpath, x.when]
109
+ end
110
+ end
111
+
112
+ # open the all_todo_detail.xml file
113
+
114
+ xmlfilepath = File.join(@filepath, 'all_todo_detail.xml')
115
+
116
+ # if the file doesn't exist save it and return from the method
117
+
118
+ unless File.exists? xmlfilepath then
119
+ File.write xmlfilepath, px.to_xml(pretty: true)
120
+ end
121
+
122
+ px2 = Polyrex.new xmlfilepath
123
+
124
+ results.each do |xpath, val|
125
+
126
+ r = px2.element(xpath + '/summary/when')
127
+ r2 = px.element(xpath + '/summary/when')
128
+ next unless r
129
+
130
+ a1, a2 = [r.text, val].map {|x| x.split(';').map(&:strip) }
131
+
132
+ # return values which in both a1 and a2
133
+ r2.text = (a1 | a2).join('; ')
134
+
135
+ end
136
+
137
+ # update the all_todo_detail.xml file
138
+
139
+ File.write xmlfilepath, px.to_xml(pretty: true)
140
+
72
141
  end
73
142
 
74
143
  def save(filepath=File.join(@filepath, 'all_todo.xml'))
75
144
 
76
145
  File.write filepath, @px.to_xml(pretty: true)
77
-
146
+
147
+ # also update the all_todo.txt and all_todo_detail.txt
148
+
149
+ File.write File.join(@filepath, 'all_todo.txt'), self.to_s
150
+
151
+ #update_detail()
152
+ #File.write File.join(@filepath, 'all_todo_detail.txt'), self.detail
153
+ 'saved'
154
+
78
155
  end
79
156
 
80
157
  def to_s()
@@ -103,7 +180,7 @@ class AllTodo < PxTodo
103
180
  status = x.status == 'done' ? 'x' : ' '
104
181
 
105
182
  todo = []
106
- todo << '* ' if x.when == 'today'
183
+ todo << '* ' if x.when =~ /today/
107
184
  todo << "%s[%s] %s" % [indent, status, x.title]
108
185
 
109
186
  lines << '' if i == 0 and parent.heading.length > 0
@@ -166,35 +243,39 @@ class AllTodo < PxTodo
166
243
  def update_today(file='todo_daily.txt')
167
244
 
168
245
  # parse the newest todo_daily.txt file
169
- pxtodo = PxTodo.new(file, filepath: @filepath)
246
+
247
+ pxtodo = PxTodo.new(file, filepath: @filepath, ignore_headings: true)
170
248
 
171
249
  # remove the id attributes
172
250
  px2 = pxtodo.to_px
173
251
  px2.xpath('//todo').each {|x| x.attributes.delete :id}
174
-
252
+
175
253
  # read the todo_daily_noid file
176
254
  px1noid = Polyrex.new(File.join(@filepath, 'todo_daily_noid.xml'))
177
-
255
+ xml = px1noid.to_xml
256
+ xml2 = px2.to_xml pretty: true
257
+
178
258
  # compare the 2 documents
179
- doc = RexleDiff.new(px1noid.to_xml, px2.to_xml).to_doc
180
-
259
+ doc = RexleDiff.new(xml, xml2).to_doc
260
+
181
261
  a = doc.xpath('//todo/summary/status[@created]../.')
182
262
 
263
+
183
264
  # update the all_todo document
184
265
  # first we need to find the ids
185
266
 
186
267
  px1 = Polyrex.new(File.join(@filepath, 'todo_daily.xml'))
187
-
268
+
188
269
  statuses = a.map do |node|
189
270
 
190
271
  e = px1.element("//summary[contains(title,'#{node.text('title')}')]")
191
272
  [e.parent.attributes[:id], node.text('status') ]
192
273
 
193
274
  end
194
-
275
+
195
276
  statuses.each do |id, status|
196
277
 
197
- todo = @px.find_by_id id
278
+ todo = @px.find_by_id id
198
279
  todo.status = status
199
280
 
200
281
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: all_todo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,7 +31,7 @@ cert_chain:
31
31
  4IWTpx4UfuUB+a/n3zRd7tPzfsCnbjv0WeNaOLxPEdrqrbPxdMp0ULnHMi6/cuMX
32
32
  +/4csIEIHj2yLg==
33
33
  -----END CERTIFICATE-----
34
- date: 2016-11-26 00:00:00.000000000 Z
34
+ date: 2016-12-03 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: px_todo
metadata.gz.sig CHANGED
Binary file