Skip to content
Browse files

#57: Only append .core to single-segment namespaces. (default, app)

  • Loading branch information...
1 parent 083e03f commit 4fe7a9011c8466fabf9e6708291b06b659a89483 @timmc timmc committed Jan 2, 2013
View
12 src/leiningen/new/app.clj
@@ -1,22 +1,24 @@
(ns leiningen.new.app
"Generate a basic application project."
(:use [leiningen.new.templates :only [renderer year project-name
- ->files sanitize-ns name-to-path]]))
+ ->files sanitize-ns name-to-path
+ multi-segment]]))
(defn app
"An application project template."
[name]
(let [render (renderer "app")
+ main-ns (multi-segment (sanitize-ns name))
data {:raw-name name
:name (project-name name)
- :namespace (sanitize-ns name)
- :nested-dirs (name-to-path name)
+ :namespace main-ns
+ :nested-dirs (name-to-path main-ns)
:year (year)}]
(println "Generating a project called" name "based on the 'app' template.")
(->files data
["project.clj" (render "project.clj" data)]
["README.md" (render "README.md" data)]
["doc/intro.md" (render "intro.md" data)]
[".gitignore" (render "gitignore" data)]
- ["src/{{nested-dirs}}/core.clj" (render "core.clj" data)]
- ["test/{{nested-dirs}}/core_test.clj" (render "test.clj" data)])))
+ ["src/{{nested-dirs}}.clj" (render "core.clj" data)]
+ ["test/{{nested-dirs}}_test.clj" (render "test.clj" data)])))
View
2 src/leiningen/new/app/core.clj
@@ -1,4 +1,4 @@
-(ns {{namespace}}.core
+(ns {{namespace}}
(:gen-class))
(defn -main
View
2 src/leiningen/new/app/project.clj
@@ -4,4 +4,4 @@
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.4.0"]]
- :main {{namespace}}.core)
+ :main {{namespace}})
View
4 src/leiningen/new/app/test.clj
@@ -1,6 +1,6 @@
-(ns {{namespace}}.core-test
+(ns {{namespace}}-test
(:use clojure.test
- {{namespace}}.core))
+ {{namespace}}))
(deftest a-test
(testing "FIXME, I fail."
View
12 src/leiningen/new/default.clj
@@ -1,18 +1,20 @@
(ns leiningen.new.default
"Generate a library project."
(:use [leiningen.new.templates :only [renderer year project-name
- ->files sanitize-ns name-to-path]]))
+ ->files sanitize-ns name-to-path
+ multi-segment]]))
(defn default
"A general project template for libraries.
Accepts a group id in the project name: `lein new foo.bar/baz`"
[name]
(let [render (renderer "default")
+ main-ns (multi-segment (sanitize-ns name))
data {:raw-name name
:name (project-name name)
- :namespace (sanitize-ns name)
- :nested-dirs (name-to-path name)
+ :namespace main-ns
+ :nested-dirs (name-to-path main-ns)
:year (year)}]
(println "Generating a project called" name "based on the 'default' template.")
(println "To see other templates (app, lein plugin, etc), try `lein help new`.")
@@ -21,5 +23,5 @@ Accepts a group id in the project name: `lein new foo.bar/baz`"
["README.md" (render "README.md" data)]
["doc/intro.md" (render "intro.md" data)]
[".gitignore" (render "gitignore" data)]
- ["src/{{nested-dirs}}/core.clj" (render "core.clj" data)]
- ["test/{{nested-dirs}}/core_test.clj" (render "test.clj" data)])))
+ ["src/{{nested-dirs}}.clj" (render "core.clj" data)]
+ ["test/{{nested-dirs}}_test.clj" (render "test.clj" data)])))
View
2 src/leiningen/new/default/core.clj
@@ -1,4 +1,4 @@
-(ns {{namespace}}.core)
+(ns {{namespace}})
(defn foo
"I don't do a whole lot."
View
4 src/leiningen/new/default/test.clj
@@ -1,6 +1,6 @@
-(ns {{namespace}}.core-test
+(ns {{namespace}}-test
(:use clojure.test
- {{namespace}}.core))
+ {{namespace}}))
(deftest a-test
(testing "FIXME, I fail."
View
9 src/leiningen/new/templates.clj
@@ -31,6 +31,15 @@
[s]
(string/replace s #"-" "_"))
+(defn multi-segment
+ "Make a namespace multi-segmented by adding another segment if necessary.
+The additional segment defaults to \"core\"."
+ ([s] (multi-segment s "core"))
+ ([s final-segment]
+ (if (.contains s ".")
+ s
+ (format "%s.%s" s final-segment))))
+
(defn name-to-path
"Constructs directory structure from fully qualified artifact name:

0 comments on commit 4fe7a90

Please sign in to comment.
Something went wrong with that request. Please try again.