-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
122 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
%% @author Marc Worrell <marc@worrell.nl> | ||
%% @copyright 2017 Marc Worrell <marc@worrell.nl> | ||
%% @doc Format exports for atom format | ||
|
||
%% Copyright 2017 Marc Worrell | ||
%% | ||
%% Licensed under the Apache License, Version 2.0 (the "License"); | ||
%% you may not use this file except in compliance with the License. | ||
%% You may obtain a copy of the License at | ||
%% | ||
%% http://www.apache.org/licenses/LICENSE-2.0 | ||
%% | ||
%% Unless required by applicable law or agreed to in writing, software | ||
%% distributed under the License is distributed on an "AS IS" BASIS, | ||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
%% See the License for the specific language governing permissions and | ||
%% limitations under the License. | ||
|
||
-module(export_encoder_atom). | ||
-author("Marc Worrell <marc@worrell.nl>"). | ||
|
||
-record(state, { | ||
id | ||
}). | ||
|
||
-export([ | ||
extension/0, | ||
mime/0, | ||
init/2, | ||
header/3, | ||
row/3, | ||
footer/3 | ||
]). | ||
|
||
-include_lib("zotonic.hrl"). | ||
|
||
extension() -> | ||
[ "atom" ]. | ||
|
||
mime() -> | ||
[ "application/atom+xml" ]. | ||
|
||
init(Options, _Context) -> | ||
{ok, #state{ | ||
id = proplists:get_value(id, Options) | ||
}}. | ||
|
||
header(Header, #state{id=Id} = State, Context) -> | ||
Vars = [ | ||
{id, Id}, | ||
{title, Header} | ||
], | ||
{Bin, _Context} = z_template:render_to_iolist("atom/feed_start.tpl", Vars, Context), | ||
{ok, iolist_to_binary(Bin), State}. | ||
|
||
row(Row, #state{} = State, Context) when is_integer(Row) -> | ||
Vars = [ | ||
{id, Row} | ||
], | ||
{Bin, _Context} = z_template:render_to_iolist({cat, "atom/entry.tpl"}, Vars, Context), | ||
{ok, iolist_to_binary(Bin), State}; | ||
row(Row, #state{} = State, Context) -> | ||
Vars = [ | ||
{id, Row} | ||
], | ||
{Bin, _Context} = z_template:render_to_iolist("atom/entry.tpl", Vars, Context), | ||
{ok, iolist_to_binary(Bin), State}. | ||
|
||
footer(_Data, #state{}, Context) -> | ||
{Bin, _Context} = z_template:render_to_iolist("atom/feed_end.tpl", [], Context), | ||
{ok, iolist_to_binary(Bin)}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{% if id and id.is_visible %} | ||
{% with id.medium as medium %} | ||
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005" xml:lang="{{ z_language }}"> | ||
<id>{{ id.uri|escapexml }}</id> | ||
<updated>{{ id.modified|date:"c" }}</updated> | ||
<published>{{ id.publication_start|date:"c" }}</published> | ||
<author>{% with id.o.author[1]|default:id.creator_id as author_id %} | ||
<name>{% filter escapexml %}{% include "_name.tpl" id=author_id %}{% endfilter %}</name> | ||
<uri>{{ author_id.uri|escapexml }}</uri> | ||
{% endwith %}</author> | ||
<link rel="alternate" type="text/html" href="{{ id.page_url_abs }}"/> | ||
{% if medium.filename %} | ||
<link rel="enclosure" type="{{ medium.mime }}" href="{% url media_attachment star=medium.filename use_abolute_url %}" /> | ||
{% elseif medium %} | ||
<link rel="enclosure" type="image/jpeg" href="{% image_url id width=400 height=400 use_absolute_url %}" /> | ||
{% endif %} | ||
{% for media_id in id.media %} | ||
<link rel="enclosure" type="image/jpeg" href="{% image_url media_id width=400 height=400 use_absolute_url %}" /> | ||
{% endfor %} | ||
<title>{{ id.title|escapexml }}</title> | ||
{% if id.body %} | ||
<summary>{{ id.summary|escapexml }}</summary> | ||
<content type="html">{{ id.body|escapexml }}</content> | ||
{% else %} | ||
<content type="text">{{ id.summary|escapexml }}</content> | ||
{% endif %} | ||
{% if medium.filename %} | ||
<content type="{{ medium.mime }}" src="{% url media_attachment star=medium.filename use_absolute_url %}" /> | ||
{% endif %} | ||
{% if id.is_a.event and id.date_start %} | ||
{# http://code.google.com/apis/gdata/docs/2.0/elements.html#gdEventKind #} | ||
<category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/g/2005#event" /> | ||
<gd:eventStatus value="http://schemas.google.com/g/2005#event.confirmed" /> | ||
<gd:when startTime="{{ id.date_start|date:"c" }}" endTime="{{ id.date_end|date:"c" }}" /> | ||
{# <gd:where>My Living Room</gd:where> #} | ||
{% endif %} | ||
|
||
<category term="{{ id.category.name }}" scheme="http://zotonic.com/id/category" /> | ||
</entry> | ||
{% endwith %} | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
</feed> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<feed xmlns="http://www.w3.org/2005/Atom" xml:base="{% url home use_absolute_url %}" xml:lang="{{ z_language }}"> | ||
<generator uri="http://zotonic.com/">Zotonic - Atom Feed Module</generator> | ||
<updated>{{ now|date:"c" }}</updated> | ||
<logo /> | ||
{# <link rel="self" type="application/atom+xml" href="{% url atom_feed cat=cat %}" /> #} | ||
<id>{% url home use_absolute_url %}</id> | ||
<title>{{ m.config.site.title.value|escapexml }}{% if title %} - {{ title|escapexml }}{% endif %}</title> |