Skip to content

Commit

Permalink
Use the Table constructor for TableFile's.
Browse files Browse the repository at this point in the history
This keeps the vocabulary of this library close to `pgfplots`.

Also convert paths to absolute if necessary, otherwise they will not
be found when compiling from temporary files.
  • Loading branch information
tpapp committed Feb 8, 2018
1 parent 2e766ee commit b685411
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
15 changes: 13 additions & 2 deletions src/axiselements.jl
Original file line number Diff line number Diff line change
Expand Up @@ -482,18 +482,29 @@ end
# TableFile #
#############

"""
$(TYPEDEF)
Placeholder for a table for which data is read directly from a file. Use the
[`Table`](@ref) constructor.
"""
struct TableFile <: OptionType
options::OrderedDict{Any, Any}
path::AbstractString
end

"""
TableFile([options], path)
$SIGNATURES
For reading tables directly from files. See the `pgfplots` manual for the
accepted format.
If you don't use an absolute path, it will be converted to one.
"""
TableFile(path::AbstractString) = TableFile(OrderedDict{Any, Any}(), path)
Table(options::OrderedDict{Any, Any}, path::AbstractString) =
TableFile(options, abspath(path))

Table(path::AbstractString) = Table(OrderedDict{Any, Any}(), path)

function print_tex(io_main::IO, tablefile::TableFile)
@unpack options, path = tablefile
Expand Down
8 changes: 5 additions & 3 deletions test/test_elements.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ end
end

@testset "tablefile" begin
@test squashed_repr_tex(pgf.TableFile(pgf.@pgf({x = "a", y = "b"}), "somefile.dat")) ==
"table [x={a}, y={b}]\n{somefile.dat}"
@test squashed_repr_tex(pgf.TableFile("somefile.dat")) == "table []\n{somefile.dat}"
path = "somefile.dat"
_abspath = abspath(path)
@test squashed_repr_tex(pgf.Table(pgf.@pgf({x = "a", y = "b"}), path)) ==
"table [x={a}, y={b}]\n{$(_abspath)}"
@test squashed_repr_tex(pgf.Table("somefile.dat")) == "table []\n{$(_abspath)}"
end

0 comments on commit b685411

Please sign in to comment.