Skip to content

Otann/garden-gnome

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Garden Gnome

:)

Helper to watch and autoreload Garden sources from REPL and outside as well.

In combination with Figwheel gives you instant sync between your Garden sources and page in the browser

Installation

Add garden-gnome as a dependency in project.clj (Leiningen) or build.boot (Boot).

[garden-gnome "0.1.0"]

Configuration

Then say you have a namespace with your styles defined:

(ns sample.styles
  (:require [garden.def :refer [defstyles]]))

(defstyles screen
  [:body {:background-color "black"}])

Add following configuration in your project.clj (same format as lein-garden)

:garden {:builds [{;; Source path where to watch for changes:
                   :source-path "dev/sample"
                   ;; The var containing your stylesheet:
                   :stylesheet  sample.styles/screen
                   ;; Compiler flags passed to `garden.core/css`:
                   :compiler    {:output-to     "resources/public/screen.css"
                                 :pretty-print? true}}]}

Reloaded Workflow

Now in your REPL whenever you start you system, a watcher will start which will observe changes in directories specified in your garden config and automatically recompile mentioned namespaces whenever files change.

If you have Figwheel set up, it will pick your changes automatically, so will have a closed loop from editing garden code to seeing changes in your browser instantly.

With Mount

(ns user
  (:require [mount.core :as mount]
            [garden-gnome.watcher :as garden-gnome]))

(mount/defstate garden
  :start (garden-gnome/start! (garden-gnome/default-config))
  :stop (garden-gnome/stop! garden))
(ns user
  (:require [com.stuartsierra.component :as component]
            [garden-gnome.watcher :as garden-gnome]))

(defrecord Gnome []
  component/Lifecycle
  (start [this]
    (let [config  (garden-gnome/default-config)
          watcher (garden-gnome/start! config)]
      (assoc this :watcher watcher)))
  (stop [this]
    (let [watcher (:watcher this)]
      (garden-gnome/stop! watcher)
      (dissoc this :watcher))))

From shell

Use following command to compile all your configurations once

$ lein run -m garden-gnome.compile

And this one to watch them from REPL

$ lein run -m garden-gnome.watch

Integrate into build process

You can easily integrate Garden Gnome into your packaging process like this:

:profiles {:uberjar {:prep-tasks ["compile"
                                  ["cljsbuild" "once" "min"]
                                  ["run" "-m" "garden-gnome.compile"]]}}

Credits

Inspired by plexus/garden-watcher and adapted to use with mount instead of lein-garden.

License

Copyright © 2017 Anton Chebotaev

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

About

🌳 Garden CSS styles autoreload watcher

Resources

License

Stars

Watchers

Forks

Packages

No packages published