Skip to content

Commit

Permalink
Generalized the configuration file support
Browse files Browse the repository at this point in the history
If the template name already as a file extension, that extension will be
used instead of .properties.
  • Loading branch information
Tony Edgin committed Oct 24, 2013
1 parent 90a64eb commit 4a17bd6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ bin
.classpath
.project
.lein*
.settings
\#*\#
/target/
/target/
4 changes: 4 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ nibblonian.swank.enabled =
nibblonian.swank.port =
```

If the name of the template has a file extension prior to the `.st` , eg. `name.ext.st`, the name
of the generated configuration file will be just the template name, eg. `name.ext`. Otherwise, the
name of the generated file will be the template name with `.properties` extension added.

Listing and Validating Configuration File Templates
---------------------------------------------------

Expand Down
11 changes: 10 additions & 1 deletion src/clavin/generator.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@
[java.util Properties]
[org.stringtemplate.v4 ST]))

(defn- name-file
"Creates the name of the configuration file. If the template name has a dot extension, the
template name will be used as the file name. Otherwise, the file name will be the template name
extended with '.properties'."
[template-name]
(if (.contains template-name ".")
template-name
(str template-name ".properties")))

(defn- write-file
"Creates a properties file for a template and environment."
[env template-dir template-name dest-dir]
(let [dest-file (file dest-dir (str template-name ".properties"))]
(let [dest-file (file dest-dir (name-file template-name))]
(print "Writing" (.getPath dest-file) "...")
(spit dest-file (gen-file env template-dir template-name))
(println "done.")))
Expand Down

0 comments on commit 4a17bd6

Please sign in to comment.