Permalink
Browse files

add noir genome

Signed-off-by: Chris Granger <ibdknox@gmail.com>
  • Loading branch information...
1 parent 1271e2c commit 4ee9a19bb3d0c6808d184acf92c633e0f6778630 @ibdknox ibdknox committed Nov 4, 2011
@@ -1,44 +0,0 @@
-(ns spawn.genome.controller
- (:require [spawn.genome :as gene]
- [clojure.string :as str]))
-
-(defn- t
- "Utility function for building a local template path"
- [name]
- (str "spawn/genome/controller/" name))
-
-(defn insert-after [base pattern s]
- "Inserts s immediately after the first occurence of pattern in base"
- (let [re (str "\\Q" pattern "\\E")
- pat (re-pattern re)
- splitted (str/split base pat)]
- (reduce str [(first splitted) pattern s (second splitted)])))
-
-(defn add-controller-ns [file projectname name]
- (let [pattern "[compojure.handler :as handler]"
- insert (str "\n [" projectname ".controllers." name " :as " name "]")]
- (insert-after file pattern insert)))
-
-(defn add-controller-routes [file name]
- (let [pattern "(GET \"/\" [] index/index-routes)"
- insert (str "\n (GET \"/" name "/*\" [] " name "/" name "-routes)")]
- (insert-after file pattern insert)))
-
-(defn update-server-file [projectname name]
- (let [dirname (gene/underscore projectname)
- filename (str "./src/" dirname "/server.clj")
- serverfile (slurp filename)]
- (if (or (not serverfile) (empty? serverfile))
- (throw (Exception. "Could not find server.clj. Did you generate this project with 'spawn webapp'?"))
- (spit filename (add-controller-routes (add-controller-ns serverfile projectname name) name)))))
-
-(defn controller
- "Creates a controller in a webapp"
- [project name]
- (let [projectname (:name project)
- dirname (gene/underscore projectname)
- data {"name" name
- "projectname" projectname}]
- (update-server-file projectname name)
- (gene/build-filesystem
- {"src" {dirname {"controllers" {(str name ".clj") (gene/apply-template (t "template_clj") data)}}}})))
@@ -1,6 +0,0 @@
-(ns {{projectname}}.controllers.$name$
- (:use compojure.core))
-
-(defroutes {{name}}-routes
- "Routes for the {{name}} controller"
- (GET "/{{name}}/" [] "You are in {{name}} controller."))
@@ -0,0 +1,33 @@
+(ns spawn.genome.noir
+ (:require [spawn.genome :as gene]))
+
+(defn- t
+ "Utility function for building a local template path"
+ [name]
+ (str "spawn/genome/noir/" name))
+
+(def noir-files ["project.clj" "README.md" "gitignore" "reset.css" "server.clj"
+ "welcome.clj" "common.clj"])
+
+(defn file-map [fs data]
+ (into {} (map (juxt keyword #(gene/apply-template (t %) data)) fs)))
+
+(defn noir
+ "A genome for creating webapps"
+ [name]
+ (let [data {:name name}
+ dirname (gene/underscore name)
+ files (file-map noir-files data)]
+ (gene/build-filesystem
+ {name {"project.clj" (:project.clj files)
+ ".gitignore" (:gitignore files)
+ "README.md" (:README.md files)
+ "src" {dirname {"server.clj" (:server.clj files)
+ "views" {"welcome.clj" (:welcome.clj files)
+ "common.clj" (:common.clj files)}
+ "models" {}}}
+ "test" {dirname {"test" {}}}
+ "resources" {"public" {"js" {}
+ "css" {"reset.css" (:reset.css files)}
+ "img" {}}}}})))
+
@@ -0,0 +1,17 @@
+# {{name}}
+
+A website written in noir.
+
+## Usage
+
+```bash
+lein deps
+lein run
+```
+
+## License
+
+Copyright (C) 2011 FIXME
+
+Distributed under the Eclipse Public License, the same as Clojure.
+
@@ -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]]))
@@ -0,0 +1,5 @@
+pom.xml
+*jar
+/lib/
+/classes/
+.lein-deps-sum
@@ -0,0 +1,6 @@
+(defproject {{name}} "0.1.0-SNAPSHOT"
+ :description "FIXME: write this!"
+ :dependencies [[org.clojure/clojure "1.3.0"]
+ [noir "1.2.0"]]
+ :main {{name}}.server)
+
@@ -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; }*/
+
+
+
@@ -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}}})))
+
@@ -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}}"]))
@@ -1,24 +0,0 @@
-(ns spawn.genome.webapp
- (:require [spawn.genome :as gene]))
-
-(defn- t
- "Utility function for building a local template path"
- [name]
- (str "spawn/genome/webapp/" name))
-
-(defn webapp
- "A genome for creating webapps"
- [name]
- (let [data {:name name}
- dirname (gene/underscore name)]
- (gene/build-filesystem
- {name {"project.clj" (gene/apply-template (t "project.clj") data)
- "README" (gene/apply-template (t "README.markdown") data)
- "src" {dirname {"server.clj" (gene/apply-template (t "src/server.clj") data)
- "controllers" {"index.clj" (gene/apply-template (t "src/controllers/index.clj") data)}
- "views" {}}}
- "test" {dirname {"test" {"server.clj" (gene/apply-template (t "test/server-test.clj") data)}}}
- "public" {"robots.txt" (gene/apply-template (t "public/robots.txt") data)
- "js" {}
- "css" {}
- "img" {}}}})))
@@ -1,13 +0,0 @@
-# sample
-
-FIXME: write description
-
-## Usage
-
-FIXME: write
-
-## License
-
-Copyright (C) 2010 FIXME
-
-Distributed under the Eclipse Public License, the same as Clojure.
@@ -1,7 +0,0 @@
-(defproject {{name}} "1.0.0-SNAPSHOT"
- :description "FIXME: project description"
- :main {{name}}.server
- :dependencies [[org.clojure/clojure "1.2.0"]
- [org.clojure/clojure-contrib "1.2.0"]
- [ring "0.3.7"]
- [compojure "0.6.2"]])
@@ -1,5 +0,0 @@
-# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
-#
-# To ban all spiders from the entire site uncomment the next two lines:
-# User-Agent: *
-# Disallow: /
@@ -1,6 +0,0 @@
-(ns {{name}}.controllers.index
- (:use compojure.core))
-
-(defroutes index-routes
- "Routes for the index controller"
- (GET "/" [] "Welcome from $name$!"))
@@ -1,22 +0,0 @@
-(ns {{name}}.server
- (:use compojure.core ring.adapter.jetty)
- (:require [compojure.route :as route]
- [compojure.handler :as handler]
- [{{name}}.controllers.index :as index]))
-
-(defroutes root-routes
- "Defines the basic set of routes used by the application"
- (GET "/" [] index/index-routes)
- (route/files "/public" {:root "public"})
- (route/not-found "<h1>Page not found. Sorry.</h1>"))
-
-(defn wrap-middleware
- "Wraps the given routes in the application's middleware"
- [routes]
- (handler/site routes))
-
-(defn -main
- "Start up a basic Jetty server"
- [& args]
- (println "Starting Jetty on port 8080...")
- (run-jetty (wrap-middleware root-routes) {:port 8080}))

0 comments on commit 4ee9a19

Please sign in to comment.