Skip to content

Commit

Permalink
New Version: 0.7.0!
Browse files Browse the repository at this point in the history
Adjusted gem.rake.

HTML scanner fixed.
Enhanced filetype.rb: .rake files, xml, yaml (preparing for YAML scanner.)
Enhanced test/ruby/1.in.rb.
Added XML scanner with example.

plugin.rb: made all_plugin_names public.
  • Loading branch information
korny committed Apr 19, 2006
1 parent 8b65a05 commit f5f50a1
Show file tree
Hide file tree
Showing 13 changed files with 28,677 additions and 21 deletions.
31 changes: 29 additions & 2 deletions bench/bench.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ def here fn = nil
begin
v = $VERBOSE
$VERBOSE = nil
output = c.convert(data)
N.times do
output = c.convert(data)
end
$VERBOSE = v
rescue => boom
output = boom.inspect
Expand All @@ -151,7 +153,10 @@ def here fn = nil

time = bm.report('SilverCity') do
Dir.chdir(here) do
`c:/Python/Scripts/source2html.pyo --generator=#{lang} example.#{lang} > test.silvercity.html`
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
Expand Down Expand Up @@ -182,3 +187,25 @@ def here fn = nil
.ruby .global { color: #7FB; }
.ruby .expr { color: #227; }
.ruby .escape { color: #277; }

.xml .normal {}
.xml .namespace { color: #B66; font-weight: bold; }
.xml .tag { color: #F88; }
.xml .comment { color: #005; font-style: italic; }
.xml .punct { color: #447; font-weight: bold; }
.xml .string { color: #944; }
.xml .number { color: #F99; }
.xml .attribute { color: #BB7; }

.yaml .normal {}
.yaml .document { font-weight: bold; color: #07F; }
.yaml .type { font-weight: bold; color: #05C; }
.yaml .key { color: #F88; }
.yaml .comment { color: #005; font-style: italic; }
.yaml .punct { color: #447; font-weight: bold; }
.yaml .string { color: #944; }
.yaml .number { color: #F99; }
.yaml .time { color: #F99; }
.yaml .date { color: #F99; }
.yaml .ref { color: #944; }
.yaml .anchor { color: #944; }
28,137 changes: 28,137 additions & 0 deletions bench/example.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/coderay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ module CodeRay
# Minor: odd for beta, even for stable
# Teeny: development state
# Revision: Subversion Revision number (generated on rake)
Version = '0.6.0'
Version = '0.7'

require 'coderay/tokens'
require 'coderay/scanner'
Expand Down
44 changes: 40 additions & 4 deletions lib/coderay/helpers/filetype.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,29 @@
#
# Version: 0.1 (2005.september.1)
#
# ==Documentation
#
# TODO
# == Documentation
#
# # determine the type of the given
# lang = FileType[ARGV.first]
#
# # return :plaintext if the file type is unknown
# lang = FileType.fetch ARGV.first, :plaintext
#
# # try the shebang line, too
# lang = FileType.fetch ARGV.first, :plaintext, true
#
module FileType

UnknownFileType = Class.new Exception

class << self

# Try to determine the file type of the file.
#
# +filename+ is a relative or absolute path to a file.
#
# The file itself is only accessed when +read_shebang+ is set to true.
# That means you can get filetypes from files that don't exist.
def [] filename, read_shebang = false
name = File.basename filename
ext = File.extname name
Expand Down Expand Up @@ -43,6 +56,9 @@ def shebang filename
end

# This works like Hash#fetch.
#
# If the filetype cannot be found, the +default+ value
# is returned.
def fetch filename, default = nil, read_shebang = false
if default and block_given?
warn 'block supersedes default value argument'
Expand All @@ -61,12 +77,17 @@ def fetch filename, default = nil, read_shebang = false
TypeFromExt = {
'rb' => :ruby,
'rbw' => :ruby,
'cpp' => :cpp,
'rake' => :ruby,
'cpp' => :c,
'c' => :c,
'h' => :c,
'xml' => :xml,
'htm' => :html,
'html' => :html,
'xhtml' => :xhtml,
'rhtml' => :rhtml,
'yaml' => :yaml,
'yml' => :yaml,
}

TypeFromShebang = /\b(?:ruby|perl|python|sh)\b/
Expand Down Expand Up @@ -118,6 +139,7 @@ def test_ruby
assert_equal :ruby, FileType['C:\\Program Files\\x\\y\\c\\test.rbw']
assert_equal :ruby, FileType['/usr/bin/something/Rakefile']
assert_equal :ruby, FileType['~/myapp/gem/Rantfile']
assert_equal :ruby, FileType['./lib/tasks\repository.rake']
assert_not_equal :ruby, FileType['test_rb']
assert_not_equal :ruby, FileType['Makefile']
assert_not_equal :ruby, FileType['set.rb/set']
Expand All @@ -133,6 +155,20 @@ def test_c
assert_not_equal :c, FileType['~/projects/blabla/c']
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 :rhtml, FileType['_form.rhtml']
end

def test_yaml
assert_equal :yaml, FileType['test.yml']
assert_equal :yaml, FileType['test.yaml']
assert_equal :yaml, FileType['my.html.yaml']
assert_not_equal :yaml, FileType['YAML']
end

def test_shebang
dir = './test'
if File.directory? dir
Expand Down
22 changes: 11 additions & 11 deletions lib/coderay/helpers/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ def plugin_hash
@plugin_hash ||= create_plugin_hash
end

# Returns an array of all .rb files in the plugin path.
#
# The extension .rb is not included.
def all_plugin_names
Dir[path_to('*')].select do |file|
File.basename(file)[/^(?!_)\w+\.rb$/]
end.map do |file|
File.basename file, '.rb'
end
end

protected
# Created a new plugin list and stores it to @plugin_hash.
def create_plugin_hash
Expand Down Expand Up @@ -204,17 +215,6 @@ def load_map
end
end

# Returns an array of all .rb files in the plugin path.
#
# The extension .rb is not included.
def all_plugin_names
Dir[path_to('*')].select do |file|
File.basename(file)[/^(?!_)\w+\.rb$/]
end.map do |file|
File.basename file, '.rb'
end
end

# Returns the Plugin for +id+.
# Use it like Hash#fetch.
#
Expand Down
4 changes: 2 additions & 2 deletions lib/coderay/scanners/html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ def scan_tokens tokens, options
next
elsif scan(/#{ENTITY}/ox)
kind = :entity
elsif match(/[\n>]/)
elsif scan(/[\n>]/)
tokens << [:close, :string]
kind = error
kind = :error
state = :initial
end

Expand Down
18 changes: 18 additions & 0 deletions lib/coderay/scanners/xml.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module CodeRay
module Scanners

load :html

# XML Scanner
#
# $Id$
#
# Currently this is the same scanner as Scanners::HTML.
class XML < HTML

register_for :xml

end

end
end
2 changes: 1 addition & 1 deletion rake_tasks/gem.rake
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace :gem do
$version = CodeRay::Version
end
puts 'Current Version: %s' % $version
$version.sub!(/\.(\d+)\./) { minor = $1; ".#{minor.to_i - 1}." }
#$version.sub!(/\.(\d+)\./) { minor = $1; ".#{minor.to_i}." }
$version << '.' << (`svn info`[/Revision: (\d+)/,1])
end

Expand Down
2 changes: 2 additions & 0 deletions test/ruby/1.in.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
public :<<

class String
def / regex
scan(regex).first
Expand Down
Loading

0 comments on commit f5f50a1

Please sign in to comment.