ToolipsSession.ToolipsSession — ModuleCreated in June, 2022 by chifi - an open source software dynasty. by team toolips This software is MIT-licensed.
ToolipsSession
Extension for:
- Toolips This module provides the capability to make web-pages interactive by simply
adding the Session extension to your ServerTemplate before starting. There are also methods contained for modifying Servables.
Module Composition
ToolipsSession.ComponentModifier — TypeComponentModifier
- rootc::Dict
- f::Function
- changes::Vector{String} The ComponentModifier stores a dictionary of components that can be indexed
using the Components themselves or their names. Methods push strings to the changes Dict. This is passed as an argument into the function provided to the on functions via the do syntax. Indexing will yield a given Component, setting the index to a pair will modify said component.
example
route("/") do c::Connection
mydiv = divider("mydiv", align = "center")
on(c, mydiv, "click") do cm::ComponentModifier
if cm[mydiv]["align"] == "center"
cm[mydiv] = "align" => "left"
else
cm[mydiv] = "align" => "center"
end
end
write!(c, mydiv)
endconstructors
ComponentModifier(html::String)
ToolipsSession.Session — TypeSession
- type::Vector{Symbol}
- f::Function
- active_routes::Vector{String}
- events::Dict{String, Pair{String, Function}}
- iptable::Dict{String, Dates.DateTime}
- timeout::Integer Provides session capabilities and full-stack interactivity to a toolips server.
Note that the route you want to be interactive must be in active_routes!
example
exts = [Session()]
st = ServerTemplate(extensions = exts)
server = st.start()
route!(server, "/") do c::Connection
myp = p("myp", text = "welcome to my site")
on(c, myp, "click") do cm::ComponentModifier
if cm[myp][:text] == "welcome to my site"
set_text!(cm, myp, "unwelcome to my site")
else
set_text!(cm, myp, "welcome to my site")
end
end
write!(c, myp)
endconstructors
Session(activeroutes::Vector{String} = ["/"]; transitionduration::AbstractFloat = 0.5, transition::String = "ease-in-out", timeout::Integer = 30 )
ToolipsSession.TimedTrigger — TypeTimedTrigger
- time::Integer
- f::Function Creates a timer which will post to the function f.
example
route("/") do c::Connection
myp = p("hello", text = "wow")
timer = TimedTrigger(5000) do cm::ComponentModifier
if cm[myp][:text] == "wow"
c[:Logger].log("wow.")
end
end
write!(c, myp)
write!(c, timer)
endconstructors
TimedTrigger(func::Function, time::Integer)
Base.append! — MethodSession Interface
append!(cm::ComponentModifier, s::Servable, child::Servable) -> _
Appends child to the servable s.
example
Base.append! — MethodSession Interface
append!(cm::ComponentModifier, name::String, child::Servable) -> _
Appends child to the servable s by name.
example
Base.getindex — MethodSession Interface
getindex(cm::ComponentModifier, s::Component) -> ::Component
Gets the Component s from the ComponentModifier cm.
example
on(c, mydiv, "click") do cm::ComponentModifier
mydiv = cm[mydiv]
mydivalignment = mydiv["align"]
endBase.getindex — MethodSession Interface
getindex(cm::ComponentModifier, s::String) -> ::Component
Gets the a Component by name from cm.
example
on(c, mydiv, "click") do cm::ComponentModifier
mydiv = cm["mydiv"]
mydivalignment = mydiv["align"]
endBase.getindex — MethodSession Interface
getindex(m::Session, s::AbstractString) -> ::Vector{Pair}
Gets a session's refs by ip.
example
route("/") do c::Connection
c[:Session][getip(c)]
endBase.setindex! — MethodSession Interface
setindex!(cm::ComponentModifier, p::Pair, s::Component) -> _
Sets the property from p[1] to p[2] on the served Component s.
example
on(c, mydiv, "click") do cm::ComponentModifier
if cm[mydiv]["align"] == "center"
cm[mydiv] = "align" => "left"
else
cm[mydiv] = "align" => "center"
end
endBase.setindex! — MethodSession Interface
setindex!(cm::ComponentModifier, p::Pair, s::String) -> _
Sets the property from p[1] to p[2] on the served with name s.
example
on(c, mydiv, "click") do cm::ComponentModifier
if cm["mydiv"]["align"] == "center"
cm["mydiv"] = "align" => "left"
else
cm["mydiv"] = "align" => "center"
end
endToolips.animate! — MethodSession Interface
animate!(cm::ComponentModifier, s::Servable, a::Animation; play::Bool) -> _
Updates the servable s's animation with the animation a.
example
s = divider("mydiv")
a = Animation("fade")
a[:from] = "opacity" => "0%"
a[:to] = "opacity" => "100%"
# where c is the Connection.
on(c, s, "click") do cm::ComponentModifier
animate!(cm, s, a)
endToolips.animate! — MethodSession Interface
animate!(cm::ComponentModifier, s::String, a::Animation; play::Bool) -> _
Updates the servable with name s's animation with the animation a.
example
``` s = divider("mydiv") a = Animation("fade") a[:from] = "opacity" => "0%" a[:to] = "opacity" => "100%"
where c is the Connection.
on(c, s, "click") do cm::ComponentModifier animate!(cm, s, a) end ```
Toolips.kill! — MethodSession Interface
kill!(c::Connection)
Kills a Connection's saved events.
example
Toolips.style! — MethodSession Interface
style!(cm::ComponentModifier, s::Servable, p::Pair) -> _
Styles the Servable s with the properties and values in p.
example
Toolips.style! — MethodSession Interface
style!(cm::ComponentModifier, s::Servable, style::Style) -> _
Changes the style class of s to the style p. Note – styles must be already written to the Connection prior.
example
Toolips.style! — MethodSession Interface
style!(cm::ComponentModifier, s::Servable, p::Pair{String, String}) -> _
Styles the Servable s with the properties and values in p.
example
Toolips.style! — MethodSession Interface
style!(cm::ComponentModifier, name::String, p::Vector{Pair{String, String}}) -> _
Styles a Servable by name with the properties and values in p.
example
Toolips.style! — MethodSession Interface
style!(cm::ComponentModifier, name::String, p::Pair) -> _
Styles a Servable by name with the properties and values in p.
example
Toolips.style! — MethodSession Interface
style!(cm::ComponentModifier, name::String, sname::String) -> _
Changes the style class of a Servable by name to the style p by name. Note – styles must be already written to the Connection prior.
example
ToolipsSession.alert! — MethodSession Interface
alert!(cm::ComponentModifier, s::String) -> _
Sends an alert to the current session.
example
on(c, s, "click") do cm::ComponentModifier
alert!(cm, "oh no!")
endToolipsSession.confirm_redirects! — MethodSession Interface
free_redirects!(cm::ComponentModifier) -> _
Adds an "are you sure you want to leave this page... unsaved changes" pop-up when trying to leave the page. Can be undone with free_redirects!
example
ToolipsSession.createcomp — MethodSession Internals
createcomp(element::Any) -> ::Component
Converts HTML node into a component, used by htmlcomponent(::String).
example
rn = firstnode(ro)
children::Dict = Dict()
for n in eachelement(rn)
comp::Component = createcomp(n)
push!(children, comp.name => comp)
endToolipsSession.document_linker — MethodSession Internals
document_linker(c::Connection) -> _
Served to /modifier/linker by the Session extension. This is where incoming data is posted to for a response.
example
ToolipsSession.free_redirects! — MethodSession Interface
free_redirects!(cm::ComponentModifier) -> _
Removes the "are you sure you wish to leave" box that can be created with confirm_redirects!
example
ToolipsSession.gen_ref — MethodSession
gen_ref() -> ::String
Creates a random string of 16 characters. This is used to map connections to specific events by the session.
example
gen_ref()
"jfuR2wgprielweh3"ToolipsSession.get_text — MethodSession Interface
get_text(cm::ComponentModifier, s::Component) -> ::String
Retrieves the text of a given Component.
example
ToolipsSession.get_text — MethodSession Interface
get_text(cm::ComponentModifier, s::String) -> ::String
Retrieves the text of a given Component by name
example
ToolipsSession.htmlcomponent — MethodSession Internals
htmlcomponent(s::String) -> ::Dict{String, Toolips.Component}
Converts HTML into a dictionary of components.
example
s = "<div id = 'hello' align = 'center'></div>"
comp = htmlcomponent(s)
comp["hello"]["align"]
"center"ToolipsSession.modify! — MethodSession Interface
modify!(cm::ComponentModifier, s::Servable, p::Pair) -> _
Modifies the key property p[1] to p[2] on s
example
ToolipsSession.modify! — MethodSession Interface
modify!(cm::ComponentModifier, s::Servable, p::Pair ...) -> _
Modifies the key properties of p[1] to the value of p[2] on s.
example
ToolipsSession.modify! — MethodSession Interface
modify!(cm::ComponentModifier, s::Servable, p::Vector{Pair{String, String}}) -> _
Modifies the key properties of i[1] => i[2] for i in p on s.
example
ToolipsSession.modify! — MethodSession Interface
modify!(cm::ComponentModifier, s::Servable, p::Pair) -> _
Modifies the key property p[1] to p[2] on s
example
ToolipsSession.move! — MethodSession Interface
move!(cm::ComponentModifier, p::Pair{Servable, Servable}) -> _
Moves the servable p[2] to be a child of p[1]
example
ToolipsSession.move! — MethodSession Interface
move!(cm::ComponentModifier, p::Pair{String, String}) -> _
Moves the servable p[2] to be a child of p[1] by name.
example
ToolipsSession.observe! — MethodSession Interface
observe!(f::Function, c::Connection, time::Integer) -> _
Creates a TimedTrigger, and then writes it to the connection.
example
route("/") do c::Connection
observe!(c, 1000) do cm::ComponentModifier
...
end
endToolipsSession.on — MethodSession Interface
on(f::Function, c::Connection, event::AbstractString)
Creates a new event for the current IP in a session. Performs the function on the event. The function should take a ComponentModifier as an argument.
example
route("/") do c::Connection
myp = p("hello", text = "wow")
on(c, "load") do cm::ComponentModifier
set_text!(cm, myp, "not so wow")
end
write!(c, myp)
endToolipsSession.on — MethodInterface
on(f::Function, c::Connection, s::Component, event::AbstractString)
Creates a new event for the current IP in a session. Performs the function on the event. The function should take a ComponentModifier as an argument.
example
route("/") do c::Connection
myp = p("hello", text = "wow")
timer = TimedTrigger(5000) do cm::ComponentModifier
if cm[myp][:text] == "wow"
c[:Logger].log("wow.")
end
end
write!(c, myp)
write!(c, timer)
endToolipsSession.on_keydown — MethodSession Interface
on_keydown(f::Function, c::Connection, key::AbstractString)
Creates a new event for the current IP in a session. Performs f when the key is pressed.
example
ToolipsSession.on_keyup — MethodSession Interface
on_keyup(f::Function, c::Connection, key::AbstractString)
Creates a new event for the current IP in a session. Performs f when the key is brought up.
example
ToolipsSession.pauseanim! — MethodSession Interface
pauseanim!(cm::ComponentModifier, s::Servable) -> _
Pauses the servable's animation.
example
on(c, s, "click") do cm::ComponentModifier
pauseanim!(cm, s)
endToolipsSession.pauseanim! — MethodSession Interface
pauseanim!(cm::ComponentModifier, name::String) -> _
Pauses a servable's animation by name.
example
on(c, s, "click") do cm::ComponentModifier
pauseanim!(cm, s.name)
endToolipsSession.playanim! — MethodSession Interface
playanim!(cm::ComponentModifier, s::Servable) -> _
Plays the servable's animation.
example
on(c, s, "click") do cm::ComponentModifier
playanim!(cm, s)
endToolipsSession.playanim! — MethodSession Interface
playanim!(cm::ComponentModifier, name::String) -> _
Plays a servable's animation by name.
example
on(c, s, "click") do cm::ComponentModifier
playanim!(cm, s.name)
endToolipsSession.redirect! — FunctionSession Interface
redirect!(cm::ComponentModifier, url::AbstractString, delay::Int64 = 0) -> _
Redirects the session to url. Can be given delay with delay.
example
ToolipsSession.remove! — MethodSession Interface
remove!(cm::ComponentModifier, s::Servable) -> _
Removes the servable s.
example
ToolipsSession.remove! — MethodSession Interface
remove!(cm::ComponentModifier, s::String) -> _
Removes the servable s by name.
example
ToolipsSession.remove! — MethodSession Interface
remove!(c::Connection, fname::AbstractString, s::Servable) -> _
Removes a given function call from a connection's Session.
example
ToolipsSession.set_children! — MethodSession Interface
set_children!(cm::ComponentModifier, s::Servable, v::Vector{Servable}) -> _
Sets the children of a given component.
example
ToolipsSession.set_children! — MethodSession Interface
set_children!(cm::ComponentModifier, s::String, v::Vector{Servable}) -> _
Sets the children of a given component by name.
example
ToolipsSession.set_text! — MethodSession Interface
set_text!(cm::ComponentModifier, s::Servable, txt::String) -> _
Sets the inner HTML of a Servable.
example
ToolipsSession.set_text! — MethodSession Interface
set_text!(cm::ComponentModifier, s::String, txt::String) -> _
Sets the inner HTML of a Servable by name
example