Skip to content

Commit

Permalink
Test with Serbea update that "polyfills" HTML safety
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredcwhite committed Nov 4, 2023
1 parent bd9259a commit 950ee52
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 20 deletions.
39 changes: 25 additions & 14 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,34 @@ PATH
lifeform (0.11.0)
hash_with_dot_access (>= 1.2)
sequel (>= 5.72)
serbea (>= 2.0)
serbea (>= 2.1)
zeitwerk (~> 2.5)

GEM
remote: https://rubygems.org/
specs:
activesupport (7.0.5)
activesupport (7.1.1)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
ansi (1.5.0)
ast (2.4.2)
backport (1.2.0)
base64 (0.1.1)
benchmark (0.2.1)
bigdecimal (3.1.4)
builder (3.2.4)
concurrent-ruby (1.2.2)
connection_pool (2.4.1)
diff-lcs (1.5.0)
drb (2.1.1)
ruby2_keywords
e2mmap (0.1.0)
erubi (1.12.0)
hash_with_dot_access (1.2.0)
Expand All @@ -36,26 +45,28 @@ GEM
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
language_server-protocol (3.17.0.3)
minitest (5.18.1)
minitest-reporters (1.6.0)
minitest (5.20.0)
minitest-reporters (1.6.1)
ansi
builder
minitest (>= 5.0)
ruby-progressbar
nokogiri (1.15.2-arm64-darwin)
mutex_m (0.1.2)
nokogiri (1.15.4-arm64-darwin)
racc (~> 1.4)
nokogiri (1.15.2-x86_64-linux)
nokogiri (1.15.4-x86_64-linux)
racc (~> 1.4)
parallel (1.23.0)
parser (3.2.2.4)
ast (~> 2.4.1)
racc
racc (1.7.3)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
rainbow (3.1.1)
rake (13.0.6)
rake (13.1.0)
regexp_parser (2.8.2)
reverse_markdown (2.1.1)
nokogiri
Expand Down Expand Up @@ -84,10 +95,10 @@ GEM
rubocop-rake (0.6.0)
rubocop (~> 1.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
sequel (5.74.0)
bigdecimal
serbea (2.0.0)
activesupport (>= 6.0)
serbea (2.1.0)
erubi (>= 1.10)
tilt (~> 2.0)
solargraph (0.45.0)
Expand All @@ -105,13 +116,13 @@ GEM
thor (~> 1.0)
tilt (~> 2.0)
yard (~> 0.9, >= 0.9.24)
thor (1.2.2)
tilt (2.2.0)
thor (1.3.0)
tilt (2.3.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
yard (0.9.34)
zeitwerk (2.6.8)
zeitwerk (2.6.12)

PLATFORMS
arm64-darwin-21
Expand Down
1 change: 1 addition & 0 deletions lib/lifeform.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require "serbea/helpers" # primarily just for HTML safety polyfill
require "serbea/pipeline"
require "zeitwerk"
loader = Zeitwerk::Loader.for_gem
Expand Down
5 changes: 3 additions & 2 deletions lib/lifeform/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ module Helpers

# Create a set of attributes from a hash.
#
# @param options [Hash] key-value pairs of HTML attributes
# @param options [Hash] key-value pairs of HTML attributes (or use keyword arguments)
# @param prefix_space [Boolean] add a starting space if attributes are present,
# useful in tag builders
# @return [String]
def html_attributes(options, prefix_space: false)
def html_attributes(options = nil, prefix_space: false, **kwargs)
options ||= kwargs
segments = []
options.each do |attr, option|
attr = dashed(attr)
Expand Down
2 changes: 1 addition & 1 deletion lib/lifeform/libraries/default/button.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def template(&block)

html -> {
<<~HTML # rubocop:disable Bridgetown/HTMLEscapedHeredoc
<#{wrapper_tag}#{html_attributes({ name: @attributes[:name] }, prefix_space: true)}>#{field_body}</#{wrapper_tag}>
<#{wrapper_tag} #{html_attributes name: @attributes[:name]}>#{field_body}</#{wrapper_tag}>
HTML
}
end
Expand Down
4 changes: 2 additions & 2 deletions lib/lifeform/libraries/default/input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def template(&block) # rubocop:disable Metrics/AbcSize
field_body = html -> {
<<~HTML # rubocop:disable Bridgetown/HTMLEscapedHeredoc
#{html(@label || -> {}).to_s.strip}
<#{input_tag}#{html_attributes({ type: @field_type.to_s, **@attributes }, prefix_space: true)}>#{
<#{input_tag} #{html_attributes type: @field_type.to_s, **@attributes}>#{
"</#{input_tag}>" if closing_tag
}
#{html -> { capture(self, &block) } if block}
Expand All @@ -74,7 +74,7 @@ def template(&block) # rubocop:disable Metrics/AbcSize

html -> {
<<~HTML # rubocop:disable Bridgetown/HTMLEscapedHeredoc
<#{wrapper_tag}#{html_attributes({ name: @attributes[:name] }, prefix_space: true)}>#{field_body.to_s.strip}</#{wrapper_tag}>
<#{wrapper_tag} #{html_attributes name: @attributes[:name]}>#{field_body.to_s.strip}</#{wrapper_tag}>
HTML
}
end
Expand Down
2 changes: 1 addition & 1 deletion lifeform.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ Gem::Specification.new do |spec|

spec.add_dependency "hash_with_dot_access", ">= 1.2"
spec.add_dependency "sequel", ">= 5.72"
spec.add_dependency "serbea", ">= 2.0"
spec.add_dependency "serbea", ">= 2.1"
spec.add_dependency "zeitwerk", "~> 2.5"
end

0 comments on commit 950ee52

Please sign in to comment.