erbse 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +3 -0
  3. data/Gemfile +3 -0
  4. data/README.md +40 -22
  5. data/Rakefile +13 -0
  6. data/lib/erbse.rb +3 -6
  7. data/lib/erbse/converter.rb +41 -241
  8. data/lib/erbse/eruby.rb +114 -0
  9. data/lib/erbse/template.rb +14 -0
  10. data/lib/erbse/version.rb +1 -1
  11. data/test/erbse_test.rb +14 -0
  12. data/test/test_helper.rb +2 -0
  13. metadata +9 -149
  14. data/CHANGES.txt +0 -828
  15. data/bin/erubis +0 -10
  16. data/lib/erbse/context.rb +0 -83
  17. data/lib/erbse/engine.rb +0 -114
  18. data/lib/erbse/engine/ec.rb +0 -117
  19. data/lib/erbse/engine/ecpp.rb +0 -113
  20. data/lib/erbse/engine/ejava.rb +0 -110
  21. data/lib/erbse/engine/ejavascript.rb +0 -119
  22. data/lib/erbse/engine/enhanced.rb +0 -126
  23. data/lib/erbse/engine/eperl.rb +0 -95
  24. data/lib/erbse/engine/ephp.rb +0 -99
  25. data/lib/erbse/engine/eruby.rb +0 -119
  26. data/lib/erbse/engine/escheme.rb +0 -114
  27. data/lib/erbse/engine/optimized.rb +0 -127
  28. data/lib/erbse/enhancer.rb +0 -723
  29. data/lib/erbse/error.rb +0 -23
  30. data/lib/erbse/evaluator.rb +0 -88
  31. data/lib/erbse/generator.rb +0 -85
  32. data/lib/erbse/helper.rb +0 -47
  33. data/lib/erbse/helpers/rails_form_helper.rb +0 -197
  34. data/lib/erbse/helpers/rails_helper.rb +0 -353
  35. data/lib/erbse/main.rb +0 -516
  36. data/lib/erbse/preprocessing.rb +0 -58
  37. data/lib/erbse/tiny.rb +0 -144
  38. data/lib/erbse/util.rb +0 -22
  39. data/test/assert-text-equal.rb +0 -44
  40. data/test/data/users-guide/Example.ejava +0 -55
  41. data/test/data/users-guide/array_example.result +0 -9
  42. data/test/data/users-guide/arraybuffer_example.result +0 -9
  43. data/test/data/users-guide/bipattern-example.rhtml +0 -4
  44. data/test/data/users-guide/bipattern_example.result +0 -6
  45. data/test/data/users-guide/bufvar-example.rb +0 -10
  46. data/test/data/users-guide/bufvar-example.result +0 -17
  47. data/test/data/users-guide/context.rb +0 -6
  48. data/test/data/users-guide/context.yaml +0 -8
  49. data/test/data/users-guide/def_method.rb +0 -14
  50. data/test/data/users-guide/def_method.result +0 -3
  51. data/test/data/users-guide/escape_example.result +0 -9
  52. data/test/data/users-guide/example.ec +0 -27
  53. data/test/data/users-guide/example.ecpp +0 -30
  54. data/test/data/users-guide/example.ejs +0 -20
  55. data/test/data/users-guide/example.eperl +0 -18
  56. data/test/data/users-guide/example.ephp +0 -18
  57. data/test/data/users-guide/example.eruby +0 -6
  58. data/test/data/users-guide/example.escheme +0 -28
  59. data/test/data/users-guide/example1.eruby +0 -6
  60. data/test/data/users-guide/example1.rb +0 -17
  61. data/test/data/users-guide/example1.result +0 -16
  62. data/test/data/users-guide/example10.rb +0 -4
  63. data/test/data/users-guide/example10.result +0 -17
  64. data/test/data/users-guide/example10.xhtml +0 -14
  65. data/test/data/users-guide/example10_x.result +0 -17
  66. data/test/data/users-guide/example11.php +0 -20
  67. data/test/data/users-guide/example11.result +0 -23
  68. data/test/data/users-guide/example11.rhtml +0 -21
  69. data/test/data/users-guide/example11_C.result +0 -10
  70. data/test/data/users-guide/example11_N.result +0 -16
  71. data/test/data/users-guide/example11_U.result +0 -16
  72. data/test/data/users-guide/example11_php.result +0 -15
  73. data/test/data/users-guide/example1_x.result +0 -9
  74. data/test/data/users-guide/example2.eruby +0 -7
  75. data/test/data/users-guide/example2.rb +0 -10
  76. data/test/data/users-guide/example2.result +0 -27
  77. data/test/data/users-guide/example2_trim.result +0 -10
  78. data/test/data/users-guide/example2_x.result +0 -10
  79. data/test/data/users-guide/example3.eruby +0 -6
  80. data/test/data/users-guide/example3.rb +0 -10
  81. data/test/data/users-guide/example31.result +0 -22
  82. data/test/data/users-guide/example32.result +0 -4
  83. data/test/data/users-guide/example3_e.result +0 -8
  84. data/test/data/users-guide/example4.eruby +0 -3
  85. data/test/data/users-guide/example4.rb +0 -11
  86. data/test/data/users-guide/example4.result +0 -10
  87. data/test/data/users-guide/example4_x.result +0 -5
  88. data/test/data/users-guide/example5.eruby +0 -6
  89. data/test/data/users-guide/example5.rb +0 -16
  90. data/test/data/users-guide/example5.result +0 -7
  91. data/test/data/users-guide/example6.rb +0 -12
  92. data/test/data/users-guide/example6.result +0 -7
  93. data/test/data/users-guide/example7.eruby +0 -8
  94. data/test/data/users-guide/example71.result +0 -13
  95. data/test/data/users-guide/example72.result +0 -13
  96. data/test/data/users-guide/example8.eruby +0 -6
  97. data/test/data/users-guide/example8_ruby.result +0 -7
  98. data/test/data/users-guide/example8_yaml.result +0 -7
  99. data/test/data/users-guide/example9.eruby +0 -3
  100. data/test/data/users-guide/example9.rb +0 -8
  101. data/test/data/users-guide/example9.result +0 -9
  102. data/test/data/users-guide/example91.result +0 -5
  103. data/test/data/users-guide/example92.result +0 -4
  104. data/test/data/users-guide/example_c.result +0 -32
  105. data/test/data/users-guide/example_java.result +0 -56
  106. data/test/data/users-guide/example_js.result +0 -22
  107. data/test/data/users-guide/example_perl.result +0 -20
  108. data/test/data/users-guide/example_php.result +0 -19
  109. data/test/data/users-guide/example_scheme.result +0 -30
  110. data/test/data/users-guide/example_scheme_display.result +0 -29
  111. data/test/data/users-guide/fasteruby-example.rb +0 -8
  112. data/test/data/users-guide/fasteruby-example.result +0 -18
  113. data/test/data/users-guide/fasteruby.rb +0 -11
  114. data/test/data/users-guide/fasteruby.result +0 -38
  115. data/test/data/users-guide/fasteruby.rhtml +0 -15
  116. data/test/data/users-guide/headerfooter-example.eruby +0 -9
  117. data/test/data/users-guide/headerfooter-example2.rb +0 -8
  118. data/test/data/users-guide/headerfooter-example2.rhtml +0 -10
  119. data/test/data/users-guide/headerfooter_example.result +0 -11
  120. data/test/data/users-guide/headerfooter_example2.result +0 -13
  121. data/test/data/users-guide/interpolation_example.result +0 -9
  122. data/test/data/users-guide/main_program1.rb +0 -8
  123. data/test/data/users-guide/main_program1.result +0 -6
  124. data/test/data/users-guide/main_program2.rb +0 -8
  125. data/test/data/users-guide/main_program2.result +0 -6
  126. data/test/data/users-guide/nocode-example.eruby +0 -14
  127. data/test/data/users-guide/nocode-php.result +0 -20
  128. data/test/data/users-guide/nocode_example.result +0 -15
  129. data/test/data/users-guide/normal-eruby-test.eruby +0 -9
  130. data/test/data/users-guide/normal_eruby_test.result +0 -11
  131. data/test/data/users-guide/notext-example.eruby +0 -14
  132. data/test/data/users-guide/notext-example.php +0 -19
  133. data/test/data/users-guide/notext-php.result +0 -20
  134. data/test/data/users-guide/notext_example.result +0 -16
  135. data/test/data/users-guide/percentline-example.rhtml +0 -6
  136. data/test/data/users-guide/percentline_example.result +0 -9
  137. data/test/data/users-guide/prefixedline-example.rb +0 -9
  138. data/test/data/users-guide/prefixedline-example.rhtml +0 -6
  139. data/test/data/users-guide/prefixedline_example.result +0 -9
  140. data/test/data/users-guide/printenable_example.result +0 -4
  141. data/test/data/users-guide/printenabled-example.eruby +0 -3
  142. data/test/data/users-guide/printenabled-example.rb +0 -8
  143. data/test/data/users-guide/printstatement_example.result +0 -8
  144. data/test/data/users-guide/simplify_example.result +0 -9
  145. data/test/data/users-guide/stderr.log +0 -3
  146. data/test/data/users-guide/stdout_exmple.result +0 -9
  147. data/test/data/users-guide/stringbuffer_example.result +0 -9
  148. data/test/data/users-guide/tail_260.result +0 -4
  149. data/test/data/users-guide/tailnewline.rhtml +0 -3
  150. data/test/data/users-guide/template1.rhtml +0 -4
  151. data/test/data/users-guide/template2.rhtml +0 -4
  152. data/test/test-engines.rb +0 -425
  153. data/test/test-enhancers.rb +0 -646
  154. data/test/test-erubis.rb +0 -887
  155. data/test/test-index-cgi.rb +0 -191
  156. data/test/test-main.rb +0 -752
  157. data/test/test-users-guide.rb +0 -73
  158. data/test/test.rb +0 -45
  159. data/test/testutil.rb +0 -111
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8cc096d1012a8f395e01e9a7445d2bd23a3b8024
4
- data.tar.gz: f8a42d194e45b147f5ee05c4d2fbab25aca5d231
3
+ metadata.gz: 37f385edabdf30c0807542d7c5560537b5db5f82
4
+ data.tar.gz: 0bd510e68988198ff9e4ef3f3e796900fde9a41a
5
5
  SHA512:
6
- metadata.gz: ccddec411ad1e76c807ae5b7abb38e5ecfd3e9feb6204748b4335706d85489bc9a24b050ecd59883454b57808ba4797c436133034dd12f51fb771025a247e3d5
7
- data.tar.gz: 5937981a7f6f5847db0841aa32d2fe412da30cbb83e4b81753677e91349121f801150243080b5dce3d04e374578621e55f119bc79fd798d2dbddede370cb2479
6
+ metadata.gz: 69a822ab5ad04ec4495f484353b9cdce8780a9b78cb25018b57193ec670224a18e10470e0c88b84c01639cfb817456d322a77057e912e04852627209f2ae7bfb
7
+ data.tar.gz: 80e5540f89a2ac0922730960d1c291e7bdd117a3db70b4b9c74f03245dc1945a279d7f59a008b806d5153d53da17b0dcfe7915b6c6814a9c692dddcdf7487c59
@@ -0,0 +1,3 @@
1
+ # 0.0.2
2
+
3
+ * First release. No escaping is happening and I'm not sure how capture works, yet. But: it's great!
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/README.md CHANGED
@@ -2,50 +2,68 @@
2
2
 
3
3
  _An updated version of Erubis._
4
4
 
5
-
5
+ Erbse compiles an ERB string to a string of Ruby. It is completely decoupled from any framework and does only one thing. Pretty boring, I know.
6
6
 
7
7
  ## Added features
8
8
 
9
- * block support a la Rails.
9
+ * Block support a la Rails.
10
+
11
+ ```erb
12
+ <%= form_tag .. do |f| %>
13
+ <%= f.fields_for do %>
14
+ ...
15
+ <% end %>
16
+ <% end %>
17
+ ```
18
+
19
+ ## API
20
+
21
+ The API is extremely simple.
10
22
 
23
+ ```ruby
24
+ Erbse::Template.new("<% ... %>").call #=> string of compiled ruby.
25
+ ```
11
26
 
12
- == About Erubis
27
+ Template only accepts a content string which is the ERB template. The only public `#call` method returns a string of the compiled template that can then be evaluated in a context.
13
28
 
14
- Erubis is an implementation of eRuby. It has the following features.
15
- * Very fast, almost three times faster than ERB and even 10% faster than eruby
16
- * Multi-language support (Ruby/PHP/C/Java/Scheme/Perl/Javascript)
17
- * Auto escaping support
18
- * Auto trimming spaces around '<% %>'
19
- * Embedded pattern changeable (default '<% %>')
20
- * Enable to handle Processing Instructions (PI) as embedded pattern (ex. '<?rb ... ?>')
21
- * Context object available and easy to combine eRuby template with YAML datafile
22
- * Print statement available
23
- * Easy to extend and customize in subclass
24
- * Ruby on Rails support
29
+ The user layer, like Tilt, has to take care of caching the `Erbse::Template` instances.
25
30
 
26
- Erubis is implemented in pure Ruby. It requires Ruby 1.8 or higher.
27
- Erubis now supports Ruby 1.9.
28
31
 
29
- See doc/users-guide.html for details.
32
+ ## Planned
30
33
 
34
+ Block inheritance.
31
35
 
36
+ ```erb
37
+ <h1><%= title %></h1>
32
38
 
39
+ <% fragment :subheader do %>
40
+ Or: <%= subheader %>
41
+ <% end %>
42
+ ```
33
43
 
44
+ This fragment could then be overridden.
34
45
 
35
- == Benchmark
46
+ Feel free to contribute!!!
36
47
 
37
- 'benchmark/erubybenchmark.rb' is a benchmark script of Erubis.
38
- Try 'ruby erubybenchmark.rb' in benchmark directory.
39
48
 
49
+ ## Used where?
50
+
51
+ Erbse is the ERB engine in [Cells 4](https://github.com/apotonick/cells).
52
+
53
+ It also hopefully gets used in Rails 5/6, so we can remove those horrible hacks from AV.
40
54
 
41
55
 
42
56
  # License
43
57
 
44
58
  MIT License
45
59
 
60
+ # Contributors
61
+
62
+ * @iazel
63
+ * @seuros
46
64
 
47
65
 
48
66
  # Authors
49
67
 
50
- Copyright 2015 Nick Sutterer <apotonick@gmail.com>
51
- Copyright 2006-2011 makoto kuwata <kwa(at)kuwata-lab.com>
68
+ * Copyright 2015 Nick Sutterer <apotonick@gmail.com>
69
+ * Copyright 2006-2011 makoto kuwata <kwa(at)kuwata-lab.com>
@@ -0,0 +1,13 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/testtask'
5
+
6
+ desc 'Default: run unit tests.'
7
+ task :default => :test
8
+
9
+ Rake::TestTask.new(:test) do |test|
10
+ test.libs << 'test'
11
+ test.pattern = 'test/*_test.rb'
12
+ test.verbose = true
13
+ end
@@ -44,9 +44,6 @@
44
44
  module Erbse
45
45
  end
46
46
 
47
- require 'erbse/engine'
48
- # require 'erbse/helper'
49
- # require 'erbse/enhancer'
50
- require 'erbse/engine/eruby'
51
-
52
- # require 'erbse/local-setting'
47
+ require "erbse/converter"
48
+ require "erbse/template"
49
+ require "erbse/eruby"
@@ -1,46 +1,31 @@
1
- ##
2
- ## $Release: 2.7.0 $
3
- ## copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
4
- ##
5
-
6
- require 'erubis/util'
7
-
8
- module Erubis
9
-
1
+ module Erbse
2
+ # convert input string into target language
3
+ class Converter
4
+ def initialize(properties={}, generator)
5
+ init_converter!(properties)
6
+ @generator = generator
7
+ end
10
8
 
11
- ##
12
- ## convert
13
- ##
14
- module Converter
9
+ def convert(input) # TODO: rename to #call.
10
+ codebuf = "" # or []
11
+ @preamble.nil? ? generator.add_preamble(codebuf) : (@preamble && (codebuf << @preamble))
12
+ convert_input(codebuf, input)
13
+ @postamble.nil? ? generator.add_postamble(codebuf) : (@postamble && (codebuf << @postamble))
14
+ @_proc = nil # clear cached proc object
15
+ return codebuf # or codebuf.join()
16
+ end
15
17
 
18
+ private
16
19
  attr_accessor :preamble, :postamble, :escape
17
20
 
18
- def self.supported_properties # :nodoc:
19
- return [
20
- [:preamble, nil, "preamble (no preamble when false)"],
21
- [:postamble, nil, "postamble (no postamble when false)"],
22
- [:escape, nil, "escape expression or not in default"],
23
- ]
24
- end
21
+ attr_reader :generator
25
22
 
26
- def init_converter(properties={})
23
+ def init_converter!(properties)
27
24
  @preamble = properties[:preamble]
28
25
  @postamble = properties[:postamble]
29
26
  @escape = properties[:escape]
30
27
  end
31
28
 
32
- ## convert input string into target language
33
- def convert(input)
34
- codebuf = "" # or []
35
- @preamble.nil? ? add_preamble(codebuf) : (@preamble && (codebuf << @preamble))
36
- convert_input(codebuf, input)
37
- @postamble.nil? ? add_postamble(codebuf) : (@postamble && (codebuf << @postamble))
38
- @_proc = nil # clear cached proc object
39
- return codebuf # or codebuf.join()
40
- end
41
-
42
- protected
43
-
44
29
  ##
45
30
  ## detect spaces at beginning of line
46
31
  ##
@@ -70,14 +55,6 @@ module Erubis
70
55
  end
71
56
  return lspace
72
57
  end
73
-
74
- ##
75
- ## (abstract) convert input to code
76
- ##
77
- def convert_input(codebuf, input)
78
- not_implemented
79
- end
80
-
81
58
  end
82
59
 
83
60
 
@@ -88,9 +65,7 @@ module Erubis
88
65
  ##
89
66
  ## basic converter which supports '<% ... %>' notation.
90
67
  ##
91
- module Basic::Converter
92
- include Erubis::Converter
93
-
68
+ class Basic::Converter < Converter
94
69
  def self.supported_properties # :nodoc:
95
70
  return [
96
71
  [:pattern, '<% %>', "embed pattern"],
@@ -98,32 +73,27 @@ module Erubis
98
73
  ]
99
74
  end
100
75
 
76
+
77
+ private
78
+
101
79
  attr_accessor :pattern, :trim
102
80
 
103
- def init_converter(properties={})
81
+ def init_converter!(properties={})
104
82
  super(properties)
105
83
  @pattern = properties[:pattern]
106
84
  @trim = properties[:trim] != false
107
85
  end
108
86
 
109
- protected
87
+
110
88
 
111
89
  ## return regexp of pattern to parse eRuby script
112
- def pattern_regexp(pattern)
90
+ def self.pattern_regexp(pattern)
113
91
  @prefix, @postfix = pattern.split() # '<% %>' => '<%', '%>'
114
- #return /(.*?)(^[ \t]*)?#{@prefix}(=+|\#)?(.*?)-?#{@postfix}([ \t]*\r?\n)?/m
115
- #return /(^[ \t]*)?#{@prefix}(=+|\#)?(.*?)-?#{@postfix}([ \t]*\r?\n)?/m
116
92
  return /#{@prefix}(=+|-|\#|%)?(.*?)([-=])?#{@postfix}([ \t]*\r?\n)?/m
117
93
  end
118
- module_function :pattern_regexp
119
94
 
120
- #DEFAULT_REGEXP = /(.*?)(^[ \t]*)?<%(=+|\#)?(.*?)-?%>([ \t]*\r?\n)?/m
121
- #DEFAULT_REGEXP = /(^[ \t]*)?<%(=+|\#)?(.*?)-?%>([ \t]*\r?\n)?/m
122
- #DEFAULT_REGEXP = /<%(=+|\#)?(.*?)-?%>([ \t]*\r?\n)?/m
123
95
  DEFAULT_REGEXP = pattern_regexp('<% %>')
124
96
 
125
- public
126
-
127
97
  def convert_input(src, input)
128
98
  pat = @pattern
129
99
  regexp = pat.nil? || pat == '<% %>' ? DEFAULT_REGEXP : pattern_regexp(pat)
@@ -137,221 +107,51 @@ module Erubis
137
107
  ch = indicator ? indicator[0] : nil
138
108
  lspace = ch == ?= ? nil : detect_spaces_at_bol(text, is_bol)
139
109
  is_bol = rspace ? true : false
140
- add_text(src, text) if text && !text.empty?
110
+ generator.add_text(src, text) if text && !text.empty?
141
111
  ## * when '<%= %>', do nothing
142
112
  ## * when '<% %>' or '<%# %>', delete spaces iff only spaces are around '<% %>'
143
113
  if ch == ?= # <%= %>
144
114
  rspace = nil if tailch && !tailch.empty?
145
- add_text(src, lspace) if lspace
115
+ generator.add_text(src, lspace) if lspace
146
116
  add_expr(src, code, indicator)
147
- add_text(src, rspace) if rspace
117
+ generator.add_text(src, rspace) if rspace
148
118
  elsif ch == ?\# # <%# %>
149
119
  n = code.count("\n") + (rspace ? 1 : 0)
150
120
  if @trim && lspace && rspace
151
- add_stmt(src, "\n" * n)
121
+ generator.add_stmt(src, "\n" * n)
152
122
  else
153
- add_text(src, lspace) if lspace
154
- add_stmt(src, "\n" * n)
155
- add_text(src, rspace) if rspace
123
+ generator.add_text(src, lspace) if lspace
124
+ generator.add_stmt(src, "\n" * n)
125
+ generator.add_text(src, rspace) if rspace
156
126
  end
157
127
  elsif ch == ?% # <%% %>
158
128
  s = "#{lspace}#{@prefix||='<%'}#{code}#{tailch}#{@postfix||='%>'}#{rspace}"
159
- add_text(src, s)
129
+ generator.add_text(src, s)
160
130
  else # <% %>
161
131
  if @trim && lspace && rspace
162
- add_stmt(src, "#{lspace}#{code}#{rspace}")
132
+ generator.add_stmt(src, "#{lspace}#{code}#{rspace}")
163
133
  else
164
- add_text(src, lspace) if lspace
165
- add_stmt(src, code)
166
- add_text(src, rspace) if rspace
134
+ generator.add_text(src, lspace) if lspace
135
+ generator.add_stmt(src, code)
136
+ generator.add_text(src, rspace) if rspace
167
137
  end
168
138
  end
169
139
  end
170
140
  #rest = $' || input # ruby1.8
171
141
  rest = pos == 0 ? input : input[pos..-1] # ruby1.9
172
- add_text(src, rest)
142
+ generator.add_text(src, rest)
173
143
  end
174
144
 
175
145
  ## add expression code to src
176
146
  def add_expr(src, code, indicator)
177
147
  case indicator
178
148
  when '='
179
- @escape ? add_expr_escaped(src, code) : add_expr_literal(src, code)
149
+ @escape ? generator.add_expr_escaped(src, code) : generator.add_expr_literal(src, code)
180
150
  when '=='
181
- @escape ? add_expr_literal(src, code) : add_expr_escaped(src, code)
151
+ @escape ? generator.add_expr_literal(src, code) : generator.add_expr_escaped(src, code)
182
152
  when '==='
183
- add_expr_debug(src, code)
184
- end
185
- end
186
-
187
- end
188
-
189
-
190
- module PI
191
- end
192
-
193
- ##
194
- ## Processing Instructions (PI) converter for XML.
195
- ## this class converts '<?rb ... ?>' and '${...}' notation.
196
- ##
197
- module PI::Converter
198
- include Erubis::Converter
199
-
200
- def self.desc # :nodoc:
201
- "use processing instructions (PI) instead of '<% %>'"
202
- end
203
-
204
- def self.supported_properties # :nodoc:
205
- return [
206
- [:trim, true, "trim spaces around <% ... %>"],
207
- [:pi, 'rb', "PI (Processing Instrunctions) name"],
208
- [:embchar, '@', "char for embedded expression pattern('@{...}@')"],
209
- [:pattern, '<% %>', "embed pattern"],
210
- ]
211
- end
212
-
213
- attr_accessor :pi, :prefix
214
-
215
- def init_converter(properties={})
216
- super(properties)
217
- @trim = properties.fetch(:trim, true)
218
- @pi = properties[:pi] if properties[:pi]
219
- @embchar = properties[:embchar] || '@'
220
- @pattern = properties[:pattern]
221
- @pattern = '<% %>' if @pattern.nil? #|| @pattern == true
222
- end
223
-
224
- def convert(input)
225
- code = super(input)
226
- return @header || @footer ? "#{@header}#{code}#{@footer}" : code
227
- end
228
-
229
- protected
230
-
231
- def convert_input(codebuf, input)
232
- unless @regexp
233
- @pi ||= 'e'
234
- ch = Regexp.escape(@embchar)
235
- if @pattern
236
- left, right = @pattern.split(' ')
237
- @regexp = /<\?#{@pi}(?:-(\w+))?(\s.*?)\?>([ \t]*\r?\n)?|#{ch}(!*)?\{(.*?)\}#{ch}|#{left}(=+)(.*?)#{right}/m
238
- else
239
- @regexp = /<\?#{@pi}(?:-(\w+))?(\s.*?)\?>([ \t]*\r?\n)?|#{ch}(!*)?\{(.*?)\}#{ch}/m
240
- end
241
- end
242
- #
243
- is_bol = true
244
- pos = 0
245
- input.scan(@regexp) do |pi_arg, stmt, rspace,
246
- indicator1, expr1, indicator2, expr2|
247
- match = Regexp.last_match
248
- len = match.begin(0) - pos
249
- text = input[pos, len]
250
- pos = match.end(0)
251
- lspace = stmt ? detect_spaces_at_bol(text, is_bol) : nil
252
- is_bol = stmt && rspace ? true : false
253
- add_text(codebuf, text) # unless text.empty?
254
- #
255
- if stmt
256
- if @trim && lspace && rspace
257
- add_pi_stmt(codebuf, "#{lspace}#{stmt}#{rspace}", pi_arg)
258
- else
259
- add_text(codebuf, lspace) if lspace
260
- add_pi_stmt(codebuf, stmt, pi_arg)
261
- add_text(codebuf, rspace) if rspace
262
- end
263
- else
264
- add_pi_expr(codebuf, expr1 || expr2, indicator1 || indicator2)
265
- end
153
+ generator.add_expr_debug(src, code)
266
154
  end
267
- #rest = $' || input # ruby1.8
268
- rest = pos == 0 ? input : input[pos..-1] # ruby1.9
269
- add_text(codebuf, rest)
270
155
  end
271
-
272
- #--
273
- #def convert_input(codebuf, input)
274
- # parse_stmts(codebuf, input)
275
- # #parse_stmts2(codebuf, input)
276
- #end
277
- #
278
- #def parse_stmts(codebuf, input)
279
- # #regexp = pattern_regexp(@pattern)
280
- # @pi ||= 'e'
281
- # @stmt_pattern ||= /<\?#{@pi}(?:-(\w+))?(\s.*?)\?>([ \t]*\r?\n)?/m
282
- # is_bol = true
283
- # pos = 0
284
- # input.scan(@stmt_pattern) do |pi_arg, code, rspace|
285
- # match = Regexp.last_match
286
- # len = match.begin(0) - pos
287
- # text = input[pos, len]
288
- # pos = match.end(0)
289
- # lspace = detect_spaces_at_bol(text, is_bol)
290
- # is_bol = rspace ? true : false
291
- # parse_exprs(codebuf, text) # unless text.empty?
292
- # if @trim && lspace && rspace
293
- # add_pi_stmt(codebuf, "#{lspace}#{code}#{rspace}", pi_arg)
294
- # else
295
- # add_text(codebuf, lspace)
296
- # add_pi_stmt(codebuf, code, pi_arg)
297
- # add_text(codebuf, rspace)
298
- # end
299
- # end
300
- # rest = $' || input
301
- # parse_exprs(codebuf, rest)
302
- #end
303
- #
304
- #def parse_exprs(codebuf, input)
305
- # unless @expr_pattern
306
- # ch = Regexp.escape(@embchar)
307
- # if @pattern
308
- # left, right = @pattern.split(' ')
309
- # @expr_pattern = /#{ch}(!*)?\{(.*?)\}#{ch}|#{left}(=+)(.*?)#{right}/
310
- # else
311
- # @expr_pattern = /#{ch}(!*)?\{(.*?)\}#{ch}/
312
- # end
313
- # end
314
- # pos = 0
315
- # input.scan(@expr_pattern) do |indicator1, code1, indicator2, code2|
316
- # indicator = indicator1 || indicator2
317
- # code = code1 || code2
318
- # match = Regexp.last_match
319
- # len = match.begin(0) - pos
320
- # text = input[pos, len]
321
- # pos = match.end(0)
322
- # add_text(codebuf, text) # unless text.empty?
323
- # add_pi_expr(codebuf, code, indicator)
324
- # end
325
- # rest = $' || input
326
- # add_text(codebuf, rest)
327
- #end
328
- #++
329
-
330
- def add_pi_stmt(codebuf, code, pi_arg) # :nodoc:
331
- case pi_arg
332
- when nil ; add_stmt(codebuf, code)
333
- when 'header' ; @header = code
334
- when 'footer' ; @footer = code
335
- when 'comment'; add_stmt(codebuf, "\n" * code.count("\n"))
336
- when 'value' ; add_expr_literal(codebuf, code)
337
- else ; add_stmt(codebuf, code)
338
- end
339
- end
340
-
341
- def add_pi_expr(codebuf, code, indicator) # :nodoc:
342
- case indicator
343
- when nil, '', '==' # @{...}@ or <%== ... %>
344
- @escape == false ? add_expr_literal(codebuf, code) : add_expr_escaped(codebuf, code)
345
- when '!', '=' # @!{...}@ or <%= ... %>
346
- @escape == false ? add_expr_escaped(codebuf, code) : add_expr_literal(codebuf, code)
347
- when '!!', '===' # @!!{...}@ or <%=== ... %>
348
- add_expr_debug(codebuf, code)
349
- else
350
- # ignore
351
- end
352
- end
353
-
354
156
  end
355
-
356
-
357
157
  end