Skip to content

More specific exception #155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/net/cgrand/enlive_html.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

(ns net.cgrand.enlive-html
"enlive-html is a selector-based transformation and extraction engine."
(:import java.util.MissingResourceException)
(:refer-clojure :exclude [flatmap])
(:require [net.cgrand.tagsoup :as tagsoup])
(:require [net.cgrand.xml :as xml])
Expand Down Expand Up @@ -86,7 +87,9 @@

(defmethod get-resource String
[path loader]
(-> (clojure.lang.RT/baseLoader) (.getResourceAsStream path) loader))
(if-let [resource-stream (-> (clojure.lang.RT/baseLoader) (.getResourceAsStream path))]
(loader resource-stream)
(throw (java.util.MissingResourceException. "HTML Resource not found (Hint: it might be missing from CLASSPATH)" "java.io.InputStream" path))))

(defmethod register-resource! String [path]
(register-resource! (.getResource (clojure.lang.RT/baseLoader) path)))
Expand All @@ -106,7 +109,7 @@
[stream loader]
(loader stream))

(defmethod register-resource! java.net.URL
(defmethod register-resource! java.net.URL
[^java.net.URL url]
(alter-meta! *ns* update-in [:net.cgrand.reload/deps] (fnil conj #{}) url))

Expand Down Expand Up @@ -142,7 +145,7 @@
([t a b c d e] (-> t (conj! a) (conj! b) (conj! c) (conj! d) (conj! e)))
([t a b c d e f] (-> t (conj! a) (conj! b) (conj! c) (conj! d) (conj! e) (conj! f)))
([t a b c d e f g] (-> t (conj! a) (conj! b) (conj! c) (conj! d) (conj! e) (conj! f) (conj! g)))
([t a b c d e f g & more]
([t a b c d e f g & more]
(reduce conj! (-> t (conj! a) (conj! b) (conj! c) (conj! d) (conj! e) (conj! f) (conj! g))
more)))

Expand Down Expand Up @@ -684,12 +687,12 @@
:else node)))))

(defn replace-words
"Takes a map of words to replacement strings and replaces
"Takes a map of words to replacement strings and replaces
all occurences. Does not recurse, you have to pair it with an appropriate
selector."
[words-to-replacements]
[words-to-replacements]
(replace-vars
(java.util.regex.Pattern/compile (str "\\b(" (str/join "|" (map #(java.util.regex.Pattern/quote %) (keys words-to-replacements))) ")\\b"))
(java.util.regex.Pattern/compile (str "\\b(" (str/join "|" (map #(java.util.regex.Pattern/quote %) (keys words-to-replacements))) ")\\b"))
words-to-replacements
identity))

Expand Down