How do I access the project map from a leiningen plugin?
Asked Answered
H

1

7

Let's say I create a new leiningen project and edit the project.clj file so it looks something like the following.

(defproject foobar "0.1.0-SNAPSHOT"
  :dependencies [[org.clojure/clojure "1.5.1"]
                 ...
                 [clj-webmaster-tools "0.1.0"]]
  :plugins [[lein-ring "0.8.6"]
            [lein-webmaster-tools "0.1.0"]
  :webmaster {:sitemap "http://www.foobar.com/sitemap-index.xml" :robots "http://www.foobar.com/robots.txt"})

My question is, how do I access the :webmaster key in the project map for use in a leningen plugin I'm writing?

Hrvatska answered 25/8, 2013 at 15:28 Comment(4)
Access it where? During the build (if so, which phase)?Sobersided
@Sobersided No, for a leiningen plugin I'm writing.Hrvatska
It's passed in as a parameter to your plugin function, which you can access like any other map. See this example: github.com/noahlz/lein-hello/blob/master/src/leiningen/…Sobersided
@Sobersided Make than an answer so I can give proper credit.Hrvatska
S
6

When you write a plugin, the first parameter passed to your plugin function is the project map. It's a standard Clojure persistent map, so you can access it like any other map, i.e.

(defn my-plugin[project] 
  (println (:webmaster project)))
Sobersided answered 26/8, 2013 at 13:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.