Class: ERB::Compiler::TrimScanner
Do not use. This class is for internal use only.
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Scanner
|
|
Instance Chain:
self,
Scanner
|
|
Inherits: |
ERB::Compiler::Scanner
|
Defined in: | lib/erb.rb |
Constant Summary
-
ERB_STAG =
# File 'lib/erb.rb', line 492%w(<%= <%# <%)
Scanner
- Inherited
Class Attribute Summary
Scanner
- Inherited
Class Method Summary
- .new(src, trim_mode, percent) ⇒ TrimScanner constructor
Scanner
- Inherited
Instance Attribute Summary
Instance Method Summary
- #explicit_trim_line(line)
- #is_erb_stag?(s) ⇒ Boolean
- #percent_line(line, &block)
- #scan(&block)
- #scan_line(line)
- #trim_line1(line)
- #trim_line2(line)
Scanner
- Inherited
Constructor Details
.new(src, trim_mode, percent) ⇒ TrimScanner
# File 'lib/erb.rb', line 385
def initialize(src, trim_mode, percent) super @trim_mode = trim_mode @percent = percent if @trim_mode == '>' @scan_reg = /(.*?)(%>\r?\n|#{( + ).join('|')}|\n|\z)/m @scan_line = self.method(:trim_line1) elsif @trim_mode == '<>' @scan_reg = /(.*?)(%>\r?\n|#{( + ).join('|')}|\n|\z)/m @scan_line = self.method(:trim_line2) elsif @trim_mode == '-' @scan_reg = /(.*?)(^[ \t]*<%\-|<%\-|-%>\r?\n|-%>|#{( + ).join('|')}|\z)/m @scan_line = self.method(:explicit_trim_line) else @scan_reg = /(.*?)(#{( + ).join('|')}|\n|\z)/m @scan_line = self.method(:scan_line) end end
Instance Method Details
#explicit_trim_line(line)
[ GitHub ]# File 'lib/erb.rb', line 474
def explicit_trim_line(line) line.scan(@scan_reg) do |tokens| tokens.each do |token| next if token.empty? if @stag.nil? && /[ \t]*<%-/ =~ token yield('<%') elsif @stag && (token == "-%>\n" || token == "-%>\r\n") yield('%>') yield(:cr) elsif @stag && token == '-%>' yield('%>') else yield(token) end end end end
#is_erb_stag?(s) ⇒ Boolean
# File 'lib/erb.rb', line 493
def is_erb_stag?(s) ERB_STAG.member?(s) end
#percent_line(line, &block)
[ GitHub ]# File 'lib/erb.rb', line 416
def percent_line(line, &block) if @stag || line[0] != ?% return @scan_line.call(line, &block) end line[0] = '' if line[0] == ?% @scan_line.call(line, &block) else yield(PercentLine.new(line.chomp)) end end
#scan(&block)
[ GitHub ]# File 'lib/erb.rb', line 404
def scan(&block) @stag = nil if @percent @src.each_line do |line| percent_line(line, &block) end else @scan_line.call(@src, &block) end nil end
#scan_line(line)
[ GitHub ]# File 'lib/erb.rb', line 429
def scan_line(line) line.scan(@scan_reg) do |tokens| tokens.each do |token| next if token.empty? yield(token) end end end
#trim_line1(line)
[ GitHub ]# File 'lib/erb.rb', line 438
def trim_line1(line) line.scan(@scan_reg) do |tokens| tokens.each do |token| next if token.empty? if token == "%>\n" || token == "%>\r\n" yield('%>') yield(:cr) else yield(token) end end end end
#trim_line2(line)
[ GitHub ]# File 'lib/erb.rb', line 452
def trim_line2(line) head = nil line.scan(@scan_reg) do |tokens| tokens.each do |token| next if token.empty? head = token unless head if token == "%>\n" || token == "%>\r\n" yield('%>') if is_erb_stag?(head) yield(:cr) else yield("\n") end head = nil else yield(token) head = nil if token == "\n" end end end end