Skip to content

Commit

Permalink
Merge pull request #29 from rdeits/fix-0.7
Browse files Browse the repository at this point in the history
fix v0.7 deprecations
  • Loading branch information
MikeInnes committed Jun 11, 2018
2 parents 7583fff + c11ebfc commit eb02b73
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ os:
- linux
- osx
julia:
- 0.5
- 0.6
- 0.7
- nightly
notifications:
email: false
Expand Down
1 change: 0 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
julia 0.7-
MacroTools 0.3.4
Compat 0.8.2
12 changes: 6 additions & 6 deletions src/Hiccup.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__precompile__()
module Hiccup

using MacroTools, Compat
using MacroTools

import MacroTools: @>

Expand All @@ -16,12 +16,12 @@ const VOID_ELEMENTS = Set([:area, :base, :br, :col, :embed, :hr, :img, :input,

# Basic Types

type Node{tag}
mutable struct Node{tag}
attrs::Dict{Any, Any}
children::Vector{Any}
end

tag{T}(node::Node{T}) = T
tag(node::Node{T}) where {T} = T
attrs(node::Node) = node.attrs
children(node::Node) = node.children

Expand All @@ -35,7 +35,7 @@ function Node(tag::Symbol, attrs::Dict = Dict(), content::AbstractVector = c();
Node{tag}(isempty(kws) ? attrs : merge(attrs, Dict([kws...])), content)
end

Node(tag::Symbol, attrs::Associative, content; kws...) =
Node(tag::Symbol, attrs::AbstractDict, content; kws...) =
Node(tag, attrs, c(content); kws...)

Node(tag::Symbol, content; kws...) =
Expand Down Expand Up @@ -66,11 +66,11 @@ Node(tag::Symbol, selector::AbstractString, content, args...; kws...) =
export htmlescape

htmlescape(s::AbstractString) =
@> s replace("&", "&amp;") replace("<", "&lt;") replace(">", "&gt;")
@> s replace("&" => "&amp;") replace("<" => "&lt;") replace(">" => "&gt;")

attrstring(xs::Vector) = join(xs, " ")
attrstring(x) =
@> x string htmlescape replace("\"", "&quot;") replace("'", "&#39;")
@> x string htmlescape replace("\"" => "&quot;") replace("'" => "&#39;")
attrstring(d::Dict) = join(("$k=\"$(attrstring(v))\"" for (k, v) in d), " ")

render(io::IO, s::AbstractString) = print(io, htmlescape(s))
Expand Down
13 changes: 6 additions & 7 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using Hiccup
using Base.Test
using Compat
using Test

@tags br, link

# hiccup div conflicts with main div, so use this as compromise
ediv = Hiccup.div

@test contains(sprint(Hiccup.render, Node(:img, "#id.class1.class2", Dict(:src=>"http://www.com"))), "class=\"class1 class2\"")
@test occursin("class=\"class1 class2\"", sprint(Hiccup.render, Node(:img, "#id.class1.class2", Dict(:src=>"http://www.com"))))

classMatching = ((".section-title", "section-title"),
(".test", "test"),
Expand All @@ -25,16 +24,16 @@ classMatching = ((".section-title", "section-title"),
("#id.-test.test2", "-test test2"),
("#id.-test.-test2", "-test -test2"))
for (in, expected) in classMatching
@test contains(sprint(Hiccup.render, Hiccup.div(in, "contents")), expected)
@test occursin(expected, sprint(Hiccup.render, Hiccup.div(in, "contents")))
end


# tests for void tags
@test string(br()) == "<br />"
@test string(img(".image-test", [])) == "<img class=\"image-test\" />"
@test contains(
string(link(Dict(:rel => "stylesheet", :href => "test.css"))),
"/>")
@test occursin(
"/>",
string(link(Dict(:rel => "stylesheet", :href => "test.css"))))
@test_throws ArgumentError img(strong(".test", "test"))

# tests for normal tags
Expand Down

0 comments on commit eb02b73

Please sign in to comment.