2014/1/11

misakiのプラグインを開発していて、nreplから接続したかったのでその方法。 下記のように修正。

mikio@gnudam:~/dev/misaki$ git diff HEAD^
diff --git a/.gitignore b/.gitignore
index fb7a616..777bdaa 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,6 +7,8 @@
 /.lein-failures
 /checkouts
 /.lein-deps-sum
+misaki/src/misaki/
+/.nrepl-port
 /blog
 /test/public
 /samples/*/public/201*
diff --git a/project.clj b/project.clj
index 82e93ff..8b0aa33 100644
--- a/project.clj
+++ b/project.clj
@@ -13,7 +13,9 @@
                  [cuma "0.0.4"]
                  [clj-gntp "0.0.1"]
                  ; cljs compiler
-                 [org.clojure/clojurescript "0.0-1586"]]
+                 [org.clojure/clojurescript "0.0-1586"]
+                 [org.clojure/tools.nrepl "0.2.3"]
+                 ]

   :plugins [[codox "0.6.4"]
             [lein-cloverage "1.0.2"]
diff --git a/samples/blog/_config.clj b/samples/blog/_config.clj
index e36a47f..0e74f47 100644
--- a/samples/blog/_config.clj
+++ b/samples/blog/_config.clj
@@ -17,6 +17,10 @@
  ;;   default value: 8080
  :port 8080

+ ;; embeded repl-server port
+ ;;   default value: 42042
+ :repl-port 42042
+
  ;; site language
  ;;   default value: "en"
  :lang "en"
diff --git a/src/misaki/config.clj b/src/misaki/config.clj
index 735874d..8865cf6 100644
--- a/src/misaki/config.clj
+++ b/src/misaki/config.clj
@@ -13,6 +13,7 @@
 ;; ## Default Value

 (def PORT     "Default dev server port." 8080)
+(def REPL-PORT "Default dev nrepl server port." 42042)
 (def LANGUAGE "Default language."        "en")
 (def COMPILER "Default compiler."        "default")
 (def POST_FILENAME_REGEXP
@@ -102,6 +103,7 @@
                         (path template-dir post-dir))
       :post-sort-type (:post-sort-type config :date-desc)
       :port           (:port config PORT)
+      :repl-port           (:repl-port config REPL-PORT)
       :lang           (:lang config LANGUAGE)
       :site           (:site config {})
       :index-name     (:index-name config "")
diff --git a/src/misaki/server.clj b/src/misaki/server.clj
index d0fee30..03a593b 100644
--- a/src/misaki/server.clj
+++ b/src/misaki/server.clj
@@ -13,7 +13,9 @@
     [watchtower.core      :refer :all]
     [compojure.core       :refer [routes]]
     [compojure.route      :refer [files]]
-    [ring.adapter.jetty   :refer [run-jetty]]))
+    [ring.adapter.jetty   :refer [run-jetty]]
+    [clojure.tools.nrepl.server :refer [start-server stop-server]]
+    ))

 ; =elapsing
 (defmacro elapsing
@@ -87,18 +89,21 @@
 (defn -main [& [dir :as args]]
   (binding [*base-dir* (normalize-path dir)]
     (with-config
-      ; compile all templates at first
-      (do-all-compile)
-
-      ; compile all only if '--compile' option is specified
-      (when-not (contains? (set args) "--compile")
-        (start-watcher (:template-dir *config*))
-        (println " * starting server: "
-                 (cyan (str "http://localhost:"
-                            (:port *config*)
-                            (:url-base *config*))))
-        (run-jetty
-          (routes (files (:url-base *config*)
-                         {:root (:public-dir *config*)}))
-          {:port (:port *config*)})))))
+      (let [repl-port (:repl-port *config*)
+            repl-server (start-server :port repl-port)]
+         ;; compile all templates at first
+         (do-all-compile)
+
+         ;; compile all only if '--compile' option is specified
+         (when-not (contains? (set args) "--compile")
+           (start-watcher (:template-dir *config*))
+           (println " * starting server: "
+                    (cyan (str "http://localhost:"
+                               (:port *config*)
+                               (:url-base *config*))))
+           (println " * starting nrepl server on port " (cyan repl-port))
+           (run-jetty
+            (routes (files (:url-base *config*)
+                           {:root (:public-dir *config*)}))
+            {:port (:port *config*)}))))))

下記で、修正したmisakiにローカルのjarが置き換わる。

$ cd ~/dev/misaki/
$ lein install

misaki本家が更新されたときは、

$ git co master
$ git fetch upsutream
$ git merge upstream/master
$ lein install

こんな感じで。

もし修正版のmisakiを使用したくなくなったら リポジトリを手動で削除すれば良い(正式なやりかたがあるかもしれんが)。

$ rm -rf ~/.m2/repository/misaki/misaki/0.2.6.2-beta
$ lein deps
blog comments powered by Disqus