Skip to content

Even further with Tag... #36

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

Open
wants to merge 148 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
148 commits
Select commit Hold shift + click to select a range
92b55c6
Tag subclasses can customize html name
bgisme Jan 2, 2023
e0d330c
name lowercased()
bgisme Jan 2, 2023
afcbf3e
Need to make rawValue public so any Tag can set the attribute
bgisme Jan 4, 2023
6344ace
Class name var
bgisme Feb 14, 2023
480e2fb
Class names for all tags
bgisme Feb 14, 2023
8e4c241
Init Tag with Optional Node
bgisme Jul 6, 2023
9187c09
Reverting to init with optional Node
bgisme Jul 6, 2023
db07415
Reverting to init with optional Node
bgisme Jul 6, 2023
677973d
Reverting to init with optional Node
bgisme Jul 6, 2023
ee7d3df
Reverting to init with optional Node
bgisme Jul 6, 2023
cb0eada
Reverting to init with optional Node
bgisme Jul 6, 2023
98132f0
TagBuilder fixes
bgisme Jul 7, 2023
0000a66
Empty resultBuilder
bgisme Jul 7, 2023
4a80233
Merge remote-tracking branch 'refs/remotes/origin/patch-1'
bgisme Jul 7, 2023
8085165
Fixing stuff
bgisme Jul 7, 2023
63cd7f6
Testing
bgisme Jul 7, 2023
d103f7f
Empty buildBlock
bgisme Jul 7, 2023
a897e29
init Tag with optional Node
bgisme Jul 7, 2023
60563e0
init Tag with optional Node
bgisme Jul 7, 2023
18c5b13
Merge remote-tracking branch 'refs/remotes/origin/patch-1'
bgisme Jul 7, 2023
2f5fc7a
Make TagBuilder convenience initializer a second designated initializer
bgisme Jul 8, 2023
64a5551
Remove TagBuilder designated initializer. Causes problems.
bgisme Jul 8, 2023
043878d
Subclasses of primary Tags maintain html nam
bgisme Jul 8, 2023
7a9cb49
Fixing subclass <tag_name>
bgisme Jul 9, 2023
562f687
Revert TagBuilder
bgisme Jul 9, 2023
d8727d3
Fixing Tag subclasses
bgisme Jul 9, 2023
6b5eecf
More fixes
bgisme Jul 9, 2023
7041b5c
More refinements
bgisme Jul 9, 2023
f90bcc1
Subclassing while maintaining root tag name
bgisme Jul 10, 2023
4fb00a3
Tweak
bgisme Jul 10, 2023
542e8f8
Node name is required at Tag level
bgisme Jul 10, 2023
aeccbc8
Make Node name non-optional
bgisme Jul 10, 2023
c06591e
Update
bgisme Jul 10, 2023
7f69a25
Testing Tag class name
bgisme Jul 10, 2023
f7a45ae
Testing Node name
bgisme Jul 10, 2023
63dd73f
Testing Node name
bgisme Jul 10, 2023
5ba01c5
Minor tweaks
bgisme Jul 10, 2023
cba89d0
Little tweaks
bgisme Jul 11, 2023
7e13aca
Updated to fit code changes
bgisme Jul 11, 2023
1f1f8ce
Fixes
bgisme Jul 11, 2023
d35f3ad
Typos
bgisme Jul 11, 2023
6004035
Typos
bgisme Jul 11, 2023
a71b92a
TagRepresentable protocol
bgisme Jul 11, 2023
3b4553b
Text changes
bgisme Jul 11, 2023
566b641
Text changes
bgisme Jul 11, 2023
8804656
Text edits
bgisme Jul 11, 2023
e4db957
Text edits
bgisme Jul 11, 2023
e79646e
Text edits
bgisme Jul 11, 2023
08fc246
Text edits
bgisme Jul 11, 2023
6e67a47
Text edits
bgisme Jul 11, 2023
ade4c9a
Text edits
bgisme Jul 11, 2023
f3650de
Text edits
bgisme Jul 11, 2023
f4c3862
Text edits
bgisme Jul 11, 2023
6fde18a
Text edits
bgisme Jul 11, 2023
3ec05f3
Text edits
bgisme Jul 11, 2023
bd61e0b
Text edits
bgisme Jul 11, 2023
2fde37b
Text edits
bgisme Jul 11, 2023
7809a4f
Removed TagRepresentable protocol... compiler fails when used in more…
bgisme Jul 11, 2023
a37b3e8
Text edits
bgisme Jul 11, 2023
196dc5e
Update ScriptTagTests.swift
bgisme Jul 11, 2023
c71fec3
Update ScriptTagTests.swift
bgisme Jul 11, 2023
6068a3f
Update README.md
bgisme Jul 11, 2023
925a3f9
Update README.md
bgisme Jul 11, 2023
1134653
Update Global.swift
bgisme Jul 11, 2023
1ff0662
Update Text.swift
bgisme Jul 11, 2023
365c5c6
Update TagCompositionTests.swift
bgisme Jul 11, 2023
b921b70
Update assert.swift
bgisme Jul 11, 2023
79fb43b
Update assert.swift
bgisme Jul 11, 2023
b16f44c
Update Tag.swift
bgisme Jul 11, 2023
af16cd9
Tag does not render by default. Init() options and subclasses allow c…
bgisme Jul 12, 2023
94f6472
Update to match changes to Tag
bgisme Jul 12, 2023
fa127cd
Update .renderless to .onlyChildren
bgisme Jul 12, 2023
c6f182f
Tag type is optional
bgisme Jul 13, 2023
f40bb1e
Node has been eliminated
bgisme Jul 13, 2023
da8dfb7
Comment
bgisme Jul 13, 2023
a64cf46
Tag default initializer uses builder func so subclasses look cleaner.
bgisme Jul 13, 2023
a33eb6b
Tag is renderless (#1)
bgisme Jul 13, 2023
85e605c
Second designated initializer with builder parameter so Tag is easier…
bgisme Jul 13, 2023
4322529
Node file
bgisme Jul 13, 2023
d63a14b
Remove Node
bgisme Jul 13, 2023
e65e802
Merge remote-tracking branch 'refs/remotes/origin/main'
bgisme Jul 13, 2023
023aebc
Typo
bgisme Jul 13, 2023
f17bc59
Default initializer with builder function causes major problems...
bgisme Jul 13, 2023
3f2bde0
Change Tag > `Type` to Kind
bgisme Jul 14, 2023
6162668
Add property for scripts
bgisme Jul 14, 2023
89acfe1
Add properties
bgisme Jul 14, 2023
263da18
Editing Properties
bgisme Jul 14, 2023
81be930
Make properties optional
bgisme Jul 14, 2023
c5b5cc7
Make scripts property optional
bgisme Jul 14, 2023
50d1ebe
Add event functions
bgisme Jul 14, 2023
e245f3f
Events now enum
bgisme Jul 14, 2023
8ba79ea
Tag > appendToAttribute()
bgisme Jul 14, 2023
0639f5a
Move Event from Tag to Attribute
bgisme Jul 14, 2023
87b9041
Make Event extensions on Tag public
bgisme Jul 14, 2023
c17e27b
Update convenience init()
bgisme Jul 14, 2023
f6160c5
Merge branch 'main' into main
bgisme Jul 23, 2023
244a579
Merge branch 'main' into TagIsRenderless
bgisme Jul 23, 2023
870030f
Typo
bgisme Jul 24, 2023
3f6d30c
Use String(describing:) to generate tag name from class name
bgisme Jul 26, 2023
f3e24a5
Make properties optional
bgisme Jul 14, 2023
ee5cc66
Make scripts property optional
bgisme Jul 14, 2023
e9bf09b
Add event functions
bgisme Jul 14, 2023
466cef3
Events now enum
bgisme Jul 14, 2023
b8df153
Tag > appendToAttribute()
bgisme Jul 14, 2023
11b6e3c
Move Event from Tag to Attribute
bgisme Jul 14, 2023
ac5bb30
Make Event extensions on Tag public
bgisme Jul 14, 2023
4e8054c
Update convenience init()
bgisme Jul 14, 2023
1f5c86b
Typo
bgisme Jul 24, 2023
f9863ed
Use String(describing:) to generate tag name from class name
bgisme Jul 26, 2023
871990d
Use String(describing:) to generate tag name from class name
bgisme Jul 26, 2023
8b2842e
Merge branch 'TagIsRenderless'
bgisme Jul 26, 2023
c0ec08f
Add language property to Html tag
bgisme Jul 26, 2023
ccce256
Add global language attribute
bgisme Jul 26, 2023
f2d7257
Minor tweaks to Head
bgisme Jul 26, 2023
00b7a1d
Minor tweaks to Head
bgisme Jul 26, 2023
4f01877
Head convenience init
bgisme Jul 26, 2023
15dab20
Remove on... prefix
bgisme Jul 26, 2023
dd51882
Move language to separate file
bgisme Jul 26, 2023
66ee00c
Fiddling with Head
bgisme Jul 26, 2023
3b6bc7d
Revert Head to original
bgisme Jul 26, 2023
ca875f3
Lang tweaks
bgisme Jul 27, 2023
e6847ca
More Lang tweaks
bgisme Jul 27, 2023
9ca13b9
More Lang tweaks
bgisme Jul 27, 2023
6895a01
Head convenience init()
bgisme Jul 27, 2023
eb252e6
Minor Tweaks
bgisme Jul 27, 2023
8f30862
Minor Tweaks
bgisme Jul 27, 2023
5960b77
Language + Country
bgisme Jul 27, 2023
7b9d3b1
Language + Country
bgisme Jul 27, 2023
3f22877
struct Lang
bgisme Jul 27, 2023
f98d517
struct Lang
bgisme Jul 27, 2023
7497f09
Shortened Language and Country enum names
bgisme Jul 27, 2023
f278a2f
Add @discardableResult
bgisme Jul 28, 2023
2062096
Minor tweak
bgisme Jul 28, 2023
c45e230
Minor tweak
bgisme Jul 28, 2023
4a3fd37
Minor tweak
bgisme Jul 28, 2023
3e344ed
Minor tweak
bgisme Jul 28, 2023
807f79c
Fix <head> not including children
bgisme Jul 30, 2023
1da4ee0
<a> attribute include nil value and condition parameters
bgisme Jul 30, 2023
f6f1b66
Add @discardableResult to <a> attributes
bgisme Jul 30, 2023
674a948
Redundant init()
bgisme Aug 1, 2023
74abc98
Tag init() with contents String
bgisme Aug 2, 2023
e950721
Remove convenience inits
bgisme Aug 2, 2023
74d45a3
Fix rendering of onEvent values
bgisme Aug 4, 2023
10ade30
Fix event raw value
bgisme Aug 4, 2023
521c71b
Minor fix to event raw value
bgisme Aug 4, 2023
7124734
Update form functions to match standard pattern
bgisme Aug 5, 2023
aec36d6
Merge remote-tracking branch 'refs/remotes/origin/main'
bgisme Aug 5, 2023
7535a7a
Minor fix
bgisme Aug 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 75 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,35 +74,54 @@ That's it.

## Creating custom tags

You can define your own custom tags by subclassing the `Tag` or `EmptyTag` class.
You can define your own custom tags a few different ways, from simple to complex cases.

You can follow the same pattern if you take a look at the core tags.
1. Subclass `Tag` and it will render with your class name lowercased.

```swift
open class Div: Tag {
class MyTag: Tag { }

// <mytag></mytag>
```

2. Subclass `Tag` and override the `name` property.

```swift
class MyTag: Tag {

override open class var name: String { "myTag" }
}

// <div></div> - standard tag
// <myTag></myTag>
```

3. Subclass `Tag` and override the `type` property. `Type` determines how your class will render. For example, to create an empty tag...

open class Br: EmptyTag {
```swift
class MyTag: Tag {

override open class var type: `Type` { .empty }
}
// <br> - no closing tag

// <myTag>
```

By default the name of the tag is automatically derived from the class name (lowercased), but you can also create your own tag type & name by overriding the `createNode()` class function.
4. Subclass `Tag`, create your own custom initializer and then call the `Tag` designated initializer.

```swift
open class LastBuildDate: Tag {

open override class func createNode() -> Node {
Node(type: .standard, name: "lastBuildDate")
class MyTag: Tag {

init(myAttributeValue: String, @TagBuilder _ builder: () -> Tag) {
let attribute = .init(key: "myKey", value: myAttributeValue)
super.init(type: .empty,
name: "myTag",
attributes: [attribute],
builder: [builder()]
)
}
}

// <lastBuildDate></lastBuildDate> - standard tag with custom name
// <myTag myKey="myAttributeValue">
```

It is also possible to create tags with altered content or default attributes.
Expand All @@ -129,6 +148,50 @@ open class Rss: Tag {
// <rss version="2.0">...</rss> - tag with a default attribute
```

To customize tags of a particular `Node` type...

```swift
// Bracketed tags... <tagname></tagname> ...use StandardTag class
class MyClass: StandardTag { }

// Single tag... <tagname> ...use EmptyTag class
class MyClass: EmptyTag { }

// Comment tag... <!-- your comments here --> ...use CommentTag class
class MyClass: CommentTag { }
```

When you need to combined multiple tags into one, but don't want the container to render, use the `GroupTag`. This class is especially handy when a function parameter requires one `Tag` but you need to supply many.

```swift
class MyTag: Tag {

init(myAttributeValue: String, @TagBuilder _ builder: () -> Tag) {
let attribute = .init(key: "myKey", value: myAttributeValue)
let node = Node(type: .empty, name: "myTag", attributes: [attribute])
super.init(node: node, [builder()])
}

convenience init(anotherValue: String) {
self.init(myAttributeValue: anotherValue) {
// must return one Tag for builder parameter
// use GroupTag because it will not render
GroupTag {
TagA()
TagB()
TagC()
}
}
}
}

// <taga></taga>
// <tagb></tagb>
// <tagc></tagc>
```

If you just need to render basic HTML — `<div>`, `<p>`, `<a>`, etc. — then use one the many pre-made classes in the library called by the same name.

## Attribute management

You can set, add or delete the attributes of a given tag.
Expand Down
Loading