Git Product home page Git Product logo

lein-garden's Introduction

lein-garden

A Leiningen plugin for automatically compiling Garden stylesheets.

Requirements

This plugin requires Clojure version 1.6.0 or higher and Leiningen version 2.4.3 or higher.

Installation

Put [lein-garden "0.2.1"] into the :plugins vector of your project.clj.

How do I use this?

Preface

Let's suppose you have a project where you are currently using Garden for CSS generation. Now, imagine you're so tired of manually recompiling your stylesheets or resorting to some other form of skulduggery that you're thinking of going back to Sass. This causes you to reflect deeply on your life for a moment before realizing that it's just negativity talking and get back to hacking.

Chapter 1

You open ~/cash-money/src/cash_money/core.clj.

(ns cash-money.core
  (:require [garden.def :refer [defstylesheet defstyles]]
            [garden.units :refer [px]]))

(defstylesheet screen
  {:output-to "resources/public/screen.css"}
  [:body
   {:font-family "sans-serif"
    :font-size (px 16)
    :line-height 1.5}])

There's a namespace to the north and a some Garden code to the south.

You think to yourself, "this is nice if you're the sort of person that doesn't mind constantly reloading the file to recompile the CSS after every save." Alas, you are not one of these "persons." Instead, you've added [lein-garden "X.X.X"] to your :plugins vector, read "Getting Things Done", and like Landon Austin are ready for anything.

Chapter 2

You open ~/cash-money/project.clj

(defproject cash-money "1.1.1"
  :plugins [[lein-garden "X.X.X"]])

To get everything going with lein garden you add the remaining ingredients.

(defproject cash-money "1.1.1"
  :plugins [[lein-garden "X.X.X"]]
  :garden {:builds [{;; Optional name of the build:
                     :id "screen"
                     ;; Source paths where the stylesheet source code is
                     :source-paths ["src/styles"]
                     ;; The var containing your stylesheet:
                     :stylesheet cash-money.core/screen
                     ;; Compiler flags passed to `garden.core/css`:
                     :compiler {;; Where to save the file:
                                :output-to "resources/screen.css"
                                ;; Compress the output?
                                :pretty-print? false}}]})

Next, you open ~/cash-money/src/cash_money/core.clj and make a small change.

(ns cash-money.core
  (:require [garden.def :refer [defstylesheet defstyles]]
            [garden.units :refer [px]]))

;; Change defstylesheet to defstyles.
(defstyles screen
  [:body
   {:font-family "sans-serif"
    :font-size (px 16)
    :line-height 1.5}])

Finally you run

$ lein garden auto

and behold as your stylesheet is automatically recompiled on save.

Chapter 3

Now you might want stylesheets to always compile whenever starting your program with leiningen. Add this to your project.clj

:hooks [leiningen.garden]

You might not want your stylesheets to compile before test-runs. Perhaps what you really wanted, is to compile stylesheets before creating a jar. You can use profiles to do this.

:profiles {:uberjar {:hooks [leiningen.garden]}}

lein-garden's People

Contributors

noprompt avatar martinklepsch avatar pasviegas avatar daveliepmann avatar

Watchers

Petra Jaros avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.