Module: Erubis::SimplifyEnhancer
- Included in:
- PrintOutSimplifiedEruby, SimplifiedEruby, StdoutSimplifiedEruby
- Defined in:
- lib/erubis/enhancer.rb
Overview
get convert faster, but spaces around ‘<%…%>’ are not trimmed.
this is language-independent.
Constant Summary collapse
- SIMPLE_REGEXP =
DEFAULT_REGEXP = /(^[ t]*)?<%(=+|#)?(.*?)-?%>([ t]*r?n)?/m
/<%(=+|\#)?(.*?)-?%>/m
Class Method Summary collapse
-
.desc ⇒ Object
:nodoc:.
Instance Method Summary collapse
Class Method Details
.desc ⇒ Object
:nodoc:
335 336 337 |
# File 'lib/erubis/enhancer.rb', line 335 def self.desc # :nodoc: "get convert faster but leave spaces around '<% %>'" end |
Instance Method Details
#convert(input) ⇒ Object
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
# File 'lib/erubis/enhancer.rb', line 342 def convert(input) src = "" add_preamble(src) #regexp = pattern_regexp(@pattern) pos = 0 input.scan(SIMPLE_REGEXP) do |indicator, code| match = Regexp.last_match index = match.begin(0) text = input[pos, index - pos] pos = match.end(0) add_text(src, text) if !indicator # <% %> add_stmt(src, code) elsif indicator[0] == ?\# # <%# %> n = code.count("\n") add_stmt(src, "\n" * n) else # <%= %> add_expr(src, code, indicator) end end #rest = $' || input # ruby1.8 rest = pos == 0 ? input : input[pos..-1] # ruby1.9 add_text(src, rest) add_postamble(src) return src end |