diff --git a/src/main/dda/masto_embed/api.cljs b/src/main/dda/masto_embed/api.cljs index 49a27ae..a5842bf 100644 --- a/src/main/dda/masto_embed/api.cljs +++ b/src/main/dda/masto_embed/api.cljs @@ -27,32 +27,6 @@ (defn mastojs->edn [response] (-> response .-data infra/js->edn)) -(defn mastocard->html [card] - (when (some? card) - (let [{:keys [title description image url]} card] - [:div {:class "card" :url url} - (when (some? image) - [:img {:class "card-img-top" :src image}]) - [:h3 {:class "card-title"} title] - [:p {:class "card-body"} description]]))) - -(defn masto->html [statuses] - [:ul {:class "list-group"} - (map (fn [status] - (let [{:keys [created_at card]} status - date (t/parse created_at)] - [:li {:class "list-group-item, card"} - [:div {:class "card-body"} - [:h2 {:class "card-title"} - [:a {:href (get-in status [:account :url])} - (t/unparse (t/formatters :date) date) " " - (t/unparse (t/formatters :hour-minute-second) date)]] - [:p {:class "card-text"} - (:content status) - (mastocard->html card)]]])) - statuses)]) - - (defn-spec mastodon-client any? [host-url ::host-url] (let [mastodon-config diff --git a/src/main/dda/masto_embed/app.cljs b/src/main/dda/masto_embed/app.cljs index 3adac0e..d42acae 100644 --- a/src/main/dda/masto_embed/app.cljs +++ b/src/main/dda/masto_embed/app.cljs @@ -15,11 +15,13 @@ ; limitations under the License. (ns dda.masto-embed.app (:require - [dda.masto-embed.api :as api] - [dda.masto-embed.infra :as infra] [cljs.core.async :refer [go close! put! take! timeout chan !]] [cljs.core.async.interop :refer-macros [
> statuus (take 4) - (api/masto->html) + (rb/masto->html) (render-html) (render-to-document)) ))) diff --git a/src/main/dda/masto_embed/js_api.cljs b/src/main/dda/masto_embed/js_api.cljs deleted file mode 100644 index 84559fe..0000000 --- a/src/main/dda/masto_embed/js_api.cljs +++ /dev/null @@ -1,38 +0,0 @@ -; Licensed to the Apache Software Foundation (ASF) under one -; or more contributor license agreements. See the NOTICE file -; distributed with this work for additional information -; regarding copyright ownership. The ASF licenses this file -; to you 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. -(ns dda.masto-embed.js-api - (:require - ["mastodon-api" :as Mastodon] - [clojure.pprint :as pprint :refer [pprint]] - [cljs.core.async :refer [go]] - [cljs.core.async.interop :refer-macros [
html [card] + (when (some? card) + (let [{:keys [title description image url]} card] + [:div {:class "card" :url url} + (when (some? image) + [:img {:class "card-img-top" :src image}]) + [:h3 {:class "card-title"} title] + [:p {:class "card-body"} description]]))) + +(defn masto->html [statuses] + [:ul {:class "list-group"} + (map (fn [status] + (let [{:keys [created_at card]} status + date (t/parse created_at)] + [:li {:class "list-group-item, card"} + [:div {:class "card-body"} + [:h2 {:class "card-title"} + [:a {:href (get-in status [:account :url])} + (t/unparse (t/formatters :date) date) " " + (t/unparse (t/formatters :hour-minute-second) date)]] + [:p {:class "card-text"} + (:content status) + (mastocard->html card)]]])) + statuses)]) diff --git a/src/test/dda/masto_embed/api_test.cljs b/src/test/dda/masto_embed/render_bootstrap_test.cljs similarity index 89% rename from src/test/dda/masto_embed/api_test.cljs rename to src/test/dda/masto_embed/render_bootstrap_test.cljs index 2b39627..675765a 100644 --- a/src/test/dda/masto_embed/api_test.cljs +++ b/src/test/dda/masto_embed/render_bootstrap_test.cljs @@ -14,10 +14,10 @@ ; See the License for the specific language governing permissions and ; limitations under the License. -(ns dda.masto-embed.api-test +(ns dda.masto-embed.render-bootstrap-test (:require [cljs.test :refer (deftest is)] - [dda.masto-embed.api :as sut])) + [dda.masto-embed.render-bootstrap :as sut])) (def statuses [{:mentions [] :emojis [] @@ -154,12 +154,12 @@ :spoiler_text ""}]) (deftest test-mastodon->html - (is (= [:ul - '([:li - [:h2 [:a {:href "https://social.meissa-gmbh.de/@team"} - "2020-05-17" "10:12:10"]] - "
We've a new asciicast ...
" - nil])] + (is (= [:ul {:class "list-group"} + '([:li {:class "list-group-item, card"} + [:div {:class "card-body"} + [:h2 {:class "card-title"} [:a {:href "https://social.meissa-gmbh.de/@team"} "2020-05-17" " " "10:12:10"]] + [:p {:class "card-text"} "We've a new asciicast ...
" + nil]]])] (sut/masto->html statuses)))) @@ -175,10 +175,9 @@ :author_name "", :image nil, :provider_url "", :height 0, :html ""}) (deftest link-card-should-show-desc-and-link - (is (= [:div {:class "card", :url "https://www.ssllabs.com/ssltest/"} - nil - [:h1 "SSL Server Test (Powered by Qualys SSL Labs)"] - [:p "A comprehensive free SSL test for your public web servers."]] + (is (= [:div {:class "card", :url "https://www.ssllabs.com/ssltest/"} nil + [:h3 {:class "card-title"} "SSL Server Test (Powered by Qualys SSL Labs)"] + [:p {:class "card-body"} "A comprehensive free SSL test for your public web servers."]] (sut/mastocard->html link-card)))) (def link-card-with-image @@ -190,7 +189,7 @@ (deftest link-card-should-show-image-and-desc-and-link (is (= [:div {:class "card", :url "https://github.com/DomainDrivenArchitecture/cryogen-core"} - [:img {:src "https://cf.mastohost.com/v1/AUTH_91eb37814936490c95da7b85993cc2ff/socialmeissagmbhde/cache/preview_cards/images/000/017/635/original/5634071238f1f91f.png"}] - [:h1 "DomainDrivenArchitecture/cryogen-core"] - [:p "Cryogen's core. Contribute to DomainDrivenArchitecture/cryogen-core development by creating an account on GitHub."]] + [:img {:class "card-img-top", :src "https://cf.mastohost.com/v1/AUTH_91eb37814936490c95da7b85993cc2ff/socialmeissagmbhde/cache/preview_cards/images/000/017/635/original/5634071238f1f91f.png"}] + [:h3 {:class "card-title"} "DomainDrivenArchitecture/cryogen-core"] + [:p {:class "card-body"} "Cryogen's core. Contribute to DomainDrivenArchitecture/cryogen-core development by creating an account on GitHub."]] (sut/mastocard->html link-card-with-image)))) \ No newline at end of file