pinpress 1.3.3 → 1.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa24927875f4c63b7ff399e51e7077cc3f54b959
4
- data.tar.gz: 8095783fe3adeedd8abfb09c73961cec1121549f
3
+ metadata.gz: 271e0acf9b01155f4eb894e840347967bb5795c7
4
+ data.tar.gz: eb6f48a7cdc0f339fd1dea648daeebd9dacb6588
5
5
  SHA512:
6
- metadata.gz: 1fe7ae484f60118e98172d0ce4e48460dddfb6e9a05f9629304ea0ee74ea0d4e50a4355115f3c0287f03c1d58ef78fd7906f7b1b8dc595f09fdbaac9eb5acd06
7
- data.tar.gz: e30951147d3927fb627979ca0140b1603fda9a13885b23967470adc30b4aa90e7370662f754d76fa9750aeb3c5d0739b2a8e12fed7236f5647cd6ddf10567052
6
+ metadata.gz: 8c92541fd0e817f807199cc9a9de82bb32bb52e7943905e2747b58ca99b5c42d6054e810e04a2a0350336d8795fb13e5efd56c73967f5e4385fa3fe39310aa90
7
+ data.tar.gz: e2241935876943ce235bc5e608560ea506e4a0084568dc7896acb9e67582edb2001e0e242010e1ad8165821b9dee2b591528ddd8f293692fb3fd5face023828a
data/HISTORY.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 1.4.0 (2014-05-13)
2
+
3
+ * Modified last_run logic to exist on each template
4
+ * Fixed a few small bugs related to template selection
5
+
1
6
  # 1.3.3 (2014-05-13)
2
7
 
3
8
  * Fixed a bug with datetimestamps in `pins last` and `tags last`
data/README.md CHANGED
@@ -42,7 +42,7 @@ SYNOPSIS
42
42
  pinpress [global options] command [command options] [arguments...]
43
43
 
44
44
  VERSION
45
- 1.3.3
45
+ 1.4.0
46
46
 
47
47
  GLOBAL OPTIONS
48
48
  --help - Show this message
@@ -97,6 +97,7 @@ grab:
97
97
 
98
98
  * `-s`: the start date to use (uses [Chronic](https://github.com/mojombo/chronic "Chronic"), which allows dates like "last Tuesday")
99
99
  * `-e`: the end date to use (also uses [Chronic](https://github.com/mojombo/chronic "Chronic"))
100
+ * `-m`: the PinPress template to use
100
101
  * `-n`: the number of pins to return (e.g., 20)
101
102
  * `-t`: a CSV list of tags (e.g., "tag1,tag2") that must exist for the returned pins
102
103
 
@@ -156,6 +157,7 @@ based on the [Tag Template](#tag-templates "Tag Templates") provided.
156
157
  Pinpress also provides some flags that allow a user to define specific tags to
157
158
  grab:
158
159
 
160
+ * `-m`: the PinPress template to use
159
161
  * `-s`: the start date to use (uses [Chronic](https://github.com/mojombo/chronic "Chronic"), which allows dates like "last Tuesday")
160
162
  * `-e`: the end date to use (also uses [Chronic](https://github.com/mojombo/chronic "Chronic"))
161
163
 
@@ -210,20 +212,20 @@ config file -- as an example:
210
212
 
211
213
  ```yaml
212
214
  pin_templates:
213
- - name: pinpress_default
214
- opener: "<ul>\n"
215
- item: >
216
- <li>
217
- <b><a title="<%= description %>" href="<%= href %>" target="_blank">
218
- <%= description %></a>.</b>
219
- <%= extended %>
220
- </li>
221
- closer: "</ul>"
215
+ pinpress_default
216
+ opener: "<ul>\n"
217
+ item: >
218
+ <li>
219
+ <b><a title="<%= description %>" href="<%= href %>" target="_blank">
220
+ <%= description %></a>.</b>
221
+ <%= extended %>
222
+ </li>
223
+ closer: "</ul>"
224
+ # ... other templates ...
222
225
  ```
223
226
 
224
227
  A Pin Template can have several different sub-keys:
225
228
 
226
- * `name` (**required**): the name of the template
227
229
  * `opener` (*optional*): the text that should exist above the pins
228
230
  * `closer` (*optional*): the text that should exist below the pins
229
231
  * `item` (**required**): the formatted text that should be output for every pin
@@ -247,7 +249,7 @@ filled by a pin's values:
247
249
  Pin Templates can be used in two ways: they can either be called dynamically:
248
250
 
249
251
  ```bash
250
- $ pinpress pins template_name
252
+ $ pinpress pins -m template_name
251
253
  ```
252
254
 
253
255
  ...or a default template can be specified in `~/.pinpress`:
@@ -259,15 +261,16 @@ pinpress:
259
261
  default_pin_template: pinpress_default
260
262
  # ... other keys ...
261
263
  pin_templates:
262
- - name: pinpress_default
263
- opener: "<ul>\n"
264
- item: >
265
- <li>
266
- <b><a href="<%= href %>">
267
- <%= description %></a>.</b>
268
- <%= extended %>
269
- </li>
270
- closer: "</ul>"
264
+ pinpress_default
265
+ opener: "<ul>\n"
266
+ item: >
267
+ <li>
268
+ <b><a title="<%= description %>" href="<%= href %>" target="_blank">
269
+ <%= description %></a>.</b>
270
+ <%= extended %>
271
+ </li>
272
+ closer: "</ul>"
273
+ # ... other templates ...
271
274
  ```
272
275
 
273
276
  So, knowing the above, both:
@@ -279,7 +282,7 @@ $ pinpress pins
279
282
  ...and:
280
283
 
281
284
  ```bash
282
- $ pinpress pins pinpress_default
285
+ $ pinpress pins -m pinpress_default
283
286
  ```
284
287
 
285
288
  ...will output pin data in the format specified by that template:
@@ -312,13 +315,12 @@ They, too, are defined in `~/.pinpress`:
312
315
 
313
316
  ```yaml
314
317
  tag_templates:
315
- - name: pinpress_default
316
- item: "<%= tag %> (<%= count %>),"
318
+ pinpress_default
319
+ item: "<%= tag %> (<%= count %>),"
317
320
  ```
318
321
 
319
322
  A Tag Template makes use of the same sub-keys as Pin Template:
320
323
 
321
- * `name` (**required**): the name of the template
322
324
  * `opener` (*optional*): the text that should exist above the tag string
323
325
  * `closer` (*optional*): the text that should exist below the tag string
324
326
  * `item` (**required**): the formatted text that should be output for every tag
@@ -336,7 +338,7 @@ range used)
336
338
  Pin Templates can be used in two ways: they can either be called dynamically:
337
339
 
338
340
  ```bash
339
- $ pinpress tags template_name
341
+ $ pinpress tags -m template_name
340
342
  ```
341
343
 
342
344
  ...or a default template can be specified in `~/.pinpress`:
@@ -350,8 +352,9 @@ pinpress:
350
352
  pin_templates:
351
353
  # ... other keys ...
352
354
  tag_templates:
353
- - name: pinpress_default
354
- item: "<%= tag %> (<%= count %>),"
355
+ pinpress_default
356
+ item: "<%= tag %> (<%= count %>),"
357
+ # ... other templates ...
355
358
  ```
356
359
 
357
360
  So, knowing the above, both:
@@ -363,7 +366,7 @@ $ pinpress tags
363
366
  ...and:
364
367
 
365
368
  ```bash
366
- $ pinpress tags pinpress_default
369
+ $ pinpress tags -m pinpress_default
367
370
  ```
368
371
 
369
372
  ...will output tag data in the format specified by that template:
@@ -420,35 +423,33 @@ pinpress:
420
423
  log_level: WARN
421
424
  version: 1.1.1
422
425
  api_token: bachya:1234567890987654321
423
- last_pins_run: 2014-04-29
424
- last_tags_run: 2014-04-29
425
426
  pin_templates:
426
- - name: pinpress_default
427
- opener: >
428
- <em>The weekly Link Mash is a curated selection of tools, stories, and
429
- other links that I found during my travels on the web. All of my curated
430
- links can be found on <a title="Bachya's Pinboard: Link Mash"
431
- href="https://pinboard.in/u:bachya/t:link-mash/" target="_blank">
432
- my Pinboard</a>; you can also find the Link Mash archives <a
433
- href="http://www.bachyaproductions.com/tag/link-mash/">here</a>.
434
- </em>
435
- <ul>
436
- item: >
437
- <li>
438
- <b><a title="<%= description %>" href="<%= href %>" target="_blank">
439
- <%= description %></a>.</b>
440
- <%= extended %>
441
- </li>
442
- closer: >
443
- </ul>
444
- <hr/>
445
- <em>This Link Mash was generated by <a title="PinPress"
446
- href="https://github.com/bachya/pinpress" target="_blank">PinPress</a>,
447
- a simple tool to generate text templates from <a title="Pinboard"
448
- href="https://pinboard.in" target="_blank">Pinboard</a> data.</em>"
427
+ pinpress_default
428
+ opener: >
429
+ <em>The weekly Link Mash is a curated selection of tools, stories, and
430
+ other links that I found during my travels on the web. All of my curated
431
+ links can be found on <a title="Bachya's Pinboard: Link Mash"
432
+ href="https://pinboard.in/u:bachya/t:link-mash/" target="_blank">
433
+ my Pinboard</a>; you can also find the Link Mash archives <a
434
+ href="http://www.bachyaproductions.com/tag/link-mash/">here</a>.
435
+ </em>
436
+ <ul>
437
+ item: >
438
+ <li>
439
+ <b><a title="<%= description %>" href="<%= href %>" target="_blank">
440
+ <%= description %></a>.</b>
441
+ <%= extended %>
442
+ </li>
443
+ closer: >
444
+ </ul>
445
+ <hr/>
446
+ <em>This Link Mash was generated by <a title="PinPress"
447
+ href="https://github.com/bachya/pinpress" target="_blank">PinPress</a>,
448
+ a simple tool to generate text templates from <a title="Pinboard"
449
+ href="https://pinboard.in" target="_blank">Pinboard</a> data.</em>"
449
450
  tag_templates:
450
- - name: pinpress_default
451
- item: "<%= tag %>,"
451
+ pinpress_default
452
+ item: "<%= tag %>,"
452
453
  ```
453
454
 
454
455
  # Known Issues & Future Releases
data/bin/pinpress CHANGED
@@ -92,11 +92,11 @@ end
92
92
  # ======================================================
93
93
  # Error (runs when an exception is raised)
94
94
  # ======================================================
95
- # on_error do |exception|
96
- # messenger.error(exception.to_s)
97
- # exit!(1)
98
- # true
99
- # end
95
+ on_error do |exception|
96
+ messenger.error(exception.to_s)
97
+ exit!(1)
98
+ true
99
+ end
100
100
 
101
101
  # ======================================================
102
102
  # Commands
@@ -130,6 +130,7 @@ end
130
130
  desc 'Get pins from Pinboard'
131
131
  command :pins do |c|
132
132
  c.flag([:e], desc: 'The end date to pull pins to')
133
+ c.flag([:m], desc: 'The pin template to use')
133
134
  c.flag([:n], desc: 'The number of results to return')
134
135
  c.flag([:s], desc: 'The start date to pull pins from')
135
136
  c.flag([:t], desc: 'The tags to use (e.g., "ruby,pinboard")')
@@ -140,7 +141,7 @@ command :pins do |c|
140
141
 
141
142
  # Figure out the template to use based on the passed argument (if any)
142
143
  # and/or the presence of a default template.
143
- template = PinPress.init_template(args[0], PinPress::Template::TYPE_PIN)
144
+ template_name, template = PinPress.init_template(options[:m], PinPress::Template::TYPE_PIN)
144
145
 
145
146
  # Assuming a valid template is found, transform CLI flags into options for
146
147
  # the Pinboard gem.
@@ -154,7 +155,7 @@ command :pins do |c|
154
155
  puts output if output
155
156
 
156
157
  # Save the last-run date to the configuration file.
157
- configuration.pinpress.last_pins_run = Time.now.utc.iso8601
158
+ configuration.pin_templates[template_name.to_sym].last_run = Time.now.utc.iso8601
158
159
  configuration.save
159
160
  end
160
161
 
@@ -163,12 +164,12 @@ command :pins do |c|
163
164
  last.action do |global_options, options, args|
164
165
  PinPress.verbose = global_options[:v]
165
166
 
166
- last_run_date = configuration.pinpress.last_pins_run
167
- if last_run_date
168
- # Figure out the template to use based on the passed argument (if any)
169
- # and/or the presence of a default template.
170
- template = PinPress.init_template(args[0], PinPress::Template::TYPE_PIN)
167
+ # Figure out the template to use based on the passed argument (if any)
168
+ # and/or the presence of a default template.
169
+ template_name, template = PinPress.init_template(options[:m], PinPress::Template::TYPE_PIN)
171
170
 
171
+ last_run_date = configuration.pin_templates[template_name.to_sym].last_run
172
+ if last_run_date
172
173
  # Set one option: the start date. Set it to the last-run date + 1.
173
174
  opts = {}
174
175
  opts.merge!(fromdt: DateTime.parse(last_run_date) + 1)
@@ -179,7 +180,7 @@ command :pins do |c|
179
180
  puts output if output
180
181
 
181
182
  # Save the last-run date to the configuration file.
182
- configuration.pinpress.last_pins_run = Time.now.utc.iso8601
183
+ configuration.pin_templates[template_name.to_sym].last_run = Time.now.utc.iso8601
183
184
  configuration.save
184
185
  else
185
186
  messenger.warn("`pinpress pins` hasn't been run before.")
@@ -196,20 +197,45 @@ end
196
197
  desc 'Get tags from Pinboard'
197
198
  command :tags do |c|
198
199
  c.flag([:e], desc: 'The end date to pull pins to')
200
+ c.flag([:m], desc: 'The template to use')
199
201
  c.flag([:t], desc: 'The tags to use (e.g., "ruby,pinboard")')
200
202
  c.flag([:s], desc: 'The start date to pull pins from')
201
203
 
204
+ c.desc 'Gets unique tags based on the passed criteria'
205
+ c.action do |global_options, options, args|
206
+ PinPress.verbose = global_options[:v]
207
+
208
+ # Figure out the template to use based on the passed argument (if any)
209
+ # and/or the presence of a default template.
210
+ template_name, template = PinPress.init_template(options[:m], PinPress::Template::TYPE_TAG)
211
+
212
+ # Assuming a valid template is found, transform CLI flags into options for
213
+ # the Pinboard gem.
214
+ opts = {}
215
+ opts.merge!(todt: Chronic.parse(options[:e])) if options[:e]
216
+ opts.merge!(fromdt: Chronic.parse(options[:s])) if options[:s]
217
+ opts.merge!(PinPress.merge_common_options(options))
218
+
219
+ # Request tag data from Pinboard and output the return data.
220
+ output = PinPress.tag_yield(template, opts)
221
+ puts output if output
222
+
223
+ # Save the last-run date to the configuration file.
224
+ configuration.tag_templates[template_name.to_sym].last_run = Time.now.utc.iso8601
225
+ configuration.save
226
+ end
227
+
202
228
  c.desc 'Gets all tags from the last run date + 1'
203
229
  c.command :last do |last|
204
230
  last.action do |global_options, options, args|
205
- last_run_date = configuration.pinpress.last_tags_run
231
+ # Figure out the template to use based on the passed argument (if any)
232
+ # and/or the presence of a default template.
233
+ template_name, template = PinPress.init_template(options[:m], PinPress::Template::TYPE_TAG)
234
+
235
+ last_run_date = configuration.tag_templates[template_name.to_sym].last_run
206
236
  if last_run_date
207
237
  PinPress.verbose = global_options[:v]
208
238
 
209
- # Figure out the template to use based on the passed argument (if any)
210
- # and/or the presence of a default template.
211
- template = PinPress.init_template(args[0], PinPress::Template::TYPE_TAG)
212
-
213
239
  # Set one option: the start date. Set it to the last-run date + 1.
214
240
  opts = {}
215
241
  opts.merge!(fromdt: DateTime.parse(last_run_date) + 1)
@@ -220,37 +246,13 @@ command :tags do |c|
220
246
  puts output if output
221
247
 
222
248
  # Save the last-run date to the configuration file.
223
- configuration.pinpress.last_tags_run = Time.now.utc.iso8601
249
+ configuration.tag_templates[template_name.to_sym].last_run = Time.now.utc.iso8601
224
250
  configuration.save
225
251
  else
226
252
  messenger.warn("`pinpress tags` hasn't been run before.")
227
253
  end
228
254
  end
229
255
  end
230
-
231
- c.desc 'Gets unique tags based on the passed criteria'
232
- c.action do |global_options, options, args|
233
- PinPress.verbose = global_options[:v]
234
-
235
- # Figure out the template to use based on the passed argument (if any)
236
- # and/or the presence of a default template.
237
- template = PinPress.init_template(args[0], PinPress::Template::TYPE_TAG)
238
-
239
- # Assuming a valid template is found, transform CLI flags into options for
240
- # the Pinboard gem.
241
- opts = {}
242
- opts.merge!(todt: Chronic.parse(options[:e])) if options[:e]
243
- opts.merge!(fromdt: Chronic.parse(options[:s])) if options[:s]
244
- opts.merge!(PinPress.merge_common_options(options))
245
-
246
- # Request tag data from Pinboard and output the return data.
247
- output = PinPress.tag_yield(template, opts)
248
- puts output if output
249
-
250
- # Save the last-run date to the configuration file.
251
- configuration.pinpress.last_tags_run = Time.now.utc.iso8601
252
- configuration.save
253
- end
254
256
  end
255
257
 
256
258
  # ------------------------------------------------------
@@ -28,5 +28,5 @@ module PinPress
28
28
  SUMMARY = 'A simple CLI to create HTML templates of Pinboard data.'
29
29
 
30
30
  # The Gem's version
31
- VERSION = '1.3.3'
31
+ VERSION = '1.4.0'
32
32
  end
data/lib/pinpress.rb CHANGED
@@ -45,11 +45,10 @@ module PinPress
45
45
  def get_template(template_name, template_type)
46
46
  case template_type
47
47
  when PinPress::Template::TYPE_PIN
48
- templates = configuration.pin_templates
48
+ configuration.pin_templates[template_name.to_sym]
49
49
  when PinPress::Template::TYPE_TAG
50
- templates = configuration.tag_templates
50
+ configuration.tag_templates[template_name.to_sym]
51
51
  end
52
- templates.find { |t| t[:name] == template_name }
53
52
  end
54
53
 
55
54
  # "Initializes" a passed template:
@@ -65,14 +64,15 @@ module PinPress
65
64
  tag_t_sym = :default_tag_template
66
65
  s = (template_type == PinPress::Template::TYPE_PIN ? pin_t_sym : tag_t_sym)
67
66
  default_template = configuration.pinpress[s]
68
- if PinPress.is_template?(explicit_template, template_type)
67
+
68
+ if explicit_template && PinPress.is_template?(explicit_template, template_type)
69
69
  messenger.debug("Using explicit template: #{ explicit_template }")
70
- return PinPress.get_template(explicit_template, template_type)
70
+ return explicit_template, PinPress.get_template(explicit_template, template_type)
71
71
  elsif PinPress.is_template?(default_template, template_type)
72
72
  messenger.debug("Using default template: #{ default_template }")
73
- return PinPress.get_template(default_template, template_type)
73
+ return default_template, PinPress.get_template(default_template, template_type)
74
74
  else
75
- fail 'Invalid template defined and/or no default template specified'
75
+ fail 'Invalid template specified and/or no default template defined'
76
76
  end
77
77
  end
78
78
 
@@ -132,7 +132,7 @@ module PinPress
132
132
  when PinPress::Template::TYPE_TAG
133
133
  templates = configuration.tag_templates
134
134
  end
135
- !templates.find { |t| t[:name] == template_name }.nil?
135
+ !templates[template_name.to_sym].nil?
136
136
  end
137
137
 
138
138
  # Present a list of installed templates to the user
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pinpress
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Bach