Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

Commit

Permalink
Implement project creation via templates
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-yakushev committed May 17, 2012
1 parent 7da373e commit 6dddef5
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/leiningen/droid/new.clj
@@ -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)])))
20 changes: 20 additions & 0 deletions templates/AndroidManifest.xml
@@ -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>
22 changes: 22 additions & 0 deletions templates/MainActivity.clj
@@ -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)))
13 changes: 13 additions & 0 deletions templates/README.md
@@ -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.
Binary file added templates/ic_launcher_hdpi.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added templates/ic_launcher_ldpi.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added templates/ic_launcher_mdpi.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions templates/project.clj
@@ -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}}"})
7 changes: 7 additions & 0 deletions templates/strings.xml
@@ -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>

0 comments on commit 6dddef5

Please sign in to comment.