diff options
author | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2009-02-23 18:45:22 +0100 |
---|---|---|
committer | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2009-02-23 18:45:22 +0100 |
commit | 7e43b4ac063f99d9b99f1e435ee887bd1ab4e209 (patch) | |
tree | 6cfde23a1059df7e9a5857452754efa1ddfa311b | |
parent | 341e5d378b8d77a0e0dbffa131231b787dd92b68 (diff) |
Use templates wherever possible.
-rw-r--r-- | cljssss-g.clj | 88 | ||||
-rw-r--r-- | simple-entry-list.st | 9 | ||||
-rw-r--r-- | simple-feed-list.st | 9 |
3 files changed, 59 insertions, 47 deletions
diff --git a/cljssss-g.clj b/cljssss-g.clj index 6f77200..be26932 100644 --- a/cljssss-g.clj +++ b/cljssss-g.clj @@ -26,13 +26,11 @@ (sql/transaction ~@body))) -;;; FIXME: clojure has no way of creating interfaces on-the-fly. So I -;;; cannot use stringtemplate here. -(defn opml-string [id] +(defn opml-string [user] (with-dbt (sql/with-query-results results - ["SELECT feed.uri, feed.link, user_feed_link.title FROM feed, user_feed_link WHERE user_feed_link.feed=feed.id AND user_feed_link.user=?" id] + ["SELECT feed.uri, feed.link, user_feed_link.title FROM feed, user_feed_link WHERE user_feed_link.feed=feed.id AND user_feed_link.user=?" user] (.toString (doto (.getInstanceOf templates "opml") (.setAttributes {"date" "" ;FIXME "feeds" @@ -44,53 +42,49 @@ "htmlurl" link}) results)})))))) -(defn lynxy-feedlist [id] +(defn lynxy-feedlist [feed] (with-dbt (sql/with-query-results - results - [(str "SELECT feed.id, feed.uri, feed.link, user_feed_link.title" - " FROM feed, user_feed_link" - " WHERE user_feed_link.feed=feed.id AND user_feed_link.user=?") - id] - (html - `[html - [head [title "Gödel-Gentzen Clojure Syndication Services Super System"]] - [body [ul - ~@(loop [back '[] r results] - (if (first r) - (recur (concat back `[[li - [a {:href ~(str "lynxy-showfeed?feed=" (:id (first r)))} - ~(:title (first r)) " - " - ~(:link (first r)) - ]]]) - (rest r)) - back))]]])))) + results + [(str "SELECT feed.id, feed.uri, feed.link, user_feed_link.title" + " FROM feed, user_feed_link" + " WHERE user_feed_link.feed=feed.id AND user_feed_link.user=?") + feed] + (.toString (doto (.getInstanceOf templates "simple-feed-list") + (.setAttributes {"feeds" + (map (fn [{title :title + id :id + link :link}] + {"title" title + "id" id + "link" link}) + results)})))))) -(defn lynxy-showfeed [id feednum] +(defn lynxy-showfeed [user feed] (with-dbt - (sql/with-query-results - results - [(str "SELECT entry.link, entry.title" - " FROM entry, feed_entry_link, user_feed_link" - " WHERE entry.id = feed_entry_link.entry" - " AND feed_entry_link.feed = user_feed_link.feed" - " AND user_feed_link.user = ?" - " AND user_feed_link.feed = ?") - id feednum] - (html - `[html - [head [title "Gödel-Gentzen Clojure Syndication Services Super System"]] - [body [ul - ~@(loop [back '[] r results] - (if (first r) - (recur (concat back `[[li - [a {:href ~(:link (first r))} - ~(:title (first r)) " - " - ~(:link (first r)) - ]]]) - (rest r)) - back))] - [a {:href "lynxy-feedlist.html"} "« To Feedlist"]]])))) + (sql/with-query-results [{feed-name :title}] + [(str "SELECT user_feed_link.title" + " FROM feed, user_feed_link" + " WHERE user_feed_link.feed = ?" + " AND user_feed_link.user = ?") + feed user] + (sql/with-query-results + results + [(str "SELECT entry.link, entry.title" + " FROM entry, feed_entry_link, user_feed_link" + " WHERE entry.id = feed_entry_link.entry" + " AND feed_entry_link.feed = user_feed_link.feed" + " AND user_feed_link.user = ?" + " AND user_feed_link.feed = ?") + user feed] + (.toString (doto (.getInstanceOf templates "simple-entry-list") + (.setAttributes {"feed_name" feed-name + "entries" + (map (fn [{title :title + link :link}] + {"title" title + "link" link}) + results)}))))))) (defmacro with-session [& body] `(if (not (~'session :id)) diff --git a/simple-entry-list.st b/simple-entry-list.st new file mode 100644 index 0000000..cf77ced --- /dev/null +++ b/simple-entry-list.st @@ -0,0 +1,9 @@ +$header(title="$feed_name$")$ + +<ul> +$entries:{entry | + <li><a href="$entry.link$">$entry.title$</a></li> +}$ +</ul> + +$footer()$ diff --git a/simple-feed-list.st b/simple-feed-list.st new file mode 100644 index 0000000..b303c10 --- /dev/null +++ b/simple-feed-list.st @@ -0,0 +1,9 @@ +$header(title="Feed list")$ + +<ul> +$feeds:{feed | + <li><a href="lynxy-showfeed?feed=$feed.id$">$feed.title$ — $feed.link$</a></li> +}$ +</ul> + +$footer()$ |