pinpress 1.2.3 → 1.3.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: abf02d81f7239b623f70a4f4e047a765fb6603f2
4
- data.tar.gz: 7c79e907be640f042376328614bee97aac71e3fc
3
+ metadata.gz: c5ad4abe5c4ffac712cbc94f5ab57629d55c7392
4
+ data.tar.gz: 13b08c63e46a7045d8a2568c133074831da84243
5
5
  SHA512:
6
- metadata.gz: c14f1e6b344374440bb047e12e5f325da73f86fd7434c9e05c0bbd8b54d2bfa67f2aa82f873107ce224d0281b84712b29d68c4623685feb1a6b8e643a57fcd58
7
- data.tar.gz: 3461ad458562a329b1234641d5b567c624367aacc704c7c13774f12aab85dcc930a337b2ed81cd545a213271c15ebfed029c19e035fa935e31c2e58d03d3a854
6
+ metadata.gz: 14951a1894355244746786152988d68e94f0a3c124ef73ba25e23f7eb2324853613fa9d965293cf1852e12339056e91f9c3d4163d06fcbfdffcbbf53e6f678fd
7
+ data.tar.gz: 08617ed674306742f5778696a0584cd3deef296f27cb3903404694789a60b02682050e340655506944558e2e38ad32c621bab046a43ea989936e7def6230eb15
data/Gemfile CHANGED
@@ -1,3 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ # gem 'simplecov', require: false
4
+ # gem 'coveralls', require: false
5
+
3
6
  gemspec
data/HISTORY.md CHANGED
@@ -1,3 +1,14 @@
1
+ # 1.3.1 (2014-05-06)
2
+
3
+ * Modified last-run to store DateTime, rather than just a Date
4
+
5
+ # 1.3.0 (2014-05-05)
6
+
7
+ * Huge refactoring; much cleaner
8
+ * Added HTML encoding to pin desriptions
9
+ * Fixed bugs with application of tags to both `pins` and `tags` command
10
+ * Bumped CLIUtils to version 2.2.3
11
+
1
12
  # 1.2.3 (2014-05-04)
2
13
 
3
14
  * Fixed a bug where error management failed
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.2.2
45
+ 1.3.1
46
46
 
47
47
  GLOBAL OPTIONS
48
48
  --help - Show this message
@@ -158,7 +158,6 @@ grab:
158
158
 
159
159
  * `-s`: the start date to use (uses [Chronic](https://github.com/mojombo/chronic "Chronic"), which allows dates like "last Tuesday")
160
160
  * `-e`: the end date to use (also uses [Chronic](https://github.com/mojombo/chronic "Chronic"))
161
- * `-t`: a CSV list of tags (e.g., "tag1,tag2") to examine for association (see [below](#getting-tags-that-have-been-used-with-other-tags)).
162
161
 
163
162
  ## Getting Tags From a Date Forward
164
163
 
@@ -184,15 +183,6 @@ $ pinpress tags -e 2014-01-01
184
183
  $ pinpress tags -s 2014-01-01 -e 2014-01-31
185
184
  ```
186
185
 
187
- ## Getting Tags that Have Been Used With Other Tags
188
-
189
- ```bash
190
- $ pinpress tags -t 'tag1,tag2' -s 2014-01-01
191
- ```
192
-
193
- ...returns all tags that have been used *alongside* `tag1` and `tag2`, starting
194
- on Jarnuary 1, 2014.
195
-
196
186
  ## Getting Tags Used Since Last Run
197
187
 
198
188
  ```bash
@@ -397,10 +387,10 @@ pinpress:
397
387
  # The default `tags` template to use
398
388
  default_tag_template
399
389
 
400
- # The default tags to be used when getting pins or associated tags
390
+ # The default tags to be used when running `pinpress pins`
401
391
  default_tags: ['tag1', 'tag2']
402
392
 
403
- # The tags to ignore when executing either `pins` or `tags`
393
+ # The tags to that are removed from the results when running `pinpress tags`
404
394
  ignored_tags: ['bad-tag', 'bad-tag2']
405
395
 
406
396
  # The default number of results to return
data/Rakefile CHANGED
@@ -8,11 +8,11 @@ end
8
8
 
9
9
  spec = eval(File.read('pinpress.gemspec'))
10
10
 
11
- require 'rake/testtask'
12
- desc 'Run unit tests'
13
- Rake::TestTask.new do |t|
14
- t.libs << "test"
15
- t.test_files = FileList['test/*_test.rb']
11
+ require 'rspec/core/rake_task'
12
+ desc "Run the specs."
13
+ RSpec::Core::RakeTask.new do |t|
14
+ t.pattern = "spec/**/*_spec.rb"
15
+ t.verbose = false
16
16
  end
17
17
 
18
18
  require 'cucumber'
@@ -53,4 +53,5 @@ task :build do
53
53
  FileUtils.mv("./pinpress-#{ version }.gem", "pkg")
54
54
  end
55
55
 
56
- task :default => [:yard, :test, :features]
56
+ task :default => [:yard, :spec, :features]
57
+ # task :default => [:spec]
data/bin/pinpress CHANGED
@@ -33,6 +33,7 @@
33
33
  require 'chronic'
34
34
  require 'cliutils'
35
35
  require 'gli'
36
+ require 'htmlentities'
36
37
  require 'pinboard'
37
38
  require 'pinpress'
38
39
 
@@ -49,15 +50,16 @@ version PinPress::VERSION
49
50
  # ======================================================
50
51
  # Global Flags and Switches
51
52
  # ======================================================
53
+ switch([:v], desc: 'Run pinpress in verbose mode')
52
54
 
53
55
  # ======================================================
54
- # Pre, Post, and Error
56
+ # Pre (runs before every command)
55
57
  # ======================================================
56
58
  pre do |global, command, options, args|
57
59
  # Load PinPress configuration module.
58
60
  load_configuration(PinPress::CONFIG_FILEPATH)
59
61
  file_logger = Logger.new(PinPress::LOG_FILEPATH)
60
- file_logger.level = LOG_LEVELS[configuration.pinpress[:log_level] || 'DEBUG']
62
+ file_logger.level = LOG_LEVELS[configuration.pinpress.log_level || 'DEBUG']
61
63
  messenger.attach(LOGFILE: file_logger)
62
64
 
63
65
  if File.exist?(PinPress::CONFIG_FILEPATH)
@@ -80,10 +82,16 @@ pre do |global, command, options, args|
80
82
  true
81
83
  end
82
84
 
85
+ # ======================================================
86
+ # Post (runs after every command)
87
+ # ======================================================
83
88
  post do |global, command, options, args|
84
89
 
85
90
  end
86
91
 
92
+ # ======================================================
93
+ # Error (runs when an exception is raised)
94
+ # ======================================================
87
95
  on_error do |exception|
88
96
  messenger.error(exception.to_s)
89
97
  exit!(1)
@@ -103,6 +111,8 @@ desc 'Install and initialize dependencies'
103
111
  command :init do |c|
104
112
  c.switch([:s], desc: 'Run init from scratch')
105
113
  c.action do |global_options, options, args|
114
+ PinPress.verbose = global_options[:v]
115
+
106
116
  if options[:s]
107
117
  PinPress.init(true)
108
118
  else
@@ -124,22 +134,58 @@ command :pins do |c|
124
134
  c.flag([:s], desc: 'The start date to pull pins from')
125
135
  c.flag([:t], desc: 'The tags to use (e.g., "ruby,pinboard")')
126
136
 
137
+ c.desc 'Gets pins from Pinboard'
138
+ c.action do |global_options, options, args|
139
+ PinPress.verbose = global_options[:v]
140
+
141
+ # Figure out the template to use based on the passed argument (if any)
142
+ # and/or the presence of a default template.
143
+ template = PinPress.init_template(args[0], PinPress::Template::TYPE_PIN)
144
+
145
+ # Assuming a valid template is found, transform CLI flags into options for
146
+ # the Pinboard gem.
147
+ opts = {}
148
+ opts.merge!(todt: Chronic.parse(options[:e])) if options[:e]
149
+ opts.merge!(fromdt: Chronic.parse(options[:s])) if options[:s]
150
+ opts.merge!(PinPress.merge_common_options(options))
151
+
152
+ # Request pin data from Pinboard and output the return data.
153
+ output = PinPress.pin_yield(template, opts)
154
+ puts output if output
155
+
156
+ # Save the last-run date to the configuration file.
157
+ configuration.pinpress.last_pins_run = Time.now.utc.iso8601
158
+ configuration.save
159
+ end
160
+
127
161
  c.desc 'Gets all pins from the last run date + 1'
128
162
  c.command :last do |last|
129
163
  last.action do |global_options, options, args|
130
- last_run_date = configuration.pinpress[:last_pins_run]
164
+ PinPress.verbose = global_options[:v]
165
+
166
+ last_run_date = configuration.pinpress.last_pins_run
131
167
  if last_run_date
132
- options[:s] = last_run_date + 1
133
- puts PinPress.get_data(PinPress::Template::TEMPLATE_TYPE_PIN, args, options)
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)
171
+
172
+ # Set one option: the start date. Set it to the last-run date + 1.
173
+ opts = {}
174
+ opts.merge!(fromdt: last_run_date + 1)
175
+ opts.merge!(PinPress.merge_common_options(options))
176
+
177
+ # Request pin data from Pinboard and output the return data.
178
+ output = PinPress.pin_yield(template, opts)
179
+ puts output if output
180
+
181
+ # Save the last-run date to the configuration file.
182
+ configuration.pinpress.last_pins_run = Time.now.utc.iso8601
183
+ configuration.save
134
184
  else
135
185
  messenger.warn("`pinpress pins` hasn't been run before.")
136
186
  end
137
187
  end
138
188
  end
139
-
140
- c.action do |global_options, options, args|
141
- puts PinPress.get_data(PinPress::Template::TEMPLATE_TYPE_PIN, args, options)
142
- end
143
189
  end
144
190
 
145
191
  # ------------------------------------------------------
@@ -156,32 +202,68 @@ command :tags do |c|
156
202
  c.desc 'Gets all tags from the last run date + 1'
157
203
  c.command :last do |last|
158
204
  last.action do |global_options, options, args|
159
- last_run_date = configuration.pinpress[:last_tags_run]
205
+ last_run_date = configuration.pinpress.last_tags_run
160
206
  if last_run_date
161
- options[:s] = last_run_date + 1
162
- puts PinPress.get_data(PinPress::Template::TEMPLATE_TYPE_TAG, args, options)
207
+ PinPress.verbose = global_options[:v]
208
+
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
+ # Set one option: the start date. Set it to the last-run date + 1.
214
+ opts = {}
215
+ opts.merge!(fromdt: last_run_date + 1)
216
+ opts.merge!(PinPress.merge_common_options(options))
217
+
218
+ # Request tag data from Pinboard and output the return data.
219
+ output = PinPress.tag_yield(template, opts)
220
+ puts output if output
221
+
222
+ # Save the last-run date to the configuration file.
223
+ configuration.pinpress.last_tags_run = Time.now.utc.iso8601
224
+ configuration.save
163
225
  else
164
226
  messenger.warn("`pinpress tags` hasn't been run before.")
165
227
  end
166
228
  end
167
229
  end
168
230
 
169
- c.desc 'Gets the unique tags based on the passed criteria'
231
+ c.desc 'Gets unique tags based on the passed criteria'
170
232
  c.action do |global_options, options, args|
171
- puts PinPress.get_data(PinPress::Template::TEMPLATE_TYPE_TAG, args, options)
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
172
253
  end
173
254
  end
174
255
 
175
256
  # ------------------------------------------------------
176
257
  # templates command
177
258
  #
178
- # Manages pin templates.
259
+ # Manages pin and tag templates.
179
260
  # ------------------------------------------------------
180
261
  desc 'Work with templates for pin output'
181
262
  command :templates do |c|
182
263
  c.desc 'List current templates'
183
264
  c.command :list do |list|
184
265
  list.action do |global_options, options, args|
266
+ PinPress.verbose = global_options[:v]
185
267
  PinPress.list_templates
186
268
  end
187
269
  end
@@ -1,4 +1,5 @@
1
1
  require 'aruba/cucumber'
2
+ # require 'simplecov'
2
3
  require_relative '../../lib/pinpress/constants'
3
4
 
4
5
  ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
data/lib/pinpress.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  require 'pinpress/constants'
2
- require 'pinpress/templates/template'
3
- require 'pinpress/templates/pin_template'
4
- require 'pinpress/templates/tag_template'
2
+ require 'pinpress/template'
5
3
 
6
4
  # The PinPress module, which wraps everything
7
5
  # in this gem.
8
6
  module PinPress
7
+ extend self
8
+
9
9
  class << self
10
10
  # Stores whether initalization has completed.
11
11
  # @return [Boolean]
@@ -16,137 +16,63 @@ module PinPress
16
16
  attr_accessor :verbose
17
17
  end
18
18
 
19
- # Establishes the template to use and yields a block with that
20
- # template an a Pinboard client.
21
- # @param [Fixnum] template_type Either a Pin or Tag template
22
- # @param [String] template_name The neame of the template to use
23
- # @yield
24
- # @return [void]
25
- def self.execute_template(template_type, template_name)
26
- template_hash = PinPress.get_template_by_name(template_type, template_name)
27
- if template_hash
28
- template = PinPress::TagTemplate.new(template_hash)
29
- client = Pinboard::Client.new(token: configuration.pinpress[:api_token])
30
- yield template, client
31
- else
32
- fail 'Invalid template provided and/or no default template'
33
- end
34
- end
35
-
36
- # Generates a string of items from pins.
37
- # @param [Fixnum] template_type
38
- # @param [PinPress::Template] template
39
- # @param [Array] pins
40
- # @return [String]
41
- def self.generate_items(template_type, template, pins, opts)
42
- output = ''
43
- case template_type
44
- when PinPress::Template::TEMPLATE_TYPE_PIN
45
- pins.each do |p|
46
- href = p[:href]
47
- description = p[:description]
48
- extended = p[:extended]
49
- tag = p[:tag]
50
- time = p[:time]
51
- replace = p[:replace]
52
- shared = p[:shared]
53
- toread = p[:toread]
54
- output += ERB.new(template.item).result(binding)
55
- end
56
- configuration.pinpress[:last_pins_run] = Date.today
57
- when PinPress::Template::TEMPLATE_TYPE_TAG
58
- tags = []
59
- pins.each { |p| tags += p[:tag] }
60
- tags = tags.uniq.map { |t| { tag: t, count: tags.count(t) } }
61
- tags.each do |t|
62
- unless t[:tag] == opts[:tag]
63
- tag = t[:tag]
64
- count = t[:count]
65
- output += ERB.new(template.item).result(binding)
66
- end
67
- end
68
- configuration.pinpress[:last_tags_run] = Date.today
69
- end
70
- output
71
- end
72
-
73
- # Generic function to get data from Pinboard.
74
- # @param [Fixnum] template_type
75
- # @param [Array] args
76
- # @param [Hash] options
77
- # @return [String]
78
- def self.get_data(template_type, args, options)
79
- output = ''
80
-
81
- # Two scenarios covered here:
82
- # 1. If the user passes a valid name, grab that template.
83
- # 2. If no name is passed, grabbed the default template
84
- # If both of these conditions fail, an error message is shown.
85
- # t_type = PinPress::Template::TEMPLATE_TYPE_PIN
86
- # t_name = args.empty? ? nil : args[0]
87
- t_name = args.empty? ? nil : args[0]
88
-
89
- PinPress.execute_template(template_type, t_name) do |template, client|
90
- opts = {}
91
- opts.merge!(todt: Chronic.parse(options[:e])) if options[:e]
92
- opts.merge!(fromdt: Chronic.parse(options[:s])) if options[:s]
93
-
94
- if options[:n]
95
- opts.merge!(results: options[:n])
96
- elsif configuration.pinpress[:default_num_results]
97
- opts.merge!(results: configuration.pinpress[:default_num_results])
98
- end
99
-
100
- if options[:t]
101
- tags = options[:t].split(',')
102
- elsif configuration.pinpress[:default_tags]
103
- tags = configuration.pinpress[:default_tags]
104
- end
105
-
106
- ignored_tags = configuration.pinpress[:ignored_tags]
107
- tags -= ignored_tags if ignored_tags
108
- opts.merge!(tag: tags) if tags
109
-
110
- begin
111
- pins = client.posts(opts)
112
- if pins.empty?
113
- messenger.warn('No matching pins...')
114
- else
115
- output += template.opener if template.opener
116
- output += PinPress.generate_items(template_type, template, pins, opts)
117
- output += template.closer if template.closer
118
- end
119
-
120
- configuration.save
121
- return output
122
- rescue StandardError => e
123
- messenger.debug(e.to_s)
124
- raise "Pinboard API failed; are you sure you've run " \
125
- " `pinpress init` (and that your API key is correct)?"
19
+ # Grabs Pinboard data (passed on passed options) and yields a block that
20
+ # allows the user to act upon that returned data.
21
+ # @param [Hash] pinboard_opts
22
+ # @yield pins
23
+ # @raise StandardError if Pinboard client fails
24
+ def execute_template(pinboard_opts)
25
+ begin
26
+ client = Pinboard::Client.new(token: configuration.pinpress.api_token)
27
+ pins = client.posts(pinboard_opts)
28
+ if pins.empty?
29
+ messenger.warn('No data matching your arguments...')
30
+ else
31
+ yield pins
126
32
  end
33
+ rescue StandardError => e
34
+ messenger.debug(e.to_s)
35
+ puts e.to_s
36
+ raise "Pinboard API failed; are you sure you've run " \
37
+ " `pinpress init` (and that your API key is correct)?"
127
38
  end
128
39
  end
129
40
 
130
- # Determines whether a template exists.
131
- # @param [Fixnum] template_type
132
- # @param [<String, Symbol>] template_name
133
- # @return [Template]
134
- def self.get_template_by_name(template_type, template_name = nil)
41
+ # Returns a template Hash from the configuration file.
42
+ # @param [String] template_name The name of the template to get
43
+ # @param [Fixnum] template_type The template type
44
+ # @return [Hash]
45
+ def get_template(template_name, template_type)
135
46
  case template_type
136
- when Template::TEMPLATE_TYPE_PIN
137
- default_t_name = configuration.pinpress[:default_pin_template]
47
+ when PinPress::Template::TYPE_PIN
138
48
  templates = configuration.pin_templates
139
- when Template::TEMPLATE_TYPE_TAG
140
- default_t_name = configuration.pinpress[:default_tag_template]
49
+ when PinPress::Template::TYPE_TAG
141
50
  templates = configuration.tag_templates
142
- else
143
- fail 'Invalid template type given'
144
51
  end
52
+ templates.find { |t| t[:name] == template_name }
53
+ end
145
54
 
146
- if template_name.nil?
147
- return templates.find { |t| t[:name] == default_t_name }
55
+ # "Initializes" a passed template:
56
+ # 1. If the template exists, returns it.
57
+ # 2. If not, return a default template (if it exists).
58
+ # 3. Throw an exception if #1 and #2 fail.
59
+ # @param [String] explicit_template A template name passed in via the CLI
60
+ # @param [Fixnum] template_type The template type
61
+ # @return [Hash]
62
+ # @raise StandardError if no explicit or default template is found
63
+ def init_template(explicit_template, template_type)
64
+ pin_t_sym = :default_pin_template
65
+ tag_t_sym = :default_tag_template
66
+ s = (template_type == PinPress::Template::TYPE_PIN ? pin_t_sym : tag_t_sym)
67
+ default_template = configuration.pinpress[s]
68
+ if PinPress.is_template?(explicit_template, template_type)
69
+ messenger.debug("Using explicit template: #{ explicit_template }")
70
+ return PinPress.get_template(explicit_template, template_type)
71
+ elsif PinPress.is_template?(default_template, template_type)
72
+ messenger.debug("Using default template: #{ default_template }")
73
+ return PinPress.get_template(default_template, template_type)
148
74
  else
149
- return templates.find { |t| t[:name] == template_name }
75
+ fail 'Invalid template defined and/or no default template specified'
150
76
  end
151
77
  end
152
78
 
@@ -154,51 +80,64 @@ module PinPress
154
80
  # collecting all necessary items and info.
155
81
  # @param [Boolean] from_scratch
156
82
  # @return [void]
157
- def self.init(from_scratch = false)
83
+ def init(from_scratch = false)
158
84
  messenger.section('INITIALIZING...')
159
85
  if from_scratch
160
86
  configuration.reset
161
- configuration.add_section(:pinpress)
162
- configuration.add_section(:pin_templates)
163
- configuration.add_section(:tag_templates)
164
87
 
165
- configuration.pinpress.merge!(
88
+ # Add initial configuration info.
89
+ configuration.add_section(:pinpress)
90
+ configuration.pinpress = {
166
91
  config_location: configuration.config_path,
167
92
  default_pin_template: 'pinpress_default',
168
93
  default_tag_template: 'pinpress_default',
169
94
  log_level: 'WARN',
170
95
  version: PinPress::VERSION
171
- )
96
+ }
172
97
 
98
+ # Add a single default pin and tag template
173
99
  default_pin_template = {
174
100
  name: 'pinpress_default',
175
101
  opener: '<ul>',
176
- item: '<li><b><a title="<%= description %>" href="<%= href %>" target="_blank"><%= description %></a>.</b> <%= extended %></li>',
102
+ item: '<li><%= href %></li>',
177
103
  closer: '</ul>'
178
104
  }
179
-
180
105
  default_tag_template = {
181
106
  name: 'pinpress_default',
182
107
  item: '<%= tag %> (<%= count %>),'
183
108
  }
184
-
185
- configuration.data['pin_templates'] = [default_pin_template]
186
- configuration.data['tag_templates'] = [default_tag_template]
109
+ configuration.pin_templates = [default_pin_template]
110
+ configuration.tag_templates = [default_tag_template]
187
111
  end
188
112
 
113
+ # Run through installation prompts and ingest the results into
114
+ # the configuration.
189
115
  pm = CLIUtils::Prefs.new(PinPress::PREF_FILES['INIT'], configuration)
190
116
  pm.ask
191
117
  configuration.ingest_prefs(pm)
192
118
 
193
- messenger.debug("Configuration values after pref collection: #{ configuration.data }")
194
-
119
+ m = "Configuration values after pref collection: #{ configuration.data }"
120
+ messenger.debug(m)
195
121
  configuration.save
196
122
  @initialized = true
197
123
  end
198
124
 
125
+ # Determines whether a template exists in the configuration file.
126
+ # @param [String] template_name The name of the template to search for
127
+ # @param [Fixnum] template_type The template type
128
+ def is_template?(template_name, template_type)
129
+ case template_type
130
+ when PinPress::Template::TYPE_PIN
131
+ templates = configuration.pin_templates
132
+ when PinPress::Template::TYPE_TAG
133
+ templates = configuration.tag_templates
134
+ end
135
+ !templates.find { |t| t[:name] == template_name }.nil?
136
+ end
137
+
199
138
  # Present a list of installed templates to the user
200
139
  # @return [void]
201
- def self.list_templates
140
+ def list_templates
202
141
  pin_templates = configuration.pin_templates
203
142
  tag_templates = configuration.tag_templates
204
143
 
@@ -221,10 +160,84 @@ module PinPress
221
160
  end
222
161
  end
223
162
 
163
+ # Helper method to merge command line options that are relevant for both pin
164
+ # and tag requests.
165
+ # @param [Hash] options
166
+ # @return [Hash]
167
+ def merge_common_options(options)
168
+ opts = {}
169
+ if options[:n]
170
+ opts.merge!(results: options[:n])
171
+ elsif configuration.pinpress.default_num_results
172
+ opts.merge!(results: configuration.pinpress.default_num_results)
173
+ end
174
+
175
+ if options[:t]
176
+ opts.merge!(tag: options[:t])
177
+ elsif configuration.pinpress.default_tags
178
+ opts.merge!(tag: configuration.pinpress.default_tags.join(','))
179
+ end
180
+ opts
181
+ end
182
+
183
+ # Creates text output from pin data (based upon a passed template).
184
+ # @param [Hash] template The template to use
185
+ # @param [Hash] opts CLI options to use
186
+ # @return [String]
187
+ def pin_yield(template, opts)
188
+ output = ''
189
+ PinPress.execute_template(opts) do |data|
190
+ html_coder = HTMLEntities.new
191
+
192
+ output += template[:opener] if template[:opener]
193
+ data.each do |i|
194
+ href = i[:href]
195
+ description = html_coder.encode(i[:description])
196
+ extended = i[:extended]
197
+ tag = i[:tag]
198
+ time = i[:time]
199
+ replace = i[:replace]
200
+ shared = i[:shared]
201
+ toread = i[:toread]
202
+ output += ERB.new(template[:item]).result(binding)
203
+ end
204
+ output += template[:closer] if template[:closer]
205
+ end
206
+ output
207
+ end
208
+
209
+ # Creates text output from tag data (based upon a passed template).
210
+ # @param [Hash] template The template to use
211
+ # @param [Hash] opts CLI options to use
212
+ # @return [String]
213
+ def tag_yield(template, opts)
214
+ output = ''
215
+ PinPress.execute_template(opts) do |data|
216
+ tags = []
217
+ ignored_tags = configuration.pinpress.ignored_tags
218
+
219
+ data.each { |i| tags += i[:tag] }
220
+ tags = (tags -= ignored_tags if ignored_tags).uniq.map do |t|
221
+ { tag: t, count: tags.count(t) }
222
+ end
223
+
224
+ output += template[:opener] if template[:opener]
225
+ tags.each do |t|
226
+ unless t[:tag] == opts[:tag]
227
+ tag = t[:tag]
228
+ count = t[:count]
229
+ output += ERB.new(template.item).result(binding)
230
+ end
231
+ end
232
+ output += template[:closer] if template[:closer]
233
+ end
234
+ output
235
+ end
236
+
224
237
  # Notifies the user that the config file needs to be
225
238
  # re-done and does it.
226
239
  # @return [void]
227
- def self.update_config_file
240
+ def update_config_file
228
241
  m = "This version needs to make some config changes. Don't worry; " \
229
242
  "when prompted, your current values for existing config options " \
230
243
  "will be presented (so it'll be easier to fly through the upgrade)."
@@ -9,7 +9,7 @@ module PinPress
9
9
 
10
10
  # The Gem's description
11
11
  DESCRIPTION = %q(A Pinboard application that allows for the creation of
12
- pin and tag templates in almost any conceivable format.)
12
+ pin and tag templates in almost any conceivable format.)
13
13
 
14
14
  # The last version to require a config update
15
15
  NEWEST_CONFIG_VERSION = '1.2.1'
@@ -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.2.3'
31
+ VERSION = '1.3.0'
32
32
  end
@@ -0,0 +1,12 @@
1
+ module PinPress
2
+ # A template for outputting Pinboard data
3
+ class Template
4
+ # Defines a pin template
5
+ # @return [Fixnum]
6
+ TYPE_PIN = 1
7
+
8
+ # Defines a tag template
9
+ # @return [Fixnum]
10
+ TYPE_TAG = 2
11
+ end
12
+ end
data/pinpress.gemspec CHANGED
@@ -16,10 +16,11 @@ Gem::Specification.new do |spec|
16
16
 
17
17
  spec.add_development_dependency('aruba', '0.5.4')
18
18
  spec.add_development_dependency('rake', '10.1.1')
19
- spec.add_development_dependency('rdoc', '4.1.1')
19
+ spec.add_development_dependency('rspec', '2.14.1')
20
20
  spec.add_development_dependency('yard', '0.8.7.4')
21
21
  spec.add_runtime_dependency('chronic', '0.10.2')
22
22
  spec.add_runtime_dependency('cliutils', '~> 2')
23
23
  spec.add_runtime_dependency('gli', '2.9.0')
24
+ spec.add_runtime_dependency('htmlentities', '4.3.1')
24
25
  spec.add_runtime_dependency('pinboard', '0.1.1')
25
26
  end
@@ -0,0 +1,16 @@
1
+ # require 'coveralls'
2
+ require 'rspec'
3
+ # require 'simplecov'
4
+ require 'stringio'
5
+
6
+ # SimpleCov.start
7
+ # Coveralls.wear!
8
+
9
+ def capture_stdout
10
+ old = $stdout
11
+ $stdout = fake = StringIO.new
12
+ yield
13
+ fake.string
14
+ ensure
15
+ $stdout = old
16
+ end
@@ -8,7 +8,7 @@ pinpress:
8
8
  pin_templates:
9
9
  - name: pinpress_default
10
10
  opener: "<ul>"
11
- item: <li><b><a title="<%= description %>" href="<%= href %>" target="_blank"><%= description %></a>.</b> <%= extended %></li>
11
+ item: <li><%= href %></li>
12
12
  closer: "</ul>"
13
13
  tag_templates:
14
14
  - name: pinpress_default
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pinpress
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Bach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-05 00:00:00.000000000 Z
11
+ date: 2014-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aruba
@@ -39,19 +39,19 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: 10.1.1
41
41
  - !ruby/object:Gem::Dependency
42
- name: rdoc
42
+ name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 4.1.1
47
+ version: 2.14.1
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: 4.1.1
54
+ version: 2.14.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: yard
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - '='
109
109
  - !ruby/object:Gem::Version
110
110
  version: 2.9.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: htmlentities
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: 4.3.1
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: 4.3.1
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: pinboard
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -124,7 +138,7 @@ dependencies:
124
138
  version: 0.1.1
125
139
  description: |-
126
140
  A Pinboard application that allows for the creation of
127
- pin and tag templates in almost any conceivable format.
141
+ pin and tag templates in almost any conceivable format.
128
142
  email:
129
143
  - bachya1208@googlemail.com
130
144
  executables:
@@ -147,16 +161,11 @@ files:
147
161
  - features/support/env.rb
148
162
  - lib/pinpress.rb
149
163
  - lib/pinpress/constants.rb
150
- - lib/pinpress/templates/pin_template.rb
151
- - lib/pinpress/templates/tag_template.rb
152
- - lib/pinpress/templates/template.rb
164
+ - lib/pinpress/template.rb
153
165
  - pinpress.gemspec
166
+ - spec/spec_helper.rb
154
167
  - support/preference_prompts.yaml
155
168
  - support/sample_config.yaml
156
- - test/pin_template_test.rb
157
- - test/pinpress_template_test.rb
158
- - test/tag_template_test.rb
159
- - test/test_helper.rb
160
169
  homepage: https://github.com/bachya/pinpress
161
170
  licenses:
162
171
  - MIT
@@ -187,8 +196,5 @@ test_files:
187
196
  - features/3.templates.feature
188
197
  - features/step_definitions/pinpress_steps.rb
189
198
  - features/support/env.rb
190
- - test/pin_template_test.rb
191
- - test/pinpress_template_test.rb
192
- - test/tag_template_test.rb
193
- - test/test_helper.rb
199
+ - spec/spec_helper.rb
194
200
  has_rdoc:
@@ -1,13 +0,0 @@
1
- module PinPress
2
- # A template for a pin; even though
3
- # currently empty, allows for future
4
- # flexibility.
5
- class PinTemplate < Template
6
- # Initializes a new Pin Template.
7
- # @param [Hash] params
8
- # @return [void]
9
- def initialize(params = {})
10
- super(params)
11
- end
12
- end
13
- end
@@ -1,13 +0,0 @@
1
- module PinPress
2
- # A template for a tag; even though
3
- # currently empty, allows for future
4
- # flexibility.
5
- class TagTemplate < Template
6
- # Initializes a new Tag Template.
7
- # @param [Hash] params
8
- # @return [void]
9
- def initialize(params = {})
10
- super(params)
11
- end
12
- end
13
- end
@@ -1,41 +0,0 @@
1
- module PinPress
2
- # A template for outputting Pinboard data
3
- class Template
4
- # Defines a pin template
5
- # @return [Fixnum]
6
- TEMPLATE_TYPE_PIN = 1
7
-
8
- # Defines a tag template
9
- # @return [Fixnum]
10
- TEMPLATE_TYPE_TAG = 2
11
-
12
- # Holds the "closer" (the string that
13
- # should come after all template items
14
- # are output)
15
- # @return [String]
16
- attr_accessor :closer
17
-
18
- # Holds the string that defines what
19
- # an item should look like.
20
- # @return [String]
21
- attr_accessor :item
22
-
23
- # Holds the name of the template.
24
- # @return [String]
25
- attr_accessor :name
26
-
27
- # Holds the "opener" (the string that
28
- # should come before all template items
29
- # are output)
30
- # @return [String]
31
- attr_accessor :opener
32
-
33
- # Initializes this class by ingesting
34
- # passed parameters.
35
- # @param [Hash] params
36
- # @return [void]
37
- def initialize(params = {})
38
- params.each { |key, value| send("#{ key }=", value) }
39
- end
40
- end
41
- end
@@ -1,21 +0,0 @@
1
- require 'test_helper'
2
-
3
- require File.join(File.dirname(__FILE__), '..', 'lib/pinpress/templates/template')
4
- require File.join(File.dirname(__FILE__), '..', 'lib/pinpress/templates/pin_template')
5
-
6
- class TestPinTemplate < Test::Unit::TestCase
7
- def test_initialization
8
- parameters = {
9
- closer: '</ul>',
10
- item: '<li></li>',
11
- name: 'default',
12
- opener: '</ul>',
13
- }
14
-
15
- t = PinPress::PinTemplate.new(parameters)
16
- assert_equal(t.closer, parameters[:closer])
17
- assert_equal(t.item, parameters[:item])
18
- assert_equal(t.name, parameters[:name])
19
- assert_equal(t.opener, parameters[:opener])
20
- end
21
- end
@@ -1,20 +0,0 @@
1
- require 'test_helper'
2
-
3
- require File.join(File.dirname(__FILE__), '..', 'lib/pinpress/templates/template')
4
-
5
- class TestPinPressTemplate < Test::Unit::TestCase
6
- def test_initialization
7
- parameters = {
8
- closer: '</ul>',
9
- item: '<li></li>',
10
- name: 'default',
11
- opener: '</ul>',
12
- }
13
-
14
- t = PinPress::Template.new(parameters)
15
- assert_equal(t.closer, parameters[:closer])
16
- assert_equal(t.item, parameters[:item])
17
- assert_equal(t.name, parameters[:name])
18
- assert_equal(t.opener, parameters[:opener])
19
- end
20
- end
@@ -1,21 +0,0 @@
1
- require 'test_helper'
2
-
3
- require File.join(File.dirname(__FILE__), '..', 'lib/pinpress/templates/template')
4
- require File.join(File.dirname(__FILE__), '..', 'lib/pinpress/templates/tag_template')
5
-
6
- class TestTagTemplate < Test::Unit::TestCase
7
- def test_initialization
8
- parameters = {
9
- closer: '</ul>',
10
- item: '<li></li>',
11
- name: 'default',
12
- opener: '</ul>',
13
- }
14
-
15
- t = PinPress::TagTemplate.new(parameters)
16
- assert_equal(t.closer, parameters[:closer])
17
- assert_equal(t.item, parameters[:item])
18
- assert_equal(t.name, parameters[:name])
19
- assert_equal(t.opener, parameters[:opener])
20
- end
21
- end
data/test/test_helper.rb DELETED
@@ -1,5 +0,0 @@
1
- require 'test/unit'
2
-
3
- class Test::Unit::TestCase
4
-
5
- end