Back
resource (clj)
(source)function
(resource n)
(resource n loader)
Returns the URL for a named resource. Use the context class loader
if no loader is specified.
Examples
clojure
(deftest t-line-column-numbers
(let [code "(ns reader-metadata-test
(:require [clojure.java.io
:refer (resource reader)]))
(let [a 5]
^:added-metadata
(defn add-5
[x]
(reduce + x (range a))))"
stream (clojure.lang.LineNumberingPushbackReader.
(java.io.StringReader. code))
top-levels (take-while identity (repeatedly #(read stream false nil)))
expected-metadata '{ns {:line 1, :column 1}
:require {:line 2, :column 3}
resource {:line 3, :column 21}
let {:line 5, :column 1}
defn {:line 6, :column 3 :added-metadata true}
reduce {:line 9, :column 5}
range {:line 9, :column 17}}
verified-forms (atom 0)]
(doseq [form top-levels]
(clojure.walk/postwalk
#(when (list? %)
(is (= (expected-metadata (first %))
(meta %)))
(is (->> (meta %)
vals
(filter number?)
(every? (partial instance? Integer))))
(swap! verified-forms inc))
form))
;; sanity check against e.g. reading returning ()
(is (= (count expected-metadata) @verified-forms))))
metabase/metabase
(ns metabase.api.slack
"/api/slack endpoints"
(:require
[clojure.java.io :as io]
[compojure.core :refer [PUT]]
[metabase.api.common :as api]
[metabase.api.common.validation :as validation]
[metabase.config :as config]
[metabase.integrations.slack :as slack]
[metabase.util.i18n :refer [tru]]
[metabase.util.malli.schema :as ms]))
(def ^:private slack-manifest
(delay (slurp (io/resource "slack-manifest.yaml"))))
quil/quil
(ns quil.snippets.rendering
(:require #?(:clj [quil.snippets.macro :refer [defsnippet]])
[quil.core :as q :include-macros true]
quil.snippets.all-snippets-internal
#?(:clj [clojure.java.io :as io]))
#?(:cljs
(:use-macros [quil.snippets.macro :only [defsnippet]])))
#?(:clj
(defsnippet load-shader
["load-shader" "loaded?" "reset-shader" "shader"]
{:renderer :p2d
:skip-image-diff? true
:setup (let [path (io/resource "SimpleShader.glsl")
shd (q/load-shader (.getPath path))]
(q/set-state! :shader shd))}
nextjournal/clerk
(ns nextjournal.clerk.config
(:require [clojure.edn :as edn]
[clojure.java.io :as io]
[clojure.string :as str]))
(def resource-manifest-from-props
(when-let [prop (System/getProperty "clerk.resource_manifest")]
(when-not (str/blank? prop)
(read-string prop))))
(def !asset-map
;; In mvn releases, the asset map is available in the artifact
(delay (or (some-> (io/resource "clerk-asset-map.edn") slurp edn/read-string)
(try ((requiring-resolve 'nextjournal.clerk.render.hashing/dynamic-asset-map))
(catch Exception e
(throw (ex-info "Error reading dynamic asset map"
(or (ex-data e)
{}) e)))))))
(defonce !resource->url
;; contains asset manifest in the form:
;; {"/js/viewer.js" "https://..."}
(atom (or resource-manifest-from-props
@!asset-map)))
#_(swap! !resource->url assoc "/css/viewer.css" "https://storage.googleapis.com/nextjournal-cas-eu/data/8VvAV62HzsvhcsXEkHP33uj4cV9UvdDz7DU9qLeVRCfEP9kWLFAzaMKL77trdx898DzcVyDVejdfxvxj5XB84UpWvQ")
#_(swap! !resource->url dissoc "/css/viewer.css")
#_(reset! !resource->url identity)
#_(reset! !resource->url default-resource-manifest)
#_(reset! !resource->url (-> (slurp lookup-url) edn/read-string))
clj-kondo/clj-kondo
(ns clj-kondo.impl.version
(:require
[clojure.java.io :as io]
[clojure.string :as str]))
(def version
(str/trim
(slurp (io/resource "CLJ_KONDO_VERSION"))))
djblue/portal
(ns ^:no-doc portal.resources
#?(:cljs (:require-macros portal.resources))
#?(:clj (:require [clojure.java.io :as io])))
#?(:clj
(defmacro inline [resource-name]
(try
(slurp (io/resource resource-name))
(catch Exception e
(println e)))))