Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Promoted to 1.0

  • Loading branch information...
commit dd0f556bc81b0cc136d81c6e1b103bb01ac04c1c 1 parent 5118dcf
Dmitry authored
Showing with 27 additions and 11 deletions.
  1. +5 −2 README.md
  2. +1 −1  project.clj
  3. +21 −8 resources/templates/db.clj
View
7 README.md
@@ -1,12 +1,15 @@
# lein-noir-gen
This is a CRUD-actions generator for a Noir-project. It is heavily inspired by the Rails generators.
-Noir-gen creates default view and model for the specified entity. It uses the Mongodb to store the models.
+Noir-gen creates default view and model for the specified entity. It uses the Mongodb to store the models and has support of heroku hosting out-of-the box.
The generated pages have some basic layout made with Bootstrap. The examples of generated pages are here: https://docs.google.com/open?id=0BzmL7xzGeOtOYjFkZjg4ZjQtYjMwNy00N2M4LTg2MzQtOGFhYzFhYmJkMWEy https://docs.google.com/open?id=0BzmL7xzGeOtOMmY4MDNlMjItODU5ZS00Y2Q1LWEzM2EtZGM1ZDRiNDUxMDk0
Also you can see a screencast about how to create a simple blog with Clojure, Noir and noir-gen in 15 minutes here: http://youtu.be/-Fo4djTlmVY
-Version noir-gen 0.5.0 is adopted to the brand-new noir 1.3.0-beta2 which has breaking changes since it uses hiccup 1.0. Tested against Clojure 1.4.0.
+Version noir-gen 1.0.0 is adopted to the brand-new noir 1.3.0-beta3 which has breaking changes since it uses hiccup 1.0. Tested against Clojure 1.4.0.
+
+##
+Warning! This release doesn't work with leiningen 2.x.
## Overview
View
2  project.clj
@@ -1,4 +1,4 @@
-(defproject lein-noir-gen "0.5.0"
+(defproject lein-noir-gen "1.0.0"
:description "Noir CRUD generator"
:dependencies [[org.clojure/clojure "1.4.0"]
[de.ubercode.clostache/clostache "0.6.0"]
View
29 resources/templates/db.clj
@@ -1,14 +1,27 @@
(ns {{namespace}}.db
- (:use [somnium.congomongo]))
+ (:use [somnium.congomongo]
+ [somnium.congomongo.config :only [*mongo-config*]]))
+
+(defn split-mongo-url [url]
+ "Parses mongodb url from heroku, eg. mongodb://user:pass@localhost:1234/db"
+ (let [matcher (re-matcher #"^.*://(.*?):(.*?)@(.*?):(\d+)/(.*)$" url)] ;; Setup the regex.
+ (when (.find matcher) ;; Check if it matches.
+ (zipmap [:match :user :pass :host :port :db] (re-groups matcher))))) ;; Construct an options map.
(defn connect-db []
- (set-connection! (make-connection "{{database}}"
- :host "127.0.0.1"
- :port 27017)))
+ (let [mongo-url (get (System/getenv) "MONGOHQ_URL")]
+ (if mongo-url
+ (let [config (split-mongo-url mongo-url)]
+ (mongo! :db (:db config)
+ :host (:host config)
+ :port (Integer. (:port config)))
+ (authenticate (:user config) (:pass config)))
+ (mongo! :db {{database}}))))
+
(defn next-id [name]
(:value (fetch-and-modify :counters
- {:name name}
- {:$inc {:value 1}}
- :upsert? true
- :return-new? true)))
+ {:name name}
+ {:$inc {:value 1}}
+ :upsert? true
+ :return-new? true)))
Please sign in to comment.
Something went wrong with that request. Please try again.