├── .gitignore ├── README.md ├── project.clj └── src └── leiningen └── new ├── ejecta_cljs.clj └── ejecta_cljs ├── AppDelegate.h ├── AppDelegate.m ├── Podfile ├── README.md ├── gitignore ├── index.js ├── init ├── project.clj ├── repl └── repl.clj /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /classes 3 | /checkouts 4 | pom.xml 5 | pom.xml.asc 6 | *.jar 7 | *.class 8 | /.lein-* 9 | /.nrepl-port 10 | .hgignore 11 | .hg/ 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ejecta-cljs-template 2 | 3 | A Leiningen template for Ejecta ClojureScript development. 4 | 5 | ## Usage 6 | 7 | There is no deployed artifact. From a checkout of this project: 8 | 9 | ```shell 10 | lein install 11 | ``` 12 | 13 | Then create a project, for example `ejecta-test`: 14 | 15 | ```shell 16 | lein new ejecta-cljs ejecta-test 17 | ``` 18 | 19 | Follow the instructions in the generated README. 20 | 21 | ## License 22 | 23 | Copyright © 2015 David Nolen 24 | 25 | Distributed under the Eclipse Public License either version 1.0 or (at 26 | your option) any later version. 27 | -------------------------------------------------------------------------------- /project.clj: -------------------------------------------------------------------------------- 1 | (defproject ejecta-cljs/lein-template "0.1.0" 2 | :description "FIXME: write description" 3 | :url "http://example.com/FIXME" 4 | :license {:name "Eclipse Public License" 5 | :url "http://www.eclipse.org/legal/epl-v10.html"} 6 | :dependencies [[org.clojure/clojure "1.6.0"]]) 7 | -------------------------------------------------------------------------------- /src/leiningen/new/ejecta_cljs.clj: -------------------------------------------------------------------------------- 1 | (ns leiningen.new.ejecta-cljs 2 | (:require [clojure.string :as string] 3 | [leiningen.new.templates :refer [renderer name-to-path ->files]])) 4 | 5 | (def render (renderer "ejecta-cljs")) 6 | 7 | (defn camelize [s] 8 | (apply str (map #(apply str (.toUpperCase (str (first %))) (rest %)) (string/split s #"-")))) 9 | 10 | (defn ejecta-cljs [name] 11 | (let [data {:name name :sanitized (name-to-path name) :camelized (camelize name)}] 12 | (->files data 13 | ;; Clojure 14 | ["project.clj" (render "project.clj" data)] 15 | ["README.md" (render "README.md" data)] 16 | [".gitignore" (render "gitignore" data)] 17 | 18 | ["script/repl.clj" (render "repl.clj" data)] 19 | ["script/repl" (render "repl" data) :executable true] 20 | ["script/init" (render "init" data) :executable true] 21 | 22 | ;; Objective-C 23 | ["resources/objc/index.js" (render "index.js" data)] 24 | ["resources/objc/Podfile" (render "Podfile" data)] 25 | ["resources/objc/AppDelegate.h" (render "AppDelegate.h")] 26 | ["resources/objc/AppDelegate.m" (render "AppDelegate.m")]))) 27 | -------------------------------------------------------------------------------- /src/leiningen/new/ejecta_cljs/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // EjectaCLJS 4 | // 5 | // Created by David Nolen on 5/20/15. 6 | // Copyright (c) 2015 dnolen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) IBOutlet UIWindow *window; 14 | 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /src/leiningen/new/ejecta_cljs/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // EjectaCLJS 4 | // 5 | // Created by David Nolen on 5/20/15. 6 | // Copyright (c) 2015 dnolen. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "EJJavaScriptView.h" 11 | #import "EJAppViewController.h" 12 | #import "ABYContextManager.h" 13 | #import "ABYServer.h" 14 | 15 | @interface AppDelegate () 16 | @property (strong, nonatomic) ABYContextManager* contextManager; 17 | @property (strong, nonatomic) ABYServer* replServer; 18 | @end 19 | 20 | @implementation AppDelegate 21 | @synthesize window; 22 | 23 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 24 | // Optionally set the idle timer disabled, this prevents the device from sleep when 25 | // not being interacted with by touch. ie. games with motion control. 26 | application.idleTimerDisabled = YES; 27 | 28 | [self loadViewControllerWithScriptAtPath:@"index.js"]; 29 | 30 | EJJavaScriptView* appView = (EJJavaScriptView*)window.rootViewController.view; 31 | JSGlobalContextRef ctx = appView.jsGlobalContext; 32 | 33 | NSURL* compilerOutputDirectory = [[self privateDocumentsDirectory] URLByAppendingPathComponent:@"cljs-out"]; 34 | [self createDirectoriesUpTo:compilerOutputDirectory]; 35 | 36 | // Set up our context 37 | self.contextManager = [[ABYContextManager alloc] initWithContext:ctx 38 | compilerOutputDirectory:compilerOutputDirectory]; 39 | [self.contextManager setupGlobalContext]; 40 | [self.contextManager setUpExceptionLogging]; 41 | [self.contextManager setUpConsoleLog]; 42 | [self.contextManager setUpTimerFunctionality]; 43 | [self.contextManager setUpAmblyImportScript]; 44 | 45 | self.replServer = [[ABYServer alloc] initWithContext:self.contextManager.context 46 | compilerOutputDirectory:compilerOutputDirectory]; 47 | BOOL successful = [self.replServer startListening]; 48 | if (!successful) { 49 | NSLog(@"Failed to start REPL server."); 50 | } else { 51 | NSLog(@"Started REPL server."); 52 | } 53 | 54 | return YES; 55 | } 56 | 57 | - (void)loadViewControllerWithScriptAtPath:(NSString *)path { 58 | // Release any previous ViewController 59 | window.frame = UIScreen.mainScreen.bounds; 60 | window.rootViewController = nil; 61 | 62 | EJAppViewController *vc = [[EJAppViewController alloc] initWithScriptAtPath:path]; 63 | window.rootViewController = vc; 64 | [window makeKeyWindow]; 65 | //[vc release]; 66 | } 67 | 68 | - (NSURL *)privateDocumentsDirectory 69 | { 70 | NSURL *libraryDirectory = [[[NSFileManager defaultManager] URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask] lastObject]; 71 | 72 | return [libraryDirectory URLByAppendingPathComponent:@"Private Documents"]; 73 | } 74 | 75 | - (void)createDirectoriesUpTo:(NSURL*)directory 76 | { 77 | if (![[NSFileManager defaultManager] fileExistsAtPath:[directory path]]) { 78 | NSError *error = nil; 79 | 80 | if (![[NSFileManager defaultManager] createDirectoryAtPath:[directory path] 81 | withIntermediateDirectories:YES 82 | attributes:nil 83 | error:&error]) { 84 | NSLog(@"Can't create directory %@ [%@]", [directory path], error); 85 | abort(); 86 | } 87 | } 88 | } 89 | 90 | - (void)applicationWillResignActive:(UIApplication *)application { 91 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 92 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 93 | } 94 | 95 | - (void)applicationDidEnterBackground:(UIApplication *)application { 96 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 97 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 98 | } 99 | 100 | - (void)applicationWillEnterForeground:(UIApplication *)application { 101 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 102 | } 103 | 104 | - (void)applicationDidBecomeActive:(UIApplication *)application { 105 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 106 | } 107 | 108 | - (void)applicationWillTerminate:(UIApplication *)application { 109 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 110 | } 111 | 112 | @end 113 | -------------------------------------------------------------------------------- /src/leiningen/new/ejecta_cljs/Podfile: -------------------------------------------------------------------------------- 1 | platform :ios, '8.0' 2 | pod 'Ambly', :git => 'https://github.com/omcljs/ambly', :branch => 'jsc-c-api' 3 | pod 'Ejecta', :git => 'https://github.com/swannodette/Ejecta', :branch => 'podspec' 4 | -------------------------------------------------------------------------------- /src/leiningen/new/ejecta_cljs/README.md: -------------------------------------------------------------------------------- 1 | ## EjectaCLJS 2 | 3 | Launch XCode and create a iOS Single View Application project. If you 4 | named your project `ejecta-test` your application should be called 5 | `EjectaTest`. From the root of your project it should go into a 6 | directory called `ObjC`. 7 | 8 | Initialize your project: 9 | 10 | ```shell 11 | script/init 12 | ``` 13 | 14 | Open your project: 15 | 16 | ``` 17 | open ObjC/ProjectName/ProjectName.xcworkspace 18 | ``` 19 | 20 | Use the *File > Add Files ...* menu option to add the newly created 21 | `App` directory containing `index.js` to your project. 22 | 23 | Build the application (Command-R). 24 | 25 | Start the REPL: 26 | 27 | ```shell 28 | script/repl 29 | ``` 30 | 31 | At the REPL try the following series of interactions: 32 | 33 | ```shell 34 | (def canvas (.getElementById js/document "canvas")) 35 | (def ctx (.getContext canvas "2d")) 36 | (set! (.-fillStyle ctx) "#ff0000") 37 | (.fillRect ctx 50 50 100 100) 38 | ``` 39 | -------------------------------------------------------------------------------- /src/leiningen/new/ejecta_cljs/gitignore: -------------------------------------------------------------------------------- 1 | .idea -------------------------------------------------------------------------------- /src/leiningen/new/ejecta_cljs/index.js: -------------------------------------------------------------------------------- 1 | console.log("Hello EjectaCLJS!"); 2 | -------------------------------------------------------------------------------- /src/leiningen/new/ejecta_cljs/init: -------------------------------------------------------------------------------- 1 | cp resources/objc/Podfile ObjC/{{camelized}}/Podfile 2 | cd ObjC/{{camelized}} 3 | pod install 4 | cd ../.. 5 | mkdir -p ObjC/{{camelized}}/App 6 | cp resources/objc/index.js ObjC/{{camelized}}/App/index.js 7 | cp resources/objc/AppDelegate.h ObjC/{{camelized}}/{{camelized}}/AppDelegate.h 8 | cp resources/objc/AppDelegate.m ObjC/{{camelized}}/{{camelized}}/AppDelegate.m 9 | 10 | -------------------------------------------------------------------------------- /src/leiningen/new/ejecta_cljs/project.clj: -------------------------------------------------------------------------------- 1 | (defproject {{name}} "0.1.0-SNAPSHOT" 2 | :description "FIXME: write this!" 3 | :url "https://example.com/FIXME" 4 | :license {:name "Eclipse Public License" 5 | :url "http://www.eclipse.org/legal/epl-v10.html"} 6 | 7 | :jvm-opts ^:replace ["-Xmx512m" "-server"] 8 | 9 | :dependencies [[org.clojure/clojure "1.7.0-beta3"] 10 | [org.clojure/clojurescript "0.0-3291"] 11 | [org.omcljs/ambly "0.3.0"]] 12 | 13 | :source-paths ["src"] 14 | :resource-paths ["resources"] 15 | :test-paths ["test"]) 16 | -------------------------------------------------------------------------------- /src/leiningen/new/ejecta_cljs/repl: -------------------------------------------------------------------------------- 1 | rlwrap lein trampoline run -m clojure.main script/repl.clj -------------------------------------------------------------------------------- /src/leiningen/new/ejecta_cljs/repl.clj: -------------------------------------------------------------------------------- 1 | (require 2 | '[cljs.repl :as repl] 3 | '[ambly.core :as ambly]) 4 | 5 | (repl/repl (ambly/repl-env)) 6 | --------------------------------------------------------------------------------