diff --git a/CHANGELOG.md b/CHANGELOG.md index 25de227..6bb0681 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 2.1.0 + +- Remove Active Support as a dependency + - This now provides rudimentary support of `html_safe` mechanics. Note that + it does NOT handle _any_ additional String methods. It simply allows cloning a string via `html_safe` to mark it safe, and `html_safe?` to query if it's safe. + - This _might_ be a breaking change, but likely not if you're using Serbea along with Rails or Bridgetown. To restore previous functionality manually, just install the `activesupport` gem and `require "active_support/core_ext/string/output_safety"` before you require the Serbea gem. + ## 2.0.0 - Add plain ol' Ruby pipeline functionality diff --git a/lib/serbea/helpers.rb b/lib/serbea/helpers.rb index f4138db..d440593 100644 --- a/lib/serbea/helpers.rb +++ b/lib/serbea/helpers.rb @@ -1,4 +1,15 @@ -require "active_support/core_ext/string/output_safety" +unless "".respond_to?(:html_safe) + # The simplest HTML safety "polyfill" around + class String + def html_safe + self.class.new(self).tap { _1.instance_variable_set(:@html_safe, true) } + end + + def html_safe? + instance_variable_get(:@html_safe) == true + end + end +end module Serbea module Helpers @@ -10,7 +21,7 @@ def capture(*args) previous_buffer_state = @_erbout @_erbout = Serbea::OutputBuffer.new result = yield(*args) - result = @_erbout.presence || result + result = @_erbout.empty? ? result : @_erbout @_erbout = previous_buffer_state Serbea::OutputBuffer === result ? result.html_safe : result @@ -36,7 +47,7 @@ def import(*args, **kwargs, &block) end def h(input) - ERB::Util.h(input.to_s) + Erubi.h(input.to_s) end alias_method :escape, :h diff --git a/lib/serbea/pipeline.rb b/lib/serbea/pipeline.rb index 945aa52..ac1789c 100644 --- a/lib/serbea/pipeline.rb +++ b/lib/serbea/pipeline.rb @@ -1,6 +1,4 @@ require "set" -require "active_support/core_ext/string/output_safety" -require "active_support/core_ext/object/blank" module Serbea class Pipeline @@ -36,7 +34,7 @@ def self.exec(template, locals = {}, include_helpers: nil, **kwargs) full_template = "{{ #{template} | assign_to: :output }}" tmpl = Tilt::SerbeaTemplate.new { full_template } - tmpl.render(pipeline_obj, locals.presence || kwargs) + tmpl.render(pipeline_obj, locals.empty? ? kwargs : locals) pipeline_obj.output end @@ -49,7 +47,7 @@ def self.output_processor=(processor) # @return [Proc] def self.output_processor @output_processor ||= lambda do |input| - (!input.html_safe? && self.autoescape) ? ERB::Util.h(input) : input.html_safe + (!input.html_safe? && self.autoescape) ? Erubi.h(input) : input.html_safe end end diff --git a/lib/version.rb b/lib/version.rb index f129b85..0259f11 100644 --- a/lib/version.rb +++ b/lib/version.rb @@ -1,3 +1,3 @@ module Serbea - VERSION = "2.0.0" + VERSION = "2.1.0" end \ No newline at end of file diff --git a/serbea.gemspec b/serbea.gemspec index 3af7e33..176e14d 100644 --- a/serbea.gemspec +++ b/serbea.gemspec @@ -16,7 +16,6 @@ Gem::Specification.new do |spec| spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r!^(test|script|spec|features|docs|serbea-rails)/!) } spec.require_paths = ["lib"] - spec.add_runtime_dependency("activesupport", ">= 6.0") spec.add_runtime_dependency("erubi", ">= 1.10") spec.add_runtime_dependency("tilt", "~> 2.0") diff --git a/test/test.rb b/test/test.rb index bbcf8de..0b6b67d 100644 --- a/test/test.rb +++ b/test/test.rb @@ -115,7 +115,7 @@ def content_tag(tag_name, *attrs, &block) processed_attrs = "" attrs[0].each do |key, value| processed_attrs << " #{key}=\"#{value}\"" - end if attrs.present? + end unless attrs.empty? "<#{tag_name}#{processed_attrs}>#{content}" end