Skip to content

Commit b92b11d

Browse files
committed
bump version, added some array-like methods such as pop!, loosen compat a bit
1 parent d747138 commit b92b11d

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

Project.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Cobweb"
22
uuid = "ec354790-cf28-43e8-bb59-b484409b7bad"
33
authors = ["joshday <[email protected]> and contributors"]
4-
version = "0.6.1"
4+
version = "0.7.0"
55

66
[deps]
77
DefaultApplication = "3f0dd361-4fe0-5fc6-8523-80b14ec94d85"
@@ -10,8 +10,8 @@ Scratch = "6c6a2e73-6563-6170-7368-637461726353"
1010

1111
[compat]
1212
DefaultApplication = "1"
13-
OrderedCollections = "1.5"
14-
Scratch = "1.1"
13+
OrderedCollections = "1"
14+
Scratch = "1"
1515
julia = "1"
1616

1717
[extras]

README.md

+11-7
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
# Features
99

10-
- View any `"text/html"`-representable object in your browser with `preview(x)`.
11-
- Nice syntax for writing HTML: `h.<tag>(children...; attrs...)`
10+
- Open `"text/html"`-representable objects in your browser with `preview(x)`.
11+
- Clean syntax for writing HTML: `h.<tag>(children...; attrs...)`
1212

1313
```julia
1414
h.div(class="myclass", style="color:red;")("content!")
@@ -29,14 +29,13 @@ body = h.body(
2929
h.script("const buttonClicked = () => alert('This button was clicked!')"),
3030
)
3131

32-
3332
preview(body)
3433
```
3534

3635
<br>
3736
<br>
3837

39-
# Creating Nodes with `Cobweb.h`
38+
# Writing HTML with `Cobweb.h`
4039

4140
### `h` is a pretty special function
4241

@@ -49,7 +48,7 @@ h.tag # == h(:tag)
4948

5049
### `h` Creates a `Cobweb.Node`
5150

52-
- `Cobweb.Node`s are callable:
51+
- `Cobweb.Node`s are callable (creates a copy with new children/attributes):
5352

5453
```julia
5554
h.div("hi") # positional arguments add *children*
@@ -65,14 +64,17 @@ h.div("hi")(style="border:none;")
6564

6665
### Child Elements can be Anything
6766

68-
- If `!showable("text/html", child)`, `child` will be added as `HTML(child)`.
67+
- If a `child` isn't `MIME"text/html"`-representable, it will be added as a `HTML(child)`.
68+
- Note: `HTML(x)` means "insert this into HTML as `print(x)`".
6969

7070
```julia
7171
# e.g. Strings have no text/html representation, so the added child is `HTML("hi")`
7272
h.div("hi")
7373
# <div>hi</div>
7474

7575
# You can take advantage of Julia structs that already have text/html representations:
76+
using Markdown
77+
7678
md_example = h.div(md"""
7779
# Here is Some Markdown
7880
@@ -102,7 +104,7 @@ node
102104
- `Node`s act like a `Vector` when it comes to children:
103105

104106
```julia
105-
node = Cobweb.h.div
107+
node = Cobweb.h.div # <div></div>
106108

107109
push!(node, Cobweb.h.h1("Hello!"))
108110

@@ -111,6 +113,8 @@ node # <div><h1>Hello!</h1></div>
111113
node[1] = "changed"
112114

113115
node # <div>changed</div>
116+
117+
collect(node) # ["changed"]
114118
```
115119

116120
<br>

src/Cobweb.jl

+13-4
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ Base.iterate(o::Node) = iterate(children(o))
8484
Base.iterate(o::Node, state) = iterate(children(o), state)
8585
Base.push!(o::Node, x) = push!(children(o), x)
8686
Base.append!(o::Node, x) = append!(children(o), x)
87+
Base.deleteat!(o::Node, x) = deleteat!(children(o), x)
88+
Base.pop!(o::Node) = pop!(children(o))
89+
Base.popfirst!(o::Node) = popfirst!(children(o))
90+
Base.splice!(o::Node, i::Integer) = splice!(children(o), i)
91+
Base.splice!(o::Node, i::Integer, x) = splice!(children(o), i, x)
92+
93+
8794

8895
#-----------------------------------------------------------------------------# show Node
8996
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, "<!-- ", o.x, " -->
244251
IFrame(content; attrs...)
245252
246253
Create an `<iframe srcdoc=\$content \$(attrs...)>`.
254+
255+
This can be helpful to work around environments that block loading scripts, such as Jupyter notebooks.
247256
"""
248-
struct IFrame{T, KW}
257+
struct IFrame{T}
249258
content::T
250-
kw::KW
251-
IFrame(x::T; kw...) where {T} = new{T, typeof(kw)}(x, kw)
259+
kw::OrderedDict{Symbol, Any}
260+
IFrame(x::T = ""; kw...) where {T} = new{T}(x, OrderedDict{Symbol,Any}(kw))
252261
end
253-
function Base.show(io::IO, ::MIME"text/html", o::IFrame)
262+
function Base.show(io::IO, ::MIME"text/html", o::IFrame{T}) where {T}
254263
show(io, h.iframe(; srcdoc=escape(repr("text/html", o.content)), o.kw...))
255264
end
256265

0 commit comments

Comments
 (0)