ToolipsSession.ComponentModifierType

ComponentModifier

  • 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)
end

constructors

ComponentModifier(html::String)

ToolipsSession.SessionType

Session

  • 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)
end

constructors

Session(activeroutes::Vector{String} = ["/"]; transitionduration::AbstractFloat = 0.5, transition::String = "ease-in-out", timeout::Integer = 30 )

ToolipsSession.TimedTriggerType

TimedTrigger

  • 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)
end

constructors

TimedTrigger(func::Function, time::Integer)

Base.append!Method

Session Interface

append!(cm::ComponentModifier, s::Servable, child::Servable) -> _


Appends child to the servable s.

example

Base.append!Method

Session Interface

append!(cm::ComponentModifier, name::String, child::Servable) -> _


Appends child to the servable s by name.

example

Base.getindexMethod

Session 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"]
end
Base.getindexMethod

Session 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"]
end
Base.getindexMethod

Session Interface

getindex(m::Session, s::AbstractString) -> ::Vector{Pair}


Gets a session's refs by ip.

example

route("/") do c::Connection
    c[:Session][getip(c)]
end
Base.setindex!Method

Session 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
end
Base.setindex!Method

Session 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
end
Toolips.animate!Method

Session 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)
end
Toolips.animate!Method

Session 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!Method

Session Interface

kill!(c::Connection)


Kills a Connection's saved events.

example

Toolips.style!Method

Session Interface

style!(cm::ComponentModifier, s::Servable, p::Pair) -> _


Styles the Servable s with the properties and values in p.

example

Toolips.style!Method

Session 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!Method

Session Interface

style!(cm::ComponentModifier, s::Servable, p::Pair{String, String}) -> _


Styles the Servable s with the properties and values in p.

example

Toolips.style!Method

Session 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!Method

Session Interface

style!(cm::ComponentModifier, name::String, p::Pair) -> _


Styles a Servable by name with the properties and values in p.

example

Toolips.style!Method

Session 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!Method

Session 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!")
end
ToolipsSession.confirm_redirects!Method

Session 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.createcompMethod

Session 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)
end
ToolipsSession.document_linkerMethod

Session 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!Method

Session 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_refMethod

Session

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_textMethod

Session Interface

get_text(cm::ComponentModifier, s::Component) -> ::String


Retrieves the text of a given Component.

example

ToolipsSession.get_textMethod

Session Interface

get_text(cm::ComponentModifier, s::String) -> ::String


Retrieves the text of a given Component by name

example

ToolipsSession.htmlcomponentMethod

Session 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!Method

Session Interface

modify!(cm::ComponentModifier, s::Servable, p::Pair) -> _


Modifies the key property p[1] to p[2] on s

example

ToolipsSession.modify!Method

Session 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!Method

Session 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!Method

Session Interface

modify!(cm::ComponentModifier, s::Servable, p::Pair) -> _


Modifies the key property p[1] to p[2] on s

example

ToolipsSession.move!Method

Session Interface

move!(cm::ComponentModifier, p::Pair{Servable, Servable}) -> _


Moves the servable p[2] to be a child of p[1]

example

ToolipsSession.move!Method

Session 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!Method

Session 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
end
ToolipsSession.onMethod

Session 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)
end
ToolipsSession.onMethod

Interface

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)
end
ToolipsSession.on_keydownMethod

Session 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_keyupMethod

Session 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!Method

Session Interface

pauseanim!(cm::ComponentModifier, s::Servable) -> _


Pauses the servable's animation.

example

on(c, s, "click") do cm::ComponentModifier
    pauseanim!(cm, s)
end
ToolipsSession.pauseanim!Method

Session 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)
end
ToolipsSession.playanim!Method

Session Interface

playanim!(cm::ComponentModifier, s::Servable) -> _


Plays the servable's animation.

example

on(c, s, "click") do cm::ComponentModifier
    playanim!(cm, s)
end
ToolipsSession.playanim!Method

Session 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)
end
ToolipsSession.redirect!Function

Session Interface

redirect!(cm::ComponentModifier, url::AbstractString, delay::Int64 = 0) -> _


Redirects the session to url. Can be given delay with delay.

example

ToolipsSession.remove!Method

Session Interface

remove!(cm::ComponentModifier, s::Servable) -> _


Removes the servable s.

example

ToolipsSession.remove!Method

Session Interface

remove!(cm::ComponentModifier, s::String) -> _


Removes the servable s by name.

example

ToolipsSession.remove!Method

Session Interface

remove!(c::Connection, fname::AbstractString, s::Servable) -> _


Removes a given function call from a connection's Session.

example

ToolipsSession.set_children!Method

Session Interface

set_children!(cm::ComponentModifier, s::Servable, v::Vector{Servable}) -> _


Sets the children of a given component.

example

ToolipsSession.set_children!Method

Session Interface

set_children!(cm::ComponentModifier, s::String, v::Vector{Servable}) -> _


Sets the children of a given component by name.

example

ToolipsSession.set_text!Method

Session Interface

set_text!(cm::ComponentModifier, s::Servable, txt::String) -> _


Sets the inner HTML of a Servable.

example

ToolipsSession.set_text!Method

Session Interface

set_text!(cm::ComponentModifier, s::String, txt::String) -> _


Sets the inner HTML of a Servable by name

example