Skip to content
Permalink
Browse files

Merge remote-tracking branch 'upstream/master'

  • Loading branch information...
mbarnach committed Jun 19, 2019
2 parents 36fba16 + f7db095 commit 4515e70effba13534f2c0a94de46febce9cdb9d7
@@ -0,0 +1,76 @@
# Vaux Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at david@okun.io. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq
@@ -0,0 +1,3 @@
**Note**: This document will likely grow over time.

If you are reading this, then thank you for considering contributing to Vaux!
@@ -6,11 +6,11 @@ import PackageDescription
let package = Package(
name: "Vaux",
products: [
.library(name: "Vaux", targets: ["Vaux"]),
.library(name: "Vaux", targets: ["Vaux"])
],
dependencies: [],
targets: [
.target(name: "Vaux", dependencies: []),
.testTarget(name: "VauxTests", dependencies: ["Vaux"]),
.testTarget(name: "VauxTests", dependencies: ["Vaux"])
]
)
@@ -7,17 +7,16 @@
import Foundation


extension HTML {

/// Allows you to specify an `align` attribute at the end of a HTML element. For example, if you specify `div { "some text" }.align(.center)`, then the rendered HTML will be `<div align="center">some text</div>`.
/// - Note: Alignment can affect multiple different elements with different behavior based on their containing elements. Best practice is to offload this to the associated CSS file.
/// - Parameters:
/// - value: The value that will be associated with the `align` tag.
public func alignment(_ value: Alignment) -> HTML {
return attr("align", value.rawValue)
}

/// Allows you to specify any attribute at the end of a HTML element. For example, if you specify `div { "some text" }.attr("tag", "123")`, then the rendered HTML will be `<div tag="123">some text</div>`.
/// - Parameters:
/// - key: The tag for the attribute that will be added to this HTML node
@@ -26,7 +25,7 @@ extension HTML {
return AttributedNode(attribute: Attribute(key: key, value: value),
child: self)
}

/// Allows you to specify a `bgcolor` attribute at the end of a HTML element. For example, if you specify `div { "some text" }.backgroundColor("555555")`, then the rendered HTML will be `<div bgcolor="555555">some text</div>`.
/// - Note: Background color is generally better to set in your associated CSS file. The hex code must be a 6 character hexadecimal string.
/// - Warning: This will eventually be refactored to allow for use of specific colors that convert to hex codes via an enum. UIColor() must not be used, which would limit this library to iOS only.
@@ -35,15 +34,15 @@ extension HTML {
public func backgroundColor(_ hexCode: String) -> HTML {
return attr("bgcolor", hexCode)
}

/// Allows you to specify a `class` attribute at the end of a HTML element. For example, if you specify `div { "some text" }.class("menu")`, then the rendered HTML will be `<div class="menu">some text</div>`.
/// - Note: In a HTML document, classes can be reused many times, and are not treated uniquely like ids.
/// - Parameters:
/// - value: The value that will be associated with the `class` tag.
public func `class`(_ value: String) -> HTML {
return attr("class", value)
}

/// Allows you to specify a `color` attribute at the end of a HTML element. For example, if you specify `span { "some text" }.color("555555")`, then the rendered HTML will be `<span color="555555">some text</span>`.
/// - Note: Color, mostly used with text, is generally better to set in your associated CSS file. The hex code must be a 6 character hexadecimal string.
/// - Warning: This will eventually be refactored to allow for use of specific colors that convert to hex codes via an enum. UIColor() must not be used, which would limit this library to iOS only.
@@ -52,39 +51,39 @@ extension HTML {
public func color(_ hexCode: String) -> HTML {
return attr("color", hexCode)
}

/// Allows you to specify a `colspan` attribute at the end of a HTML element. For example, if you specify `tableData { "some text" }.columnSpan(4)`, then the rendered HTML will be `<td colspan="4">some text</td>`.
/// - Note: In a HTML table, colspan is used to define how many columns a particular element should go across. This is easier to see when you have clearly defined borders and cell padding for your table.
/// - Parameters:
/// - value: The value that will be associated with the `colspan` tag.
public func columnSpan(_ value: Int) -> HTML {
return attr("colspan", String(value))
}

/// Allows you to specify a `id` attribute at the end of a HTML element. For example, if you specify `div { "some text" }.id("12345")`, then the rendered HTML will be `<div id="12345">some text</div>`.
/// - Warning: In a HTML document, IDs must be considered unique, and cannot be reused.
/// - Parameters:
/// - value: The value that will be associated with the `id` tag.
public func `id`(_ value: String) -> HTML {
return attr("id", value)
}

/// Allows you to specify a `rowspan` attribute at the end of a HTML element. For example, if you specify `tableData { "some text" }.rowSpan(4)`, then the rendered HTML will be `<td rowspan="4">some text</td>`.
/// - Note: In a HTML table, rowspan is used to define how many rows a particular element should go across. This is easier to see when you have clearly defined borders and cell padding for your table.
/// - Parameters:
/// - value: The value that will be associated with the `rowspan` tag.
public func rowSpan(_ value: Int) -> HTML {
return attr("rowspan", String(value))
}

/// Allows you to specify a `scope` attribute at the end of a HTML element. For example, if you specify `tableData { "some text" }.scope(.row)`, then the rendered HTML will be `<td scope="row">some text</td>`.
/// - Note: The scope attribute identifies whether a cell is a header for a column, row, or group of columns or rows.
/// - Parameters:
/// - value: The value that will be associated with the `scope` tag.
public func scope(_ value: Scope) -> HTML {
return attr("scope", value.rawValue)
}

/// Allows you to specify inline CSS (cascading style sheets) style for a HTML element.
/// - Note: Inline CSS style on HTML elements is often times frowned upon. It is recommended to instead use a link to a separate stylesheet that is defined on its own. You can do this with the `linkStylesheet()` builder.
/// - Example: This:
@@ -111,7 +110,7 @@ extension HTML {
}
return attr("style", inlineStyle)
}

/// Allow you to specify a media type for a HTML element.
///
/// This could be used for link, script, input, and any other tags which support it.
@@ -128,7 +127,7 @@ extension HTML {
public func type(_ mime: String) -> HTML {
return attr("type", mime)
}

public func type(_ mime: MIME) -> HTML {
return attr("type", mime.rawValue)
}
@@ -24,5 +24,5 @@ extension VauxFileHelperError: LocalizedError {
}

enum VauxError: Error {

}
@@ -19,7 +19,7 @@ public class VauxFileHelper {
manager.createFile(atPath: "\(file.path)\(file.name).html", contents: nil, attributes: nil)
return URL(fileURLWithPath: "\(file.path)\(file.name).html")
}

/// Deletes file with given name at given path.
public class func deleteFile(_ file: Filepath) throws {
let manager = FileManager()
@@ -29,7 +29,7 @@ public class VauxFileHelper {
throw error
}
}

/// Returns content from file as `String`, usually effective for testing.
public class func getRenderedContent(from file: Filepath) throws -> String {
let manager = FileManager()
@@ -11,28 +11,28 @@ import Foundation
/// A function builder that provides transformations for control flow concepts into HTML components.
@_functionBuilder
public struct HTMLBuilder {

/// If there are no children in an HTMLBuilder closure, then return an empty `MultiNode`
public static func buildBlock() -> HTML {
return MultiNode(children: [])
}

/// Allows you to return one child directly.
public static func buildBlock(_ content: HTML) -> HTML {
return content
}

/// Variadic function that allows you to return all children as a `MultiNode`.
public static func buildBlock(_ content: HTML...) -> HTML {
return MultiNode(children: content)
}

/// Return an empty `MultiNode` or the wrapped value.
public static func buildIf(_ content: HTML?) -> HTML {
if let content = content { return content }
return MultiNode(children: [])
}

/// If the condition of an `if` statement is `true`, then this method will
/// be called and the result of evaluating the expressions in the `true` block
/// will be returned unmodified.
@@ -44,7 +44,7 @@ public struct HTMLBuilder {
public static func buildEither(first: HTML) -> HTML {
return first
}

/// If the condition of an `if` statement is `false`, then this method will
/// be called and the result of evaluating the expressions in the `false`
/// block will be returned unmodified.
@@ -16,7 +16,7 @@ extension String: HTML {
stream.write("\n")
}
}

public func getTag() -> String? {
return nil
}
@@ -28,7 +28,7 @@ extension Int: HTML {
let string = String(self)
string.renderAsHTML(into: stream, attributes: attributes)
}

public func getTag() -> String? {
return nil
}
@@ -40,7 +40,7 @@ extension Double: HTML {
let string = String(self)
string.renderAsHTML(into: stream, attributes: attributes)
}

public func getTag() -> String? {
return nil
}
@@ -52,7 +52,7 @@ extension Float: HTML {
let string = String(self)
string.renderAsHTML(into: stream, attributes: attributes)
}

public func getTag() -> String? {
return nil
}
@@ -66,7 +66,7 @@ extension Optional: HTML where Wrapped: HTML {
html.renderAsHTML(into: stream, attributes: attributes)
}
}

public func getTag() -> String? {
if let html = self {
return html.getTag()
@@ -13,38 +13,38 @@ struct HTMLNode: HTML {
var tag: String
var child: HTML?
var inline = false

func getTag() -> String? {
return self.tag
}

func renderAsHTML(into stream: HTMLOutputStream, attributes: [Attribute]) {
/// Open the tag
stream.writeIndent()
stream.write("<")
stream.write(tag)

/// Append the tag with all attributes.
for attr in attributes {
stream.write(" ")
stream.write(attr.key)

/// If an attribute does not have a value, do not add the equal sign.
if let value = attr.value {
stream.write("=")
stream.writeDoubleQuoted(value)
}
}

/// If the element has no children, close it on the same line.
guard let child = child else {
stream.write("/>")
stream.writeNewline()
return
}

stream.write(">")

/// Check to see if the tag being streamed should write its child and close it on the same line
if inline {
if let childString = child as? String {
@@ -83,11 +83,11 @@ public struct StyleAttribute {
struct AttributedNode: HTML {
let attribute: Attribute
let child: HTML

func getTag() -> String? {
return child.getTag()
}

func renderAsHTML(into stream: HTMLOutputStream, attributes: [Attribute]) {
var fullAttrs = attributes
fullAttrs.append(attribute)
@@ -98,16 +98,15 @@ struct AttributedNode: HTML {
/// MultiNode is an implementation detail for representing multiple sequenced
/// HTML nodes
struct MultiNode: HTML {

func getTag() -> String? {
return nil
}

let children: [HTML]
func renderAsHTML(into stream: HTMLOutputStream, attributes: [Attribute]) {
for child in children {
child.renderAsHTML(into: stream, attributes: attributes)
}
}
}

0 comments on commit 4515e70

Please sign in to comment.
You can’t perform that action at this time.