diff options
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | lib/coderay/helpers/plugin.rb | 2 | ||||
-rw-r--r-- | lib/coderay/scanner.rb | 8 | ||||
-rw-r--r-- | lib/coderay/scanners/html.rb | 2 | ||||
-rw-r--r-- | rake_helpers/code_statistics.rb | 53 | ||||
-rw-r--r-- | rake_tasks/statistic.rake | 5 | ||||
-rw-r--r-- | test/html/ampersand.in.html | 1 | ||||
-rw-r--r-- | test/html/ampersand.out.raydebug | 1 |
8 files changed, 43 insertions, 31 deletions
@@ -34,7 +34,7 @@ Encoders: HTML:
L 1 2 dynamic CSS creation: new CSS class
Colors:
-3/4 1 2 So colorschemes
+3/4 1 2 colorschemes
Statistic:
L 3 1 return Statistic object with to_s method instead of String
diff --git a/lib/coderay/helpers/plugin.rb b/lib/coderay/helpers/plugin.rb index 938d1a8..3383828 100644 --- a/lib/coderay/helpers/plugin.rb +++ b/lib/coderay/helpers/plugin.rb @@ -224,7 +224,7 @@ protected plugin_hash.fetch validate_id(id), *args, &blk
end
- # Returns the path to the encoder for format.
+ # Returns the expected path to the plugin file for the given id.
def path_to plugin_id
File.join plugin_path, "#{plugin_id}.rb"
end
diff --git a/lib/coderay/scanner.rb b/lib/coderay/scanner.rb index 8affb53..55c1485 100644 --- a/lib/coderay/scanner.rb +++ b/lib/coderay/scanner.rb @@ -65,6 +65,10 @@ module CodeRay is_a? Streamable
end
+ def normify code
+ code = code.to_s.to_unix
+ end
+
end
=begin
@@ -96,7 +100,7 @@ module CodeRay raise "I am only the basic Scanner class. I can't scan "\
"anything. :( Use my subclasses." if self.class == Scanner
- super code.to_s.to_unix
+ super Scanner.normify(code)
@tokens = options[:tokens]
if @options[:stream]
@@ -122,7 +126,7 @@ module CodeRay end
def string= code
- code = code.to_s.to_unix
+ code = Scanner.normify(code)
super code
reset_instance
end
diff --git a/lib/coderay/scanners/html.rb b/lib/coderay/scanners/html.rb index f37a8dd..cbf8a55 100644 --- a/lib/coderay/scanners/html.rb +++ b/lib/coderay/scanners/html.rb @@ -74,7 +74,7 @@ module Scanners kind = :plain
elsif scan(/#{ENTITY}/ox)
kind = :entity
- elsif scan(/>/)
+ elsif scan(/[>&]/)
kind = :error
else
raise_inspect '[BUG] else-case reached with state %p' % [state], tokens
diff --git a/rake_helpers/code_statistics.rb b/rake_helpers/code_statistics.rb index 4c4b65c..b015403 100644 --- a/rake_helpers/code_statistics.rb +++ b/rake_helpers/code_statistics.rb @@ -45,15 +45,16 @@ private DEFAULT_FILE_PATTERN = /\.rb$/ def calculate_statistics - @pairs.inject({}) do |stats, (name, path, pattern)| + @pairs.inject({}) do |stats, (name, path, pattern, is_ruby_code)| pattern ||= DEFAULT_FILE_PATTERN path = File.join path, '*.rb' - stats[name] = calculate_directory_statistics path, pattern + stats[name] = calculate_directory_statistics path, pattern, is_ruby_code stats end end - def calculate_directory_statistics directory, pattern = DEFAULT_FILE_PATTERN + def calculate_directory_statistics directory, pattern = DEFAULT_FILE_PATTERN, is_ruby_code = true + is_ruby_code = true if is_ruby_code.nil? stats = Hash.new 0 Dir[directory].each do |file_name| @@ -66,28 +67,32 @@ private File.readlines(file_name).each do |line| lines += 1 - case line - when /^=end\b/ - comment_lines += 1 - in_comment_block = false - when in_comment_block - comment_lines += 1 - when /^\s*class\b/: classes += 1 - when /^\s*module\b/: modules += 1 - when /^\s*def\b/: methods += 1 - when /^\s*#/: comment_lines += 1 - when /^\s*$/: empty_lines += 1 - when /^=begin\b/ - in_comment_block = false - comment_lines += 1 - when /^__END__$/ - in_comment_block = true - end + if line[/^\s*$/] + empty_lines += 1 + elsif is_ruby_code + case line + when /^=end\b/ + comment_lines += 1 + in_comment_block = false + when in_comment_block + comment_lines += 1 + when /^\s*class\b/: classes += 1 + when /^\s*module\b/: modules += 1 + when /^\s*def\b/: methods += 1 + when /^\s*#/: comment_lines += 1 + when /^=begin\b/ + in_comment_block = false + comment_lines += 1 + when /^__END__$/ + in_comment_block = true + end + end end codelines = lines - comment_lines - empty_lines stats[:lines] += lines + stats[:comments] += comment_lines stats[:codelines] += codelines stats[:classes] += classes stats[:modules] += modules @@ -118,12 +123,12 @@ private def print_header print_splitter - puts "| T=Test Name | Files | Lines | LOC | Classes | Modules | Methods | M/C | LOC/M |" + puts "| T=Test Name | Files | Lines | LOC | Comments | Classes | Modules | Methods | M/C | LOC/M |" print_splitter end def print_splitter - puts "+---------------------------+-------+-------+-------+---------+---------+---------+-----+-------+" + puts "+---------------------------+-------+-------+-------+----------+---------+---------+---------+-----+-------+" end def print_line name, statistics @@ -136,8 +141,8 @@ private name = " #{name}" end - line = "| %-25s | %5d | %5d | %5d | %7d | %7d | %7d | %3d | %5d |" % ( - [name, *statistics.values_at(:files, :lines, :codelines, :classes, :modules, :methods)] + + line = "| %-25s | %5d | %5d | %5d | %8d | %7d | %7d | %7d | %3d | %5d |" % ( + [name, *statistics.values_at(:files, :lines, :codelines, :comments, :classes, :modules, :methods)] + [m_over_c, loc_over_m] ) puts line diff --git a/rake_tasks/statistic.rake b/rake_tasks/statistic.rake index 6114547..eb49493 100644 --- a/rake_tasks/statistic.rake +++ b/rake_tasks/statistic.rake @@ -3,12 +3,13 @@ task :stats do require 'rake_helpers/code_statistics'
CodeStatistics.new(
['Main', 'lib'],
- ['CodeRay', 'lib/coderay/'],
+ ['CodeRay', 'lib/{.,coderay}/'],
[' Scanners', 'lib/coderay/scanners/**'],
[' Encoders', 'lib/coderay/encoders/**'],
[' Helpers', 'lib/coderay/helpers/**'],
[' Styles', 'lib/coderay/styles/**'],
- ['Test', 'test/**', /\/\w+.rb$/],
+ ['Test', 'test'],
+ [' Test Data', 'test/*/**', /\.in\./, false],
['Demo Tests', 'demo/**']
).print
end
diff --git a/test/html/ampersand.in.html b/test/html/ampersand.in.html new file mode 100644 index 0000000..4bd7e7a --- /dev/null +++ b/test/html/ampersand.in.html @@ -0,0 +1 @@ +& diff --git a/test/html/ampersand.out.raydebug b/test/html/ampersand.out.raydebug new file mode 100644 index 0000000..fced304 --- /dev/null +++ b/test/html/ampersand.out.raydebug @@ -0,0 +1 @@ +error(&)
|