0.10.0
Breaking changes
Content update by @RandomHashTags
Single Macro
This update replaces all html element macros with a single macro. Usage of the html element macros now drop the macro delimiter, compiled via the new #html
macro, and should remain at the end of the parameter list to behave identically as before.
The main reason behind this change is due to very poor code completion and compilation performance in projects that use this project extensively, which even I personally experienced. Plus it no longer pollutes the global namespace with over 100 related macros.
Other Changes
- The
#escapeHTML
macro remains unchanged, but the macros for different types have been replaced by the newHTMLEncoding
parameter in the new html macro. - All attribute values can now accept
nil
values. Attributes withnil
values are completely ignored when compiled/rendered. - The
var
element was renamed tovariable
- updated README to reflect all these changes (and updated benchmark pngs)
Removals
- Removed
swift-nio
dependency. You will need toimport NIOCore
if you want to useByteBuffer
as the HTMLEncoding.
New Syntax Examples
Examples of the new syntax
// <div class="dark"><p>Macros are beautiful</p></div>
#html(
div(attributes: [.class(["dark"])],
p("Macros are beautiful")
)
)
// <a href="https://github.com/RandomHashTags/litleagues" target="_blank"></a>
#html(
a(href: "https://github.com/RandomHashTags/litleagues", target: ._blank)
)
// <input id="funny-number" max="420" min="69" name="funny_number" step="1" type="number" value="69">
#html(
input(
attributes: [.id("funny-number")],
max: 420,
min: 69,
name: "funny_number",
step: 1,
type: .number,
value: "69"
)
)
Examples of the new HTMLEncoding
#html(
encoding: .string,
div()
)
#html(
encoding: .utf8Array,
div()
)
#html(
encoding: .utf16Array,
div()
)
#html(
encoding: .foundationData,
div()
)
#html(
encoding: .byteBuffer,
div()
)
Closing Notes
View the README to learn how to use the new syntax in a more in-depth manner. This update also allows developers to directly call the parsing code via HTMLKitUtilities.parseArguments
(and the escape html logic), which allows custom macros to incorporate the HTML expansions, which is especially useful if you want to fully implement a compile time solution for your custom static content (I know I do!).
Also contains a few bug fixes to corner cases and explicit usability.
Full Changelog: 0.9.0...0.10.0
I expect only additions and more fixes to corner cases for the 1.0.0 release. It is pretty much feature complete now, and I will be battle testing it more in the coming weeks.