Browse files

Merge pull request #6 from Raynes/master

lein-newnew
  • Loading branch information...
2 parents ef37329 + 280bc9a commit d5ed6e68c4c1f5d81f0d9cd1fb5c22cad9d58d5e @ibdknox committed May 1, 2012
View
10 README.md
@@ -1,16 +1,16 @@
# lein-noir
-A [leiningen](https://github.com/technomancy/leiningen) plugin to help create and manage noir projects.
+A [leiningen](https://github.com/technomancy/leiningen) plugin to help create and manage noir projects. It only has a lein-newnew template for creating noir projects at the moment, but it'll eventually have tasks for managing and deploying noir websites.
## Usage
+lein-noir includes a template for lein-newnew. To use it, you'll need to install that. `lein install plugin lein-newnew 0.1.1`.
+
```bash
-lein plugin install lein-noir 1.2.0
-lein noir new my-website
+lein plugin install lein-noir 1.3.0
+lein new noir my-website
```
-Currently the only supported operation is new, but more will be coming to help deploy and manage projects.
-
## License
Copyright (C) 2011 Chris Granger
View
5 project.clj
@@ -1,3 +1,2 @@
-(defproject lein-noir "1.2.1"
- :description "A leiningen plugin to create and manage noir projects"
- :dependencies [[org.clojure/clojure "1.2.1"]])
+(defproject lein-noir "1.3.0"
+ :description "A lein-newnew template for generating new noir projects.")
View
24 src/leiningen/new/noir.clj
@@ -0,0 +1,24 @@
+(ns leiningen.new.noir
+ (:use leiningen.new.templates))
+
+(def render (renderer "noir"))
+
+(defn noir
+ "A skeleton Noir project."
+ [name]
+ (let [data {:name name
+ :sanitized (sanitize name)}]
+ (println "Generating a lovely new Noir project named" (str name "..."))
+ (->files data
+ ["project.clj" (render "project.clj" data)]
+ [".gitignore" (render "gitignore" data)]
+ ["README.md" (render "README.md" data)]
+ ["src/{{sanitized}}/server.clj" (render "server.clj" data)]
+ ["src/{{sanitized}}/views/welcome.clj" (render "welcome.clj" data)]
+ ["src/{{sanitized}}/views/common.clj" (render "common.clj" data)]
+ ["resources/public/css/reset.css" (render "reset.css" data)]
+ "resources/public/js"
+ "resources/public/img"
+ "src/{{sanitized}}/models"
+ "test/{{sanitized}}")))
+
View
19 src/leiningen/new/noir/README.md
@@ -0,0 +1,19 @@
+# {{name}}
+
+A website written in noir.
+
+## Usage
+
+If you use cake, substitute 'lein' with 'cake' below. Everything should work fine.
+
+```bash
+lein deps
+lein run
+```
+
+## License
+
+Copyright (C) 2011 FIXME
+
+Distributed under the Eclipse Public License, the same as Clojure.
+
View
12 src/leiningen/new/noir/common.clj
@@ -0,0 +1,12 @@
+(ns {{name}}.views.common
+ (:use [noir.core :only [defpartial]]
+ [hiccup.page-helpers :only [include-css html5]]))
+
+(defpartial layout [& content]
+ (html5
+ [:head
+ [:title "{{name}}"]
+ (include-css "/css/reset.css")]
+ [:body
+ [:div#wrapper
+ content]]))
View
6 src/leiningen/new/noir/gitignore
@@ -0,0 +1,6 @@
+pom.xml
+*jar
+/lib/
+/classes/
+.lein-deps-sum
+.cake
View
6 src/leiningen/new/noir/project.clj
@@ -0,0 +1,6 @@
+(defproject {{name}} "0.1.0-SNAPSHOT"
+ :description "FIXME: write this!"
+ :dependencies [[org.clojure/clojure "1.3.0"]
+ [noir "1.2.2"]]
+ :main {{name}}.server)
+
View
57 src/leiningen/new/noir/reset.css
@@ -0,0 +1,57 @@
+html {
+ margin:0;
+ padding:0;
+ border:0;
+}
+
+body, div, span, object, iframe,
+h1, h2, h3, h4, h5, h6, p, blockquote, pre,
+a, abbr, acronym, address, code,
+del, dfn, em, img, q, dl, dt, dd, ol, ul, li,
+fieldset, form, label, legend,
+table, caption, tbody, tfoot, thead, tr, th, td,
+article, aside, dialog, figure, footer, header,
+hgroup, nav, section {
+ margin: 0;
+ padding: 0;
+ border: 0;
+ font-weight: inherit;
+ font-style: inherit;
+ font-size: 100%;
+ font-family: inherit;
+ vertical-align: baseline;
+}
+
+article, aside, dialog, figure, footer, header,
+hgroup, nav, section {
+ display:block;
+}
+
+body {
+ line-height: 1.5;
+ background: white;
+}
+
+table {
+ border-collapse: separate;
+ border-spacing: 0;
+}
+
+caption, th, td {
+ text-align: left;
+ font-weight: normal;
+ float:none !important;
+}
+table, th, td {
+ vertical-align: middle;
+}
+
+blockquote:before, blockquote:after, q:before, q:after { content: ''; }
+blockquote, q { quotes: "" ""; }
+
+a img { border: none; }
+
+/*:focus { outline: 0; }*/
+
+
+
View
11 src/leiningen/new/noir/server.clj
@@ -0,0 +1,11 @@
+(ns {{name}}.server
+ (:require [noir.server :as server]))
+
+(server/load-views-ns '{{name}}.views)
+
+(defn -main [& m]
+ (let [mode (keyword (or (first m) :dev))
+ port (Integer. (get (System/getenv) "PORT" "8080"))]
+ (server/start port {:mode mode
+ :ns '{{name}}})))
+
View
9 src/leiningen/new/noir/welcome.clj
@@ -0,0 +1,9 @@
+(ns {{name}}.views.welcome
+ (:require [{{name}}.views.common :as common]
+ [noir.content.pages :as pages])
+ (:use [noir.core :only [defpage]]
+ [hiccup.core :only [html]]))
+
+(defpage "/welcome" []
+ (common/layout
+ [:p "Welcome to {{name}}"]))
View
20 src/leiningen/noir.clj
@@ -1,20 +0,0 @@
-(ns leiningen.noir
- (:require [leiningen.noir.new :as nnew])
- (:use [leiningen.help :only (help-for)]))
-
-(defn new [& [proj-name]]
- (if-not proj-name
- (println "No project name given:\r\n~ lein noir new my-website")
- (nnew/create proj-name)))
-
-(defn noir
- "Create and manage noir projects."
- {:help-arglists '([new])
- :subtasks [#'new]}
- ([]
- (println (help-for "noir")))
- ([subtask & args]
- (case subtask
- "new" (apply leiningen.noir/new args)
- (println (help-for "noir"))
- )))
View
77 src/leiningen/noir/new.clj
@@ -1,77 +0,0 @@
-(ns leiningen.noir.new
- (:require [clojure.string :as string])
- (:use clojure.java.io))
-
-(declare *project-dir* *project* *dirs*)
-(def dir-keys [:css :js :img :views :models :test])
-
-;;From the maginalia source: http://fogus.me/fun/marginalia/
-(defn slurp-resource
- [resource-name]
- (try
- (-> (.getContextClassLoader (Thread/currentThread))
- (.getResourceAsStream resource-name)
- (java.io.InputStreamReader.)
- (slurp))
- (catch java.lang.NullPointerException npe
- (println (str "Could not locate resources at " resource-name))
- (println " ... attempting to fix.")
- (let [resource-name (str "./resources/" resource-name)]
- (try
- (-> (.getContextClassLoader (Thread/currentThread))
- (.getResourceAsStream resource-name)
- (java.io.InputStreamReader.)
- (slurp))
- (catch java.lang.NullPointerException npe
- (println (str " STILL could not locate resources at " resource-name ". Giving up!"))))))))
-
-(defn get-dir [n]
- (get *dirs* n))
-
-(defn clean-proj-name [n]
- (string/replace n #"-" "_"))
-
-(defn get-template [n]
- (let [tmpl (slurp-resource (str "templates/" n))]
- (-> tmpl
- (string/replace #"\$project\$" *project*)
- (string/replace #"\$safeproject\$" (clean-proj-name *project*)))))
-
-(defn mkdir [args]
- (.mkdirs (apply file *project-dir* args)))
-
-(defn ->file [path file-name content]
- (spit (apply file *project-dir* (conj path file-name)) content))
-
-(defn create-dirs []
- (doseq [k dir-keys]
- (mkdir (get-dir k))))
-
-(defn populate-dirs []
- (->file [] "README.md" (get-template "README.md"))
- (->file [] "project.clj" (get-template "project.clj"))
- (->file [] ".gitignore" (get-template "gitignore"))
- (->file (get-dir :css) "reset.css" (get-template "reset.css"))
- (->file (get-dir :src) "server.clj" (get-template "server.clj"))
- (->file (get-dir :views) "common.clj" (get-template "common.clj"))
- (->file (get-dir :views) "welcome.clj" (get-template "welcome.clj")))
-
-(defn create [proj-name]
- (let [clean-name (clean-proj-name proj-name)]
- (binding [*project* proj-name
- *project-dir* (-> (System/getProperty "leiningen.original.pwd")
- (file proj-name)
- (.getAbsolutePath))
- *dirs* {:src ["src" clean-name]
- :views ["src" clean-name "views"]
- :models ["src" clean-name "models"]
- :test ["test" clean-name]
- :css ["resources" "public" "css"]
- :js ["resources" "public" "js"]
- :img ["resources" "public" "img"]}]
- (println "Creating noir project: " *project*)
- (println "Creating new dirs at: " *project-dir*)
- (create-dirs)
- (println "Adding files...")
- (populate-dirs)
- (println "Project created!"))))
View
6 test/lein_noir/test/core.clj
@@ -1,6 +0,0 @@
-(ns lein-noir.test.core
- (:use [lein-noir.core])
- (:use [clojure.test]))
-
-(deftest replace-me ;; FIXME: write
- (is false "No tests have been written."))

0 comments on commit d5ed6e6

Please sign in to comment.