项目作者: roosta

项目描述 :
🌿 Clojurescript CSS styling using functions.
高级语言: Clojure
项目地址: git://github.com/roosta/herb.git
创建时间: 2018-01-20T19:51:01Z
项目社区:https://github.com/roosta/herb

开源协议:Eclipse Public License 1.0

下载














Herb is a CSS styling library for
Clojurescript, built using
Garden, whose main focus is on
component level styling using functions.

Requirements

Herb requires at least Clojure 1.9.0 and ClojureScript 1.9.542 due to
use of
clojure.spec.alpha to
validate macro input.

Quick start

Clojars Project

  1. (ns user
  2. (:require [herb.core :refer [<class]]))
  3. (defn style []
  4. {:background "red"})
  5. (defn component
  6. [:div {:class (<class style)}])

Herb has two main macros, <class and <id, these macros takes a
function that returns a Garden
style map, and returns a classname/id based on the functions fully
qualified name, in this case user/style.

The style is injected into the DOM when any one of Herb’s macros are
called.

Pass arguments:

  1. (ns user
  2. (:require [herb.core :refer [<class]]))
  3. (defn style
  4. [color]
  5. {:color color})
  6. (defn component []
  7. [:div {:class (<class style "red")}])

Extend existing functions:

  1. (ns user
  2. (:require [herb.core :refer [<class]]))
  3. (defn button-style [text-color]
  4. {:display "inline-block"
  5. :color text-color
  6. :text-transform "uppercase"
  7. :cursor "pointer"
  8. :padding (px 12)})
  9. (defn red-button-style []
  10. ^{:extend [button-style "white"]}
  11. {:background-color "red"})
  12. (defn button []
  13. [:button {:class (<class red-button-style)}])

Garden is used to translate the
style map to CSS, which enables most of Gardens functionality, so
familiarizing yourself with its features is a good idea.

Refer to the tutorial for a full overview
and examples of Herbs features.

Advanced optimizations

During a production build add this to the :compiler config
:closure-defines {"goog.DEBUG" false}. This flag tells Herb to
minify styles, remove unneeded style element attributes, and ensure
anonymous functions gets the correct minified name.

Debugging advanced compilation

During advanced compilation Herb minify styles and removes the
data-herb attribute. If you need to debug production build it can be
helpful to see the function namespaces unmunged to get a clearer image
of what is happening.

To do this remove the goog.DEBUG false from production build and
enable :pseudo-names:

  1. :cljsbuild {:builds {:min {:source-paths ["src" "env/prod"]
  2. :compiler {:pseudo-names true
  3. :optimizations :advanced
  4. ...
  5. }}

That way you will see both full classnames and the namespace reflected
in the data-herb HTML attribute.

Development

Start figwheel main with the development build

  1. lein fig:build

Figwheel-main will automatically push cljs changes to the browser. Once Figwheel
starts up, you should be able to open http://localhost:9500 for the
development server.

Testing

Either run:

  1. lein fig:test

For a headless test environment using chrome, make sure its
installed on your system.

You can also start the dev build and navigate to
http://localhost:9500/figwheel-extra-main/auto-testing
to get a nice interface while coding that runs the tests on each save.

License

Copyright © 2021 Daniel Berg

Distributed under the Eclipse Public License, the same as Clojure.