class OdtHandlebars::OdtCleaner
Public Class Methods
clean(content)
click to toggle source
# File lib/odt_handlebars/odt_cleaner.rb, line 7 def self.clean(content) new(content).clean end
new(content)
click to toggle source
# File lib/odt_handlebars/odt_cleaner.rb, line 11 def initialize(content) @content=content end
Public Instance Methods
clean()
click to toggle source
# File lib/odt_handlebars/odt_cleaner.rb, line 15 def clean out="" scanstart(StringScanner.new(@content),out) end
Private Instance Methods
scanend(scanner,out)
click to toggle source
# File lib/odt_handlebars/odt_cleaner.rb, line 46 def scanend(scanner,out) curlend=0 until curlend == 2 if res=scanner.scan(/<[^>]+>/) # puts "ignored: #{res}" #out << res elsif res=scanner.scan(/[^}<]+/) # puts "match: #{res}" out << res.gsub(/\n/,'') elsif res=scanner.scan(/}/) # puts "match: #{res}" out << "}" curlend += 1 else warn("failed to scan handlebars end") # puts "else case" end end # puts "found end" end
scanstart(scanner,out)
click to toggle source
# File lib/odt_handlebars/odt_cleaner.rb, line 22 def scanstart(scanner,out) curlstart=0 until scanner.eos? if res=scanner.scan(/<[^>]+>/) # puts "match: #{res}" out << res elsif res=scanner.scan(/[^{<]+/) # puts "match: #{res}" curlstart = 0 out << res elsif res=scanner.scan(/{/) # puts "match: #{res}" curlstart += 1 out << "{" # found one if curlstart == 2 # puts "looking for end" scanend(scanner,out) curlstart=0 end end end out end