-module(atomb). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([render/1]). -export_type([feed/0, generator/0, person/0, link/0, category/0, entry/0, text_media_type/0, text_content/0, content/0]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. ?MODULEDOC( " Atom feeds! See the RFC for details:\n" " \n" ). -type feed() :: {feed, binary(), binary(), gleam@time@timestamp:timestamp(), gleam@option:option(text_content()), gleam@option:option(text_content()), gleam@option:option(binary()), gleam@option:option(binary()), list(person()), list(link()), list(category()), list(person()), gleam@option:option(generator()), list(entry())}. -type generator() :: {generator, binary(), gleam@option:option(binary()), gleam@option:option(binary())}. -type person() :: {person, binary(), gleam@option:option(binary()), gleam@option:option(binary())}. -type link() :: {link, binary(), gleam@option:option(binary())}. -type category() :: {category, binary(), gleam@option:option(binary()), gleam@option:option(binary())}. -type entry() :: {entry, binary(), binary(), gleam@time@timestamp:timestamp(), gleam@option:option(content()), gleam@option:option(text_content()), list(category()), list(link()), list(person()), list(person()), gleam@option:option(gleam@time@timestamp:timestamp()), gleam@option:option(binary())}. -type text_media_type() :: text | html | xhtml. -type text_content() :: {text_content, text_media_type(), binary()}. -type content() :: {inline_text, text_media_type(), binary()} | {out_of_line, binary(), binary()}. -file("src/atomb.gleam", 123). -spec generator(generator()) -> xmb:xml(). generator(Generator) -> {generator, T, Uri, Version} = Generator, Values = [gleam@option:map(Uri, fun(S) -> {<<"uri"/utf8>>, S} end), gleam@option:map(Version, fun(S@1) -> {<<"version"/utf8>>, S@1} end)], xmb:x(<<"generator"/utf8>>, gleam@option:values(Values), [xmb:text(T)]). -file("src/atomb.gleam", 170). -spec timestamp_element(binary(), gleam@time@timestamp:timestamp()) -> xmb:xml(). timestamp_element(Tag, Timestamp) -> xmb:x( Tag, [], [xmb:text(gleam@time@timestamp:to_rfc3339(Timestamp, {duration, 0, 0}))] ). -file("src/atomb.gleam", 174). -spec category(category()) -> xmb:xml(). category(Category) -> {category, Term, Scheme, Label} = Category, Values = [{some, {<<"term"/utf8>>, Term}}, gleam@option:map(Scheme, fun(S) -> {<<"scheme"/utf8>>, S} end), gleam@option:map(Label, fun(S@1) -> {<<"label"/utf8>>, S@1} end)], xmb:x(<<"category"/utf8>>, gleam@option:values(Values), []). -file("src/atomb.gleam", 184). -spec link(link()) -> xmb:xml(). link(Link) -> {link, Href, Rel} = Link, Values = [{some, {<<"href"/utf8>>, Href}}, gleam@option:map(Rel, fun(S) -> {<<"rel"/utf8>>, S} end)], xmb:x(<<"link"/utf8>>, gleam@option:values(Values), []). -file("src/atomb.gleam", 202). -spec text_element(binary(), binary()) -> xmb:xml(). text_element(Name, Content) -> xmb:x(Name, [], [xmb:text(Content)]). -file("src/atomb.gleam", 206). -spec text_content(binary(), text_content()) -> xmb:xml(). text_content(Name, Content) -> {Media_type, Content@1} = case erlang:element(2, Content) of html -> {<<"html"/utf8>>, xmb:cdata(erlang:element(3, Content))}; text -> {<<"text"/utf8>>, xmb:text(erlang:element(3, Content))}; xhtml -> {<<"xhtml"/utf8>>, begin _pipe = erlang:element(3, Content), _pipe@1 = gleam_stdlib:identity(_pipe), xmb_ffi:identity(_pipe@1) end} end, xmb:x(Name, [{<<"type"/utf8>>, Media_type}], [Content@1]). -file("src/atomb.gleam", 161). -spec content_element(content()) -> xmb:xml(). content_element(Content) -> case Content of {inline_text, Media_type, Content@1} -> text_content( <<"content"/utf8>>, {text_content, Media_type, Content@1} ); {out_of_line, Media_type@1, Src_uri} -> xmb:x( <<"content"/utf8>>, [{<<"type"/utf8>>, Media_type@1}, {<<"src"/utf8>>, Src_uri}], [] ) end. -file("src/atomb.gleam", 220). -spec 'maybe'(gleam@option:option(FIU), fun((FIU) -> xmb:xml())) -> xmb:xml(). 'maybe'(Item, Render) -> case Item of {some, Value} -> Render(Value); none -> xmb:nothing() end. -file("src/atomb.gleam", 193). -spec person(binary(), person()) -> xmb:xml(). person(Tag, Person) -> {person, Name, Uri, Email} = Person, xmb:x( Tag, [], [xmb:x(<<"name"/utf8>>, [], [xmb:text(Name)]), 'maybe'( Uri, fun(_capture) -> text_element(<<"uri"/utf8>>, _capture) end ), 'maybe'( Email, fun(_capture@1) -> text_element(<<"email"/utf8>>, _capture@1) end )] ). -file("src/atomb.gleam", 227). -spec many(list(FIW), fun((FIW) -> xmb:xml())) -> xmb:xml(). many(Items, Render) -> _pipe = gleam@list:map(Items, Render), xmb_ffi:identity(_pipe). -file("src/atomb.gleam", 132). -spec entry(entry()) -> xmb:xml(). entry(Entry) -> {entry, Id, Title, Updated, Content, Summary, Categories, Links, Authors, Contributors, Published, Rights} = Entry, xmb:x( <<"entry"/utf8>>, [], [xmb:x(<<"title"/utf8>>, [], [xmb:text(Title)]), xmb:x(<<"id"/utf8>>, [], [xmb:text(Id)]), timestamp_element(<<"updated"/utf8>>, Updated), 'maybe'( Summary, fun(_capture) -> text_content(<<"summary"/utf8>>, _capture) end ), 'maybe'( Rights, fun(_capture@1) -> text_element(<<"rights"/utf8>>, _capture@1) end ), 'maybe'( Published, fun(_capture@2) -> timestamp_element(<<"published"/utf8>>, _capture@2) end ), many(Categories, fun category/1), many( Authors, fun(_capture@3) -> person(<<"author"/utf8>>, _capture@3) end ), many( Contributors, fun(_capture@4) -> person(<<"contributor"/utf8>>, _capture@4) end ), many(Links, fun link/1), 'maybe'(Content, fun content_element/1)] ). -file("src/atomb.gleam", 87). -spec render(feed()) -> gleam@string_tree:string_tree(). render(Feed) -> {feed, Title, Id, Updated, Subtitle, Rights, Icon, Logo, Authors, Links, Categories, Contributors, Gen, Entries} = Feed, _pipe = xmb:x( <<"feed"/utf8>>, [{<<"xmlns"/utf8>>, <<"http://www.w3.org/2005/Atom"/utf8>>}], [xmb:x(<<"title"/utf8>>, [], [xmb:text(Title)]), xmb:x(<<"id"/utf8>>, [], [xmb:text(Id)]), xmb:x( <<"updated"/utf8>>, [], [xmb:text( gleam@time@timestamp:to_rfc3339( Updated, {duration, 0, 0} ) )] ), 'maybe'( Subtitle, fun(_capture) -> text_content(<<"subtitle"/utf8>>, _capture) end ), 'maybe'( Rights, fun(_capture@1) -> text_content(<<"rights"/utf8>>, _capture@1) end ), 'maybe'( Icon, fun(_capture@2) -> text_element(<<"icon"/utf8>>, _capture@2) end ), 'maybe'( Logo, fun(_capture@3) -> text_element(<<"logo"/utf8>>, _capture@3) end ), 'maybe'(Gen, fun generator/1), many( Authors, fun(_capture@4) -> person(<<"author"/utf8>>, _capture@4) end ), many( Contributors, fun(_capture@5) -> person(<<"contributor"/utf8>>, _capture@5) end ), many(Links, fun link/1), many(Categories, fun category/1), many(Entries, fun entry/1)] ), _pipe@1 = gleam@list:wrap(_pipe), xmb:render(_pipe@1).