From 0cfdf7fc022c3212b7193fe62bd28d2c72325985 Mon Sep 17 00:00:00 2001 From: jem Date: Tue, 23 Jun 2020 20:09:00 +0200 Subject: [PATCH] first styling --- shadow-cljs.edn | 1 + src/main/dda/masto_embed/api.cljs | 12 +- src/main/dda/masto_embed/app.cljs | 18 +-- src/main/dda/masto_embed/infra.cljs | 5 +- src/test/dda/masto_embed/api_test.cljs | 163 +++++++++++++++++++++++++ src/test/dda/masto_embed/app_test.cljs | 20 --- 6 files changed, 189 insertions(+), 30 deletions(-) create mode 100644 src/test/dda/masto_embed/api_test.cljs delete mode 100644 src/test/dda/masto_embed/app_test.cljs diff --git a/shadow-cljs.edn b/shadow-cljs.edn index 9d5cf88..e894fdd 100644 --- a/shadow-cljs.edn +++ b/shadow-cljs.edn @@ -6,6 +6,7 @@ :dependencies [[orchestra "2019.02.06-1"] + [hiccups "0.3.0"] [cider/cider-nrepl "0.21.0"]] :dev-http {8080 "public"} :builds diff --git a/src/main/dda/masto_embed/api.cljs b/src/main/dda/masto_embed/api.cljs index e864baa..440c8e2 100644 --- a/src/main/dda/masto_embed/api.cljs +++ b/src/main/dda/masto_embed/api.cljs @@ -23,9 +23,19 @@ (s/def ::account-id string?) (s/def ::host-url string?) -(defn masto->edn [response] +(defn mastojs->edn [response] (-> response .-data infra/js->edn)) +(defn masto->html [statuus] + [:ul + (map (fn [status] [:li + [:h2 + [:a {:href (get-in status [:account :url])} + (:created_at status)]] + (:content status) + (:card status)]) statuus)]) + + (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 f62bb77..4825bad 100644 --- a/src/main/dda/masto_embed/app.cljs +++ b/src/main/dda/masto_embed/app.cljs @@ -19,7 +19,7 @@ [dda.masto-embed.infra :as infra] [cljs.core.async :refer [go close! put! take! timeout chan !]] [cljs.core.async.interop :refer-macros [! out (->> (edn + api/mastojs->edn (filter #(= account-name (:acct %))) (map :id) first))) @@ -64,13 +64,17 @@ account-id (or (account-id-from-document) ( - (edn) + statuus (-> + (edn) ] (print host-url) (print account-name) (print account-id) - (print status) - (render-to-document status) + (->> statuus + (take 4) + (api/masto->html) + (render-html) + (infra/debug) + (render-to-document)) ))) diff --git a/src/main/dda/masto_embed/infra.cljs b/src/main/dda/masto_embed/infra.cljs index 4da07e0..d6fc0df 100644 --- a/src/main/dda/masto_embed/infra.cljs +++ b/src/main/dda/masto_embed/infra.cljs @@ -16,7 +16,8 @@ (ns dda.masto-embed.infra (:require [cljs.core.async :refer [go]] - [cljs.core.async.interop :refer-macros [clj data :keywordize-keys true)) (defn debug [elem] - (print elem) + (pprint elem) elem) \ No newline at end of file diff --git a/src/test/dda/masto_embed/api_test.cljs b/src/test/dda/masto_embed/api_test.cljs new file mode 100644 index 0000000..41723c0 --- /dev/null +++ b/src/test/dda/masto_embed/api_test.cljs @@ -0,0 +1,163 @@ +; 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.api-test + (:require + [cljs.test :refer (deftest is)] + [dda.masto-embed.api :as sut])) + +(def statuus [{:mentions [] + :emojis [] + :tags [] + :reblog + {:mentions [] + :emojis [] + :tags + [{:name "hetzner" + :url "https://social.meissa-gmbh.de/tags/hetzner"} + {:name "devops", :url "https://social.meissa-gmbh.de/tags/devops"} + {:name "k8s", :url "https://social.meissa-gmbh.de/tags/k8s"} + {:name "cheap", :url "https://social.meissa-gmbh.de/tags/cheap"}] + :reblog nil + :replies_count 0 + :in_reply_to_account_id nil + :reblogs_count 1 + :application nil + :content + "mentioned:

We've a new asciicast ...

" + :sensitive false + :favourites_count 2 + :in_reply_to_id nil + :poll nil + :account + {:acct "jerger" + :last_status_at "2020-06-14" + :emojis [] + :bot false + :group false + :following_count 64 + :avatar_static + "https://cf.mastohost.com/v1/AUTH_91eb37814936490c95da7b85993cc2ff/socialmeissagmbhde/accounts/avatars/000/000/001/original/794ca61bfd71bbe1.jpg" + :fields + [{:name "blog" + :value + "https://domaindrivenarchitecture.org/" + :verified_at nil} + {:name "interests" + :value "Clojure, sci-fi, tech, DevOps, public weal" + :verified_at nil} + {:name "location" + :value "Reutlingen, de, eu" + :verified_at nil}] + :username "jerger" + :header_static + "https://cf.mastohost.com/v1/AUTH_91eb37814936490c95da7b85993cc2ff/socialmeissagmbhde/accounts/headers/000/000/001/original/2a45f78fa1af0815.jpg" + :discoverable true + :statuses_count 135 + :header + "https://cf.mastohost.com/v1/AUTH_91eb37814936490c95da7b85993cc2ff/socialmeissagmbhde/accounts/headers/000/000/001/original/2a45f78fa1af0815.jpg" + :note + "

meissa GmbH, Maintainer, dda-pallet, Clojure, OpenSource, DevOps, DomainDrivenDesign, Demokratie, Bürgerbeteiligung, Europa, Klettern, Wandern

" + :locked false + :id "1" + :avatar + "https://cf.mastohost.com/v1/AUTH_91eb37814936490c95da7b85993cc2ff/socialmeissagmbhde/accounts/avatars/000/000/001/original/794ca61bfd71bbe1.jpg" + :url "https://social.meissa-gmbh.de/@jerger" + :display_name "jerger" + :followers_count 24 + :created_at "2019-06-02T10:41:41.919Z"} + :card + {:description + "We use our dda-k8s-crate to install kubernetes automatically with a nexux repository manager. See our GitHub page for more details :) https://github.com/DomainDrivenArchitecture/dda-k8s-crate" + :author_url "" + :width 400 + :type "link" + :embed_url "" + :title "Automatic kubernetes installation" + :provider_name "" + :url "https://asciinema.org/a/329800" + :author_name "" + :image + "https://cf.mastohost.com/v1/AUTH_91eb37814936490c95da7b85993cc2ff/socialmeissagmbhde/cache/preview_cards/images/000/024/180/original/8562ddca088c16e3.png" + :provider_url "" + :height 311 + :html ""} + :language "en" + :id "104172691066899431" + :url "https://social.meissa-gmbh.de/@jerger/104172691066899431" + :media_attachments [] + :uri + "https://social.meissa-gmbh.de/users/jerger/statuses/104172691066899431" + :visibility "public" + :created_at "2020-05-15T13:25:19.190Z" + :spoiler_text ""} + :replies_count 0 + :in_reply_to_account_id nil + :reblogs_count 0 + :application nil + :content + "

We've a new asciicast ...

" + :sensitive false + :favourites_count 0 + :in_reply_to_id nil + :poll nil + :account + {:acct "team" + :last_status_at "2020-05-17" + :emojis [] + :bot false + :group false + :following_count 2 + :avatar_static + "https://cf.mastohost.com/v1/AUTH_91eb37814936490c95da7b85993cc2ff/socialmeissagmbhde/accounts/avatars/000/000/002/original/1aaff0c626a2ade3.png" + :fields [] + :username "team" + :header_static + "https://cf.mastohost.com/v1/AUTH_91eb37814936490c95da7b85993cc2ff/socialmeissagmbhde/accounts/headers/000/000/002/original/2e6a592b61a2d505.jpg" + :discoverable true + :statuses_count 12 + :header + "https://cf.mastohost.com/v1/AUTH_91eb37814936490c95da7b85993cc2ff/socialmeissagmbhde/accounts/headers/000/000/002/original/2e6a592b61a2d505.jpg" + :note + "

DevOps, Cloud, KI, Clojure, Java, Python, Reutlingen, Tübingen, Stuttgart, genossenschaftlich, OpenSource, TestDriven, Maintainer

" + :locked false + :id "2" + :avatar + "https://cf.mastohost.com/v1/AUTH_91eb37814936490c95da7b85993cc2ff/socialmeissagmbhde/accounts/avatars/000/000/002/original/1aaff0c626a2ade3.png" + :url "https://social.meissa-gmbh.de/@team" + :display_name "meissa-team" + :followers_count 3 + :created_at "2019-06-02T10:50:28.976Z"} + :card nil + :language nil + :id "104183256213204298" + :url + "https://social.meissa-gmbh.de/users/team/statuses/104183256213204298/activity" + :media_attachments [] + :uri + "https://social.meissa-gmbh.de/users/team/statuses/104183256213204298/activity" + :visibility "public" + :created_at "2020-05-17T10:12:10.403Z" + :spoiler_text ""}]) + +(deftest test-mastodon-2-html + (is (= [:ul + '([:li + [:h2 [:a {:href "https://social.meissa-gmbh.de/@team"} + "2020-05-17T10:12:10.403Z"]] + "

We've a new asciicast ...

" + [:p ]])] + (sut/masto->html statuus)))) diff --git a/src/test/dda/masto_embed/app_test.cljs b/src/test/dda/masto_embed/app_test.cljs deleted file mode 100644 index f2aef8b..0000000 --- a/src/test/dda/masto_embed/app_test.cljs +++ /dev/null @@ -1,20 +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.app-test - (:require - [cljs.test :refer (deftest is)] - [dda.masto-embed.app :as sut]))