Mercurial > hg > soundsoftware-site
comparison vendor/gems/coderay-0.9.7/lib/coderay/scanners/.svn/text-base/rhtml.rb.svn-base @ 210:0579821a129a
Update to Redmine trunk rev 4802
author | Chris Cannam |
---|---|
date | Tue, 08 Feb 2011 13:51:46 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
128:07fa8a8b56a8 | 210:0579821a129a |
---|---|
1 module CodeRay | |
2 module Scanners | |
3 | |
4 load :html | |
5 load :ruby | |
6 | |
7 # RHTML Scanner | |
8 class RHTML < Scanner | |
9 | |
10 include Streamable | |
11 register_for :rhtml | |
12 title 'HTML ERB Template' | |
13 | |
14 KINDS_NOT_LOC = HTML::KINDS_NOT_LOC | |
15 | |
16 ERB_RUBY_BLOCK = / | |
17 <%(?!%)[=-]? | |
18 (?> | |
19 [^\-%]* # normal* | |
20 (?> # special | |
21 (?: %(?!>) | -(?!%>) ) | |
22 [^\-%]* # normal* | |
23 )* | |
24 ) | |
25 (?: -?%> )? | |
26 /x | |
27 | |
28 START_OF_ERB = / | |
29 <%(?!%) | |
30 /x | |
31 | |
32 private | |
33 | |
34 def setup | |
35 @ruby_scanner = CodeRay.scanner :ruby, :tokens => @tokens, :keep_tokens => true | |
36 @html_scanner = CodeRay.scanner :html, :tokens => @tokens, :keep_tokens => true, :keep_state => true | |
37 end | |
38 | |
39 def reset_instance | |
40 super | |
41 @html_scanner.reset | |
42 end | |
43 | |
44 def scan_tokens tokens, options | |
45 | |
46 until eos? | |
47 | |
48 if (match = scan_until(/(?=#{START_OF_ERB})/o) || scan_until(/\z/)) and not match.empty? | |
49 @html_scanner.tokenize match | |
50 | |
51 elsif match = scan(/#{ERB_RUBY_BLOCK}/o) | |
52 start_tag = match[/\A<%[-=#]?/] | |
53 end_tag = match[/-?%?>?\z/] | |
54 tokens << [:open, :inline] | |
55 tokens << [start_tag, :inline_delimiter] | |
56 code = match[start_tag.size .. -1 - end_tag.size] | |
57 if start_tag == '<%#' | |
58 tokens << [code, :comment] | |
59 else | |
60 @ruby_scanner.tokenize code | |
61 end | |
62 tokens << [end_tag, :inline_delimiter] unless end_tag.empty? | |
63 tokens << [:close, :inline] | |
64 | |
65 else | |
66 raise_inspect 'else-case reached!', tokens | |
67 end | |
68 | |
69 end | |
70 | |
71 tokens | |
72 | |
73 end | |
74 | |
75 end | |
76 | |
77 end | |
78 end |