Skip to content

Commit

Permalink
lots of fixes, module additions + package feature
Browse files Browse the repository at this point in the history
  • Loading branch information
runexec committed Jul 9, 2013
1 parent 7073f93 commit e214ab4
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 25 deletions.
48 changes: 45 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ ClojureHomePage is a Clojure Web Framework that provides the following.
* [CSS Generation](#clojure-and-css-generation)
* [JavaScript Generation](#clojure-and-javascript-generation)
* [CHP Modules](#modules)
* [Module Packages](#module-packages)

<b> SQL Configuration, Migrations, and Manipulation </b>

Expand Down Expand Up @@ -871,8 +872,8 @@ Deleting resources/middleware/verbose-log.clj
$ lein mod-list

resources/modules
resources/modules/migration
resources/modules/migration/01-add-admin.clj
resources/modules/migrations
resources/modules/migrations/01-add-admin.clj
resources/modules/cljs
resources/modules/middleware
resources/modules/middleware/example.clj
Expand All @@ -883,7 +884,48 @@ resources/modules/schema
resources/modules/schema/example.clj
resources/modules/schema/user.clj
resources/modules/schema/blog-post.clj
resources/modules/binding
resources/modules/bindings
resources/modules/bindings/user.clj
```

# Module Packages

Module packages are stored in ```resources/packages/```. Each package is a clj file that describes what modules to install when calling ```lein package-run name1 name2 etc...```

```bash
$ cat resources/packages/admin.clj
```
```clojure
;; CHP Admin module
;; {:module-type [:module :module :module etc..]}

{:schema [:user] ;; resources/modules/schema/user.clj
:migrations [:01-add-admin] ;; resources/modules/migrations/01-add-admin.clj
:bindings [:user] ;; resources/modules/bindings/user.clj
:middleware [] ;; resources/modules/middleware/ -- nothing
:cljs []} ;; resources/modules/cljs/ -- nothing
```

```bash
$ lein package-run admin

Loading for :schema
Copying resources/modules/schema/user.clj -> resources/schema/user.clj
Creating Table => resources/schema/user.clj
OKAY

Loading for :migrations
Copying resources/modules/migrations/01-add-admin.clj -> resources/migrations/01-add-admin.clj
Jul 09, 2013 7:52:37 PM com.mchange.v2.log.MLog <clinit>
INFO: MLog clients using java 1.4+ standard logging.
create-chp-admin

Loading for :bindings
Copying resources/modules/bindings/user.clj -> resources/bindings/user.clj

Loading for :middleware

Loading for :cljs
```

# Getting started
Expand Down
3 changes: 2 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
;; MOD
"mod-list" ["run" "-m" "chp.module/mod-list"]
"mod-enable" ["run" "-m" "chp.module/mod-enable"]
"mod-disable" ["run" "-m" "chp.module/mod-disable"]}
"mod-disable" ["run" "-m" "chp.module/mod-disable"]
"package-run" ["run" "-m" "chp.package/load-packages"]}
:cljsbuild {:builds [{:source-paths ["resources/cljs"]
:compiler {:output-to "resources/public/js/main.js"
:optimizations :advanced
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions resources/packages/admin.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

;; CHP Admin module
;; {:module-type [:module :module :module etc..]}

{:schema [:user] ;; resources/modules/schema/user.clj
:migrations [:01-add-admin] ;; resources/modules/migrations/01-add-admin.clj
:bindings [:user] ;; resources/modules/bindings/user.clj
:middleware [] ;; resources/modules/middleware/ -- nothing
:cljs []} ;; resources/modules/cljs/ -- nothing
17 changes: 0 additions & 17 deletions resources/schema/example.clj

This file was deleted.

2 changes: 1 addition & 1 deletion src/chp/module.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
(def mod-path "resources/modules/")

(defn- mpath-copy
"types: :middleware :migration :schema :cljs :binding
"types: :middleware :migrations :schema :cljs :binding
file: is a :name without the .clj extension"
[-type -file & [enable?]]
(let [-type (if (keyword? -type) (name -type) (str -type))
Expand Down
47 changes: 47 additions & 0 deletions src/chp/package.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
(ns chp.package
;; for schema load
(:refer-clojure :exclude [bigint
boolean
char
double
float
time])
(:use [chp.schema
:only [load-schemas]]
[chp.migration
:only [chp-migrate]]
[chp.module
:only [mod-enable]]))

(def package-dir "resources/packages/")

(defn force-string [-name]
(if (keyword? -name)
(name -name)
(str -name)))

(defn name->clj [-name]
(let [-name (force-string -name)
-file (str -name ".clj")]
(->> -file
(str package-dir)
slurp
read-string)))


(defn load-package [-name]
(doseq [_ (name->clj -name)
:let [[-type mods] _]]
(println "\n Loading for" -type)
(doseq [_ mods]
(mod-enable -type _)
(case -type
:schema (load-schemas)
:migrations (chp-migrate)
:bindings true
:middleware true
:cljs true
:unknown-type))))

(defn load-packages [& -name]
(doseq [_ -name] (load-package _)))
2 changes: 1 addition & 1 deletion src/chp/schema.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
(filter #(.. % (endsWith ".clj")))
(map #(str schema-dir %))))

(defn- fp->schema
(defn fp->schema
"File path to schema"
[schema-src-path]
(->> schema-src-path
Expand Down
8 changes: 6 additions & 2 deletions src/lobos/migrations.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@
schema
helpers
connectivity)
chp.core
chp.login
[chp.core
:exclude [korma-db]]
[chp.login
:exclude [korma-db]]
chp.password
[chp.db
:only [*db*]]
[chp.migration
:only [load-migrations]]))

(kdb/defdb korma-db *db*)

(eval (load-migrations))

0 comments on commit e214ab4

Please sign in to comment.