refactoring

This commit is contained in:
Christian Mueller
2014-02-01 11:38:11 +01:00
parent 0764aaaed1
commit f8a2c5f03d
3 changed files with 10 additions and 12 deletions
+4 -6
View File
@@ -5,7 +5,7 @@
[notehub.settings] [notehub.settings]
[ring.util.codec :only [url-encode]] [ring.util.codec :only [url-encode]]
[clojure.string :rename {replace sreplace} [clojure.string :rename {replace sreplace}
:only [replace blank? lower-case split-lines split]]) :only [replace blank? trim lower-case split-lines split]])
(:require (:require
[ring.util.codec] [ring.util.codec]
[hiccup.util :as util] [hiccup.util :as util]
@@ -84,12 +84,10 @@
(let [[year month day] (map str (get-date)) (let [[year month day] (map str (get-date))
password (opts :password) password (opts :password)
params (opts :params {}) params (opts :params {})
untrimmed-line (filter #(or (= \- %) (Character/isLetterOrDigit %)) raw-title (filter #(or (= \- %) (Character/isLetterOrDigit %))
(-> note split-lines first (sreplace " " "-") lower-case)) (-> note derive-title trim (sreplace " " "-") lower-case))
trim (fn [s] (apply str (drop-while #(= \- %) s)))
title-uncut (-> untrimmed-line trim reverse trim reverse)
max-length (get-setting :max-title-length #(Integer/parseInt %) 80) max-length (get-setting :max-title-length #(Integer/parseInt %) 80)
proposed-title (apply str (take max-length title-uncut)) proposed-title (apply str (take max-length raw-title))
date [year month day] date [year month day]
title (first (drop-while #(storage/note-exists? (build-key date %)) title (first (drop-while #(storage/note-exists? (build-key date %))
(cons proposed-title (cons proposed-title
+1 -2
View File
@@ -1,8 +1,7 @@
(ns notehub.handler (ns notehub.handler
(:use compojure.core (:use compojure.core
[notehub.settings] [notehub.settings]
[clojure.string :rename {replace sreplace} [clojure.string :rename {replace sreplace} :only [replace]]
:only [escape split replace blank? split-lines lower-case]]
[clojure.core.incubator :only [-?>]] [clojure.core.incubator :only [-?>]]
[hiccup.form] [hiccup.form]
[hiccup.core] [hiccup.core]
+5 -4
View File
@@ -1,6 +1,7 @@
(ns notehub.settings (ns notehub.settings
(:refer-clojure :exclude [replace reverse]) (:use [clojure.string
(:use [clojure.string])) :rename {replace sreplace}
:only [blank? trim split split-lines replace upper-case]]))
; Loads and parses any file with each line consisting a key and ; Loads and parses any file with each line consisting a key and
; a value separated by a "=", and returns a corresponding key-value map. ; a value separated by a "=", and returns a corresponding key-value map.
@@ -37,8 +38,8 @@
; set) shell variables without commiting their content to CVS ; set) shell variables without commiting their content to CVS
value (if value value value (if value value
(System/getenv (System/getenv
(upper-case (upper-case
(replace (name key) #"-" ""))))] (sreplace (name key) #"-" ""))))]
(if value (if value
(if (fn? converter) (converter value) value) (if (fn? converter) (converter value) value)
default))) default)))