servables

Servables are any non-core data-structure that is built with the objective of being written to a stream.

requests

Toolips has some bindings that pre-parse responses fro you, these are both post and get requests.

Base.getFunction

Interface

get(url::String) -> ::String


Quick binding for an HTTP GET request.

example

body = get("/")
    "hi"
Toolips.postFunction

Interface

post(url::String, body::String) -> ::String


Quick binding for an HTTP POST request.

example

response = post("/")
    "my response"

components

A component is a Servable which contains markup information and can easily be translated into elements with properties..

Toolips.ComponentType

Component <: Servable

  • name::String
  • f::Function
  • properties::Dict A component is a standard servable which is used to represent HTML tag

structures. Indexing a Component with a Symbol or a String will return or set a Component's property to that index. The two special indexes are :children and :text. :text will change the inner content of the Component and :children is where components that will be written inside the Component go. You can add to these with push!(c::Servable, c2::Servable)

example

using Toolips

image_style = Style("example")
image_anim = Animation("img_anim")
image_anim[:from] = "opacity" => "0%"
image_anim[:to] = "opacity" => "100%"
animate!(image_style)

r = route("/") do c::AbstractConnection
    newimage = img("newimage", src = "/logo.png")
    style!(newimage, image_style)
    write!(c, newimage)
end

field info

  • name::String - The name field is the way that a component is denoted in code.
  • f::Function - The function that gets called with the Connection as an

argument.

  • properties::Dict - A dictionary of symbols and values.

constructors

  • Component(name::String = "", tag::String = "", properties::Dict = Dict())
  • Component(name::String, tag::String, props::Base.Pairs)

Indexing a component will yield its .properties:

Base.getindexMethod

Interface

getindex(s::Component, symb::Symbol) -> ::Any


Returns a property value by symbol or name.

example

c = p("hello", text = "Hello world")
c[:text]
    "Hello world!"

c["opacity"] = "50%"
c["opacity"]
    "50%"
Base.getindexMethod

Interface

getindex(::Servable, ::String) -> ::Any


Returns a property value by string or name.

example

c = p("hello", text = "Hello world")
c[:text]
    "Hello world!"

c["opacity"] = "50%"
c["opacity"]
    "50%"
Base.setindex!Method

Interface

setindex!(s::Servable, a::Any, symb::Symbol) -> _


Sets the property represented by the symbol to the provided value.

example

c = p("world")
c[:text] = "hello world!"
Base.getindexMethod

Interface

getindex(c::VectorServable, str::String) -> ::Servable


Returns the Servable (likely a Component) with the name str

example

comp1 = p("hello")
comp2 = p("anotherp")
cs = components(comp1, comp2)
cs["hello"]
    Component("hello" ...)
Base.setindex!Method

Interface

setindex!(s::Servable, a::Any, symb::String) -> _


Sets the property represented by the string to the provided value. Use the appropriate web-format, such as "50%" or "50px".

example

c = p("world")
c["align"] = "center"
Base.getindexMethod

Interface

getindex(::Servable, ::String) -> ::Any


Returns a property value by string or name.

example

c = p("hello", text = "Hello world")
c[:text]
    "Hello world!"

c["opacity"] = "50%"
c["opacity"]
    "50%"

There is a library of default components that comes with toolips. Generally, their name coincides with a docstring. All of these take an infinite number of key-word arguments. These arguments become the properties of a Servable.

Toolips.imgFunction

img(name::String; args ...) -> ::Component


Returns the img Component with the key-word arguments provided in args as properties.

example

image = img("mylogo", src = "assets/logo.png")
write!(c, image)
Toolips.linkFunction

link(name::String; args ...) -> ::Component


Returns the link Component with the key-word arguments provided in args as properties.

example

mylink = link("mylink", href = "http://toolips.app")
write!(c, mylink)
Toolips.metaFunction

meta(name::String; args ...) -> ::Component


Returns the meta Component with the key-word arguments provided in args as properties.

example

metainfo = meta("metainfo", rel = "meta-description", text = "hello")
write!(c, metainfo)
Toolips.inputFunction

input(name::String; args ...) -> ::Component


Returns the input Component with the key-word arguments provided in args as properties.

example

element = input("mylogo")
write!(c, element)
Toolips.aFunction

a(name::String; args ...) -> ::Component


Returns the a Component with the key-word arguments provided in args as properties.

example

element = a("mylogo")
write!(c, element)
Toolips.pFunction

p(name::String; args ...) -> ::Component


Returns the p Component with the key-word arguments provided in args as properties.

example

p1 = input("mylogo")
write!(c, p)
Toolips.hFunction

h(name::String; args ...) -> ::Component


Returns the h Component with the key-word arguments provided in args as properties.

example

h1 = h("heading1", 1)
write!(c, h1)
Toolips.ulFunction

ul(name::String; args ...) -> ::Component


Returns the ul Component with the key-word arguments provided in args as properties.

example

ul1 = ul("mylogo")
write!(c, ul)
Toolips.liFunction

li(name::String; args ...) -> ::Component


Returns the li Component with the key-word arguments provided in args as properties.

example

li1 = li("mylogo")
write!(c, li)
Toolips.dividerFunction

divider(name::String; args ...) -> ::Component


Returns the div Component with the key-word arguments provided in args as properties.

example

divider1 = divider("mylogo")
write!(c, divider)
Toolips.brFunction

br(name::String; args ...) -> ::Component


Returns the br Component with the key-word arguments provided in args as properties.

example

comp = br("newcomp")
write!(c, comp)
Toolips.iFunction

i(name::String; args ...) -> ::Component


Returns the i Component with the key-word arguments provided in args as properties.

example

comp = i("newcomp")
write!(c, comp)
Toolips.titleFunction

title(name::String; args ...) -> ::Component


Returns the title Component with the key-word arguments provided in args as properties.

example

comp = title("newcomp")
write!(c, comp)
Toolips.spanFunction

span(name::String; args ...) -> ::Component


Returns the span Component with the key-word arguments provided in args as properties.

example

comp = span("newcomp")
write!(c, comp)
Toolips.iframeFunction

iframe(name::String; args ...) -> ::Component


Returns the iframe Component with the key-word arguments provided in args as properties.

example

comp = iframe("newcomp")
write!(c, comp)
Toolips.svgFunction

svg(name::String; args ...) -> ::Component


Returns the svg Component with the key-word arguments provided in args as properties.

example

comp = svg("newcomp")
write!(c, comp)
Toolips.elementFunction

element(name::String; args ...) -> ::Component


Returns the element Component with the key-word arguments provided in args as properties.

example

comp = element("newcomp")
write!(c, comp)
Toolips.labelFunction

label(name::String; args ...) -> ::Component


Returns the label Component with the key-word arguments provided in args as properties.

example

lbl = label("mylogo", src = "assets/logo.png")
write!(c, lbl)
Toolips.scriptFunction

script(name::String; args ...) -> ::Component


Returns the script Component with the key-word arguments provided in args as properties.

example

comp = script("newcomp")
write!(c, comp)
Toolips.navFunction

nav(name::String; args ...) -> ::Component


Returns the nav Component with the key-word arguments provided in args as properties.

example

comp = nav("newcomp")
write!(c, comp)
Toolips.buttonFunction

button(name::String; args ...) -> ::Component


Returns the button Component with the key-word arguments provided in args as properties.

example

comp = button("newcomp")
write!(c, comp)
Toolips.formFunction

form(name::String; args ...) -> ::Component


Returns the form Component with the key-word arguments provided in args as properties.

example

comp = form("newcomp")
write!(c, comp)

We can also compose components together using push!, and work with them using the following methods:

Base.push!Method

Interface

push!(s::Component, d::Component ...) -> ::Component


Adds the child or children d to s.properties[:children]

example

c = Component()
otherc = Component()
push!(c, otherc)
Toolips.style!Function

Interface

style!(c::Servable, s::Style) -> _


Applies the style to a servable.

example

serv = p("wow")
mystyle = Style("mystyle", color = "lightblue")
style!(serv, mystyle)

Interface

style!(c::Servable, s::Pair ...) -> _


Applies the style pairs to the servable's "style" property.

example

mycomp = p("mycomp")
style!(mycomp, "background-color" => "lightblue", "color" => "white")

Interface

style!(::Style, ::Style) -> _


Copies the properties from the second style into the first style.

example

style1 = Style("firsts")
style2 = Style("seconds")
style1["color"] = "orange"
style!(style2, style1)

style2["color"]
    "orange"
Toolips.componentsFunction

Interface

components(cs::Servable ...) -> ::Vector{Servable}


Creates a Vector{Servable} from multiple servables. This is useful because a vector of components could potentially become a Vector{Component}, for example and this is not the dispatch that is used universally across the package.

example

c = Component()
c2 = Component()
components(c, c2)
    Vector{Servable}(Component(), Component())
Toolips.has_childrenFunction

Interface

has_children(c::Component) -> ::Bool


Returns true if the given component has children.

example

c = Component()
otherc = Component()
push!(c, otherc)

has_children(c)
    true
has_children(otherc)
    false
Toolips.properties!Function

Interface

properties!(c::Servable, s::Servable) -> _


Copies properties from s,properties into c.properties.

example

comp = Component()
othercomp = Component()
othercomp["opacity"] = "100%"
properties!(comp, othercomp)

comp["opacity"]
        100%

style components

Style components change the style of a Component

Toolips.StyleComponentType

abstract type StyleComponent <: Servable

No different from a normal Servable, simply an abstract type step for the interface to separate working with Animations and Styles.

Servable Consistencies

Servables can be written to a Connection via thier f() function and the
interface. They can also be indexed with strings or symbols to change properties
##### Consistencies
- f::Function - Function whose output to be written to http. Must take a single
positonal argument of type ::Connection or ::AbstractConnection

The main style components are Animations and Styles.

Toolips.StyleType

Style

  • name::String
  • f::Function
  • properties::Dict{Any, Any}
  • extras::String Creates a style from attributes, can style a Component using the style! method.

Names should be consistent with CSS names. For example, a default h1 style would be named "h1". A heading style for a specific class should be "h1.myheading"

example

style = Style("p.mystyle", color = "blue")
style["opacity"] = "50%"
comp = Component()
style!(comp, style)

field info

  • name::String - The name of the style. Should be consistent with CSS naming.
  • f::Function - The function f, called by write! when writing to a Connection.
  • properties::Dict{Any, Any} - A dict of style attributes.
  • extras::String - Extra components to be written along with the style. Usually

this is an animation.

constructors

  • Style(name::String; props ...)
Toolips.AnimationType

Animation

  • name::String
  • keyframes::Dict
  • f::Function
  • delay::Float64
  • length::Float64
  • iterations::Integer An animation can be used to animate Styles with the animate! method. Animating

is done by indexing by either percentage, or symbols, such as from and to.

example

anim = Animation("myanim")
anim[:from] = "opacity" => "0%"
anim[:to] = "opacity" => "100%"
style = Style("example")
animate!(style, anim)

field info

  • name::String - The name of the animation.
  • keyframes::Dict - The keyframes that have been pushed so far.
  • f::Function - The function called when writing to a Connection.
  • delay::Float64 - The delay before the animation begins.
  • length::Float64 - The amount of time the animation should play.
  • iterations::Integer - The number of times the animation should repeat. When

set to 0 the animation will loop indefinitely.

constructors

Animation(name::String = "animation", delay::Float64 = 0.0, length::Float64 = 5.2, iterations::Integer = 1)

Toolips.animate!Function

Interface

animate!(s::Style, a::Animation) -> _


Sets the Animation as a property of the style.

example

anim = Animation("fade_in")
anim[:from] = "opacity" => "0%"
anim[:to] = "opacity" => "100%"

animated_style = Style("example")
animate!(animated_style, anim)
Toolips.delete_keyframe!Function

Interface

delete_keyframe!(a::Animation, key::Int64) -> _


Deletes a given keyframe from an animation by keyframe percentage.

example

anim = Animation("")
anim[0] = "opacity" => "0%"
delete_keyframe!(anim, 0)

Interface

delete_keyframe!(a::Animation, key::Symbol) -> _


Deletes a given keyframe from an animation by keyframe name.

example

anim = Animation("")
anim[:to] = "opacity" => "0%"
delete_keyframe!(anim, :to)

Animating and property adjustment is done with indexing.

Base.setindex!Method

Interface

setindex!(anim::Animation, set::Pair, n::Symbol) -> _


Sets the animation at the corresponding key-word's position. Usually these are :to and :from.

example

a = Animation("world")
a[:to] = "opacity" => "0%"
Base.setindex!Method

Interface

setindex!(anim::Animation, set::Pair, n::Int64) -> _


Sets the animation at the percentage of the Int64 to modify the properties of pair.

example

a = Animation("world")
a[0] = "opacity" => "0%"

other servables

The file Servable, as you might expect, serves a file via a directory.

Toolips.FileType

File <: Servable

dir::String f::Function Serves a file into a Connection.

example

f = File("hello.txt")
r = route("/") do c
    write!(c, f)
end

field info

  • dir::String - The directory of a file to serve.
  • f::Function - Function whose output to be written to http().

constructors

  • File(dir::String)

Servables are also incredibly easy to write, and part of the beauty of toolips is just how easy it is to create these kinds of extensions in toolips!