This repository has been archived by the owner on Apr 25, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement project creation via templates
- Loading branch information
1 parent
7da373e
commit 6dddef5
Showing
9 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
(ns leiningen.droid.new | ||
(:require [clojure.string :as string] | ||
[clojure.java.io :as io]) | ||
(:use [leiningen.new.templates :only [render-text slurp-resource sanitize ->files]])) | ||
|
||
(defn- render | ||
[template-name & [data]] | ||
(let [file (io/file "templates" template-name)] | ||
(if data | ||
(render-text (slurp file) data) | ||
file))) | ||
|
||
(defn package-to-path [package-name] | ||
(string/replace package-name #"\." "/")) | ||
|
||
(defn create-project | ||
"FIXME: write documentation" | ||
[name package-name & {:keys [activity min-sdk app-name], | ||
:or {activity "MainActivity", min-sdk "10", | ||
app-name name}}] | ||
(let [data {:name name | ||
:package package-name | ||
:package-sanitized (sanitize package-name) | ||
:path (package-to-path (sanitize package-name)) | ||
:activity activity | ||
:min-sdk min-sdk | ||
:app-name app-name}] | ||
(println data) | ||
(->files | ||
data | ||
"assets" | ||
["AndroidManifest.xml" (render "AndroidManifest.xml" data)] | ||
["project.clj" (render "project.clj" data)] | ||
["res/drawable-hdpi/ic_launcher.png" (render "ic_launcher_hdpi.png")] | ||
["res/drawable-mdpi/ic_launcher.png" (render "ic_launcher_mdpi.png")] | ||
["res/drawable-ldpi/ic_launcher.png" (render "ic_launcher_ldpi.png")] | ||
"src/java" | ||
["src/clojure/{{path}}/{{activity}}.clj" | ||
(render "MainActivity.clj" data)]))) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="{{package-sanitized}}" | ||
android:versionCode="1" | ||
android:versionName="1.0" > | ||
|
||
<uses-sdk android:minSdkVersion="{{min-sdk}}" /> | ||
|
||
<application | ||
android:icon="@drawable/ic_launcher" | ||
android:label="@string/app_name" > | ||
<activity android:name="{{activity}}"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
<category android:name="android.intent.category.LAUNCHER"/> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
(ns {{package}}.{{activity}} | ||
(:import [android.widget TextView LinearLayout]) | ||
(:require [neko.compilation :as neko] | ||
[neko.repl :as repl]) | ||
(:gen-class | ||
:main false | ||
:extends android.app.Activity | ||
:exposes-methods {onCreate superOnCreate})) | ||
|
||
(defn init [context] | ||
(neko/init context "classes") | ||
(repl/try-start-repl)) | ||
|
||
(defn -onCreate [this bundle] | ||
(init this) | ||
(let [hello_text (TextView. this) | ||
layout (LinearLayout. this)] | ||
(.setText hello_text "Hello Android from Clojure!") | ||
(doto this | ||
(.superOnCreate bundle) | ||
(.setContentView layout)) | ||
(.addView layout hello_text))) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# sample | ||
|
||
This is a Clojure/Android application. | ||
|
||
## Usage | ||
|
||
FIXME | ||
|
||
## License | ||
|
||
Copyright © 2012 FIXME | ||
|
||
Distributed under the Eclipse Public License, the same as Clojure. |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
(defproject {{name}}/{{name}} "0.0.1-SNAPSHOT" | ||
:description "FIXME: Android project description" | ||
:url "http://example.com/FIXME" | ||
:license {:name "Eclipse Public License" | ||
:url "http://www.eclipse.org/legal/epl-v10.html"} | ||
:middleware [leiningen.droid.utils/android-parameters] | ||
:min-lein-version "2.0.0" | ||
|
||
:source-paths ["src/clojure"] | ||
:java-source-paths ["src/java" "gen"] | ||
;; The following two definitions are optional. The default | ||
;; target-path is "target", but you can change it to whatever you like. | ||
;; :target-path "bin" | ||
;; :compile-path "bin/classes" | ||
:aot :all-with-unused ;; This one is necessary, please keep it | ||
:aot-exclude-ns ["clojure.parallel"] | ||
|
||
:dependencies [[android/clojure "1.4.0"] | ||
[neko/neko "1.0.1-SNAPSHOT"]] | ||
:profiles {:dev {:dependencies [[org.clojure/tools.nrepl "0.2.0-beta6"]]} | ||
:release {:android {:keystore-path "/home/unlogic/private.keystore"}}} | ||
|
||
:android {;; Specify the path to the Android SDK directory either | ||
;; here or in your ~/.lein/profiles.clj file. | ||
;; :sdk-path "/home/user/path/to/android-sdk/" | ||
:target-version "{{min-sdk}}"}) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<string name="hello">Hello Android from Clojure!</string> | ||
<string name="app_name">{{app-name}}</string> | ||
|
||
</resources> |