Skip to content

Commit

Permalink
Remove Zeitwerk (#633)
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldrapper authored Jan 30, 2024
1 parent 14505e4 commit 125cda0
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 53 deletions.
2 changes: 0 additions & 2 deletions config/sus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@
Bundler.require :test

require_relative "../fixtures/view_helper"

Zeitwerk::Loader.eager_load_all
35 changes: 20 additions & 15 deletions lib/phlex.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
# frozen_string_literal: true

require "erb"
require "zeitwerk"

module Phlex
autoload :Context, "phlex/context"
autoload :DeferredRender, "phlex/deferred_render"
autoload :ElementClobberingGuard, "phlex/element_clobbering_guard"
autoload :Elements, "phlex/elements"
autoload :HTML, "phlex/html"
autoload :Helpers, "phlex/helpers"
autoload :SGML, "phlex/sgml"
autoload :SVG, "phlex/svg"
autoload :Unbuffered, "phlex/unbuffered"
autoload :ConcurrentMap, "phlex/concurrent_map"

# Included in all Phlex exceptions allowing you to match any Phlex error.
# @example Rescue any Phlex error:
# rescue Phlex::Error
module Error; end

if defined?(ERB::Escape)
Escape = ERB::Escape
elsif defined?(ERB::Util)
Escape = ERB::Util
else
Escape = BasicEscape
Escape = ERB::Util
end

# A specialised ArgumentError for Phlex.
Expand All @@ -27,17 +35,14 @@ class NameError < ::NameError
include Error
end

# @api private
Loader = Zeitwerk::Loader.for_gem(warn_on_extra_files: false).tap do |loader|
loader.inflector.inflect(
"html" => "HTML",
"svg" => "SVG",
"sgml" => "SGML"
)
loader.ignore("#{__dir__}/phlex/testing")
loader.setup
end

# @api private
ATTRIBUTE_CACHE = Phlex::ConcurrentMap.new
end

if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.0")
class Symbol
def name
to_s
end
end
end
16 changes: 0 additions & 16 deletions lib/phlex/basic_escape.rb

This file was deleted.

4 changes: 0 additions & 4 deletions lib/phlex/elements.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# frozen_string_literal: true

if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.0")
using Phlex::Overrides::Symbol::Name
end

# Extending this module provides the {register_element} macro for registering your own custom elements. It's already extended by {HTML} and {SVG}.
# @example
# module MyCustomElements
Expand Down
4 changes: 0 additions & 4 deletions lib/phlex/helpers.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# frozen_string_literal: true

if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.0")
using Phlex::Overrides::Symbol::Name
end

module Phlex::Helpers
private

Expand Down
3 changes: 3 additions & 0 deletions lib/phlex/html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
module Phlex
# @abstract Subclass and define {#template} to create an HTML component class.
class HTML < SGML
autoload :StandardElements, "phlex/html/standard_elements"
autoload :VoidElements, "phlex/html/void_elements"

# A list of HTML attributes that have the potential to execute unsafe JavaScript.
EVENT_ATTRIBUTES = %w[onabort onafterprint onbeforeprint onbeforeunload onblur oncanplay oncanplaythrough onchange onclick oncontextmenu oncopy oncuechange oncut ondblclick ondrag ondragend ondragenter ondragleave ondragover ondragstart ondrop ondurationchange onemptied onended onerror onfocus onhashchange oninput oninvalid onkeydown onkeypress onkeyup onload onloadeddata onloadedmetadata onloadstart onmessage onmousedown onmousemove onmouseout onmouseover onmouseup onmousewheel onoffline ononline onpagehide onpageshow onpaste onpause onplay onplaying onpopstate onprogress onratechange onreset onresize onscroll onsearch onseeked onseeking onselect onstalled onstorage onsubmit onsuspend ontimeupdate ontoggle onunload onvolumechange onwaiting onwheel].to_h { [_1, true] }.freeze

Expand Down
6 changes: 0 additions & 6 deletions lib/phlex/overrides/symbol/name.rb

This file was deleted.

4 changes: 0 additions & 4 deletions lib/phlex/sgml.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# frozen_string_literal: true

if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.0")
using Phlex::Overrides::Symbol::Name
end

module Phlex
# **Standard Generalized Markup Language** for behaviour common to {HTML} and {SVG}.
class SGML
Expand Down
2 changes: 2 additions & 0 deletions lib/phlex/svg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module Phlex
class SVG < SGML
autoload :StandardElements, "phlex/svg/standard_elements"

include StandardElements

# This should be extended after all method definitions
Expand Down
2 changes: 0 additions & 2 deletions phlex.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,5 @@ Gem::Specification.new do |spec|
end
spec.require_paths = ["lib"]

spec.add_dependency "zeitwerk", "~> 2.6"

spec.metadata["rubygems_mfa_required"] = "true"
end

0 comments on commit 125cda0

Please sign in to comment.