ERB::Compiler::ExplicitScanner (Class)

In: libraries/erb.rb
Parent: Scanner

Methods

scan  

Public Instance methods

[Source]

     # File libraries/erb.rb, line 218
218:         def scan
219:           new_line = true
220:           stag_reg = /(.*?)(<%%|<%=|<%#|<%-|<%|\n|\z)/
221:           etag_reg = /(.*?)(%%>|-%>|%>|\n|\z)/
222:           scanner = StringScanner.new(@src)
223:           while ! scanner.eos?
224:             if new_line && @stag.nil? && scanner.scan(/[ \t]*<%-/)
225:               yield('<%')
226:               new_line = false
227:               next
228:             end
229:             scanner.scan(@stag ? etag_reg : stag_reg)
230:             text = scanner[1]
231:             elem = scanner[2]
232:             new_line = (elem == "\n")
233:             yield(text) unless text.empty?
234:             if elem == '-%>'
235:               yield('%>')
236:               if scanner.scan(/(\n|\z)/)
237:                 yield(:cr)
238:                 new_line = true
239:               end
240:             elsif elem == '<%-'
241:               yield('<%')
242:             else
243:               yield(elem) unless elem.empty?
244:             end
245:           end
246:         end

[Validate]