lib/css_parser/parser.rb in css_parser-1.20.0 vs lib/css_parser/parser.rb in css_parser-1.21.0
- old
+ new
@@ -357,13 +357,13 @@
in_charset = false # @charset is ignored for now
in_string = false
in_at_media_rule = false
in_media_block = false
- current_selectors = String.new
- current_media_query = String.new
- current_declarations = String.new
+ current_selectors = +''
+ current_media_query = +''
+ current_declarations = +''
# once we are in a rule, we will use this to store where we started if we are capturing offsets
rule_start = nil
start_offset = nil
end_offset = nil
@@ -403,39 +403,40 @@
add_rule_options = {
selectors: current_selectors, block: current_declarations,
media_types: current_media_queries
}
if options[:capture_offsets]
- add_rule_options.merge!(filename: options[:filename], offset: rule_start..end_offset)
+ add_rule_options[:filename] = options[:filename]
+ add_rule_options[:offset] = rule_start..end_offset
end
add_rule!(**add_rule_options)
end
- current_selectors = String.new
- current_declarations = String.new
+ current_selectors = +''
+ current_declarations = +''
# restart our search for selectors and declarations
rule_start = nil if options[:capture_offsets]
end
- elsif token =~ /@media/i
+ elsif /@media/i.match?(token)
# found '@media', reset current media_types
in_at_media_rule = true
current_media_queries = []
elsif in_at_media_rule
if token.include?('{')
block_depth += 1
in_at_media_rule = false
in_media_block = true
current_media_queries << CssParser.sanitize_media_query(current_media_query)
- current_media_query = String.new
+ current_media_query = +''
elsif token.include?(',')
# new media query begins
token.tr!(',', ' ')
token.strip!
current_media_query << token << ' '
current_media_queries << CssParser.sanitize_media_query(current_media_query)
- current_media_query = String.new
+ current_media_query = +''
else
token.strip!
# special-case the ( and ) tokens to remove inner-whitespace
# (eg we'd prefer '(width: 500px)' to '( width: 500px )' )
case token
@@ -476,11 +477,12 @@
add_rule_options = {
selectors: current_selectors, block: current_declarations,
media_types: current_media_queries
}
if options[:capture_offsets]
- add_rule_options.merge!(filename: options[:filename], offset: rule_start..end_offset)
+ add_rule_options[:filename] = options[:filename]
+ add_rule_options[:offset] = rule_start..end_offset
end
add_rule!(**add_rule_options)
end
# Load a remote CSS file.
@@ -716,10 +718,10 @@
lines = val.split(';')
nodes = {}
lines.each do |line|
parts = line.split(':', 2)
- if parts[1] =~ /:/
+ if parts[1].include?(':')
nodes[parts[0]] = css_node_to_h(hash, parts[0], parts[1])
else
nodes[parts[0].to_s.strip] = parts[1].to_s.strip
end
end