Mercurial > hg > soundsoftware-site
comparison vendor/gems/coderay-1.0.0/lib/coderay/encoders/lines_of_code.rb @ 909:cbb26bc654de redmine-1.3
Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author | Chris Cannam |
---|---|
date | Fri, 24 Feb 2012 19:09:32 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
908:c6c2cbd0afee | 909:cbb26bc654de |
---|---|
1 module CodeRay | |
2 module Encoders | |
3 | |
4 # Counts the LoC (Lines of Code). Returns an Integer >= 0. | |
5 # | |
6 # Alias: +loc+ | |
7 # | |
8 # Everything that is not comment, markup, doctype/shebang, or an empty line, | |
9 # is considered to be code. | |
10 # | |
11 # For example, | |
12 # * HTML files not containing JavaScript have 0 LoC | |
13 # * in a Java class without comments, LoC is the number of non-empty lines | |
14 # | |
15 # A Scanner class should define the token kinds that are not code in the | |
16 # KINDS_NOT_LOC constant, which defaults to [:comment, :doctype]. | |
17 class LinesOfCode < TokenKindFilter | |
18 | |
19 register_for :lines_of_code | |
20 | |
21 NON_EMPTY_LINE = /^\s*\S.*$/ | |
22 | |
23 protected | |
24 | |
25 def setup options | |
26 if scanner | |
27 kinds_not_loc = scanner.class::KINDS_NOT_LOC | |
28 else | |
29 warn "Tokens have no associated scanner, counting all nonempty lines." if $VERBOSE | |
30 kinds_not_loc = CodeRay::Scanners::Scanner::KINDS_NOT_LOC | |
31 end | |
32 | |
33 options[:exclude] = kinds_not_loc | |
34 | |
35 super options | |
36 end | |
37 | |
38 def finish options | |
39 output @tokens.text.scan(NON_EMPTY_LINE).size | |
40 end | |
41 | |
42 end | |
43 | |
44 end | |
45 end |