bolismauro / StencilSwiftKit

A framework bringing additional nodes & filters to Stencil dedicated to Swift code generation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

StencilSwiftKit

Build Status CocoaPods Compatible Platform Swift 3.0

StencilSwiftKit is a framework bringing additional Stencil nodes & filters dedicated to Swift code generation.

Nodes

TODO: Write more extension Documentation

  • MacroNode & CallNode
    • {% macro <Name> <Params> %}…{% endmacro %}
    • Defines a macro that will be replaced by the nodes inside of this block later when called
    • {% call <Name> <Params> %}
    • Calls a previously defined macro, passing it some parameters
  • SetNode
    • {% set <Name> %}…{% endset %}
    • Renders the nodes inside this block immediately, and stores the result in the <Name> variable of the current context.

Filters

TODO: Write more extension Documentation

  • swiftIdentifier: Transforms an arbitrary string into a valid Swift identifier (using only valid characters for a Swift identifier as defined in the Swift language reference)
  • join: Deprecated. Will be removed now that the same filter exists in Stencil proper.
  • lowerFirstWord
  • snakeToCamelCase / snakeToCamelCaseNoPrefix
  • titlecase
  • hexToInt
  • int255toFloat
  • percent
  • escapeReservedKeywords: Escape keywods reserved in the Swift language, by wrapping them inside backticks so that the can be used as regular escape keywords in Swift code.

SwiftTemplate

This framwork also contains a SwiftTemplate class, which is a subclass of Stencil.Template dedicated to remove extra newlines when rendering the template.

Indeed, such extra newlines could otherwise be inserted in the generated output because you want your template to be well formatted, and that can end up with Stencil nodes like {% for … %} and {% if … %} be alone in some lines of your template and that would render into nothing by themselves, generating empty lines in the output.

This template subclass aims to remove those lines generated by using a simple workaround when rendering, until there's an embeded way to handle that in Stencil proper (see Stencil/#22).

Stencil.Extension

This framework also contains a stencilSwiftExtension() function which returns a Stencil.Extension already configured with all the nodes and filters listed above.

Use it when you configure your code to tell Stencil to register those nodes & filters, for example when building your Stencil.Environment(extension: …, templateClass: …)

About

A framework bringing additional nodes & filters to Stencil dedicated to Swift code generation

License:MIT License


Languages

Language:Swift 94.4%Language:Ruby 5.6%