Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Moving to version 0.3.0

  • Loading branch information...
commit f625a264e87b17074de3726da4e12cbfecf9d3df 1 parent 8c498a6
@ohpauleez ohpauleez authored
View
19 project.clj
@@ -1,7 +1,14 @@
-(defproject com.cemerick/shoreleave-remote-ring "0.0.2"
- :description "A Ring- (and Compojure-) friendly server-side alternative to
-https://github.com/shoreleave/shoreleave-remote-noir"
- :url "http://github.com/cemerick/shoreleave-remote-ring"
+(defproject shoreleave/shoreleave-remote-ring "0.3.0"
+ :description "A smarter client-side with ClojureScript : Ring- (and Compojure-) server-side Remotes support"
+ :url "https://github.com/shoreleave/shoreleave-remote-ring"
:license {:name "Eclipse Public License - v 1.0"
- :url "http://www.eclipse.org/legal/epl-v10.html"}
- :dependencies [[org.clojure/clojure "1.4.0"]])
+ :url "http://www.eclipse.org/legal/epl-v10.html"
+ :distribution :repo
+ :comments "See the notice in README.mkd or details in LICENSE_epl.html"}
+ :dependencies [[org.clojure/clojure "1.4.0"]
+ [org.clojure/tools.reader "0.7.0"]]
+ :dev-dependencies [;[cdt "1.2.6.2-SNAPSHOT"]
+ ;[lein-cdt "1.0.0"] ; use lein cdt to attach
+ ;[lein-autodoc "0.9.0"]
+ [lein-marginalia "0.7.1"]])
+
View
5 src/cemerick/shoreleave/rpc.clj
@@ -3,6 +3,11 @@ Mostly copied from https://github.com/shoreleave/shoreleave-remote-noir;
changed to eliminate the noir-isms..."}
cemerick.shoreleave.rpc)
+;; ATTENTION
+;; ===========
+;; This is here for backwards compatibility only, please use `shoreleave.middleware.rpc`
+
+
(def default-remote-uri "/_fetch")
(def remotes (atom {}))
View
14 src/shoreleave/middleware/rpc.clj
@@ -4,7 +4,12 @@
shoreleave.middleware.rpc
(:require [shoreleave.server-helpers :refer [safe-read]]))
+;; By default, remotes will hit `/_shoreleave` as their endpoint,
+;; but this can be overriden in the middleware hookup itself.
+;; For example: `(shoreleave.middleware.rpc/wrap-rpc "/_a_different_endpoint")`
(def default-remote-uri "/_shoreleave")
+
+;; The remotes get collected in a hashmap: `{remote-name-kw remote-fn, ...}`
(def remotes (atom {}))
(defn add-remote [key func]
@@ -26,7 +31,13 @@ metadata to the function name, e.g.:
~name)
(var ~name)))
-(defn remote-ns [namesp-sym & opts]
+(defn remote-ns
+ "Exposes an entire namespace as a remote API
+ and optionally aliases for use on the client side.
+
+ For example: `(remote-ns 'baseline.controllers.api :as \"api\")`
+ will allow you to call your client side API calls to look like `api/some-fn-there`"
+ [namesp-sym & opts]
(let [{:keys [as]} (apply hash-map opts)
namesp (try
(require namesp-sym)
@@ -54,6 +65,7 @@ metadata to the function name, e.g.:
(call-remote (keyword remote) (safe-read params)))
(defn wrap-rpc
+ "Top-level Ring middleware to enable Shoreleave RPC calls"
([app] (wrap-rpc app default-remote-uri))
([app remote-uri]
(fn [{:keys [request-method uri] :as request}]
View
25 src/shoreleave/server_helpers.clj
@@ -1,7 +1,20 @@
-(ns shoreleave.server-helpers)
+(ns shoreleave.server-helpers
+ "Simple functions to smooth over server idioms"
+ (:require [clojure.tools.reader.edn :as edn]))
+
+;; This causes precious-file.txt to be created if it doesn't
+;; exist, or if it does exist, its contents will be erased (given
+;; appropriate JVM sandboxing permissions, and underlying OS file
+;; permissions).
+;`(old-safe-read "#java.io.FileWriter[\"precious-file.txt\"]")`
+
+; (defn old-safe-read [s]
+; (binding [*read-eval* false]
+; (read-string s)))
+
+(defn safe-read
+ "This is a data-only // edn-only read.
+ It takes a string of data (s) and returns Clojure/EDN data"
+ [s]
+ (edn/read-string s))
-(defn safe-read [s]
- ;; can we please have a civilization!?
- (binding [*read-eval* false]
- (read-string s)))
-
Please sign in to comment.
Something went wrong with that request. Please try again.