Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for 0.7 and add some basic tests #6

Merged
merged 5 commits into from
Aug 15, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ various web elements on the DOM.
using WebIO
using CSSUtil

el1 = node(:div, "Hello world!")
el2 = node(:div, "Goodbye world!")
el1 = Node(:div, "Hello world!")
el2 = Node(:div, "Goodbye world!")

el3 = hbox(el1, el2) # aligns horizontally
el4 = hline() # draws horizontal line
Expand Down
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
julia 0.6
Compat
Compat 0.61.0 # for uppercasefirst
Measures
Colors
WebIO
Expand Down
16 changes: 13 additions & 3 deletions src/CSSUtil.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
module CSSUtil

import Base: @md_str
using Compat
using Compat.Markdown

import Compat.Markdown: @md_str

export style, empty
export @md_str
Expand All @@ -9,6 +12,13 @@ using WebIO
using JSON
import WebIO: render, Node

if isdefined(WebIO, :node) # TODO: remove once a new WebIO tag is in
using WebIO: node
else
using WebIO: Node
const node = Node
end

using Measures
using Colors

Expand All @@ -28,11 +38,11 @@ function style(elem, p::Pair...)
render(elem)(style(p...))
end

function style(::Void, arg::Pair...)
function style(::Nothing, arg::Pair...)
style(arg...)
end

function style(::Void, arg::Dict)
function style(::Nothing, arg::Dict)
style(arg)
end

Expand Down
2 changes: 1 addition & 1 deletion src/layout.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function flex(elem=nothing)
style(elem, "display"=>"flex")
end

function container(xs...)
function container(xs::AbstractVector)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was necessary because after the Node -> node change, this would otherwise create a PersistentVector{Vector{Node}} instead of a PersistentVector{Node}.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this fixes #5.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Probably worth adding a container(xs...) = container([xs...]) method as well: this function is exported so we should try to preserve the multi-argument method.

dom"div"(xs...)
end

Expand Down
10 changes: 5 additions & 5 deletions src/theme.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export border, borderstyle, bordercolor, borderwidth, hline, vline,

function _border_prefix(side::Union{Symbol, String})
assertoneof(side, ["top", "bottom", "left", "right"], "side")
"border$(ucfirst(side))"
"border$(uppercasefirst(side))"
end

function assertstyle(style)
Expand Down Expand Up @@ -39,11 +39,11 @@ end
"""
hline()

Draw a horizonal line.
Draw a horizonal line.

Keyword Arguments:
=================
- style: Indicates whether line should be solid or dotted.
- style: Indicates whether line should be solid or dotted.
Defaults to "solid"
- w: Specifies line width. Defaults to 1px
- color: specifies color in hex code RGB. Defaults to "#dedede".
Expand All @@ -55,11 +55,11 @@ end
"""
vline()

Draw a vertical line.
Draw a vertical line.

Keyword Arguments:
=================
- style: Indicates whether line should be solid or dotted.
- style: Indicates whether line should be solid or dotted.
Defaults to "solid"
- w: Specifies line width. Defaults to 1px
- color: specifies color in hex code RGB. Defaults to "#dedede".
Expand Down
15 changes: 11 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@ using CSSUtil
using WebIO
using Compat.Test

if isdefined(WebIO, :node) # TODO: remove once a new WebIO tag is in
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just got tagged, could you update this?

using WebIO: node
else
using WebIO: Node
const node = Node
end

@testset "hbox" begin
el1 = node(:div, "Hello world!")
el2 = node(:div, "Goodbye world!")
box = hbox(el1, el2)
@test props(box)[:style]["display"] == "flex"
@test props(box)[:style]["flex-direction"] == "row"
@test el1 ∈ children(box)[1]
@test el2 ∈ children(box)[1]
@test el1 ∈ children(box)
@test el2 ∈ children(box)
end

@testset "vbox" begin
Expand All @@ -18,8 +25,8 @@ end
box = vbox(el1, el2)
@test props(box)[:style]["display"] == "flex"
@test props(box)[:style]["flex-direction"] == "column"
@test el1 ∈ children(box)[1]
@test el2 ∈ children(box)[1]
@test el1 ∈ children(box)
@test el2 ∈ children(box)
end

@testset "hline" begin
Expand Down