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

RSS macros #5

Merged
merged 4 commits into from Nov 9, 2019

Conversation

@iamFIREcracker
Copy link
Contributor

iamFIREcracker commented Nov 2, 2019

This PR adds WITH-RSS-CHANNEL-HEADER and WITH-RSS-ITEM macros to the package API (well, it adds support for <generator> and fixes a format issue with EMPTY-TAG too, but these changes can be easily moved into a new PR if need be).

The argument in favor of these new macros is that it would make it easier for users to customize the generated XML; "easier", because currently, in case a missing support for a specific element, users are forced to either one of these:

  • submit a bunch of PRs to add support for <generator>, or <atom:link>
  • don't use WITH-RSS at all, and simply rely on low-level macros (the ones defined inside xml.lisp)

Few use cases this change will support.

Support for <guid isPermaLink></guid> inside items

Without macros, you have to submit a PR in order to change RSS-ITEM to customize how <guid> gets created (e.g. #3); with macros on the other hand, one could easily implement this on the application side:

      :do (xml-emitter:with-rss-item (date :link *link*
                                           :pubDate pub-date)
            (xml-emitter::simple-tag "guid" guid '(("isPermaLink" "false")))

Support for <atom:link> with rel=self inside

Without macros, you would have to submit a PR and change RSS-CHANNEL-HEADER to add an additional <atom:link> element; with macros instead, one could go with the following:

    (xml-emitter::with-rss-channel-header (*title* *link* :description (read-channel-description)
                                                          :generator *generator*
                                                          :image *image*)
      (xml-emitter::empty-tag "atom:link" `(("href" ,*atom-link-self*)
                                            ("rel" "self")
                                            ("type" "application/rss+xml"))))

Wrapping elements inside CDATA blocks

Sometimes you need to wrap description fields inside <![CDATA[...]]> blocks to tell clients not to parse their content, and currently there is no easy way to support this (well, unless you exposed a way to let users specify wrap-pre/wrap-post strings, and changed the implementation to output these wrap-pre/wrap-post strings, as-is, before outputting the content of description); and what if you wanted to do something similar for other fields too? Well, with macros, users can do deal with all this on their side:

      :do (xml-emitter:with-rss-item (date :link * :pubDate pub-date)
            (xml-emitter::simple-tag "guid" (format NIL "~a#~a" *link* date)
                                     '(("isPermaLink" "false")))
            (xml-emitter::with-simple-tag ("description")
              (xml-emitter::xml-as-is "<![CDATA[<pre>")
              (xml-emitter::xml-out (plan-day-content day))
              (xml-emitter::xml-as-is "</pre>]]>"))))))
@VitoVan

This comment has been minimized.

Copy link
Owner

VitoVan commented Nov 5, 2019

I have checked this PR, and looks good to me.

@VitoVan

This comment has been minimized.

Copy link
Owner

VitoVan commented Nov 5, 2019

Hi Matteo Landi, do you mind I put your name into the author list here after merged?

@iamFIREcracker

@iamFIREcracker

This comment has been minimized.

Copy link
Contributor Author

iamFIREcracker commented Nov 5, 2019

@VitoVan VitoVan merged commit 403e07c into VitoVan:master Nov 9, 2019
@iamFIREcracker

This comment has been minimized.

Copy link
Contributor Author

iamFIREcracker commented Nov 11, 2019

@VitoVan - any plans for a Quicklisp release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.