core: plain Literal sigil
This commit is contained in:
parent
06854efbd8
commit
d0b511c771
2 changed files with 38 additions and 4 deletions
|
@ -12,7 +12,33 @@ defmodule RDF.Sigils do
|
|||
RDF.uri("http://example.com")
|
||||
|
||||
"""
|
||||
defmacro sigil_I({:<<>>, _, [iri]}, []) when is_binary(iri),
|
||||
do: Macro.escape(RDF.uri(iri))
|
||||
defmacro sigil_I({:<<>>, _, [iri]}, []) when is_binary(iri) do
|
||||
Macro.escape(RDF.uri(iri))
|
||||
end
|
||||
|
||||
@doc ~S"""
|
||||
Handles the sigil `~L` for plain Literals.
|
||||
|
||||
The sigil modifier can be used to specify a language tag.
|
||||
|
||||
Note: Languages with subtags are not supported.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> import RDF.Sigils
|
||||
iex> ~L"foo"
|
||||
RDF.literal("foo")
|
||||
iex> ~L"foo"en
|
||||
RDF.literal("foo", language: "en")
|
||||
|
||||
"""
|
||||
defmacro sigil_L(value, language)
|
||||
|
||||
defmacro sigil_L({:<<>>, _, [value]}, []) when is_binary(value) do
|
||||
Macro.escape(RDF.Literal.new(value))
|
||||
end
|
||||
|
||||
defmacro sigil_L({:<<>>, _, [value]}, language) when is_binary(value) do
|
||||
Macro.escape(RDF.Literal.new(value, %{language: to_string(language)}))
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,11 +6,19 @@ defmodule RDF.SigilsTest do
|
|||
doctest RDF.Sigils
|
||||
|
||||
describe "IRI sigil without interpolation" do
|
||||
|
||||
test "it can create a URI struct from a sigil" do
|
||||
test "creating an URI" do
|
||||
assert ~I<http://example.com> == RDF.uri("http://example.com")
|
||||
end
|
||||
end
|
||||
|
||||
describe "Literal sigil without interpolation" do
|
||||
test "creating a plain Literal" do
|
||||
assert ~L"foo" == RDF.literal("foo")
|
||||
end
|
||||
|
||||
test "creating a language-tagged Literal" do
|
||||
assert ~L"foo"en == RDF.literal("foo", language: "en")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue