Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jun 5, 2019. It is now read-only.

Any-way-you-want-it, type-safe HTML in Swift.

License

NotificationsYou must be signed in to change notification settings

sahandnayebaziz/Hypertext

Repository files navigation

header

Compose valid HTML in Swift any way you want to.

Usage

import Hypertexttitle{"hello world."}.render()// <title>hello world.</title>head{title{"hello world."}}.render()// <head><title>hello world.</title></head>head{title{"hello world."}}.render(startingWithSpaces:0, indentingWithSpaces:2)// <head>//   <title>//     hello world.//   </title>// </head>

Requirements

  • Swift 3.0+

Full usage

  1. Rendering a tag

    div().render() // <div></div>
  2. Rendering a tag with child text

    div{"hello world."}.render()// <div>hello world.</div>
  3. Rendering a tag with a child tag

    div{img()}.render()// <div><img/></div>
  4. Rendering a tag with multiple child tags

    div{[img(),img(),img()]}.render()// <div><img/><img/><img/></div>
  5. Rendering a tag with attributes

    link(["rel":"stylesheet","type":"text/css","href":"./style.css"]).render()// <link rel="stylesheet" type="text/css" href="./style.css"/>
  6. Rendering a tag with attributes and children

    div(["class":"container"]){"hello world."}// <div>hello world.</div>
  7. Rendering a doctype declaration

    doctype(.html5).render()// <!DOCTYPE html>
  8. Rendering unminified, with newlines and indentation

    head{title{"hello world."}}.render(startingWithSpaces:0, indentingWithSpaces:2)// <head>//   <title>//     hello world.//   </title>// </head>
  9. Rendering a tag in a novel way, any way you want to

    func createTitleTag(forPageNamed pageName:String)->title{returntitle{"Hypertext -\(pageName)"}}head{createTitleTag(forPageNamed:"Documentation")}.render()// <head><title>Hypertext - Documentation</title></head>
  10. Rendering a custom tag

    publicclassmyNewTag:tag{overridepublicvarisSelfClosing:Bool{returntrue}}myNewTag().render()// <my-new-tag/>
  11. Rendering a custom type by adopting the protocolRenderable

    extensionMyType:Renderable{publicfunc render()->String{...}publicfunc render(startingWithSpaces:Int, indentingWithSpaces:Int)->String{...}}

About

Any-way-you-want-it, type-safe HTML in Swift.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors4

  •  
  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp