toolips
a manic web-development framework
Toolips.Toolips — ModuleCreated in June, 2022 by chifi - an open source software dynasty. by team toolips This software is MIT-licensed.
Toolips
Toolips.jl is a fast, asynchronous, low-memory, full-stack, and reactive web-development framework always written in pure Julia.
Module Composition
Toolips.Component — TypeComponent <: Servable
name::String f::Function properties::Dict –––––––––
- 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)
Toolips.Connection — TypeConnection
- routes::Dict
- http::HTTP.Stream
- extensions::Dict
The connection type is passed into route functions and pages as an argument. This is both for functions, as well as Servable.f() methods. This constructor should not be called directly. Instead, it is called by the server and passed through the function pipeline. Indexing a Connection will return the extension named with that symbol.
example
# v The Connection
home = route("/") do c::Connection
c[Logger].log("We can index extensions.")
c.routes["/"] = c::Connection -> write!(c, "rerouting!")
httpstream = c.http
write!(c, "Hello world!")
myheading::Component = h("myheading", 1, text = "Whoa!")
write!(c, myheading)
endField Info
- routes::Dict - A dictionary of routes where the keys
are the routed URL and the values are the functions to those keys.
- http::HTTP.Stream - The stream for this current peer's connection.
- extensions::Dict - A dictionary of extensions to load with the
name to reference as keys and the extension as the pair.
Constructors
- Connection
Toolips.File — TypeFile
dir::String f::Function –––––––––
- dir::String - The directory of a file to serve.
- f::Function - Function whose output to be written to http().
constructors
File(dir::String)
Toolips.Files — TypeFiles
type::Symbol directory::String f::Function –––––––––
- type::Symbol - The type of extension. There are three different selections
you can choose from. :connection :routing :func. A :connection extension will be provided in Connection.extensions. A :routing function is passed a Dict of routes as an argument. The last is a function argument, which is just a specific function to run from the top-end to the server.
- directory::String - The directory to route the files from.
- f::Function - The function f() called with a Connection.
constructors
Files(dir::String)
Toolips.Logger — TypeLogger
out::String levels::Dict log::Function –––––––––
Field Info
- out::String
Rgw output file for the logger to write to.
- log::Function
A Logger logs information with different levels. Holds the function log(), connected to the function _log(). Methods:
- log(::Int64, ::String)
- log(::String)
- log(::HTTP.Stream, ::String)
Writes to HTML console, and also logs at level 1 with logger.
- levels::Dict
Constructors
Logger(levels::Dict{level_count::Int64 => crayon::Crayons.Crayon}; out::String = pwd() * "logs/log.txt") Logger(; out::String = pwd() * "/logs/log.txt")
Toolips.Route — TypeRoute{T}
- path::String
- page::T
A route is added to a ServerTemplate using either its constructor, or the ServerTemplate.add(::Route) method. Each route calls either a particular servable or function; the type of which denoted by T. The Route type is commonly constructed using the do syntax with the route(::Function, String) method.
example
# Constructors
route = Route("/", p(text = "hello"))
function example(c::Connection)
write!(c, "hello")
end
route = Route("/", example)
# method
route = route("/") do c
write!(c, "Hello world!")
write!(c, p(text = "hello"))
# we can also use extensions!
c[:logger].log("hello world!")
endfields
- path::String
The path, e.g. "/" at which to direct to the given component.
- page::T (::Function || T <: Component)
The servable to serve at this given route.
constructors
- Route(path::String, f::Function) where
- Route(path::String, s::Servable)
Toolips.Servable — Typeabstract type Servable
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().
- properties::Dict - The properties of a given Servable. These are written
into the servable on the calling of f().
Toolips.ServerExtension — Typeabstract type ServerExtension
Server extensions are loaded into the server on startup, and can have a few different abilities according to their type field's value. There are three types to be aware of.
Consistencies
Toolips.ServerTemplate — TypeServerTemplate
- ip::String
- port::Integer
- routes::Vector{Route}
- extensions::Dict
- remove::Function
- add::Function
- start::Function
The ServerTemplate is used to configure a server before running. These are usually made and started inside of a main server file. –––––––––
Field Info
- ip::String
- port::Integer
- routes::Vector{Route}
- extensions::Dict
- remove::Function
- add::Function
- start::Function
Constructors
ServerTemplate(ip::String, port::Int64, routes::Dict; extensions::Dict)
Toolips.StyleComponent — Typeabstract 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().
- properties::Dict - The properties of a given Servable. These are written
into the servable on the calling of f().Toolips.ToolipsServer — Typeabstract type ToolipsServer
ToolipsServers are returned whenever the ServerTemplate.start() field is called. If you are running your server as a module, it should be noted that commonly a global start() method is used and returns this server, and dev is where this module is loaded, served, and revised.
Consistencies
- routes::Dict - The server's route => function dictionary.
- extensions::Dict - The server's currently loaded extensions.
- server::Any - The server, whatever type it may be...
Toolips.WebServer — TypeBase.get — MethodInterface
get() -> ::Dict
Quick binding for an HTTP GET request.
example
Base.getindex — MethodBase.getindex — MethodBase.getindex — MethodInterface
getindex(::Servable, ::String) -> ::Any
Returns a property value by string or name.
example
Base.getindex — MethodInterface
getindex(::Servable, ::Symbol) -> ::Any
Returns a property value by symbol or name.
example
Base.getindex — MethodBase.push! — MethodInterface
push!(::Animation, p::Pair) -> _
Pushes a keyframe pair into an animation.
example
Base.push! — MethodInterface
push!(::Component, ::Component) ->
example
Base.push! — MethodInterface
push!(::Component, ::Component ...) -> ::Component
example
Base.push! — MethodBase.setindex! — MethodInterface
setindex!(::Animation, ::Pair, ::Int64) -> _
Sets the animation at the percentage of the Int64 to modify the properties of pair.
example
Base.setindex! — MethodInterface
setindex!(::Animation, ::Pair, ::Int64) -> _
Sets the animation at the corresponding key-word's position.
example
Base.setindex! — MethodBase.setindex! — MethodInterface
setindex!(::Servable, ::String, ::Any) -> ::Any
Sets the property represented by the string to the provided value.
example
Base.setindex! — MethodInterface
setindex!(::Servable, ::Symbol, ::Any) -> ::Any
Sets the property represented by the symbol to the provided value.
example
Toolips._log — Method_log(http::HTTP.Stream, message::String) -> _
Binded call for the field log() inside of Logger(). This will log both to the JavaScript/HTML console –––––––––
example (Closure from Logger)
log(http::HTTP.Stream, message::String) = _log(http, message)
Toolips._log — Method_log(level::Int64, message::String, levels::Dict, out::String) -> _
Binded call for the field log() inside of Logger(). See ?(Logger) for more details on the field log. All arguments are fields of that type. Return is a printout into the REPL as well as an append to the log file, provided by the out URI. –––––––––
example (Closure from Logger)
log(level::Int64, message::String) = _log(level, message, levels, out) log(message::String) = _log(1, message, levels, out)
Toolips._start — MethodCore
_start(routes::AbstractVector, ip::String, port::Integer,
extensions::Dict) -> (::Sockets.HTTPServer)
This is an internal function for the ServerTemplate. This function is binded to the ServerTemplate.start field.
example
Toolips.animate! — MethodInterface
animate!(::StyleComponent, ::Animation) -> _
Sets the Animation as a rule for the StyleComponent. Note that the Animation still needs to be written to the same Connection, preferably in a StyleSheet.
example
Toolips.argsplit — MethodToolips.components — MethodToolips.create_serverdeps — Methodcreate_serverdeps(::String) -> _
Creates the essential portions of the webapp file structure.
example
Toolips.delete_keyframe! — MethodInterface
delete_keyframe!(::Animation, ::String) -> _
Deletes a given keyframe from an animation by keyframe name.
example
Toolips.download! — MethodInterface
download!() ->
Downloads a file to a given user's computer.
example
Toolips.generate_router — MethodCore
generate_router(routes::AbstractVector, server::Any, extensions::Dict)
This method is used internally by the _start method. It returns a closure function that both routes and calls functions.
example
Toolips.getarg — MethodInterface
getarg(::Connection, ::Symbol, ::Type) -> ::Vector
This method is the same as getargs(::HTTP.Stream, ::Symbol), however types are parsed as type T(). Note that "Cannot convert..." errors are possible with this method.
example
Toolips.getarg — MethodInterface
getargs(::Connection, ::Symbol) -> ::Dict
Returns the requested arguments from the target.
example
Toolips.getargs — MethodInterface
getargs(::Connection) -> ::Dict
The getargs method returns arguments from the HTTP header (GET requests.) Returns a full dictionary of these values.
example
Toolips.getip — MethodToolips.navigate! — MethodInterface
navigate!(::Connection, ::String) -> _
Routes a connected stream to a given URL.
example
Toolips.new_app — Functionnew_app(::String) -> _
Creates a minimalistic app, usually used for creating endpoints – but can be used for anything. For an app with a real front-end, it might make sense to add some extensions.
example
Toolips.new_webapp — Functionnew_webapp(::String) -> _
Creates a fully-featured web-app. Adds CanonicalToolips.jl to provide more high-level interface origrannubg from Julia.
example
Toolips.post — MethodInterface
post() ->
Quick binding for an HTTP POST request.
example
Toolips.postarg — MethodInterface
postarg(::Connection, ::String) -> ::Any
Get a body argument of a POST response by name.
example
Toolips.postargs — MethodInterface
postargs(::Connection, ::Symbol, ::Type) -> ::Dict
Get arguments from the request body.
example
Toolips.properties! — MethodInterface
properties!(::Servable, ::Servable) -> _
Copies properties from s,properties into c.properties.
example
Toolips.route! — MethodInterface
route!(::Connection, ::Route) -> _
Modifies the routes on the Connection.
example
Toolips.route! — MethodInterface
route!(::Function, ::Connection, ::String) -> _
Routes a given String to the Function.
example
Toolips.route! — MethodToolips.route! — MethodToolips.route — MethodInterface
route(::Function, ::String) -> ::Route
Creates a route from the Function.
example
Toolips.route — MethodToolips.route — MethodInterface
route(::String, ::Servable) -> ::Route
Creates a route from a Servable.
example
Toolips.route_from_dir — Methodroutefromdir(dir::String) -> ::Vector{String}
Recursively appends filenames for a directory AND all subsequent directories.
example
x::Vector{String} = routefromdir("mypath")
Toolips.routes — MethodInterface
routes(::Route ...) -> ::Vector{Route}
Turns routes provided as arguments into a Vector{Route} with indexable routes. This is useful because this is the type that the ServerTemplate constructor likes.
example
Toolips.serverfuncdefs — MethodCore
serverfuncdefs(::AbstractVector, ::String, ::Integer,
::Dict) -> (::Function, ::Function, ::Function)
This method is used internally by a constructor to generate the functions add, start, and remove for the ServerTemplate.
example
Toolips.startread! — MethodInterface
startread!(::Connection) -> _
Resets the seek on the Connection.
example
Toolips.stop! — MethodInterface
stop!(x::Any) -> _
An alternate binding for close(x). Stops a server from running.
example
Toolips.style! — MethodInterface
style!(::Style, ::Style) -> _
Copies the properties from the second style into the first style.
example
Toolips.style! — MethodInterface
style!(::Servable, ::Style) -> _
Applies the style to a servable.
example
Toolips.style! — MethodToolips.unroute! — MethodInterface
unroute!(::Connection, ::String) -> _
Removes the route with the key equivalent to the String.
example
Toolips.write! — MethodInterface
write!(::Connection, ::Any) -> _
Attempts to write any type to the Connection's stream.
example
Toolips.write! — MethodInterface
write!(::Connection, ::String) -> _
Writes the String into the Connection as HTML.
example
Toolips.write! — MethodInterface
write!(::Connection, ::Servable) -> _
Writes a Servable's return to a Connection's stream.
example
Toolips.write! — MethodToolips.write! — MethodInterface
write!(c::Connection, s::Vector{Servable}) -> _
Writes, in order of element, each Servable inside of a Vector of Servables.
example
Toolips.@L_str — MacroInterface
L_str -> _
Creates a literal string
example