Skip to content

Commit

Permalink
Merge pull request #38 from porterjamesj/0.6-fixes
Browse files Browse the repository at this point in the history
0.6 fixes
  • Loading branch information
porterjamesj authored Jul 6, 2017
2 parents e04f0d1 + 74d8c6a commit 2684051
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 34 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ os:
- linux
- osx
julia:
- 0.5
- 0.6
- nightly
matrix:
Expand Down
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
julia 0.5
Compat 0.23.0
BinDeps
AbstractTrees 0.0.4
AbstractTrees 0.1.0
12 changes: 5 additions & 7 deletions src/htmltypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@ using Compat

@compat abstract type HTMLNode end

# TODO change all these to use struct / mutable struct in the next release

# TODO immutable?
type HTMLText <: HTMLNode
struct HTMLText <: HTMLNode
parent::HTMLNode
text::AbstractString
end

# convenience method for defining without parent
HTMLText(text::AbstractString) = HTMLText(NullNode(), text)

type NullNode <: HTMLNode end
struct NullNode <: HTMLNode end

type HTMLElement{T} <: HTMLNode
mutable struct HTMLElement{T} <: HTMLNode
children::Vector{HTMLNode}
parent::HTMLNode
attributes::Dict{AbstractString,AbstractString}
Expand All @@ -24,11 +22,11 @@ end
# convenience method for defining an empty element
HTMLElement(T::Symbol) = HTMLElement{T}(HTMLNode[],NullNode(),Dict{AbstractString,AbstractString}())

type HTMLDocument
mutable struct HTMLDocument
doctype::AbstractString
root::HTMLElement
end

type InvalidHTMLException <: Exception
struct InvalidHTMLException <: Exception
msg::AbstractString
end
24 changes: 5 additions & 19 deletions src/manipulation.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# functions for accessing and manipulation HTML types

import AbstractTrees
import Base: depwarn

# elements

tag{T}(elem::HTMLElement{T}) = T
Expand All @@ -13,12 +11,13 @@ function setattr!(elem::HTMLElement, name::AbstractString, value::AbstractString
end
getattr(elem::HTMLElement, name) = elem.attributes[name]


AbstractTrees.children(elem::HTMLElement) = elem.children

# TODO sometimes convenient but this should arguably be an error
# breadthfirst traversal will have to be updated
AbstractTrees.children(elem::HTMLNode) = HTMLNode[]
# TODO there is a naming conflict here if you want to use both packages
# (see https://github.com/porterjamesj/Gumbo.jl/issues/31)
#
# I still think exporting `children` from Gumbo is the right thing to
# do, since it's probably more common to be using this package alone

children = AbstractTrees.children

Expand All @@ -32,16 +31,3 @@ Base.push!(elem::HTMLElement,val) = push!(elem.children, val)
# text

text(t::HTMLText) = t.text

# tree traversals, deprecated wrappers around AbstractTrees

for (name, replacement) in [(:preorder, :PreOrderDFS),
(:postorder, :PostOrderDFS),
(:breadthfirst, :StatelessBFS)]
@eval @deprecate $name(e::HTMLElement) AbstractTrees.$replacement(e)
@eval function $name(f::Function, el::HTMLElement)
for node in $name(el)
f(node)
end
end
end
9 changes: 3 additions & 6 deletions test/comparison.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
let
x = HTMLText("test")
y = HTMLText("test")
x1 = HTMLText("test1")
@test x == y
@test hash(x) == hash(y)
x.text *= "1"
@test x != y
@test hash(x) != hash(y)
y.text *= "1"
@test x == y
@test hash(x) == hash(y)
@test x1 != y
@test hash(x1) != hash(y)
end

let
Expand Down

0 comments on commit 2684051

Please sign in to comment.