Commits

Marco Yuen committed bef827f

Initial commit. Index page shows long and lat.

Comments (0)

Files changed (7)

+/target
+/lib
+/classes
+/checkouts
+pom.xml
+*.jar
+*.class
+.lein-deps-sum
+.lein-failures
+.lein-plugins
+# nextrain
+
+## License
+
+Copyright © 2012 Marco Yuen
+
+Distributed under the Eclipse Public License, the same as Clojure.
+(defproject nextrain "0.0.1"
+  :description "When is the next train!?"
+  :url "http://marcoyuen.com"
+  :license {:name "Eclipse Public License"
+            :url "http://www.eclipse.org/legal/epl-v10.html"}
+  :plugins      [[lein-ring  "0.7.1"]
+                 [lein-swank "1.4.4"]
+                 [lein-midje "1.0.10"]]
+  :dependencies [[org.clojure/clojure     "1.3.0"]
+                 [org.clojure/tools.trace "0.7.3"]
+                 [org.clojure/java.jdbc   "0.2.1"]
+                 [org.xerial/sqlite-jdbc  "3.7.2"]
+                 [compojure               "1.1.0"]
+                 [hiccup                  "1.0.0"]
+                 [ring-json-response      "0.2.0"]
+                 [useful                  "0.8.3-alpha2"]]
+  :dev-dependencies [[clojure-source "1.3.0"]
+                     [midje          "1.4.0"]
+                     [ring-serve     "0.1.2"]
+                     [ring-mock      "0.1.2"]]
+  :resources-path "resources"
+  :ring {:handler nextrain.core/app})

resources/public/js/location.js

+$(function() {
+  if (navigator.geolocation) {
+    navigator.geolocation.getCurrentPosition(success, error);
+  } else {
+    alert('Geolocation not supported');
+  }
+
+  function success(position) {
+    console.log(position);
+    $("#lng").html(position.coords.longitude);
+    $("#lat").html(position.coords.latitude);
+  }
+
+  function error() {
+    console.log("No location");
+  }
+});
+
+//var loc = {};
+//if(google.loader.ClientLocation) {
+//  loc.lat = google.loader.ClientLocation.latitude;
+//  loc.lng = google.loader.ClientLocation.longitude;
+//}

src/nextrain/core.clj

+(ns nextrain.core
+  (:use compojure.core
+        nextrain.pages)
+  (:require [compojure.route :as route]
+            [compojure.handler :as handler]))
+
+(defn testsession [params session]
+  (println params)
+  (println session)
+  (if-let [n (:n session)]
+    {:body (str session)
+     :session (assoc session :n (inc n))}
+    {:body (str session)
+     :session (assoc session :n 1)}))
+
+(defroutes main-routes
+  (GET "/" [] (index-page))
+  (GET "/ses" {params :params
+               session :session} (testsession params session))
+  (route/resources "/")
+  (route/not-found "Page not found"))
+
+;(def app
+;  (-> #'main-routes
+;      handler/site))
+(def app (handler/site main-routes))
+

src/nextrain/pages.clj

+(ns nextrain.pages
+  (:use [hiccup.page :only (html5 include-css include-js)]
+        [hiccup.element :only (javascript-tag)]))
+
+(defn index-page []
+  (html5
+    [:head
+      [:title "NexTrain"]
+      [:meta {:name "viewport" :content "width=device-width, initial-scale=1"}]
+      (include-css "http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css")
+      (include-js "https://www.google.com/jsapi"
+                  "https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"
+                  "/js/location.js"
+                  "http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js")]
+    [:body
+      [:div {:data-rote "page"}
+        [:div#lng "longitude"]
+        [:div#lat "latitude"]]]))
+

test/nextrain/core_test.clj

+(ns nextrain.core-test
+  (:use clojure.test
+        nextrain.core))
+
+(deftest a-test
+  (testing "FIXME, I fail."
+    (is (= 0 1))))