lib/volt/server/html_parser/sandlebars_parser.rb in volt-0.8.15 vs lib/volt/server/html_parser/sandlebars_parser.rb in volt-0.8.16

- old
+ new

@@ -14,28 +14,28 @@ class SandlebarsParser def self.truth_hash(array) hash = {} array.each { |v| hash[v] = true } - return hash + hash end # regex matchers START_TAG = /^<([-!\:A-Za-z0-9_]+)((?:\s+[\w\-]+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/ END_TAG = /^<\/([-!\:A-Za-z0-9_]+)[^>]*>/ ATTRIBUTES = /([-\:A-Za-z0-9_]+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|([^>\s]+)))?/ # Types of elements - BLOCK = truth_hash(%w{a address applet blockquote button center dd del dir div dl dt fieldset form frameset hr iframe ins isindex li map menu noframes noscript object ol p pre script table tbody td tfoot th thead tr ul}) - EMPTY = truth_hash(%w{area base basefont br col frame hr img input isindex link meta param embed}) - INLINE = truth_hash(%w{abbr acronym applet b basefont bdo big br button cite code del dfn em font i iframe img input ins kbd label map object q s samp script select small span strike strong sub sup textarea tt u var}) - CLOSE_SELF = truth_hash(%w{colgroup dd dt li options p td tfoot th thead tr}) - SPECIAL = truth_hash(%w{script style}) + BLOCK = truth_hash(%w(a address applet blockquote button center dd del dir div dl dt fieldset form frameset hr iframe ins isindex li map menu noframes noscript object ol p pre script table tbody td tfoot th thead tr ul)) + EMPTY = truth_hash(%w(area base basefont br col frame hr img input isindex link meta param embed)) + INLINE = truth_hash(%w(abbr acronym applet b basefont bdo big br button cite code del dfn em font i iframe img input ins kbd label map object q s samp script select small span strike strong sub sup textarea tt u var)) + CLOSE_SELF = truth_hash(%w(colgroup dd dt li options p td tfoot th thead tr)) + SPECIAL = truth_hash(%w(script style)) - FILL_IN_ATTRIBUTES = truth_hash(%w{checked compact declare defer disabled ismap multiple nohref noresize noshade nowrap readonly selected}) + FILL_IN_ATTRIBUTES = truth_hash(%w(checked compact declare defer disabled ismap multiple nohref noresize noshade nowrap readonly selected)) - def initialize(html, handler, file_path=nil) + def initialize(html, handler, file_path = nil) @html = StringScanner.new(html) @handler = handler @file_path = file_path @stack = [] @@ -120,11 +120,11 @@ elsif match == "\n" || @html.eos? # Starting new tag, should be closed before this # or end of doc before closed binding raise_parse_error("unclosed binding: {#{binding.strip}") else - raise "should not reach here" + fail 'should not reach here' end end binding = binding[0..-3] @handler.binding(binding) if @handler.respond_to?(:binding) @@ -134,11 +134,11 @@ line_number = @html.pre_match.count("\n") + 1 error_str = error + " on line: #{line_number}" error_str += " of #{@file_path}" if @file_path - raise HTMLParseError, error_str + fail HTMLParseError, error_str end def start_tag(tag, tag_name, rest, unary) section_tag = tag_name[0] == ':' && tag_name[1] =~ /[A-Z]/ @@ -195,32 +195,32 @@ # If no tag name is provided, close all the way up new_size = 0 if tag # Find the closest tag that closes. - (@stack.size-1).downto(0) do |index| + (@stack.size - 1).downto(0) do |index| if @stack[index] == tag_name new_size = index break end end end if new_size >= 0 if @handler.respond_to?(:end_tag) - (@stack.size-1).downto(new_size) do |index| + (@stack.size - 1).downto(new_size) do |index| @handler.end_tag(@stack[index]) end end @stack = @stack[0...new_size] end end def special_tag(close_tag, body) - body = body[0..((-1 * close_tag.size)-1)] + body = body[0..((-1 * close_tag.size) - 1)] - body = body.gsub(/\<\!--(.*?)--\>/, "\\1").gsub(/\<\!\[CDATA\[(.*?)\]\]\>/, "\\1") + body = body.gsub(/\<\!--(.*?)--\>/, '\\1').gsub(/\<\!\[CDATA\[(.*?)\]\]\>/, '\\1') text(body) end_tag(last, last) end