-
-
Save johnbendi/3629127 to your computer and use it in GitHub Desktop.
poor api doc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Our file-generating function, `->files` is very simple. We'd like | |
;; to keep it that way. Sometimes you need your file paths to be | |
;; templates as well. This function just renders a string that is the | |
;; path to where a file is supposed to be placed by a template. | |
;; It is private because you shouldn't have to call it yourself, since | |
;; `->files` does it for you. | |
(defn- template-path [name path data] | |
(io/file name (render-text path data))) | |
;; A template, at its core, is meant to generate files and directories that | |
;; represent a project. This is our way of doing that. `->files` is basically | |
;; a mini-DSL for generating files. It takes your mustache template data and | |
;; any number of vectors or strings. It iterates through those arguments and | |
;; when it sees a vector, it treats the first element as the path to spit to | |
;; and the second element as the contents to put there. If it encounters a | |
;; string, it treats it as an empty directory that should be created. Any parent | |
;; directories for any of our generated files and directories are created | |
;; automatically. All paths are considered mustache templates and are rendered | |
;; with our data. Of course, this doesn't effect paths that don't have templates | |
;; in them, so it is all transparent unless you need it. | |
(defn ->files | |
"Generate a file with content. path can be a java.io.File or string. | |
It will be turned into a File regardless. Any parent directories will | |
be created automatically. Data should include a key for :name so that | |
the project is created in the correct directory" | |
[{:keys [name] :as data} & paths] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment