Permalink
Browse files

Change code generation from multiple files in folder to one file

  • Loading branch information...
swlkr committed Feb 10, 2019
1 parent 02abf15 commit 82ca5571ff9b483a85b6084282f9cee935aab042
3 coast
@@ -47,8 +47,7 @@ Examples:
coast gen migration <name> # Creates a new edn migration file
coast gen sql:migration <name> # Creates a new sql migration file
coast gen action <resource> # Creates a five new clj files with view/action functions in src/<resource>/new/show/edit/delete/index.clj
coast gen action <resource>:<action> # Creates a new clj file with view/action functions in src/<resource>/<action>.clj"))
coast gen code <table> # Creates a new clj file with handler functions in src/<table>.clj
EOF
exit 0
}

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,69 @@
(ns __table__
(:require [coast]))


(defn index [request]
(let [rows (coast/q '[:pull [__index-pull-symbols__]
:order __table__/id])]
__table-html__))


(defn view [request]
(let [__table__ (coast/fetch :__table__/id (-> request :params :__table__-id))]
[:div
__dl-elements__
[:div
[:a {:href (coast/url-for ::index) :style "margin-right: 5px"} "List"]
[:a {:href (coast/url-for ::edit (:params request)) :style "margin-right: 5px"} "Edit"]
[:a {:href (coast/url-for ::delete (:params request))} "Delete"]]]))


(defn build [request]
(coast/form-for ::create
__form-elements__

[:a {:href (coast/url-for ::index)} "Cancel"]
[:input {:type "submit" :value "New __table__"}]))


(defn create [request]
(let [[_ errors] (-> (coast/validate (:params request) [[:required [__qualified-keywords__]]])
(select-keys [__qualified-keywords__])
(coast/insert)
(coast/rescue))]
(if (nil? errors)
(coast/redirect-to ::index)
(build (merge request errors)))))


(defn edit [request]
(let [__table__ (merge (coast/fetch :__table__/id (-> request :params :__table__-id)) (:params request))]
(coast/form-for ::change __table__
__edit-elements__

[:div
[:a {:href (coast/url-for ::index)} "Cancel"]
[:input {:type "submit" :value "Update __table__"}]])))


(defn change [request]
(let [__table__ (coast/fetch :__table__/id (-> request :params :__table__-id))
[_ errors] (-> (select-keys __table__ [:__table__/id])
(merge (:params request))
(coast/validate [[:required [__change-keywords__]]])
(select-keys [__change-keywords__])
(coast/update)
(coast/rescue))]
(if (nil? errors)
(coast/redirect-to ::view __table__)
(edit (merge request errors)))))


(defn delete [request]
(let [[_ errors] (-> (coast/fetch :__table__/id (-> request :params :__table__-id))
(coast/delete)
(coast/rescue))]
(if (nil? errors)
(coast/redirect-to ::index)
(-> (coast/redirect-to ::index)
(coast/flash "Something went wrong!")))))

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -1,7 +1,7 @@
(ns coast.generators
(:require [clojure.string :as string]
[clojure.java.io :as io]
[coast.generators.action :as generators.action]
[coast.generators.code :as generators.code]
[coast.generators.migration :as generators.migration]))


@@ -15,15 +15,14 @@ Examples:
coast gen migration <name> # Creates a new migration file
coast gen migration <name>.sql # Creates a new plain old sql migration file
coast gen action <resource> # Creates a five new clj files with view/action functions in src/<resource>/create/read/update/delete/list.clj
coast gen action <resource>:<action> # Creates a new clj file with view/action functions in src/<resource>/<action>.clj"))
coast gen code <table> # Creates a new clj file with handler functions in src/<table>.clj"))


(defn gen [args]
(let [[_ kind arg] args]
(case kind
"migration" (generators.migration/write (drop 2 args))
"action" (generators.action/write arg)
"code" (generators.code/write arg)
(usage))))


This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 82ca557

Please sign in to comment.