Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #6 from jumpper/enhancement/PatronizeClasses
Browse files Browse the repository at this point in the history
Adjusts and tests
  • Loading branch information
micheltlutz authored Jul 11, 2020
2 parents 440f6bf + 831fc19 commit 75b3dad
Show file tree
Hide file tree
Showing 76 changed files with 974 additions and 388 deletions.
2 changes: 2 additions & 0 deletions .hound.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
swiftlint:
config_file: .swiftlint.yml
62 changes: 62 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
disabled_rules: # rule identifiers to exclude from running
- identifier_name
- large_tuple
- trailing_whitespace
- type_body_length
- cyclomatic_complexity
- function_parameter_count

excluded: # paths to ignore during linting. Takes precedence over `included`.
- Carthage
- Pods

type_name:
min_length: 1
max_length: 40

identifier_name:
min_length: # only min_length
error: 3 # only error
excluded: # excluded via string array
- id
- i
- ok
- x
- y
- URL
- GlobalAPIKey
- yes
- no
- A
- H1
- H2
- H3
- H4
- H5
- H6
- UL
- LI
- OL
- DD
- DL
- DT
- Tr
- Td
- Th
- Em
- Em



line_length:
warning: 150
error: 300
ignores_comments: true
ignores_urls: true
ignores_function_declarations: true
### works up until this config rule
ignores_interpolated_strings: true

function_body_length:
warning: 60
error: 80
6 changes: 3 additions & 3 deletions Sources/jumpper/HTML/Base/Attribute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ public typealias AttributeType = (String, String?)

/// This class is responsible for managing attributes of HTML elements
public final class Attribute {
/// Contains a array of AttributeType
/// Contains a array of AttributeType. Default is `[]`
private var attributes: [AttributeType] = []
// MARK: - Initialization
/// Init with array of AttributeType
/// - Parameter: **attributes** `[AttributeType]`
/// - Parameter attributes: `[AttributeType]`
public init(_ attributes: [AttributeType]){
self.attributes = attributes
}

// MARK: - Functions

/// This method add a new single attribute
/// - Parameter: **attr** `AttributeType`
/// - Parameter attr: `AttributeType`
public func add(_ attr: AttributeType){
attributes.append(attr)
}
Expand Down
37 changes: 37 additions & 0 deletions Sources/jumpper/HTML/Base/ContainerElementBase.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// ContainerElementBase.swift
//
//
// Created by Michel Anderson Lutz Teixeira on 10/07/20.
//

import Foundation

/// Define a base class to containered tag elements
public class ContainerElementBase: GenericElement {
///Override container element defaults is `true`
override var container: Bool {
get {
return true
}
}
///This method append a new element in objects list
/// - Parameter element: Generic Type `ElementProtocol` or `String`
func add<T>(_ element: T) {
if let textElement = element as? String {
let text = factoryTextWith(textElement)

objects.append(text)
} else {
guard let genericElement = element as? ElementProtocol else { return }

objects.append(genericElement)
}
}
/// This method create a `Text` element to user when element T String is passed on add method
/// - Parameter text: `String` to create `Text` element
/// - Returns: `Text` Element with string passed
private func factoryTextWith(_ text: String) -> Text {
return Text(text)
}
}
21 changes: 14 additions & 7 deletions Sources/jumpper/HTML/Base/GenericElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,32 @@ import Foundation
public class GenericElement: ElementProtocol {
///Contains a array with `AttributeType`
public var attributes: [AttributeType] = []
///Contains `String` with tag element
///Contains `String` with tag element. Default is `""`
private(set) var tag: String = ""
///Define if element is block tag or line tag
///Define if element is block tag or line tag. Default is `false`
private(set) var container: Bool = false
///Define if element is a form element
///Define if element is a form element. Default is `false`
private(set) var formElement: Bool = false
///Contains a array of elements
public var objects: [ElementProtocol] = [ElementProtocol]()

// MARK: - Initialization
/// Init with array of AttributeType
/// - Parameter: **attributes** `AttributeType...` CVarArg
///
/// - Usage: `init(("class", "myclass"), ("id", "myId"))`
///
/// - Parameter attributes: `AttributeType...` CVarArg
public init(_ attributes: AttributeType...){
self.attributes = attributes
}
/// Init with array of AttributeType
/// - Parameter: **attributes** `[AttributeType]`
/// - Parameter attributes: `[AttributeType]`
public init(_ attributes: [AttributeType]){
self.attributes = attributes
}
// MARK: - Functions
/// This method add a new single attribute
/// - Parameter: **attr** `AttributeType`
/// - Parameter attr: `AttributeType`
public func addAttribute(_ attr: AttributeType) {
attributes.append(attr)
}
Expand Down Expand Up @@ -78,7 +81,11 @@ public class GenericElement: ElementProtocol {
code += obj.getString()
}
}
code += closeTag()

if container {
code += closeTag()
}

return code
}

Expand Down
16 changes: 8 additions & 8 deletions Sources/jumpper/HTML/Base/InputElementBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@

import Foundation

/// This is a Base class for Input Elements
public class InputElementBase: GenericElement {
///Override tag element for input elements. Default is `input`
override var tag: String {
get {
return "input"
}
}

override var container: Bool {
get {
return false
}
}

///Override formElement info input elements are form element for default is `true`
override var formElement: Bool {
get {
return true
}
}

// MARK: - Initialization
/// Default initializer input element
/// - Parameters:
/// - value: This is a value for input **value** `String`
/// - type: This is a type for input **type** `String`
public init(_ value: String, type: String) {
super.init()

Expand Down
8 changes: 7 additions & 1 deletion Sources/jumpper/HTML/Base/TableColumnBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@

import Foundation

/// This is a Base class for Table Column Elements
public class TableColumnBase: GenericElement {
///Override container element for table row elements defaults is `true`
override var container: Bool {
get {
return true
}
}

///This method append a new element in objects list
/// Parameter element: Generic Type `ElementProtocol` or `String`
public func add<T>(_ element: T) {
if let textElement = element as? String {
let text = factoryTextWith(textElement)
Expand All @@ -43,6 +46,9 @@ public class TableColumnBase: GenericElement {
}
}

/// This method create a `Text` element to user when element T String is passed on add method
/// Parameter text: `String` to create `Text` element
/// Returns: `Text` Element with string passed
private func factoryTextWith(_ text: String) -> Text {
return Text(text)
}
Expand Down
10 changes: 6 additions & 4 deletions Sources/jumpper/HTML/Base/TableRowBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@

import Foundation

/// This is a Base class for Table Row Elements
public class TableRowBase: GenericElement {
///Override container element for table row elements defaults is `true`
override var container: Bool {
get {
return true
}
}

public func add<T>(_ element: T) {
guard let genericElement = element as? ElementProtocol else { return }

objects.append(genericElement)
///This method append a new element in objects list
///- Parameter element: `ElementProtocol`
public func add(_ element: ElementProtocol) {
objects.append(element)
}
}
20 changes: 14 additions & 6 deletions Sources/jumpper/HTML/Base/TypographyElementBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,24 @@

import Foundation

/// This is a Base class for Typography Elements
public class TypographyElementBase: GenericElement {
public init<T>(_ element: T) {
super.init()

self.add(element)
}

///Override container element for table row elements defaults is `true`
override var container: Bool {
get {
return true
}
}
///Initialization with Generic Type
/// - Parameter element: Generic Type `ElementProtocol` or `String`
public init<T>(_ element: T) {
super.init()

self.add(element)
}

///This method append a new element in objects list
/// - Parameter element: Generic Type `ElementProtocol` or `String`
public func add<T>(_ element: T) {
if let textElement = element as? String {
let text = factoryTextWith(textElement)
Expand All @@ -49,6 +54,9 @@ public class TypographyElementBase: GenericElement {
}
}

/// This method create a `Text` element to user when element T String is passed on add method
/// - Parameter text: `String` to create `Text` element
/// - Returns: `Text` Element with string passed
private func factoryTextWith(_ text: String) -> Text {
return Text(text)
}
Expand Down
26 changes: 3 additions & 23 deletions Sources/jumpper/HTML/Elements/ATag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,12 @@

import Foundation

public final class Link: GenericElement {
/// A tag element class
public final class A: ContainerElementBase {
///Override tag element for element. Default is `a`
override var tag: String {
get {
return "a"
}
}

override var container: Bool {
get {
return true
}
}

public func add<T>(_ element: T) {
if let textElement = element as? String {
let text = factoryTextWith(textElement)

objects.append(text)
} else {
guard let genericElement = element as? ElementProtocol else { return }

objects.append(genericElement)
}
}

private func factoryTextWith(_ text: String) -> Text {
return Text(text)
}
}
26 changes: 3 additions & 23 deletions Sources/jumpper/HTML/Elements/Blockquote.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,12 @@

import Foundation

public final class Blockquote: GenericElement {
///Blockquote tag element class
public final class Blockquote: ContainerElementBase {
///Override tag element for element. Default is `blockquote`
override var tag: String {
get {
return "blockquote"
}
}

override var container: Bool {
get {
return true
}
}

public func add<T>(_ element: T) {
if let textElement = element as? String {
let text = factoryTextWith(textElement)

objects.append(text)
} else {
guard let genericElement = element as? ElementProtocol else { return }

objects.append(genericElement)
}
}

private func factoryTextWith(_ text: String) -> Text {
return Text(text)
}
}
8 changes: 2 additions & 6 deletions Sources/jumpper/HTML/Elements/Br.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,12 @@

import Foundation

///Br tag element class
public final class Br: GenericElement {
///Override tag element for element. Default is `br`
override var tag: String {
get {
return "br"
}
}

override var container: Bool {
get {
return false
}
}
}
Loading

0 comments on commit 75b3dad

Please sign in to comment.