diff --git a/README.md b/README.md index be032f0..1d639f7 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,9 @@
- + ----- Welcome to **jumpper**. Is an open source framework, which is independent of other web frameworks or toolkits available on the market, such as Vapor, Kitura and Perfect. It can be used in conjunction with any of them and even alone. This shows how simple it is to build HTML pages using only **Swift**. diff --git a/Sources/jumpper/HTML/Elements/ATag.swift b/Sources/jumpper/HTML/Tags/ATag.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/ATag.swift rename to Sources/jumpper/HTML/Tags/ATag.swift diff --git a/Sources/jumpper/HTML/Elements/Blockquote.swift b/Sources/jumpper/HTML/Tags/Blockquote.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Blockquote.swift rename to Sources/jumpper/HTML/Tags/Blockquote.swift diff --git a/Sources/jumpper/HTML/Elements/Br.swift b/Sources/jumpper/HTML/Tags/Br.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Br.swift rename to Sources/jumpper/HTML/Tags/Br.swift diff --git a/Sources/jumpper/HTML/Elements/Button.swift b/Sources/jumpper/HTML/Tags/Button.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Button.swift rename to Sources/jumpper/HTML/Tags/Button.swift diff --git a/Sources/jumpper/HTML/Elements/Canvas.swift b/Sources/jumpper/HTML/Tags/Canvas.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Canvas.swift rename to Sources/jumpper/HTML/Tags/Canvas.swift diff --git a/Sources/jumpper/HTML/Elements/Center.swift b/Sources/jumpper/HTML/Tags/Center.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Center.swift rename to Sources/jumpper/HTML/Tags/Center.swift diff --git a/Sources/jumpper/HTML/Elements/Code.swift b/Sources/jumpper/HTML/Tags/Code.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Code.swift rename to Sources/jumpper/HTML/Tags/Code.swift diff --git a/Sources/jumpper/HTML/Elements/Div.swift b/Sources/jumpper/HTML/Tags/Div.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Div.swift rename to Sources/jumpper/HTML/Tags/Div.swift diff --git a/Sources/jumpper/HTML/Tags/Document/Body.swift b/Sources/jumpper/HTML/Tags/Document/Body.swift new file mode 100644 index 0000000..cb66a59 --- /dev/null +++ b/Sources/jumpper/HTML/Tags/Document/Body.swift @@ -0,0 +1,41 @@ +// +// MIT License +// +// Copyright (c) 2020 micheltlutz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// + +import Foundation + +/** + Body tag element class + + ### Usage Example: ### + ```` + let body = Body() + body.add(/* Any Element*/) + ```` +*/ +public final class Body: ContainerElementBase { + /// Override tag element. Default is `body` + override var tag: String { + return "body" + } +} diff --git a/Sources/jumpper/HTML/Tags/Document/Doctype.swift b/Sources/jumpper/HTML/Tags/Document/Doctype.swift new file mode 100644 index 0000000..27ca601 --- /dev/null +++ b/Sources/jumpper/HTML/Tags/Document/Doctype.swift @@ -0,0 +1,50 @@ +// +// MIT License +// +// Copyright (c) 2020 micheltlutz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// + +import Foundation + +/** + DOCTYPE tag element class + + ### Usage Example: ### + ```` + let doctype = Doctype() + doctype.getString() // or doctype.generate() + ```` +*/ +public final class Doctype: ElementProtocol { + private let tag: String + + public init() { + tag = "" + } + + public func getString() -> String { + return tag + } + + public func generate() { + print(tag) + } +} diff --git a/Sources/jumpper/HTML/Tags/Document/Head.swift b/Sources/jumpper/HTML/Tags/Document/Head.swift new file mode 100644 index 0000000..4277c66 --- /dev/null +++ b/Sources/jumpper/HTML/Tags/Document/Head.swift @@ -0,0 +1,41 @@ +// +// MIT License +// +// Copyright (c) 2020 micheltlutz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// + +import Foundation + +/** + Head tag element class + + ### Usage Example: ### + ```` + let head = Head() + head.add(/* Any Element*/) + ```` +*/ +public final class Head: ContainerElementBase { + /// Override tag element for element. Default is `head` + override var tag: String { + return "head" + } +} diff --git a/Sources/jumpper/HTML/Tags/Document/Html.swift b/Sources/jumpper/HTML/Tags/Document/Html.swift new file mode 100644 index 0000000..bf79d48 --- /dev/null +++ b/Sources/jumpper/HTML/Tags/Document/Html.swift @@ -0,0 +1,41 @@ +// +// MIT License +// +// Copyright (c) 2020 micheltlutz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// + +import Foundation + +/** + Html tag element class + + ### Usage Example: ### + ```` + let html = Html() + html.add(/* Any Element*/) + ```` +*/ +public final class Html: ContainerElementBase { + /// Override tag element. Default is `html` + override var tag: String { + return "html" + } +} diff --git a/Sources/jumpper/HTML/Tags/Document/LinkStylesheet.swift b/Sources/jumpper/HTML/Tags/Document/LinkStylesheet.swift new file mode 100644 index 0000000..4981eed --- /dev/null +++ b/Sources/jumpper/HTML/Tags/Document/LinkStylesheet.swift @@ -0,0 +1,46 @@ +// +// MIT License +// +// Copyright (c) 2020 micheltlutz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// + +import Foundation + +/** + Link stylesheet tag element class + + ### Usage Example: ### + ```` + let linkCssTag = LinkStylesheet("/styles/milligram.min.css") + ```` +*/ +public class LinkStylesheet: Link { + // MARK: - Initialization + /// Default initializer element + /// - Parameters: + /// - href: This is a src attribute for link **href** `String` + /// - attributes: This is a attr **attributes** `AttributeType...` CVarArg + public init(_ href: String) { + super.init(href) + + addAttribute(("rel", "stylesheet")) + } +} diff --git a/Sources/jumpper/HTML/Tags/Document/LinkTag.swift b/Sources/jumpper/HTML/Tags/Document/LinkTag.swift new file mode 100644 index 0000000..e0a9780 --- /dev/null +++ b/Sources/jumpper/HTML/Tags/Document/LinkTag.swift @@ -0,0 +1,51 @@ +// +// MIT License +// +// Copyright (c) 2020 micheltlutz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// + +import Foundation + +/** + link tag element class + + ### Usage Example: ### + ```` + let linkTag = Link("/styles/milligram.min.css", attributes: ("rel", "stylesheet")) + ```` +*/ +public class Link: GenericElement { + ///Override tag element for element. Default is `link` + override var tag: String { + return "link" + } + + // MARK: - Initialization + /// Default initializer element + /// - Parameters: + /// - href: This is a src attribute for link **href** `String` + /// - attributes: This is a attr **attributes** `AttributeType...` CVarArg + public init(_ href: String, attributes: AttributeType...) { + super.init(attributes) + + addAttribute(("href", href)) + } +} diff --git a/Sources/jumpper/HTML/Tags/Document/MetaTag.swift b/Sources/jumpper/HTML/Tags/Document/MetaTag.swift new file mode 100644 index 0000000..36bcdc2 --- /dev/null +++ b/Sources/jumpper/HTML/Tags/Document/MetaTag.swift @@ -0,0 +1,48 @@ +// +// MIT License +// +// Copyright (c) 2020 micheltlutz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// + +import Foundation + +/** + Meta tag element class + + ### Usage Example: ### + ```` + let meta = Meta(("charset", "utf-8"))) + ```` +*/ +public class Meta: GenericElement { + /// Override tag element for element. Default is `meta` + override var tag: String { + return "meta" + } + + // MARK: - Initialization + /// Default initializer + /// - Parameters: + /// - attributes: This is a **attributes** `AttributeType...` CVarArg + public override init(_ attributes: AttributeType...) { + super.init(attributes) + } +} diff --git a/Sources/jumpper/HTML/Tags/Document/ScriptTag.swift b/Sources/jumpper/HTML/Tags/Document/ScriptTag.swift new file mode 100644 index 0000000..a03f181 --- /dev/null +++ b/Sources/jumpper/HTML/Tags/Document/ScriptTag.swift @@ -0,0 +1,53 @@ +// +// MIT License +// +// Copyright (c) 2020 micheltlutz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// + +import Foundation + +/** + This class define a Script element + + ### Usage Example: ### + ```` + let script = Script() + script.add("var myJsVar = 1") + + let script = Script(("src","myScript.js")) + ```` +*/ +public final class Script: GenericElement { + ///Override tag element for option. Default is `script` + override var tag: String { + return "script" + } + /// Override container element defaults is `true` + override var container: Bool { + return true + } + /// This method add a text in script body element + /// - Parameters: + /// - text: This is a content for tag **text** `String` + public func add(_ text: String) { + objects.append(Text(text)) + } +} diff --git a/Sources/jumpper/HTML/Tags/Document/TitleTag.swift b/Sources/jumpper/HTML/Tags/Document/TitleTag.swift new file mode 100644 index 0000000..4a3f402 --- /dev/null +++ b/Sources/jumpper/HTML/Tags/Document/TitleTag.swift @@ -0,0 +1,50 @@ +// +// MIT License +// +// Copyright (c) 2020 micheltlutz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// + +import Foundation + +/** + title tag element class + + ### Usage Example: ### + ```` + let pageTitle = Title("This is Page.") + ```` + */ +public final class Title: ContainerElementBase { + /// Override tag element. Default is `title` + override var tag: String { + return "title" + } + + // MARK: - Initialization + /// Default initializer + /// - Parameters: + /// - text: This is a **text** `String` + public init(_ text: String) { + super.init() + + add(text) + } +} diff --git a/Sources/jumpper/HTML/Elements/Em.swift b/Sources/jumpper/HTML/Tags/Em.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Em.swift rename to Sources/jumpper/HTML/Tags/Em.swift diff --git a/Sources/jumpper/HTML/Elements/Fieldset.swift b/Sources/jumpper/HTML/Tags/Fieldset.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Fieldset.swift rename to Sources/jumpper/HTML/Tags/Fieldset.swift diff --git a/Sources/jumpper/HTML/Tags/Footer.swift b/Sources/jumpper/HTML/Tags/Footer.swift new file mode 100644 index 0000000..b8cd162 --- /dev/null +++ b/Sources/jumpper/HTML/Tags/Footer.swift @@ -0,0 +1,41 @@ +// +// MIT License +// +// Copyright (c) 2020 micheltlutz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// + +import Foundation + +/** + footer tag element class + + ### Usage Example: ### + ```` + let footer = Footer() + footer.add(/* Any Element*/) + ```` +*/ +public final class Footer: ContainerElementBase { + /// Override tag element. Default is `footer` + override var tag: String { + return "footer" + } +} diff --git a/Sources/jumpper/HTML/Elements/Form.swift b/Sources/jumpper/HTML/Tags/Form.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Form.swift rename to Sources/jumpper/HTML/Tags/Form.swift diff --git a/Sources/jumpper/HTML/Elements/HTags.swift b/Sources/jumpper/HTML/Tags/HTags.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/HTags.swift rename to Sources/jumpper/HTML/Tags/HTags.swift diff --git a/Sources/jumpper/HTML/Tags/Header.swift b/Sources/jumpper/HTML/Tags/Header.swift new file mode 100644 index 0000000..a89006c --- /dev/null +++ b/Sources/jumpper/HTML/Tags/Header.swift @@ -0,0 +1,41 @@ +// +// MIT License +// +// Copyright (c) 2020 micheltlutz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// + +import Foundation + +/** + header tag element class + + ### Usage Example: ### + ```` + let header = Header() + header.add(/* Any Element*/) + ```` +*/ +public final class Header: ContainerElementBase { + /// Override tag element. Default is `header` + override var tag: String { + return "header" + } +} diff --git a/Sources/jumpper/HTML/Elements/Hr.swift b/Sources/jumpper/HTML/Tags/Hr.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Hr.swift rename to Sources/jumpper/HTML/Tags/Hr.swift diff --git a/Sources/jumpper/HTML/Elements/Img.swift b/Sources/jumpper/HTML/Tags/Img.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Img.swift rename to Sources/jumpper/HTML/Tags/Img.swift diff --git a/Sources/jumpper/HTML/Elements/Inputs/Checkbox.swift b/Sources/jumpper/HTML/Tags/Inputs/Checkbox.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Inputs/Checkbox.swift rename to Sources/jumpper/HTML/Tags/Inputs/Checkbox.swift diff --git a/Sources/jumpper/HTML/Elements/Inputs/InputText.swift b/Sources/jumpper/HTML/Tags/Inputs/InputText.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Inputs/InputText.swift rename to Sources/jumpper/HTML/Tags/Inputs/InputText.swift diff --git a/Sources/jumpper/HTML/Elements/Inputs/Option.swift b/Sources/jumpper/HTML/Tags/Inputs/Option.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Inputs/Option.swift rename to Sources/jumpper/HTML/Tags/Inputs/Option.swift diff --git a/Sources/jumpper/HTML/Elements/Inputs/Select.swift b/Sources/jumpper/HTML/Tags/Inputs/Select.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Inputs/Select.swift rename to Sources/jumpper/HTML/Tags/Inputs/Select.swift diff --git a/Sources/jumpper/HTML/Elements/Inputs/Submit.swift b/Sources/jumpper/HTML/Tags/Inputs/Submit.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Inputs/Submit.swift rename to Sources/jumpper/HTML/Tags/Inputs/Submit.swift diff --git a/Sources/jumpper/HTML/Elements/Inputs/Textarea.swift b/Sources/jumpper/HTML/Tags/Inputs/Textarea.swift similarity index 91% rename from Sources/jumpper/HTML/Elements/Inputs/Textarea.swift rename to Sources/jumpper/HTML/Tags/Inputs/Textarea.swift index dedd239..e2f27f6 100644 --- a/Sources/jumpper/HTML/Elements/Inputs/Textarea.swift +++ b/Sources/jumpper/HTML/Tags/Inputs/Textarea.swift @@ -29,11 +29,12 @@ import Foundation ### Usage Example: ### ```` - Textarea(("placeholder", "Hi Mike …"), ("id", "commentField")) + let textArea = Textarea(("placeholder", "Hi Mike …"), ("id", "commentField")) + textArea.add("My Text") ```` */ public final class Textarea: GenericElement { - ///Override tag element for option. Default is `option` + ///Override tag element for option. Default is `textarea` override var tag: String { get { return "textarea" diff --git a/Sources/jumpper/HTML/Elements/Label.swift b/Sources/jumpper/HTML/Tags/Label.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Label.swift rename to Sources/jumpper/HTML/Tags/Label.swift diff --git a/Sources/jumpper/HTML/Elements/Lists/DD.swift b/Sources/jumpper/HTML/Tags/Lists/DD.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Lists/DD.swift rename to Sources/jumpper/HTML/Tags/Lists/DD.swift diff --git a/Sources/jumpper/HTML/Elements/Lists/DL.swift b/Sources/jumpper/HTML/Tags/Lists/DL.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Lists/DL.swift rename to Sources/jumpper/HTML/Tags/Lists/DL.swift diff --git a/Sources/jumpper/HTML/Elements/Lists/DT.swift b/Sources/jumpper/HTML/Tags/Lists/DT.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Lists/DT.swift rename to Sources/jumpper/HTML/Tags/Lists/DT.swift diff --git a/Sources/jumpper/HTML/Elements/Lists/LI.swift b/Sources/jumpper/HTML/Tags/Lists/LI.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Lists/LI.swift rename to Sources/jumpper/HTML/Tags/Lists/LI.swift diff --git a/Sources/jumpper/HTML/Elements/Lists/OL.swift b/Sources/jumpper/HTML/Tags/Lists/OL.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Lists/OL.swift rename to Sources/jumpper/HTML/Tags/Lists/OL.swift diff --git a/Sources/jumpper/HTML/Elements/Lists/UL.swift b/Sources/jumpper/HTML/Tags/Lists/UL.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Lists/UL.swift rename to Sources/jumpper/HTML/Tags/Lists/UL.swift diff --git a/Sources/jumpper/HTML/Elements/MainTag.swift b/Sources/jumpper/HTML/Tags/MainTag.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/MainTag.swift rename to Sources/jumpper/HTML/Tags/MainTag.swift diff --git a/Sources/jumpper/HTML/Elements/PTag.swift b/Sources/jumpper/HTML/Tags/PTag.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/PTag.swift rename to Sources/jumpper/HTML/Tags/PTag.swift diff --git a/Sources/jumpper/HTML/Elements/Pre.swift b/Sources/jumpper/HTML/Tags/Pre.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Pre.swift rename to Sources/jumpper/HTML/Tags/Pre.swift diff --git a/Sources/jumpper/HTML/Elements/Section.swift b/Sources/jumpper/HTML/Tags/Section.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Section.swift rename to Sources/jumpper/HTML/Tags/Section.swift diff --git a/Sources/jumpper/HTML/Elements/Small.swift b/Sources/jumpper/HTML/Tags/Small.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Small.swift rename to Sources/jumpper/HTML/Tags/Small.swift diff --git a/Sources/jumpper/HTML/Elements/Strong.swift b/Sources/jumpper/HTML/Tags/Strong.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Strong.swift rename to Sources/jumpper/HTML/Tags/Strong.swift diff --git a/Sources/jumpper/HTML/Elements/Table/TBody.swift b/Sources/jumpper/HTML/Tags/Table/TBody.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Table/TBody.swift rename to Sources/jumpper/HTML/Tags/Table/TBody.swift diff --git a/Sources/jumpper/HTML/Elements/Table/THead.swift b/Sources/jumpper/HTML/Tags/Table/THead.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Table/THead.swift rename to Sources/jumpper/HTML/Tags/Table/THead.swift diff --git a/Sources/jumpper/HTML/Elements/Table/Table.swift b/Sources/jumpper/HTML/Tags/Table/Table.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Table/Table.swift rename to Sources/jumpper/HTML/Tags/Table/Table.swift diff --git a/Sources/jumpper/HTML/Elements/Table/Td.swift b/Sources/jumpper/HTML/Tags/Table/Td.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Table/Td.swift rename to Sources/jumpper/HTML/Tags/Table/Td.swift diff --git a/Sources/jumpper/HTML/Elements/Table/Th.swift b/Sources/jumpper/HTML/Tags/Table/Th.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Table/Th.swift rename to Sources/jumpper/HTML/Tags/Table/Th.swift diff --git a/Sources/jumpper/HTML/Elements/Table/Tr.swift b/Sources/jumpper/HTML/Tags/Table/Tr.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Table/Tr.swift rename to Sources/jumpper/HTML/Tags/Table/Tr.swift diff --git a/Sources/jumpper/HTML/Elements/Text.swift b/Sources/jumpper/HTML/Tags/Text.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/Text.swift rename to Sources/jumpper/HTML/Tags/Text.swift diff --git a/Sources/jumpper/HTML/Elements/UTag.swift b/Sources/jumpper/HTML/Tags/UTag.swift similarity index 100% rename from Sources/jumpper/HTML/Elements/UTag.swift rename to Sources/jumpper/HTML/Tags/UTag.swift diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift index 9b80f96..13d534d 100644 --- a/Tests/LinuxMain.swift +++ b/Tests/LinuxMain.swift @@ -1,7 +1,7 @@ import XCTest import DivTests -import LinkTests +import ATagTests import BlockquoteTests import BrTests import ButtonTests @@ -22,10 +22,20 @@ import PreTests import PTests import CompositeElementsTests import FactoryElementsTests +import TextAreaTests +import BodyTests +import HeadTests +import HtmlTests +import LinkTests +import MetaTests +import ScriptTests +import TitleTests +import HeaderTests +import FooterTests var tests = [XCTestCaseEntry]() tests += DivTests.allTests() -tests += LinkTests.allTests() +tests += ATagTests.allTests() tests += BlockquoteTests.allTests() tests += BrTests.allTests() tests += ButtonTests.allTests() @@ -48,4 +58,15 @@ tests += SectionTest.allTests() tests += TextTest.allTests() tests += CompositeElementsTests.allTests() tests += FactoryElementsTests.allTests() +tests += TextareaTests.allTests() +tests += BodyTests.allTests() +tests += HeadTests.allTests() +tests += HtmlTests.allTests() +tests += LinkTests.allTests() +tests += MetaTests.allTests() +tests += ScriptTests.allTests() +tests += TitleTests.allTests() +tests += HeaderTests.allTests() +tests += FooterTests.allTests() + XCTMain(tests) diff --git a/Tests/jumpperTests/ATagTests.swift b/Tests/jumpperTests/ATagTests.swift new file mode 100644 index 0000000..7b2f7df --- /dev/null +++ b/Tests/jumpperTests/ATagTests.swift @@ -0,0 +1,23 @@ +import XCTest +@testable import jumpper + +final class ATagTests: XCTestCase { + func testElement() { + let link = A(("href", "#")) + link.add("My Link") + + XCTAssertEqual(link.getString(), "My Link") + } + + func testElementAttr() { + let link = A(("href", "#"), ("class", "class-link")) + link.add("My Link") + + XCTAssertEqual(link.getString(), "My Link") + } + + static var allTests = [ + ("testElement", testElement), + ("testElementAttr", testElementAttr) + ] +} diff --git a/Tests/jumpperTests/BodyTests.swift b/Tests/jumpperTests/BodyTests.swift new file mode 100644 index 0000000..36c52b6 --- /dev/null +++ b/Tests/jumpperTests/BodyTests.swift @@ -0,0 +1,24 @@ +import XCTest +@testable import jumpper + +final class BodyTests: XCTestCase { + func testElement() { + let element = Body() + element.add("Hello, World!") + + XCTAssertEqual(element.getString(), "Hello, World!") + } + + func testElementAttr() { + let element = Body(("class", "sameClass")) + element.add("Hello, World!") + element.addAttribute(("id", "main")) + + XCTAssertEqual(element.getString(), "Hello, World!") + } + + static var allTests = [ + ("testElement", testElement), + ("testElementAttr", testElementAttr) + ] +} diff --git a/Tests/jumpperTests/FooterTests.swift b/Tests/jumpperTests/FooterTests.swift new file mode 100644 index 0000000..4c03f26 --- /dev/null +++ b/Tests/jumpperTests/FooterTests.swift @@ -0,0 +1,22 @@ +import XCTest +@testable import jumpper + +final class FooterTests: XCTestCase { + func testElement() { + let element = Footer() + + XCTAssertEqual(element.getString(), "") + } + + func testElementAttr() { + let element = Footer(("class", "sameClass")) + element.addAttribute(("id", "footer")) + + XCTAssertEqual(element.getString(), "") + } + + static var allTests = [ + ("testElement", testElement), + ("testElementAttr", testElementAttr) + ] +} diff --git a/Tests/jumpperTests/HeadTests.swift b/Tests/jumpperTests/HeadTests.swift new file mode 100644 index 0000000..615f071 --- /dev/null +++ b/Tests/jumpperTests/HeadTests.swift @@ -0,0 +1,23 @@ +import XCTest +@testable import jumpper + +final class HeadTests: XCTestCase { + func testElement() { + let element = Head() + + XCTAssertEqual(element.getString(), "") + } + + func testElementAttr() { + let element = Head(("class", "sameClass")) + element.addAttribute(("id", "head")) + element.add(Title("My Site")) + + XCTAssertEqual(element.getString(), "
+
+
+ CompositeElements
+
+ Undocumented
+ + See more +Swift
+public final class CompositeElements : ElementProtocol
+
+
@@ -705,6 +766,293 @@ Declaration
+
+
+ Body
+
+ Body tag element class
+let body = Body()
+body.add(/* Any Element
+
+
+ See more
+ Swift
+public final class Body : ContainerElementBase
+
+
+
+
+ Doctype
+
+ DOCTYPE tag element class
+let doctype = Doctype()
+doctype.getString() // or doctype.generate()
+
+
+ See more
+ Swift
+public final class Doctype : ElementProtocol
+
+
+
+
+ Head
+
+ Head tag element class
+let head = Head()
+head.add(/* Any Element
+
+
+ See more
+ Swift
+public final class Head : ContainerElementBase
+
+
+
+
+ Html
+
+ Html tag element class
+ +### Usage Example: ###
+ let html = Html()
+ html.add(/* Any Element
+
+
+ See more
+ Swift
+public final class Html : ContainerElementBase
+
+
+
+
+ LinkStylesheet
+
+
+
+
+ Link
+
+ link tag element class
+let linkTag = Link("/styles/milligram.min.css", attributes: ("rel", "stylesheet"))
+
+
+ See more
+ Swift
+public class Link : GenericElement
+
+
+
+
+ Meta
+
+ Swift
+public class Meta : GenericElement
+
+
+
+
+ Script
+
+ This class define a Script element
+let script = Script()
+script.add("var myJsVar = 1")
+
+let script = Script(("src","myScript.js"))
+
+
+ See more
+ Swift
+public final class Script : GenericElement
+
+
+
+
+ Title
+
+ Swift
+public final class Title : ContainerElementBase
+
+
@@ -780,6 +1128,38 @@ Declaration
+
+
+ Footer
+
+ footer tag element class
+let footer = Footer()
+footer.add(/* Any Element
+
+
+ See more
+ Swift
+public final class Footer : ContainerElementBase
+
+
@@ -1096,6 +1476,38 @@ Declaration
+
+
+ Header
+
+ header tag element class
+let header = Header()
+header.add(/* Any Element
+
+
+ See more
+ Swift
+public final class Header : ContainerElementBase
+
+
@@ -1336,7 +1748,8 @@ Declaration
This class define a Textarea element
### Usage Example: ###
- Textarea(("placeholder", "Hi Mike …"), ("id", "commentField"))
+ let textArea = Textarea(("placeholder", "Hi Mike …"), ("id", "commentField"))
+ textArea.add("My Text")
See more
@@ -2017,40 +2430,12 @@ Declaration
-
-
- CompositeElements
-
- Undocumented
- - See more -Swift
-public final class CompositeElements : ElementProtocol
-
-