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

Support content and dc namespaces #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
31 changes: 31 additions & 0 deletions lib/gluttony/handlers/rss2_content.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
defmodule Gluttony.Handlers.RSS2Content do
@moduledoc false

@behaviour Gluttony.Handler

@impl true
def handle_element(attrs, stack) do
case stack do
_ ->
{:cont, attrs}
end
end

@impl true
def handle_content(chars, stack) do
case stack do
["content:encoded", "item" | _] ->
{:entry, :content, chars}

_ ->
{:cont, chars}
end
end

@impl true
def handle_cached(cached, stack) do
case stack do
_ -> {:cont, cached}
end
end
end
31 changes: 31 additions & 0 deletions lib/gluttony/handlers/rss2_dc.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
defmodule Gluttony.Handlers.RSS2DC do
@moduledoc false

@behaviour Gluttony.Handler

@impl true
def handle_element(attrs, stack) do
case stack do
_ ->
{:cont, attrs}
end
end

@impl true
def handle_content(chars, stack) do
case stack do
["dc:creator", "item" | _] ->
{:entry, :author, chars}

_ ->
{:cont, chars}
end
end

@impl true
def handle_cached(cached, stack) do
case stack do
_ -> {:cont, cached}
end
end
end
8 changes: 8 additions & 0 deletions lib/gluttony/parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ defmodule Gluttony.Parser do
@feedburner_namespace "http://rssnamespace.org/feedburner/ext/1.0"
@googleplay_namespace "http://www.google.com/schemas/play-podcasts/1.0"
@atom_namespace "http://www.w3.org/2005/Atom"
@content_namespace "http://purl.org/rss/1.0/modules/content/"
@dc_namespace "http://purl.org/dc/elements/1.1/"

@doc false
def handle_event(:start_document, _prolog, opts) do
Expand Down Expand Up @@ -97,6 +99,12 @@ defmodule Gluttony.Parser do
{"xmlns:googleplay", @googleplay_namespace}, acc ->
[Gluttony.Handlers.RSS2Googleplay | acc]

{"xmlns:content", @content_namespace}, acc ->
[Gluttony.Handlers.RSS2Content | acc]

{"xmlns:dc", @dc_namespace}, acc ->
[Gluttony.Handlers.RSS2DC | acc]

_kv, acc ->
acc
end)
Expand Down
5 changes: 4 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ defmodule Gluttony.MixProject do
description: description(),
package: package(),
docs: docs(),
deps: deps()
deps: deps(),
preferred_cli_env: [
vcr: :test, "vcr.delete": :test, "vcr.check": :test, "vcr.show": :test
],
thiagomajesk marked this conversation as resolved.
Show resolved Hide resolved
]
end

Expand Down
Loading