rouge 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/bin/rougify CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  require 'pathname'
4
4
  ROOT_DIR = Pathname.new(__FILE__).dirname.parent
5
- $:.push(ROOT_DIR.join('lib').to_s)
6
5
  load ROOT_DIR.join('lib/rouge.rb')
7
6
  load ROOT_DIR.join('lib/rouge/cli.rb')
8
7
 
data/lib/rouge/cli.rb CHANGED
@@ -75,10 +75,14 @@ module Rouge
75
75
  def initialize(options={})
76
76
  end
77
77
 
78
- def error!(msg, status=1)
78
+ def self.error!(msg, status=1)
79
79
  raise Error.new(msg, status)
80
80
  end
81
81
 
82
+ def error!(*a)
83
+ self.class.error!(*a)
84
+ end
85
+
82
86
  def self.class_from_arg(arg)
83
87
  case arg
84
88
  when 'version', '--version'
@@ -237,20 +241,18 @@ module Rouge
237
241
  @lexer_opts = opts[:lexer_opts]
238
242
 
239
243
  formatter_class = Formatter.find(opts[:formatter]) \
240
- or error! "unknown formatter #{opts[:formatter]}"
244
+ or error! "unknown formatter #{opts[:formatter]}"
241
245
 
242
246
  @formatter = formatter_class.new(opts[:formatter_opts])
243
247
  end
244
248
 
245
249
  def run
246
- formatter.format(lexer.lex(input)) do |chunk|
247
- print chunk
248
- end
250
+ formatter.format(lexer.lex(input), &method(:print))
249
251
  end
250
252
 
251
253
  private
252
254
  def self.parse_cgi(str)
253
- pairs = CGI.parse(str).map { |k, v| v.first }
255
+ pairs = CGI.parse(str).map { |k, v| [k.to_sym, v.first] }
254
256
  Hash[pairs]
255
257
  end
256
258
  end
@@ -289,7 +291,8 @@ module Rouge
289
291
  end
290
292
 
291
293
  def initialize(opts)
292
- theme_class = Theme.find(opts.delete(:theme_name)) \
294
+ theme_name = opts.delete(:theme_name)
295
+ theme_class = Theme.find(theme_name) \
293
296
  or error! "unknown theme: #{theme_name}"
294
297
 
295
298
  @theme = theme_class.new(opts)
@@ -69,10 +69,10 @@ module Rouge
69
69
  end.join
70
70
 
71
71
  yield "<div class=#{@css_class.inspect}>" if @wrap
72
- yield "<table><tbody><tr>"
72
+ yield '<table style="border-spacing: 0"><tbody><tr>'
73
73
 
74
74
  # the "gl" class applies the style for Generic.Lineno
75
- yield '<td class="gutter gl">'
75
+ yield '<td class="gutter gl" style="text-align: right">'
76
76
  yield numbers
77
77
  yield '</td>'
78
78
 
@@ -14,7 +14,7 @@ module Rouge
14
14
  state :root do
15
15
  rule /[^<&]+/m, Text
16
16
  rule /&\S*?;/, Name::Entity
17
- rule /<!DOCTYPE .*?>/i, Comment::Preproc
17
+ rule /<!DOCTYPE .*?>/im, Comment::Preproc
18
18
  rule /<!\[CDATA\[.*?\]\]>/m, Comment::Preproc
19
19
  rule /<!--/, Comment, :comment
20
20
  rule /<\?.*?\?>/m, Comment::Preproc # php? really?
@@ -31,7 +31,7 @@ module Rouge
31
31
  @primitives ||= Set.new %w(unit int float bool string char list array)
32
32
  end
33
33
 
34
- operator = %r([\[\];,{}_()!$%&*+./:<=>?@^|~-]+)
34
+ operator = %r([\[\];,{}_()!$%&*+./:<=>?@^|~#-]+)
35
35
  id = /[a-z][\w']*/i
36
36
  upper_id = /[A-Z][\w']*/
37
37
 
@@ -15,12 +15,17 @@ module Rouge
15
15
  code.gsub! /^ /, "\t"
16
16
  end
17
17
 
18
- formatter = Formatters::HTML.new(
18
+ formatter = rouge_formatter(
19
19
  :css_class => "highlight #{lexer.tag}"
20
20
  )
21
21
 
22
22
  formatter.format(lexer.lex(code))
23
23
  end
24
+
25
+ protected
26
+ def rouge_formatter(opts={})
27
+ Formatters::HTML.new(opts)
28
+ end
24
29
  end
25
30
  end
26
31
  end
data/lib/rouge/theme.rb CHANGED
@@ -140,10 +140,8 @@ module Rouge
140
140
  return enum_for(:render).to_a.join("\n") unless b
141
141
 
142
142
  # shared styles for tableized line numbers
143
- yield "#{@scope} table { border-spacing: 0; }"
144
143
  yield "#{@scope} table td { padding: 5px; }"
145
144
  yield "#{@scope} table pre { margin: 0; }"
146
- yield "#{@scope} table .gutter { text-align: right; }"
147
145
 
148
146
  styles.each do |tok, style|
149
147
  style.render(css_selector(tok), &b)
data/lib/rouge/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Rouge
2
2
  def self.version
3
- "1.2.0"
3
+ "1.3.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rouge
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
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-11-26 00:00:00.000000000 Z
12
+ date: 2013-12-23 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Rouge aims to a be a simple, easy-to-extend drop-in replacement for pygments.
15
15
  email: