Skip to content

Commit

Permalink
v0.27.0 - support for custom HTML elements
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian committed Feb 28, 2020
1 parent 4063116 commit e8ea18e
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Genie"
uuid = "c43c736e-a2d1-11e8-161f-af95117fbd1e"
authors = ["Adrian Salceanu <[email protected]>"]
version = "0.26.2"
version = "0.27.0"

[deps]
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Core genie configuration / settings functionality.
"""
module Configuration

const GENIE_VERSION = v"0.26.2"
const GENIE_VERSION = v"0.27.0"

import Logging
import Genie
Expand Down
7 changes: 6 additions & 1 deletion src/renderers/Html.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ const NORMAL_ELEMENTS = [ :html, :head, :body, :title, :style, :address, :articl
:q, :rp, :rt, :rtc, :ruby, :s, :samp, :small, :spam, :strong, :sub, :sup, :time,
:u, :var, :wrb, :audio, :map, :void, :embed, :object, :canvas, :noscript, :script,
:del, :ins, :caption, :col, :colgroup, :table, :tbody, :td, :tfoot, :th, :thead, :tr,
:button, :datalist, :fieldset, :form, :label, :legend, :meter, :optgroup, :option,
:button, :datalist, :fieldset, :label, :legend, :meter,
:output, :progress, :select, :textarea, :details, :dialog, :menu, :menuitem, :summary,
:slot, :template, :blockquote, :center]
const VOID_ELEMENTS = [:base, :link, :meta, :hr, :br, :area, :img, :track, :param, :source, :input]
const CUSTOM_ELEMENTS = [:form, :select]
const BOOL_ATTRIBUTES = [:checked, :disabled, :selected]

export HTMLString, html
Expand Down Expand Up @@ -625,6 +626,10 @@ function register_elements() :: Nothing
register_void_element(elem)
end

for elem in CUSTOM_ELEMENTS
Core.eval(@__MODULE__, """include("html/$elem.jl")""" |> Meta.parse)
end

nothing
end

Expand Down
17 changes: 17 additions & 0 deletions src/renderers/html/form.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function form(f::Function, args...; attrs...) :: HTMLString
normal_element(f, "form", [args...], attr(attrs...))
end

function form(children::Union{String,Vector{String}} = "", args...; attrs...) :: HTMLString
normal_element(children, "form", [args...], attr(attrs...))
end

function attr(attrs...)
attrs = Pair{Symbol,Any}[attrs...]

for p in attrs
p[1] == :enctype && return attrs
end

push!(attrs, :enctype => "multipart/form-data")
end
39 changes: 39 additions & 0 deletions src/renderers/html/select.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Base.@kwdef struct option
disabled::Bool = false
selected::Bool = false
value::String = ""
text::String = value
end


function Base.string(o::option) :: HTMLString
attributes = String[]

o.disabled && push!(attributes, "disabled")
o.selected && push!(attributes, "selected")
push!(attributes, "value=\"$(o.value)\"")

"<option $(join(attributes, " "))>$(o.text)</option>"
end


function select(options::Vector{option}, args...; attrs...) :: HTMLString
children = String[]

for o in options
push!(children, string(o))
end

normal_element(children, "select", [args...], Pair{Symbol,Any}[attrs...])
end


function optgroup(options::Vector{option}, args...; attrs...) :: HTMLString
children = String[]

for o in options
push!(children, string(o))
end

normal_element(children, "optgroup", [args...], Pair{Symbol,Any}[attrs...])
end

2 comments on commit e8ea18e

@essenciary
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/10257

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.27.0 -m "<description of version>" e8ea18e9b7e4b2d6c84f76d1741733d12b10eba1
git push origin v0.27.0

Please sign in to comment.