Skip to content

Commit

Permalink
Slim::Splat::Builder simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
minad committed Sep 18, 2023
1 parent 4ccd62e commit 338dd67
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/slim/splat/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ class InvalidAttributeNameError < StandardError; end
module Splat
# @api private
class Builder
# https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
INVALID_ATTRIBUTE_NAME_REGEX = /[ \0"'>\/=]/
# https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
INVALID_ATTRIBUTE_NAME_REGEX = /[ \0"'>\/=]/

def initialize(options)
@options = options
@attrs = {}
Expand All @@ -18,7 +19,7 @@ def code_attr(name, escape, value)
elsif @options[:hyphen_attrs].include?(name) && Hash === value
hyphen_attr(name, escape, value)
elsif value != false && value != nil
attr(name, escape_html(value != true && escape, value))
attr(name, escape_html(escape, value))
end
end

Expand Down Expand Up @@ -101,12 +102,12 @@ def hyphen_attr(name, escape, value)
end
end
else
attr(name, escape_html(value != true && escape, value))
attr(name, escape_html(escape, value))
end
end

def escape_html(escape, value)
return value unless escape
return value if !escape || value == true
@options[:use_html_safe] ? Temple::Utils.escape_html_safe(value) : Temple::Utils.escape_html(value)
end
end
Expand Down

0 comments on commit 338dd67

Please sign in to comment.