jtag 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  = jtag
2
2
 
3
- jTag is a simple command line application for manipulating Jekyll tags in the YAML headers. It can perform mass operations such as tag addition, removal, merging and sorting. It can also suggest relevant tags based on the content of the post matched against your existing tagset (requires a plugin/template in your jekyll install).
3
+ jTag is a command line application for manipulating Jekyll tags in the YAML headers. It can perform mass operations such as tag addition, removal, merging and sorting. It can also suggest relevant tags based on the content of the post matched against your existing tagset (requires a plugin/template in your jekyll install).
4
4
 
5
5
  Configuration includes a persistent blacklist and synonym definitions. Tags manually added to posts are automatically whitelisted for the auto-tagger. The autotagger can update your posts directly, or be used to provide suggestions that you can manually insert in the post.
6
6
 
data/bin/jtag CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # encoding: utf-8
2
3
  require 'gli'
3
4
  require 'jtag'
4
5
 
@@ -140,17 +141,34 @@ command :tags do |c|
140
141
  c.flag [:f,:format], :must_match => /^(csv|list|yaml|json)$/, :type => String
141
142
 
142
143
  c.action do |global_options,options,args|
143
- args.each{|file|
144
- tags = @jt.post_tags(file)
144
+
145
+ if @piped_content
146
+ tags = @jt.post_tags(@piped_content,true)
145
147
  if args.length > 1
146
148
  console_log
147
- console_log File.basename(file) + ":"
149
+ console_log "STDIN:"
148
150
  end
149
151
  if tags.empty? || tags.nil?
150
152
  console_log "No tags in post", {:err => true}
151
153
  else
152
154
  output_tags(tags,options[:format])
153
155
  end
156
+ end
157
+ args.each{|file|
158
+ if File.exists?(file)
159
+ tags = @jt.post_tags(file)
160
+ if args.length > 1
161
+ console_log
162
+ console_log File.basename(file) + ":"
163
+ end
164
+ if tags.empty? || tags.nil?
165
+ console_log "No tags in post", {:err => true}
166
+ else
167
+ output_tags(tags,options[:format])
168
+ end
169
+ else
170
+ raise "File not found: #{file}"
171
+ end
154
172
  }
155
173
  end
156
174
  end
@@ -334,11 +352,21 @@ command :tag do |c|
334
352
  c.flag [:f,:format], :must_match => /^(csv|list|yaml|json)$/, :type => String
335
353
 
336
354
  c.action do |global_options,options,args|
337
-
355
+ if @piped_content
356
+ suggestions = @jt.suggest(@piped_content)
357
+ if !global_options[:s] || global_options[:t]
358
+ if args.length > 1
359
+ console_log
360
+ console_log "STDIN:", {:err => true}
361
+ end
362
+ output_tags(suggestions,options[:format])
363
+ end
364
+ end
338
365
  args.each {|file|
339
366
  if File.exists?(File.expand_path(file))
340
367
  input = IO.read(File.expand_path(file))
341
368
  suggestions = @jt.suggest(input)
369
+
342
370
  unless global_options[:t]
343
371
  if @jt.update_file_tags(file, suggestions)
344
372
  console_log
@@ -408,6 +436,13 @@ pre do |global,command,options,args|
408
436
 
409
437
  global[:config] = YAML::load(File.open(configfile,"r"))
410
438
  global[:support] = File.expand_path("~/.jtag")
439
+
440
+ if STDIN.stat.size > 0
441
+ @piped_content = STDIN.read
442
+ else
443
+ @piped_content = false
444
+ end
445
+
411
446
  @jt = JTag.new(global[:support], global[:config])
412
447
 
413
448
  true
@@ -1,2 +1,3 @@
1
1
  ---
2
2
  tags_location: localhost/data/tags.json
3
+ min_matches: 2
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  class JTag
2
3
 
3
4
  def initialize(support_dir, config)
@@ -60,21 +61,24 @@ class JTag
60
61
  def split_post(file)
61
62
  input = IO.read(file)
62
63
  # Check to see if it's a full post with YAML headers
63
- post_parts = input.split(/^---\s*$/)
64
- raise "File has improper YAML header" unless post_parts.length == 3
65
- after = post_parts[2].strip
66
- yaml = YAML::load(input)
64
+ post_parts = input.split(/^[\.\-]{3}\s*$/)
65
+ if post_parts.length >= 3
66
+ after = post_parts[2].strip
67
+ yaml = YAML::load(input)
68
+ else
69
+ after = input
70
+ yaml = YAML::load("--- title: #{File.basename(file)}")
71
+ end
67
72
  [yaml, after]
68
73
  end
69
74
 
70
- def post_tags(file)
71
- if File.exists?(file)
72
- input = IO.read(file)
73
- yaml = YAML::load(input) || false
74
- exit_now! "Invalid post header" unless yaml
75
+ def post_tags(file,piped=false)
76
+ begin
77
+ input = piped ? file : IO.read(file)
78
+ yaml = YAML::load(input)
75
79
  return yaml["tags"] || []
76
- else
77
- raise "File #{file} does not exist"
80
+ rescue
81
+ return []
78
82
  end
79
83
  end
80
84
 
@@ -95,15 +99,26 @@ class JTag
95
99
 
96
100
 
97
101
  def suggest(input)
98
- yaml = YAML::load(input) || false
99
- exit_now! "Invalid post header" unless yaml
100
- current_tags = yaml["tags"] || []
101
- title = yaml["title"] || ""
102
- @content = (title + after).strip_all.strip_urls rescue input.strip_all.strip_urls
102
+ parts = input.split(/^[\.\-]{3}\s*$/)
103
+ if parts.length >= 2
104
+ begin
105
+ yaml = YAML::load(parts[1])
106
+ current_tags = yaml["tags"] || []
107
+ title = yaml["title"] || ""
108
+ rescue
109
+ current_tags = []
110
+ title = ""
111
+ end
112
+ else
113
+ current_tags = []
114
+ title = ""
115
+ end
116
+ @content = (title + parts[2..-1].join(" ")).strip_all.strip_urls rescue input.strip_all.strip_urls
103
117
  @words = split_words
104
118
  @auto_tags = []
105
119
  populate_auto_tags
106
- @auto_tags.concat(current_tags).uniq!
120
+
121
+ @auto_tags.concat(current_tags).uniq
107
122
  end
108
123
 
109
124
  def split_words
@@ -121,7 +136,7 @@ class JTag
121
136
  @words.each { |word| freqs[word] += 1 }
122
137
  freqs.delete_if {|k,v| v < @min_matches }
123
138
 
124
- exit_with_message "No high frequency words", 1 if freqs.empty?
139
+ return [] if freqs.empty?
125
140
 
126
141
  freqs.sort_by {|k,v| [v * -1, k] }.each {|word|
127
142
  index = @tags.keys.index(word[0])
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  class String
2
3
  # convert "WikiLink" to "Wiki link"
3
4
  def break_camel
@@ -1,3 +1,3 @@
1
1
  module Jtag
2
- VERSION = '0.1.6'
2
+ VERSION = '0.1.7'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jtag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-26 00:00:00.000000000 Z
12
+ date: 2013-08-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -130,12 +130,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
130
130
  - - ! '>='
131
131
  - !ruby/object:Gem::Version
132
132
  version: '0'
133
+ segments:
134
+ - 0
135
+ hash: -591621506323502236
133
136
  required_rubygems_version: !ruby/object:Gem::Requirement
134
137
  none: false
135
138
  requirements:
136
139
  - - ! '>='
137
140
  - !ruby/object:Gem::Version
138
141
  version: '0'
142
+ segments:
143
+ - 0
144
+ hash: -591621506323502236
139
145
  requirements: []
140
146
  rubyforge_project:
141
147
  rubygems_version: 1.8.25