gliss 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/gliss.rb +63 -16
  3. metadata +5 -5
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.2.0
@@ -20,6 +20,12 @@
20
20
  require 'grit'
21
21
  require 'optparse'
22
22
  require 'set'
23
+ begin
24
+ require 'maruku'
25
+ $HAS_MARUKU=true
26
+ rescue LoadError=>le
27
+ $HAS_MARUKU=false
28
+ end
23
29
 
24
30
  module Gliss
25
31
  Gloss = Struct.new(:sha, :tag, :text)
@@ -131,6 +137,8 @@ module Gliss
131
137
  end
132
138
 
133
139
  class App
140
+ OUTPUT_KINDS=%w{html latex}
141
+
134
142
  def initialize(args=nil)
135
143
  @args = (args || ARGV.dup)
136
144
  end
@@ -165,9 +173,17 @@ module Gliss
165
173
  tag = gloss.tag
166
174
  msg = gloss.text
167
175
  puts "#{sha} (#{tag})"
168
- msg.each_line {|line| puts " #{line.chomp}"}
176
+ if @format_glosses && tag =~ @output_tag_filter
177
+ puts Maruku.new(msg).send(@markdown_backend_msg)
178
+ else
179
+ msg.each_line {|line| puts " #{line.chomp}"}
180
+ end
169
181
  end
170
182
 
183
+ @output_filter_kind = :latex
184
+ @output_tag_filter = nil
185
+ @markdown_list = ""
186
+
171
187
  oparser.parse!(@args)
172
188
  unless @args.size <= 2 && @args.size >= 1
173
189
  puts "fatal: you must specify at least one branch or tag name"
@@ -175,15 +191,24 @@ module Gliss
175
191
  exit(1)
176
192
  end
177
193
 
194
+ if @whole_commit && @format_glosses
195
+ puts "fatal: --whole-commit is incompatible with --format-glosses-matching; please\nchoose at most one of these options"
196
+ exit(1)
197
+ end
198
+
178
199
  @filter ||= /.*/
179
200
 
180
201
  @from, @to = @args
181
202
  @to ||= "master"
203
+
204
+ @markdown_backend_msg = "to_#{@output_filter_kind}#{@markdown_list}"
182
205
  end
183
206
 
184
207
  def oparser
185
208
  @oparser ||= OptionParser.new do |opts|
186
- opts.banner = "gliss [options] FROM [TO]\nDisplays all gliss-formatted glosses reachable from TO but not from FROM.\nIf TO is not specified, use \"master\"."
209
+ opts.banner = "gliss [options] FROM [TO]\nDisplays all gliss-formatted glosses reachable from TO but not from FROM.\nTO and FROM are commit SHAs, branch names, or tag names.\nIf TO is not specified, gliss will use \"master\" as the TO argument."
210
+
211
+ opts.separator("\nGeneral options:")
187
212
 
188
213
  opts.on("-h", "--help", "Displays this message") do
189
214
  puts opts
@@ -194,25 +219,15 @@ module Gliss
194
219
  @repo = repo
195
220
  end
196
221
 
197
- opts.on("-f REGEX", "--filter REGEX", "Output only messages with tags matching", "REGEX (default is all tags)") do |filter|
222
+ opts.on("-f REGEX", "--filter REGEX", "Output only messages with tags matching", "REGEX (default is all tags).", "Applying this multiple times will select", "tags matching any supplied expression.") do |filter|
198
223
  new_filter = Regexp.new(filter)
199
224
  @filter = @filter ? Regexp.union(@filter, new_filter) : new_filter
200
225
  end
201
226
 
202
- opts.on("--split-glosses", "Attempt to find multiple glosses in a line.", "Note that this option may return","spurious glosses") do
203
- @split_glosses = true
204
- end
205
-
206
- opts.on("--allow-indented-glosses", "Find glosses that don't begin at","the beginning of a line") do
207
- @allow_indented_glosses = true
208
- end
209
-
210
- opts.on("--permissive", "Find as many malformed glosses as possible.","Implies --allow-indented-glosses and", "--split-glosses") do
211
- @split_glosses = true
212
- @allow_indented_glosses = true
213
- end
227
+ opts.separator("\nFormatting options:")
214
228
 
215
- opts.on("-w", "--whole-commit", "Output entire commit messages that contain glosses") do
229
+ opts.on("-w", "--whole-commit", "Output entire commit messages that", "contain glosses") do
230
+ @whole_commit = true
216
231
  @seen_messages = Set.new
217
232
  @output_proc = Proc.new do |gloss|
218
233
  unless @seen_messages.include?(gloss.sha)
@@ -225,6 +240,38 @@ module Gliss
225
240
  end
226
241
  end
227
242
  end
243
+
244
+ if $HAS_MARUKU
245
+ opts.on("--format-glosses-matching REGEX", "Apply Markdown formatting to tags matching", "REGEX (default is format no tags)", "Applying this multiple times will select", "tags matching any supplied expression.") do |re|
246
+ @format_glosses = true
247
+ new_oft_re = Regexp.new(re)
248
+ @output_tag_filter = @output_tag_filter ? Regexp.union(@output_tag_filter, new_oft_re) : new_oft_re
249
+ end
250
+
251
+ opts.on("--markdown-output KIND", OUTPUT_KINDS, "Select the type of Markdown output","to generate: #{OUTPUT_KINDS.join(" or ")}. (The default","is latex)") do |ok|
252
+ @output_filter_kind = ok.to_sym
253
+ end
254
+
255
+ opts.on("--markdown-as-list", "Output Markdown glosses as list items") {@markdown_list="_li"}
256
+ else
257
+ opts.separator("More formatting options are available if you install the maruku gem\nwith 'gem install maruku'")
258
+ end
259
+
260
+ opts.separator("\nOptions to handle potentially-malformed input:")
261
+
262
+ opts.on("--split-glosses", "Attempt to find multiple glosses in a", "line. Note that this option may return","spurious glosses") do
263
+ @split_glosses = true
264
+ end
265
+
266
+ opts.on("--allow-indented-glosses", "Find glosses that don't begin at the","beginning of a line. Note that this","option may return spurious glosses.") do
267
+ @allow_indented_glosses = true
268
+ end
269
+
270
+ opts.on("--permissive", "Find as many malformed gloss candidates as","possible. Implies --allow-indented-glosses", "and --split-glosses") do
271
+ @split_glosses = true
272
+ @allow_indented_glosses = true
273
+ end
274
+
228
275
  end
229
276
  end
230
277
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gliss
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 3
10
- version: 0.1.3
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Will Benton
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-20 00:00:00 -05:00
18
+ date: 2011-07-21 00:00:00 -05:00
19
19
  default_executable: gliss
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency