diff --git a/Project.toml b/Project.toml index a8d0247..6e0ba1b 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Cobweb" uuid = "ec354790-cf28-43e8-bb59-b484409b7bad" authors = ["joshday and contributors"] -version = "0.6.1" +version = "0.7.0" [deps] DefaultApplication = "3f0dd361-4fe0-5fc6-8523-80b14ec94d85" @@ -10,8 +10,8 @@ Scratch = "6c6a2e73-6563-6170-7368-637461726353" [compat] DefaultApplication = "1" -OrderedCollections = "1.5" -Scratch = "1.1" +OrderedCollections = "1" +Scratch = "1" julia = "1" [extras] diff --git a/README.md b/README.md index 6eb134b..c541fff 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,8 @@ # Features -- View any `"text/html"`-representable object in your browser with `preview(x)`. -- Nice syntax for writing HTML: `h.(children...; attrs...)` +- Open `"text/html"`-representable objects in your browser with `preview(x)`. +- Clean syntax for writing HTML: `h.(children...; attrs...)` ```julia h.div(class="myclass", style="color:red;")("content!") @@ -29,14 +29,13 @@ body = h.body( h.script("const buttonClicked = () => alert('This button was clicked!')"), ) - preview(body) ```

-# ✨ Creating Nodes with `Cobweb.h` +# ✨ Writing HTML with `Cobweb.h` ### `h` is a pretty special function @@ -49,7 +48,7 @@ h.tag # == h(:tag) ### `h` Creates a `Cobweb.Node` -- `Cobweb.Node`s are callable: +- `Cobweb.Node`s are callable (creates a copy with new children/attributes): ```julia h.div("hi") # positional arguments add *children* @@ -65,7 +64,8 @@ h.div("hi")(style="border:none;") ### Child Elements can be Anything -- If `!showable("text/html", child)`, `child` will be added as `HTML(child)`. +- If a `child` isn't `MIME"text/html"`-representable, it will be added as a `HTML(child)`. +- Note: `HTML(x)` means "insert this into HTML as `print(x)`". ```julia # e.g. Strings have no text/html representation, so the added child is `HTML("hi")` @@ -73,6 +73,8 @@ h.div("hi") #
hi
# You can take advantage of Julia structs that already have text/html representations: +using Markdown + md_example = h.div(md""" # Here is Some Markdown @@ -102,7 +104,7 @@ node - `Node`s act like a `Vector` when it comes to children: ```julia -node = Cobweb.h.div +node = Cobweb.h.div #
push!(node, Cobweb.h.h1("Hello!")) @@ -111,6 +113,8 @@ node #

Hello!

node[1] = "changed" node #
changed
+ +collect(node) # ["changed"] ```
diff --git a/src/Cobweb.jl b/src/Cobweb.jl index e24f9bb..5c5569c 100644 --- a/src/Cobweb.jl +++ b/src/Cobweb.jl @@ -84,6 +84,13 @@ Base.iterate(o::Node) = iterate(children(o)) Base.iterate(o::Node, state) = iterate(children(o), state) Base.push!(o::Node, x) = push!(children(o), x) Base.append!(o::Node, x) = append!(children(o), x) +Base.deleteat!(o::Node, x) = deleteat!(children(o), x) +Base.pop!(o::Node) = pop!(children(o)) +Base.popfirst!(o::Node) = popfirst!(children(o)) +Base.splice!(o::Node, i::Integer) = splice!(children(o), i) +Base.splice!(o::Node, i::Integer, x) = splice!(children(o), i, x) + + #-----------------------------------------------------------------------------# show Node function print_opening_tag(io::IO, o::Node; self_close::Bool = false) @@ -244,13 +251,15 @@ Base.show(io::IO, ::MIME"text/html", o::Comment) = print(io, " IFrame(content; attrs...) Create an `