mirror of
https://github.com/MillironX/Kelpie.jl.git
synced 2024-11-14 21:43:10 +00:00
Convert array checking to argument splatting
Signed-off-by: Thomas A. Christensen II <25492070+MillironX@users.noreply.github.com>
This commit is contained in:
parent
afafae2769
commit
58244fcb5d
1 changed files with 19 additions and 25 deletions
|
@ -61,10 +61,10 @@ const HTML_ELEMENTS = [
|
||||||
]
|
]
|
||||||
|
|
||||||
"""
|
"""
|
||||||
link_or_text!(node, content)
|
link_or_text!(node, content...)
|
||||||
|
|
||||||
Converts `content` to an `EzXML.TextNode` if it isn't already an `EzXML.Node` and links it
|
Converts each `content` to an `EzXML.TextNode` if it isn't already an `EzXML.Node` and links
|
||||||
to `node`. Will link all nodes in `content` if content is a vector.
|
it to `node`.
|
||||||
|
|
||||||
```jldoctest
|
```jldoctest
|
||||||
julia> import EzXML: ElementNode, prettyprint; import Kelpie: link_or_text!
|
julia> import EzXML: ElementNode, prettyprint; import Kelpie: link_or_text!
|
||||||
|
@ -77,30 +77,24 @@ julia> prettyprint(link_or_text!(ElementNode("div"), ElementNode("br")))
|
||||||
julia> prettyprint(link_or_text!(ElementNode("h1"), "Kelpie.jl"))
|
julia> prettyprint(link_or_text!(ElementNode("h1"), "Kelpie.jl"))
|
||||||
<h1>Kelpie.jl</h1>
|
<h1>Kelpie.jl</h1>
|
||||||
|
|
||||||
julia> prettyprint(link_or_text!(ElementNode("div"), ["The end", ElementNode("hr")]))
|
julia> prettyprint(link_or_text!(ElementNode("div"), "The end", ElementNode("hr")))
|
||||||
<div>The end<hr/></div>
|
<div>The end<hr/></div>
|
||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
function link_or_text!(node, content)
|
function link_or_text!(node, content...)
|
||||||
if typeof(content) <: EzXML.Node
|
|
||||||
link!(node, content)
|
|
||||||
else
|
|
||||||
link!(node, EzXML.TextNode(string(content)))
|
|
||||||
end #if
|
|
||||||
|
|
||||||
return node
|
|
||||||
end #function
|
|
||||||
|
|
||||||
function link_or_text!(node, content::AbstractArray)
|
|
||||||
for con in content
|
for con in content
|
||||||
link_or_text!(node, con)
|
if typeof(con) <: EzXML.Node
|
||||||
|
link!(node, con)
|
||||||
|
else
|
||||||
|
link!(node, EzXML.TextNode(string(con)))
|
||||||
|
end #if
|
||||||
end #for
|
end #for
|
||||||
|
|
||||||
return node
|
return node
|
||||||
end #function
|
end #function
|
||||||
|
|
||||||
"""
|
"""
|
||||||
html_element(name, content=nothing; kwargs...)
|
html_element(name, content...=nothing; kwargs...)
|
||||||
|
|
||||||
Creates a new `EzXML.Node` with name `name`, containing `content`, and with attributes
|
Creates a new `EzXML.Node` with name `name`, containing `content`, and with attributes
|
||||||
specified by `kwargs`.
|
specified by `kwargs`.
|
||||||
|
@ -117,7 +111,7 @@ julia> prettyprint(html_element("span", "MillironX"; class="label-primary"))
|
||||||
<span class="label-primary">MillironX</span>
|
<span class="label-primary">MillironX</span>
|
||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
function html_element(name::AbstractString, content=nothing; kwargs...)
|
function html_element(name::AbstractString, content...=nothing; kwargs...)
|
||||||
el = EzXML.ElementNode(name)
|
el = EzXML.ElementNode(name)
|
||||||
|
|
||||||
for (key, value) in kwargs
|
for (key, value) in kwargs
|
||||||
|
@ -125,34 +119,34 @@ function html_element(name::AbstractString, content=nothing; kwargs...)
|
||||||
end #for
|
end #for
|
||||||
|
|
||||||
if !isnothing(content)
|
if !isnothing(content)
|
||||||
link_or_text!(el, content)
|
link_or_text!(el, content...)
|
||||||
end #if
|
end #if
|
||||||
|
|
||||||
return el
|
return el
|
||||||
end #function
|
end #function
|
||||||
|
|
||||||
"""
|
"""
|
||||||
html(content)
|
html(content...)
|
||||||
|
|
||||||
Creates a new HTML document filled with `content`.
|
Creates a new HTML document filled with `content`.
|
||||||
"""
|
"""
|
||||||
function html(content)
|
function html(content...)
|
||||||
doc = EzXML.HTMLDocumentNode(nothing, nothing)
|
doc = EzXML.HTMLDocumentNode(nothing, nothing)
|
||||||
link_or_text!(doc, content)
|
link_or_text!(doc, content...)
|
||||||
return doc
|
return doc
|
||||||
end #function
|
end #function
|
||||||
|
|
||||||
for symbol in HTML_ELEMENTS
|
for symbol in HTML_ELEMENTS
|
||||||
name = string(symbol)
|
name = string(symbol)
|
||||||
|
|
||||||
@eval function $symbol(content=nothing; kwargs...)
|
@eval function $symbol(content...=nothing; kwargs...)
|
||||||
return html_element($name, content; kwargs...)
|
return html_element($name, content...; kwargs...)
|
||||||
end #function
|
end #function
|
||||||
|
|
||||||
@eval export $symbol
|
@eval export $symbol
|
||||||
end
|
end
|
||||||
|
|
||||||
function html_div(content=nothing; kwargs...)
|
function html_div(content...=nothing; kwargs...)
|
||||||
return html_element("div", content; kwargs...)
|
return html_element("div", content; kwargs...)
|
||||||
end #function
|
end #function
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue