Permalink
Browse files

More work on Cling

  • Loading branch information...
1 parent 6b251e3 commit 93959d0f0572aaddbe8f91ada3d212f54a509630 @mmcgrana committed Jan 25, 2009
View
@@ -1,7 +1,33 @@
good textile + syntax highlighting
- @@clj (+ 1 2) @@
- what about @ @ and <pre><code>
- internal linking (wiki syntax?)
+ Inline code: @(+ 1 2)@ or @@(+ 1 2)@@ or @@:clj (+ 1 2)@@ or
+ <code>(+ 1 2)</code> or <code:clj>(+ 1 2)</code>
+ Block code:
+ @@
+ (def plus [x y]
+ (+ 1 2))
+ @@
+ or
+ @@:clj
+ (def plus [x y]
+ (+ 1 2))
+ @@
+ or
+ <code>
+ (def plus [x y]
+ (+ 1 2))
+ </code>
+ or
+ <code:clj>
+ (def plus [x y]
+ (+ 1 2))
+ </code>
+
+ <pre><code> - allowing would make us a nice superset of textile
+ How are you going to put @@ on the wiki!!! use diff. syntax for each??
+
+ /pages/foo-bar:"Foo Bar" for external links,
+ [[Foo Bar]], for internal links to allow tracking??
+ note that we should disallow overlapping permalinks foo-2 etc.
diffs
@@ -11,6 +37,7 @@ search - in layout, on top
pagination integration
Batched lucene
pagination integration
+ or not?
users
@@ -34,7 +34,9 @@
(stash/find-all models/+page-version+ {:order [:updated_at :asc] :limit 10}))))
(defn search-pages [req]
- (respond (views/search-pages (models/search-pages (params req :query)))))
+ (let [query (params req :query)
+ pager (models/search-pages query)]
+ (respond (views/search-pages query pager))))
(defn new-page [req]
(respond (views/new-page (stash/init models/+page+))))
@@ -4,7 +4,7 @@
(defmigration create-pages 1
(create-table :pages
- [[:id :uuid {:pk true :auto true}]
+ [[:id :uuid {:pk true}]
[:title :string]
[:body :string]
[:created_at :datetime]
@@ -10,7 +10,7 @@
[(s 'index-pages) :index-pages :get "/pages" ]
[(s 'index-pages-versions) :index-pages-versions :get "/pages/versions" ]
[(s 'index-pages-versions-atom) :index-pages-versions-atom :get "/pages/versions.atom" ]
- [(s 'search-pages) :search-pages :get "/pages/search/:query" ]
+ [(s 'search-pages) :search-pages :get "/pages/search" ]
[(s 'new-page) :new-page :get "/pages/new" ]
[(s 'show-page) :show-page :get "/pages/:permalink" ]
[(s 'show-page-versions) :show-page-versions :get "/pages/:permalink/versions" ]
@@ -1,10 +1,17 @@
(ns cling.view-helpers
(:use
- (clojure.contrib prxml))
+ (clojure.contrib prxml shell-out))
(:import
(org.eclipse.mylyn.wikitext.core.parser MarkupParser)
(org.eclipse.mylyn.wikitext.textile.core TextileLanguage)))
+(defn highlight
+ [lexer source]
+ (sh "pygmentize"
+ "-l" lexer
+ "-f" "html"
+ :in source))
+
(defn textilize [markup]
(let [parser (MarkupParser. (TextileLanguage.))
html (.parseToHtml parser markup)
View
@@ -28,7 +28,7 @@
(form {:to (path-info :search-pages {:query ""})}
(html
[:p "Search:"]
- (text-field-tag "query")))]
+ (text-field-tag "query" (get assigns# :query))))]
[:div#content
~@body]]]])))
@@ -103,8 +103,14 @@
(textilize (:body page))]]])])
(defn search-pages
- [pager]
- (h (pr-str pager)))
+ [query pager]
+ (layout {:query query}
+ (if (= 0 (total-entries pager))
+ (html [:h1 "No Results for " (quote-title query)])
+ (html [:h1 "Results for " (quote-title query)]
+ [:ul
+ (for-html [page (entries pager)]
+ [:li (link-to (str (h (:title page))) (path :show-page page))])]))))
(defn new-page
[page]
View
@@ -0,0 +1,84 @@
+<html>
+ <head>
+ <style type="text/css">
+html{color:#000;background:#FFF;}body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td{margin:0;padding:0;}table{border-collapse:collapse;border-spacing:0;}fieldset,img{border:0;}address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal;}li{list-style:none;}caption,th{text-align:left;}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;}q:before,q:after{content:'';}abbr,acronym{border:0;font-variant:normal;}sup{vertical-align:text-top;}sub{vertical-align:text-bottom;}input,textarea,select{font-family:inherit;font-size:inherit;font-weight:inherit;}input,textarea,select{*font-size:100%;}legend{color:#000;}del,ins{text-decoration:none;}
+
+ .hll { background-color: #ffffcc }
+ .c { color: #408080; font-style: italic } /* Comment */
+ .err { border: 1px solid #FF0000 } /* Error */
+ .k { color: #008000; font-weight: bold } /* Keyword */
+ .o { color: #666666 } /* Operator */
+ .cm { color: #408080; font-style: italic } /* Comment.Multiline */
+ .cp { color: #BC7A00 } /* Comment.Preproc */
+ .c1 { color: #408080; font-style: italic } /* Comment.Single */
+ .cs { color: #408080; font-style: italic } /* Comment.Special */
+ .gd { color: #A00000 } /* Generic.Deleted */
+ .ge { font-style: italic } /* Generic.Emph */
+ .gr { color: #FF0000 } /* Generic.Error */
+ .gh { color: #000080; font-weight: bold } /* Generic.Heading */
+ .gi { color: #00A000 } /* Generic.Inserted */
+ .go { color: #808080 } /* Generic.Output */
+ .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
+ .gs { font-weight: bold } /* Generic.Strong */
+ .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
+ .gt { color: #0040D0 } /* Generic.Traceback */
+ .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
+ .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
+ .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
+ .kp { color: #008000 } /* Keyword.Pseudo */
+ .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
+ .kt { color: #B00040 } /* Keyword.Type */
+ .m { color: #666666 } /* Literal.Number */
+ .s { color: #BA2121 } /* Literal.String */
+ .na { color: #7D9029 } /* Name.Attribute */
+ .nb { color: #008000 } /* Name.Builtin */
+ .nc { color: #0000FF; font-weight: bold } /* Name.Class */
+ .no { color: #880000 } /* Name.Constant */
+ .nd { color: #AA22FF } /* Name.Decorator */
+ .ni { color: #999999; font-weight: bold } /* Name.Entity */
+ .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
+ .nf { color: #0000FF } /* Name.Function */
+ .nl { color: #A0A000 } /* Name.Label */
+ .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
+ .nt { color: #008000; font-weight: bold } /* Name.Tag */
+ .nv { color: #19177C } /* Name.Variable */
+ .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
+ .w { color: #bbbbbb } /* Text.Whitespace */
+ .mf { color: #666666 } /* Literal.Number.Float */
+ .mh { color: #666666 } /* Literal.Number.Hex */
+ .mi { color: #666666 } /* Literal.Number.Integer */
+ .mo { color: #666666 } /* Literal.Number.Oct */
+ .sb { color: #BA2121 } /* Literal.String.Backtick */
+ .sc { color: #BA2121 } /* Literal.String.Char */
+ .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */
+ .s2 { color: #BA2121 } /* Literal.String.Double */
+ .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
+ .sh { color: #BA2121 } /* Literal.String.Heredoc */
+ .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
+ .sx { color: #008000 } /* Literal.String.Other */
+ .sr { color: #BB6688 } /* Literal.String.Regex */
+ .s1 { color: #BA2121 } /* Literal.String.Single */
+ .ss { color: #19177C } /* Literal.String.Symbol */
+ .bp { color: #008000 } /* Name.Builtin.Pseudo */
+ .vc { color: #19177C } /* Name.Variable.Class */
+ .vg { color: #19177C } /* Name.Variable.Global */
+ .vi { color: #19177C } /* Name.Variable.Instance */
+ .il { color: #666666 } /* Literal.Number.Integer.Long */
+
+ code {
+ background: lightgrey;
+ }
+
+ div.codeblock {
+ background: lightgrey;
+ width: 500px;
+ }
+
+
+ </style>
+ </head>
+ <body>
+ <p>Some text here</p><p>Some text <code><span class="p">(</span><span class="nb">+ </span><span class="mi">1</span> <span class="mi">2</span><span class="p">)</span></code> with code here</p><pre><code><div class="codeblock"><span class="p">(</span><span class="k">def </span><span class="nv">foo</span> <span class="p">[</span><span class="nv">bar</span><span class="p">]</span>
+ <span class="p">(</span><span class="nb">+ </span><span class="nv">bar</span> <span class="mi">2</span><span class="p">)</span></code></pre></div>
+ </body>
+</html>
View
@@ -0,0 +1,22 @@
+Copyright (c) 2009 Mark McGranaghan
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
View
@@ -1 +1,5 @@
-A caching abstraction for Clojure.
+A caching abstraction for Clojure.
+
+---
+
+Copyright (c) 2009 Mark McGranaghan and released under an MIT license.
View
@@ -0,0 +1,14 @@
+what if we want binary vals and object vals in the same file cache?
+ file-bytes
+ file-string
+ file-object
+ header in data file
+ ok, but then non-transparent files
+ option in init restricting to one
+
+other stores
+ file
+ in-process memcache
+ remote memcache
+
+tests
View
@@ -0,0 +1,14 @@
+<project name="clj-cache" default="jar">
+ <property name="jarfile" location="clj-cache.jar"/>
+
+ <target name="clean">
+ <delete file="${jarfile}"/>
+ </target>
+
+ <target name="jar">
+ <jar jarfile="${jarfile}">
+ <path location="LICENSE"/>
+ <fileset dir="./src" includes="clj_cache/**/*.clj"/>
+ </jar>
+ </target>
+</project>
@@ -1,72 +1,34 @@
(ns clj-cache.core)
-(defn marshal
- "Returns marshaled bytes for the Clojure object."
- [obj]
- (.getBytes (pr-str obj)))
-
-(defn unmarshal
- "Returns a Clojure object for the marshaled bytes."
- [bytes]
- (read-string (String. bytes)))
-
-(defmacro log
+(defn- log
[store action key]
- `(if-let [logger (:logger store)]
- (if ((:test logger) :info)
- ((:log logger) (format (str "cache " action ": " key))))))
-
-(defn write*
- [store key data]
- (log store "write" key)
- ((:write store) key data))
-
-(defn read*
- [store key]
- (if-let [data ((:read store) key)]
- (do
- )
- (do
- (log store "miss"))
-
-(defn delete*
- [store key]
- ((:delete store) key))
-
-(defn flush*
- [store key]
- ((:flush store) key))
-
-(def ttl->time []
- (if ttl (+ (System/currentTimeMillis) (* ttl 1000))))
-
-(defn stale? [time]
- (and time (> (System/currentTimeMillis) time)))
+ (if-let [logger (:logger store)]
+ (if ((:test logger) :info)
+ ((:log logger) (str "cache " action ": " key)))))
(defn cache-set
[store key val & [ttl]]
- (let [data (marshal [(ttl->time ttl) val])]
- (write* store key data)
- val))
+ (log store "set" key)
+ ((:set store) key data))
(defn cache-get
[store key]
- (if-let [data (read* store key)]
- (let [[time val] (unmarshal data)]
- (if (not (stale? time))
- val
- (cache-expire store key)))))
+ (let [data ((:get store) key)]
+ (log store (if data "get (hit)" "get (miss)") key)
+ data))
(defn cache-delete
[store key]
- (delete* store key))
+ (log store "delete" key)
+ ((:delete store) key))
(defn cache-flush
[store key]
- (flush* store key))
+ (log store "flush" key)
+ ((:flush store) key))
(defn cache-fetch [store key ttl val-fn]
(let [data (cache-get store key)]
(if (nil? data)
(cache-set store key ttl (val-fn))
- data))
+ data)))
@@ -1,35 +0,0 @@
-(ns clj-cache.memory
- (:use clojure.contrib.str-utils file-utils)
- (:import org.apache.commons.io.IOUtils
- (java.io FileInputStream FileOutputStream)))
-
-(defn- cache-file [dir key]
- (apply file-utils/file dir (re-split #"/" key)))
-
-(defn- maybe-cache-file [dir key]
- (let [cfile (cache-file dir key)]
- (if (.exists cfile)
- cfile)))
-
-(defn- cache-parent-and-file [dir key]
- (let [file (cache-file dir key)]
- [(.getParentFile file) file]))
-
-(defn init [dir & [logger]]
- {:type :file
- :logger logger
- :marshal true
- :dir dir
- :read (fn [key]
- (if-let [cfile (maybe-cache-file dir key)]
- (with-open [cistream (FileInputSream. cfile)]
- (IOUtils/toByteArray cistream))))
- :write (fn [key data]
- (let [[parent file] (cache-parent-and-file dir key)]
- (mkdir-p parent)
- (with-open [fistream (FileInputStream. file)]
- (IOUtils/copy data file))))
- :delete (fn [key]
- (if-let [cfile (maybe-cache-file dir key)]
- (file-utils/rm-f cfile)))
- :flush (fn [] (file-utils/rm-rf dir))})
Oops, something went wrong.

0 comments on commit 93959d0

Please sign in to comment.