diff options
-rw-r--r-- | Changes.textile | 2 | ||||
-rw-r--r-- | bench/bench.rb | 61 | ||||
-rwxr-xr-x | bin/coderay | 2 | ||||
-rw-r--r-- | etc/CodeRay.tmproj | 4 | ||||
-rw-r--r-- | lib/coderay/duo.rb | 2 | ||||
-rw-r--r-- | lib/coderay/encoders/_map.rb | 15 | ||||
-rw-r--r-- | lib/coderay/encoders/div.rb | 17 | ||||
-rw-r--r-- | lib/coderay/encoders/html.rb | 2 | ||||
-rw-r--r-- | lib/coderay/encoders/html/output.rb | 2 | ||||
-rw-r--r-- | lib/coderay/encoders/page.rb | 4 | ||||
-rw-r--r-- | lib/coderay/encoders/span.rb | 19 | ||||
-rw-r--r-- | lib/coderay/helpers/file_type.rb | 11 | ||||
-rw-r--r-- | rake_tasks/benchmark.rake | 2 | ||||
-rw-r--r-- | test/executable/suite.rb | 7 | ||||
-rwxr-xr-x | test/functional/basic.rb | 4 | ||||
-rwxr-xr-x | test/functional/examples.rb | 4 | ||||
-rw-r--r-- | test/unit/file_type.rb | 6 |
17 files changed, 57 insertions, 107 deletions
diff --git a/Changes.textile b/Changes.textile index f42e448..f63c8c0 100644 --- a/Changes.textile +++ b/Changes.textile @@ -273,7 +273,7 @@ Stripped down to 19 LOC. h3. @FileType@ * *REMOVED* @FileType#shebang@ is a protected method now. -* *NEW*: Recognizes @.gemspec@, @.rjs@, @.rpdf@ extensions and @Capfile@ as Ruby. +* *NEW*: Recognizes @.gemspec@, @.rjs@, @.rpdf@ extensions, @Gemfile@, and @Capfile@ as Ruby. Thanks to the authors of the TextMate Ruby bundle! diff --git a/bench/bench.rb b/bench/bench.rb index 00fe8b2..5663466 100644 --- a/bench/bench.rb +++ b/bench/bench.rb @@ -39,8 +39,7 @@ require 'benchmark' require 'fileutils' if format == 'comp' - format = 'html' - compare = true + format = 'page' begin require 'syntax' require 'syntax/convertors/html.rb' @@ -80,8 +79,6 @@ N.times do options = { :tab_width => 2, - :wrap => :page, - :line_numbers => :table, :css => $style ? :style : :class, } $hl = CodeRay.encoder(format, options) unless $dump_output @@ -93,15 +90,12 @@ N.times do raise 'Can\'t dump stream.' end $o = $hl.encode(data, lang, options) - @token_count = 253528 #$hl.token_stream.count rescue 1 else if $dump_input tokens = CodeRay::Tokens.load data else tokens = CodeRay.scan(data, lang) end - @token_count = tokens.count - p @token_count tokens.optimize! if $optimize if $dump_output $o = tokens.optimize.dump @@ -121,60 +115,9 @@ N.times do time_real = time.real - puts "\t%7.2f KB/s (%d.%d KB)\t%0.2f KTok/s" % [((@size / 1000.0) / time_real), @size / 1000, @size % 1000, ((@token_count / 1000.0) / time_real)] + puts "\t%7.2f KB/s (%d.%d KB)" % [((@size / 1000.0) / time_real), @size / 1000, @size % 1000] puts $o if ARGV.include? '-o' - if compare - if defined? Syntax - time = bm.report('Syntax') do - c = Syntax::Convertors::HTML.for_syntax lang - puts 'No Syntax syntax found!' if c.tokenizer.is_a? Syntax::Default - begin - v = $VERBOSE - $VERBOSE = nil - N.times do - output = c.convert(data) - end - $VERBOSE = v - rescue => boom - output = boom.inspect - end - Dir.chdir(here) do - File.open('test.syntax.' + format, 'wb') do |f| - f.write '<html><head><style>%s</style></head><body><div class="ruby">%s</div></body></html>' % [DATA.read, output] - end - end - $file_created << ", test.syntax.#{format}" - end - puts "\t%7.2f KB/s" % ((@size / 1024.0) / time.real) - end - -=begin - time = bm.report('SilverCity') do - Dir.chdir(here) do - File.open('input-data', 'w') { |f| f.write data } - N.times do - `c:/Python/Scripts/source2html.pyo --generator=#{lang} input-data > test.silvercity.html` - end - end - $file_created << ", test.silvercity.#{format}" - end - puts "\t%7.2f KB/s" % ((@size / 1024.0) / time.real) -=end - time = bm.report('Pygments') do - Dir.chdir(here) do - Dir.chdir File.expand_path('~/Python/pygments') do - File.open('input-data', 'wb') { |f| f.write data } - N.times do - `pygmentize -O encoding=utf-8 -l#{lang} -fhtml -Ofull input-data > /dev/null` - end - end - end - #$file_created << ", test.silvercity.#{format}" - end - puts "\t%7.2f KB/s" % ((@size / 1024.0) / time.real) - end - end end puts "Files created: #$file_created" diff --git a/bin/coderay b/bin/coderay index 2a4ba3b..fa87fa9 100755 --- a/bin/coderay +++ b/bin/coderay @@ -30,7 +30,7 @@ usage: defaults: language detect from input file name or shebang; fall back to plain text input STDIN - format detect from output file name or use terminal; fall back to HTML page + format detect from output file name or use terminal; fall back to HTML output STDOUT common: diff --git a/etc/CodeRay.tmproj b/etc/CodeRay.tmproj index 8c3f1a5..aef1391 100644 --- a/etc/CodeRay.tmproj +++ b/etc/CodeRay.tmproj @@ -133,7 +133,7 @@ <key>filename</key> <string>../test/scanners/coderay_suite.rb</string> <key>lastUsed</key> - <date>2011-05-08T16:19:54Z</date> + <date>2011-06-26T01:18:25Z</date> </dict> <dict> <key>filename</key> @@ -157,7 +157,7 @@ <key>filename</key> <string>../bench/bench.rb</string> <key>lastUsed</key> - <date>2011-02-20T05:36:12Z</date> + <date>2011-06-26T15:21:10Z</date> </dict> </array> <key>fileHierarchyDrawerWidth</key> diff --git a/lib/coderay/duo.rb b/lib/coderay/duo.rb index 171768c..cb3f8ee 100644 --- a/lib/coderay/duo.rb +++ b/lib/coderay/duo.rb @@ -21,7 +21,7 @@ module CodeRay # Create a new Duo, holding a lang and a format to highlight code. # # simple: - # CodeRay::Duo[:ruby, :page].highlight 'bla 42' + # CodeRay::Duo[:ruby, :html].highlight 'bla 42' # # with options: # CodeRay::Duo[:ruby, :html, :hint => :debug].highlight '????::??' diff --git a/lib/coderay/encoders/_map.rb b/lib/coderay/encoders/_map.rb index c9a20cc..24ada0a 100644 --- a/lib/coderay/encoders/_map.rb +++ b/lib/coderay/encoders/_map.rb @@ -2,15 +2,16 @@ module CodeRay module Encoders map \ - :loc => :lines_of_code, - :term => :terminal, - :tty => :terminal, - :plain => :text, - :plaintext => :text, + :loc => :lines_of_code, + :html => :page, + :plain => :text, + :plaintext => :text, :remove_comments => :comment_filter, - :stats => :statistic + :stats => :statistic, + :term => :terminal, + :tty => :terminal - # No default because Tokens#nonsense would not raise NoMethodError. + # No default because Tokens#nonsense should raise NoMethodError. end end diff --git a/lib/coderay/encoders/div.rb b/lib/coderay/encoders/div.rb index f9741e3..efd9435 100644 --- a/lib/coderay/encoders/div.rb +++ b/lib/coderay/encoders/div.rb @@ -1,22 +1,23 @@ module CodeRay module Encoders - + load :html # Wraps HTML output into a DIV element, using inline styles by default. # # See Encoders::HTML for available options. class Div < HTML - + FILE_EXTENSION = 'div.html' - + register_for :div - + DEFAULT_OPTIONS = HTML::DEFAULT_OPTIONS.merge \ - :css => :style, - :wrap => :div - + :css => :style, + :wrap => :div, + :line_numbers => false + end - + end end diff --git a/lib/coderay/encoders/html.rb b/lib/coderay/encoders/html.rb index 724f3eb..ec73d2c 100644 --- a/lib/coderay/encoders/html.rb +++ b/lib/coderay/encoders/html.rb @@ -91,7 +91,7 @@ module Encoders register_for :html - FILE_EXTENSION = 'html' + FILE_EXTENSION = 'snippet.html' DEFAULT_OPTIONS = { :tab_width => 8, diff --git a/lib/coderay/encoders/html/output.rb b/lib/coderay/encoders/html/output.rb index 5aa80a7..004351b 100644 --- a/lib/coderay/encoders/html/output.rb +++ b/lib/coderay/encoders/html/output.rb @@ -126,7 +126,7 @@ module Encoders TABLE = Template.new <<-TABLE <table class="CodeRay"><tr> <td class="line_numbers" title="double click to toggle" ondblclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }"><pre><%LINE_NUMBERS%></pre></td> - <td class="code"><pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }"><%CONTENT%></pre></td> + <td class="code"><pre><%CONTENT%></pre></td> </tr></table> TABLE diff --git a/lib/coderay/encoders/page.rb b/lib/coderay/encoders/page.rb index 8db45cd..800e73f 100644 --- a/lib/coderay/encoders/page.rb +++ b/lib/coderay/encoders/page.rb @@ -14,8 +14,8 @@ module Encoders register_for :page DEFAULT_OPTIONS = HTML::DEFAULT_OPTIONS.merge \ - :css => :class, - :wrap => :page, + :css => :class, + :wrap => :page, :line_numbers => :table end diff --git a/lib/coderay/encoders/span.rb b/lib/coderay/encoders/span.rb index 1596044..da705bd 100644 --- a/lib/coderay/encoders/span.rb +++ b/lib/coderay/encoders/span.rb @@ -1,22 +1,23 @@ module CodeRay module Encoders - + load :html - + # Wraps HTML output into a SPAN element, using inline styles by default. # # See Encoders::HTML for available options. class Span < HTML - + FILE_EXTENSION = 'span.html' - + register_for :span - + DEFAULT_OPTIONS = HTML::DEFAULT_OPTIONS.merge \ - :css => :style, - :wrap => :span - + :css => :style, + :wrap => :span, + :line_numbers => false + end - + end end diff --git a/lib/coderay/helpers/file_type.rb b/lib/coderay/helpers/file_type.rb index 61f0049..19cc5ac 100644 --- a/lib/coderay/helpers/file_type.rb +++ b/lib/coderay/helpers/file_type.rb @@ -88,8 +88,8 @@ module CodeRay 'groovy' => :groovy, 'gvy' => :groovy, 'h' => :c, - 'htm' => :html, - 'html' => :html, + 'htm' => :page, + 'html' => :page, 'html.erb' => :rhtml, 'java' => :java, 'js' => :java_script, @@ -101,6 +101,7 @@ module CodeRay 'php3' => :php, 'php4' => :php, 'php5' => :php, + 'prawn' => :ruby, 'py' => :python, 'py3' => :python, 'pyw' => :python, @@ -111,11 +112,12 @@ module CodeRay 'rhtml' => :rhtml, 'rjs' => :ruby, 'rpdf' => :ruby, + 'ru' => :ruby, 'rxml' => :ruby, 'sch' => :scheme, 'sql' => :sql, 'ss' => :scheme, - 'xhtml' => :xhtml, + 'xhtml' => :page, 'xml' => :xml, 'yaml' => :yaml, 'yml' => :yaml, @@ -127,9 +129,10 @@ module CodeRay TypeFromShebang = /\b(?:ruby|perl|python|sh)\b/ TypeFromName = { - 'Capfile' => :ruby, + 'Capfile' => :ruby, 'Rakefile' => :ruby, 'Rantfile' => :ruby, + 'Gemfile' => :ruby, } end diff --git a/rake_tasks/benchmark.rake b/rake_tasks/benchmark.rake index c6d5ebb..040951b 100644 --- a/rake_tasks/benchmark.rake +++ b/rake_tasks/benchmark.rake @@ -1,7 +1,7 @@ desc 'Do a benchmark' task :benchmark do ruby "-v" - ruby "-wIlib bench/bench.rb ruby div 1000 N5" + ruby "-wIlib bench/bench.rb ruby div 3000 N5" end task :bench => :benchmark diff --git a/test/executable/suite.rb b/test/executable/suite.rb index ef2ebb3..37acab9 100644 --- a/test/executable/suite.rb +++ b/test/executable/suite.rb @@ -1,4 +1,5 @@ require 'test/unit' +require 'rubygems' unless defined? Gem require 'shoulda-context' require 'pathname' @@ -100,7 +101,7 @@ class TestCodeRayExecutable < Test::Unit::TestCase source = File.read source_file - pre = %r{<pre [^>]*>(.*?)</pre>}m + pre = %r{<td class="code"><pre>(.*?)</pre>}m tag = /<[^>]*>/ should 'not throw an error' do @@ -155,7 +156,7 @@ class TestCodeRayExecutable < Test::Unit::TestCase source = File.read source_file - pre = %r{<pre [^>]*>(.*?)</pre>}m + pre = %r{<td class="code"><pre>(.*?)</pre>}m tag_class = /<span class="([^>"]*)"?[^>]*>/ should 'respect the file extension and highlight the input as Python' do @@ -170,7 +171,7 @@ class TestCodeRayExecutable < Test::Unit::TestCase source = File.read source_file - pre = %r{<pre [^>]*>(.*?)</pre>}m + pre = %r{<td class="code"><pre>(.*?)</pre>}m tag_class = /<span class="([^>"]*)"?[^>]*>/ should 'ignore the file extension and highlight the input as Ruby' do diff --git a/test/functional/basic.rb b/test/functional/basic.rb index c9879dd..dae7de6 100755 --- a/test/functional/basic.rb +++ b/test/functional/basic.rb @@ -64,7 +64,7 @@ class BasicTest < Test::Unit::TestCase end def test_highlight - assert_match '<div class="code"><pre>test</pre></div>', CodeRay.highlight('test', :python) + assert_match '<pre>test</pre>', CodeRay.highlight('test', :python) end def test_highlight_file @@ -173,7 +173,7 @@ more code # and another comment, in-line. def test_encoder_file_extension assert_nothing_raised do - assert_equal 'html', CodeRay::Encoders::HTML::FILE_EXTENSION + assert_equal 'html', CodeRay::Encoders::Page::FILE_EXTENSION assert_equal 'cocoa', Milk::FILE_EXTENSION assert_equal 'cocoa', Milk.new.file_extension assert_equal 'honeybee', HoneyBee::FILE_EXTENSION diff --git a/test/functional/examples.rb b/test/functional/examples.rb index aed7605..f80c90c 100755 --- a/test/functional/examples.rb +++ b/test/functional/examples.rb @@ -24,7 +24,7 @@ end <a href="#n2" name="n2">2</a> <a href="#n3" name="n3">3</a> </pre></td> - <td class="code"><pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }"><span style="color:#00D">5</span>.times <span style="color:#080;font-weight:bold">do</span> + <td class="code"><pre><span style="color:#00D">5</span>.times <span style="color:#080;font-weight:bold">do</span> puts <span style="background-color:hsla(0,100%,50%,0.08)"><span style="color:#710">'</span><span style="color:#D20">Hello, world!</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">end</span></pre></td> </tr></table> @@ -38,7 +38,7 @@ end <table class="CodeRay"><tr> <td class="line_numbers" title="double click to toggle" ondblclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }"><pre> </pre></td> - <td class="code"><pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">puts <span class="s"><span class="dl">"</span><span class="k">Hello, world!</span><span class="dl">"</span></span></pre></td> + <td class="code"><pre>puts <span class="s"><span class="dl">"</span><span class="k">Hello, world!</span><span class="dl">"</span></span></pre></td> </tr></table> </body> diff --git a/test/unit/file_type.rb b/test/unit/file_type.rb index aa54ba2..dfd5b17 100644 --- a/test/unit/file_type.rb +++ b/test/unit/file_type.rb @@ -74,9 +74,9 @@ class FileTypeTests < Test::Unit::TestCase end def test_html - assert_equal :html, FileType['test.htm'] - assert_equal :xhtml, FileType['test.xhtml'] - assert_equal :xhtml, FileType['test.html.xhtml'] + assert_equal :page, FileType['test.htm'] + assert_equal :page, FileType['test.xhtml'] + assert_equal :page, FileType['test.html.xhtml'] assert_equal :rhtml, FileType['_form.rhtml'] assert_equal :rhtml, FileType['_form.html.erb'] end |