-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Tag easier to subclass #35
Open
bgisme
wants to merge
159
commits into
BinaryBirds:main
Choose a base branch
from
bgisme:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Conflicts: Sources/SwiftSgml/TagBuilder.swift
Other Global Attributes... add nil values and conditions
Conflicts: Sources/SwiftHtml/Attributes/Events.swift Sources/SwiftHtml/Tags/Body.swift Sources/SwiftHtml/Tags/Head.swift Sources/SwiftHtml/Tags/Html.swift Sources/SwiftSgml/Tag.swift Tests/SwiftHtmlTests/SwiftHtmlTests.swift
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request attempts to make
Tag
more straightforward to subclass.Right now, if you take a basic html tag like
Div
and customize it, the rendered tag name will be the same as your custom subclass.Example...
class MyClass: Div { }
Renders as...
<myclass></myclass>
So if you want to subclass an html tag like
Div
and keep that name, you have to add extra code.This seems like overkill. And prone to mistakes. Like changing the superclass from 'Div' to 'P' and then forgetting to change the node name to match.
The proposed code changes try to fix this. And in the process, make customizing a tag name simple—either take the name of your subclass or override one class variable.
The HTML tags still use their own class name as the node name, to prevent typos. And all subclasses get it for free.
The code changes also try to make
Tag
more accommodating to complicated setups.Here are the different ways to use
Tag
from simple to complex.Tag
and it will render with your class name lowercased.Tag
and override thename
property.Tag
and override thenode
property.Tag
, create your own custom initializer and then call theTag
designated initializer.A few other subtle but important changes...
•
Node
names are no longer optional. There were some forced unwraps inDocumentRenderer
that seemed like a bad place to crash. And sinceTag
automatically generates a name, leaving it optional seemed unnecessary.• An extension was added to
String
forinit()
with a class name. This is used in all the html tags to convert their class names into node names. And since the class names are type checked, it helps prevent typos if the class name changes.• A new intermediate class
TypedTag
was created for subclasses with a specific node type: .standard, .empty, .comment, .group. It seemed appropriate to keep all their initializers in one file instead of many. So now there's a subclass for each node type:GroupTag
,EmptyTag
,StandardTag
,CommentTag
. And these make reading the html tags a little more clear. You can immediately tell how the tag will render...