Class: I18n::ErbParser
- Inherits:
-
Object
- Object
- I18n::ErbParser
- Defined in:
- lib/i18n/parser/erb_parser.rb
Defined Under Namespace
Classes: Scanner
Instance Method Summary collapse
Instance Method Details
#content_dump(string) ⇒ Object
50 51 52 |
# File 'lib/i18n/parser/erb_parser.rb', line 50 def content_dump(string) string.split("\n").map { |s| s.to_whitespace }.join("\n") end |
#to_ruby(source) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/i18n/parser/erb_parser.rb', line 30 def to_ruby(source) result = '' comment = false scanner = ERB::Compiler.new(nil).make_scanner(source) scanner.scan do |token| comment = true if token == '<%#' if scanner.stag.nil? result << token.to_whitespace scanner.stag = token if ['<%', '<%-', '<%=', '<%#', "\n"].include?(token) elsif ['%>', '-%>'].include?(token) result << token.to_whitespace scanner.stag = nil else result << (comment ? token.to_whitespace : token) # so, this is the ruby code, then comment = false end end result end |