Permalink
Browse files

Gather path utility functions in own ns

  • Loading branch information...
1 parent d54e134 commit b734dfed452195ef67f7ec270a443edfbcf9b9bc @magnars committed Jan 13, 2014
Showing with 32 additions and 23 deletions.
  1. +1 −9 src/optimus/assets/creation.clj
  2. +1 −14 src/optimus/assets/load_css.clj
  3. +22 −0 src/optimus/paths.clj
  4. +8 −0 test/optimus/paths_test.clj
@@ -1,7 +1,7 @@
(ns optimus.assets.creation
(:require [clojure.java.io :as io]
[clojure.string :as str]
- [pathetic.core :as pathetic]
+ [optimus.paths :refer [just-the-filename filename-ext]]
[optimus.class-path :refer [file-paths-on-class-path]])
(:import [java.io FileNotFoundException]
[java.net URL]
@@ -61,11 +61,6 @@
(create-asset path (slurp resource)
:last-modified (last-modified resource))))
-(defn- filename-ext
- "Returns the file extension of a filename or filepath."
- [filename]
- (second (re-find #"\.([^./\\]+)$" filename)))
-
(defmulti load-asset (fn [_ path] (filename-ext path)))
(defmethod load-asset :default
@@ -80,9 +75,6 @@
(subs s (+ (count public-dir)
(.indexOf s (str public-dir "/")))))
-(defn- just-the-filename [path]
- (last (pathetic/split path)))
-
(defn- emacs-file-artefact? [#^String path]
(let [filename (just-the-filename path)]
(or (.startsWith filename ".#")
@@ -1,21 +1,8 @@
(ns optimus.assets.load-css
(:require [optimus.assets.creation :refer [create-asset existing-resource original-path last-modified]]
- [pathetic.core :as pathetic]
+ [optimus.paths :refer [just-the-path to-absolute-url]]
[clojure.string :as str]))
-(defn- just-the-path [url]
- (-> url
- pathetic/parse-path
- pathetic/up-dir
- pathetic/render-path
- pathetic/ensure-trailing-separator))
-
-(defn- to-absolute-url [container-url relative-url]
- (-> container-url
- (just-the-path)
- (pathetic/resolve relative-url)
- (pathetic/normalize)))
-
(def css-url-re #"(?:url\(['\"]?([^\)]+?)['\"]?\)|@import ['\"](.+?)['\"])")
(defn- data-url? [#^String url]
View
@@ -0,0 +1,22 @@
+(ns optimus.paths
+ (:require [pathetic.core :as pathetic]))
+
+(defn just-the-path [path]
+ (-> path
+ pathetic/parse-path
+ pathetic/up-dir
+ pathetic/render-path
+ pathetic/ensure-trailing-separator))
+
+(defn just-the-filename [path]
+ (last (pathetic/split path)))
+
+(defn to-absolute-url [container-url relative-url]
+ (-> container-url
+ (just-the-path)
+ (pathetic/resolve relative-url)
+ (pathetic/normalize)))
+
+(defn filename-ext [filename]
+ (second (re-find #"\.([^./\\]+)$" filename)))
+
@@ -0,0 +1,8 @@
+(ns optimus.paths-test
+ (:require [optimus.paths :refer :all]
+ [midje.sweet :refer :all]))
+
+(fact (just-the-path "/theme/styles/main.css") => "/theme/styles/")
+(fact (just-the-filename "/theme/styles/main.css") => "main.css")
+(fact (to-absolute-url "/theme/styles/main.css" "../images/bg.png") => "/theme/images/bg.png")
+(fact (filename-ext "/theme/styles/main.css") => "css")

0 comments on commit b734dfe

Please sign in to comment.