Skip to content

Commit

Permalink
Merge pull request #10 from pink-gorilla/unittests
Browse files Browse the repository at this point in the history
Unittests
  • Loading branch information
awb99 committed Mar 26, 2020
2 parents 83fd3e2 + df17246 commit bf08104
Show file tree
Hide file tree
Showing 14 changed files with 245 additions and 254 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ pom.xml.asc
/.cljs_node_repl
/node_modules
/resources
.shadow-cljs/*
.shadow-cljs/*
.classpath
.project
.settings/*
14 changes: 0 additions & 14 deletions LICENCE.txt

This file was deleted.

9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
of visual repesentation so that the notebook can render them
- For all clojure/clojurescript datatypes default renderers are defined here
- Custom data-types can implement the renderable protocol
- The notebook receves the render-datastructure and renders it to the notebook cell.
- The notebook receives the render-datastructure and renders it to the notebook cell.

```
(defprotocol Renderable
Expand All @@ -20,12 +20,7 @@ Clojure/Clojurescript Data => (render) => Renderable DataStructure => (render) =

Clojure:
```
NOT IMPLEMENTED
```

Clojurescript:
```
TODO
lein test
```


Expand Down
6 changes: 1 addition & 5 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@
:description "The protocol for custom rendering in Pink Gorilla Notebook."
:url "https://github.com/pink-gorilla/gorilla-renderable"
:license {:name "MIT"}
;:deploy-repositories [["releases" :clojars]]
:deploy-repositories [["releases" {:url "https://clojars.org/repo"
:username :env/release_username
:password :env/release_password
:sign-releases false}]]
:dependencies [[org.clojure/clojure "1.10.1"]
;; TODO: Still needed? Used by old vega renderer
[org.clojure/data.json "0.2.6"]
[hiccup "1.0.5"]]
:dependencies [[org.clojure/clojure "1.10.1"]]

:profiles {:dev {:dependencies [[clj-kondo "2019.11.23"]]
:plugins [[lein-cljfmt "0.6.6"]
Expand Down
64 changes: 61 additions & 3 deletions src/pinkgorilla/ui/helper.cljc
Original file line number Diff line number Diff line change
@@ -1,18 +1,76 @@
(ns pinkgorilla.ui.helper
"plugin to render text in pink-gorilla"
"helper functions which should be available from the repl"
(:require
[pinkgorilla.ui.gorilla-renderable :as render] ; define Renderable (which has render function)
[pinkgorilla.ui.gorilla-renderable :refer [Renderable render]] ; define Renderable (which has render function)
))

(defn text!
"renders text to a gorilla cell"
[text]
(reify render/Renderable
(reify Renderable
(render [_]
{:type :text
:content
{:text text}
;:value (pr-str self) ; DO NOT SET VALUE; this will fuckup loading. (at least in original gorilla)
})))

(defn R!
"renders a reagent widget"
[r]
(reify Renderable
(render [_]
{:type :reagent
:content {:hiccup r
:map-kewords true
:widget true}
:value (pr-str r)
;:value (pr-str self) ; DO NOT SET VALUE; this will fuckup loading. (at least in original gorilla)
})))

(defn html!
"renders html to a gorilla cell
if (type string) assumes it is valid html and renders as is
otherwise will assume it is valid hiccup syntax and render hiccup syntax"
[html-as-string]
^:R [:html html-as-string])



;; table-view


(defrecord TableView [contents opts])

(defn table-view [contents & opts]
(TableView. contents opts))

(defn- list-like
[data value open close separator]
{:type :list-like
:open open
:close close
:separator separator
:items data
:value value})

(extend-type TableView
Renderable
(render [self]
(let [contents (:contents self)
opts-map (apply hash-map (:opts self))
rows (map (fn [r] (list-like (map render r) (pr-str r) "<tr><td>" "</td></tr>" "</td><td>")) contents)
heading (if-let [cols (:columns opts-map)]
[(list-like (map render cols) (pr-str cols) "<tr><th>" "</th></tr>" "</th><th>")]
[])
body (list-like (concat heading rows) (pr-str self) "<center><table>" "</table></center>" "\n")]
body)))

(comment
(render (R! '[:h1 "hello, world"]))
(render (R! '[clock "hello, world"]))

(render (html! [:h1 "hello"]))

; comment end
)
26 changes: 0 additions & 26 deletions src/pinkgorilla/ui/hiccup.clj

This file was deleted.

0 comments on commit bf08104

Please sign in to comment.