Skip to content

Commit

Permalink
Remove Active Support, release 2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredcwhite committed Nov 4, 2023
1 parent 1a2fb14 commit eb9a1bd
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
17 changes: 14 additions & 3 deletions lib/serbea/helpers.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down
6 changes: 2 additions & 4 deletions lib/serbea/pipeline.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Serbea
VERSION = "2.0.0"
VERSION = "2.1.0"
end
1 change: 0 additions & 1 deletion serbea.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion test/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}</#{tag_name}>"
end
Expand Down

0 comments on commit eb9a1bd

Please sign in to comment.