From 950ee52d48299178aab6beeee774ebbaeb2775f6 Mon Sep 17 00:00:00 2001 From: Jared White Date: Sat, 4 Nov 2023 07:54:16 -0700 Subject: [PATCH] Test with Serbea update that "polyfills" HTML safety --- Gemfile.lock | 39 +++++++++++++++--------- lib/lifeform.rb | 1 + lib/lifeform/helpers.rb | 5 +-- lib/lifeform/libraries/default/button.rb | 2 +- lib/lifeform/libraries/default/input.rb | 4 +-- lifeform.gemspec | 2 +- 6 files changed, 33 insertions(+), 20 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 0173dff..63c22ba 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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 @@ -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) @@ -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 diff --git a/lib/lifeform.rb b/lib/lifeform.rb index 94eb586..53e35a6 100644 --- a/lib/lifeform.rb +++ b/lib/lifeform.rb @@ -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 diff --git a/lib/lifeform/helpers.rb b/lib/lifeform/helpers.rb index 6f97b48..b042b63 100644 --- a/lib/lifeform/helpers.rb +++ b/lib/lifeform/helpers.rb @@ -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) diff --git a/lib/lifeform/libraries/default/button.rb b/lib/lifeform/libraries/default/button.rb index 9749337..a0825f0 100644 --- a/lib/lifeform/libraries/default/button.rb +++ b/lib/lifeform/libraries/default/button.rb @@ -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} #{html_attributes name: @attributes[:name]}>#{field_body} HTML } end diff --git a/lib/lifeform/libraries/default/input.rb b/lib/lifeform/libraries/default/input.rb index 95e9be2..49a8e99 100644 --- a/lib/lifeform/libraries/default/input.rb +++ b/lib/lifeform/libraries/default/input.rb @@ -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}>#{ "" if closing_tag } #{html -> { capture(self, &block) } if block} @@ -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} #{html_attributes name: @attributes[:name]}>#{field_body.to_s.strip} HTML } end diff --git a/lifeform.gemspec b/lifeform.gemspec index c34c393..3734124 100644 --- a/lifeform.gemspec +++ b/lifeform.gemspec @@ -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