Skip to content

Commit

Permalink
Remove support for process_attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldrapper committed Feb 18, 2024
1 parent b64ed48 commit 61ee14c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 36 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
- [Breaking] Removed support for `process_attributes`. Instead, override `__attributes__`, calling `super` with your processed attributes. `__attributes__` receives a single positional argument which is the original attributes hash.

## [1.9.0] 2024-11-24

- Improved documentation
Expand Down
6 changes: 3 additions & 3 deletions lib/phlex/elements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ def #{method_name}(**attributes, &block)
if attributes.length > 0 # with attributes
if block # with content block
target << "<#{tag}" << (Phlex::ATTRIBUTE_CACHE[attributes.hash] ||= __attributes__(**attributes)) << ">"
target << "<#{tag}" << __attributes__(attributes) << ">"
yield_content(&block)
target << "</#{tag}>"
else # without content block
target << "<#{tag}" << (Phlex::ATTRIBUTE_CACHE[attributes.hash] ||= __attributes__(**attributes)) << "></#{tag}>"
target << "<#{tag}" << __attributes__(attributes) << "></#{tag}>"
end
else # without attributes
if block # with content block
Expand Down Expand Up @@ -77,7 +77,7 @@ def #{method_name}(**attributes)
target = @_context.target
if attributes.length > 0 # with attributes
target << "<#{tag}" << (Phlex::ATTRIBUTE_CACHE[attributes.hash] ||= __attributes__(**attributes)) << ">"
target << "<#{tag}" << __attributes__(attributes) << ">"
else # without attributes
target << "<#{tag}>"
end
Expand Down
26 changes: 12 additions & 14 deletions lib/phlex/sgml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -348,23 +348,21 @@ def __text__(content)
end

# @api private
def __attributes__(**attributes)
if respond_to?(:process_attributes)
attributes = process_attributes(**attributes)
end

if attributes[:href]&.start_with?(/\s*javascript:/)
attributes.delete(:href)
end
def __attributes__(attributes)
Phlex::ATTRIBUTE_CACHE[attributes.hash] ||= (
if attributes[:href]&.start_with?(/\s*javascript:/)
attributes.delete(:href)
end

if attributes["href"]&.start_with?(/\s*javascript:/)
attributes.delete("href")
end
if attributes["href"]&.start_with?(/\s*javascript:/)
attributes.delete("href")
end

buffer = +""
__build_attributes__(attributes, buffer: buffer)
buffer = +""
__build_attributes__(attributes, buffer: buffer)

buffer
buffer
)
end

# @api private
Expand Down
19 changes: 0 additions & 19 deletions test/phlex/view/process_attributes.rb

This file was deleted.

0 comments on commit 61ee14c

Please sign in to comment.