Class: ERB::Compiler::TrimScanner

Inherits:
Scanner
  • Object
show all
Defined in:
lib/sinarey_support/erb/html_safe.rb

Instance Method Summary collapse

Instance Method Details

#explicit_trim_line(line) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/sinarey_support/erb/html_safe.rb', line 123

def explicit_trim_line(line)
  line.scan(/(.*?)(^[ \t]*<%\-|<%\-|<%%|%%>|<%==|<%=|<%#|<%|-%>\n|-%>|%>|\z)/m) do |tokens|
    tokens.each do |token|
      next if token.empty?
      if @stag.nil? && /[ \t]*<%-/ =~ token
        yield('<%')
      elsif @stag && token == "-%>\n"
        yield('%>')
        yield(:cr)
      elsif @stag && token == '-%>'
        yield('%>')
      else
        yield(token)
      end
    end
  end
end

#is_erb_stag?(s) ⇒ Boolean

Returns:

  • (Boolean)


141
142
143
# File 'lib/sinarey_support/erb/html_safe.rb', line 141

def is_erb_stag?(s)
  ERB_STAG.member?(s)
end

#scan_line(line) ⇒ Object



81
82
83
84
85
86
87
88
# File 'lib/sinarey_support/erb/html_safe.rb', line 81

def scan_line(line)
  line.scan(/(.*?)(<%%|%%>|<%==|<%=|<%#|<%|%>|\n|\z)/m) do |tokens|
    tokens.each do |token|
      next if token.empty?
      yield(token)
    end
  end
end

#trim_line1(line) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/sinarey_support/erb/html_safe.rb', line 89

def trim_line1(line)
  line.scan(/(.*?)(<%%|%%>|<%==|<%=|<%#|<%|%>\n|%>|\n|\z)/m) do |tokens|
    tokens.each do |token|
      next if token.empty?
      if token == "%>\n"
        yield('%>')
        yield(:cr)
      else
        yield(token)
      end
    end
  end
end

#trim_line2(line) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/sinarey_support/erb/html_safe.rb', line 102

def trim_line2(line)
  head = nil
  line.scan(/(.*?)(<%%|%%>|<%==|<%=|<%#|<%|%>\n|%>|\n|\z)/m) do |tokens|
    tokens.each do |token|
      next if token.empty?
      head = token unless head
      if token == "%>\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