-
Notifications
You must be signed in to change notification settings - Fork 70
added support for literal paths in requires #169
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -656,8 +656,8 @@ approach and supports only one essential way of importing modules: | |
[fs] | ||
[wisp.backend.javascript.writer :as writer] | ||
[wisp.sequence | ||
:refer [first rest] | ||
:rename {first car rest cdr}])) | ||
:refer [first rest] | ||
:rename {first car rest cdr}])) | ||
``` | ||
|
||
Let's go through the above example to get a complete picture regarding | ||
|
@@ -674,20 +674,23 @@ and is completely optional. | |
3. The `(:require ...)` form defines dependencies that will be | ||
imported at runtime, and the example above imports multiple modules: | ||
|
||
1. First it imports the `start-host!` function from the | ||
`interactivate.host` module. That will be loaded from the | ||
`../host` location, since because module paths are resolved | ||
relative to a name, but only if they share the same root. | ||
2. The second form imports `fs` module and makes it available under | ||
the same name. Note that in this case it could have been | ||
written without wrapping it in brackets. | ||
3. The third form imports `wisp.backend.javascript.writer` module | ||
from `wisp/backend/javascript/writer` and makes it available | ||
via the name `writer`. | ||
4. The last and most complex form imports `first` and `rest` | ||
functions from the `wisp.sequence` module, although it also | ||
renames them and there for makes available under different | ||
`car` and `cdr` names. | ||
1. First it imports the `start-host!` function from the | ||
`interactivate.host` module. That will be loaded from the | ||
`../host` location, since because module paths are resolved | ||
relative to a name, but only if they share the same root. | ||
2. The second form imports `fs` module and makes it available under | ||
the same name. Note that in this case it could have been | ||
written without wrapping it in brackets. | ||
3. The third form imports `wisp.backend.javascript.writer` module | ||
from `wisp/backend/javascript/writer` and makes it available | ||
via the name `writer`. | ||
4. The last and most complex form imports `first` and `rest` | ||
functions from the `wisp.sequence` module, although it also | ||
renames them and there for makes available under different | ||
`car` and `cdr` names. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed indent here. |
||
|
||
It's also possible to specify a string literal instead of a module name; | ||
this allows for providing custom require paths when you're having trouble with generated ones. | ||
|
||
While Clojure has many other kinds of reference forms they are | ||
not recognized by _wisp_ and will therefore be ignored. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -711,30 +711,32 @@ | |
|
||
(defn resolve | ||
[from to] | ||
(let [requirer (split (name from) \.) | ||
requirement (split (name to) \.) | ||
relative? (and (not (identical? (name from) | ||
(name to))) | ||
(identical? (first requirer) | ||
(first requirement)))] | ||
(if relative? | ||
(loop [from requirer | ||
to requirement] | ||
(if (identical? (first from) | ||
(first to)) | ||
(recur (rest from) (rest to)) | ||
(join \/ | ||
(concat [\.] | ||
(repeat (dec (count from)) "..") | ||
to)))) | ||
(join \/ requirement)))) | ||
(if (string? to) | ||
to | ||
(let [requirer (split (name from) \.) | ||
requirement (split (name to) \.) | ||
relative? (and (not (identical? (name from) | ||
(name to))) | ||
(identical? (first requirer) | ||
(first requirement)))] | ||
(if-not relative? | ||
(join \/ requirement) | ||
(loop [from requirer | ||
to requirement] | ||
(if (identical? (first from) | ||
(first to)) | ||
(recur (rest from) (rest to)) | ||
(join \/ | ||
(concat [\.] | ||
(repeat (dec (count from)) "..") | ||
to)))))))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indented |
||
|
||
(defn id->ns | ||
"Takes namespace identifier symbol and translates to new | ||
symbol without . special characters | ||
wisp.core -> wisp*core" | ||
[id] | ||
(symbol nil (join \* (split (name id) \.)))) | ||
(symbol nil (join \* (split (name id) #"[./]")))) | ||
|
||
|
||
(defn write-require | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
(ns wisp.test.ast | ||
(:require [wisp.test.util :refe [is thrown?]] | ||
(:require [wisp.test.util :refer [is thrown?]] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. …Apparently importing macros does nothing after all? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah it will import all macros regardless. Intention was to only import ones been referred, but that never made it. |
||
[wisp.src.reader :refer [read-from-string]] | ||
[wisp.src.sequence :refer [list]] | ||
[wisp.src.runtime :refer [str =]] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,8 +42,9 @@ | |
(do | ||
(.push *failed* '~form) | ||
(console.error (str "Fail: " ~msg "\n" | ||
"expected: " | ||
(pr-str '~form) "\n" | ||
"expected: " | ||
(pr-str '~expected) "\n" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This way makes it easier to compare long literals. |
||
" actual: " | ||
(pr-str (try ~actual (catch error (list 'throw (list 'Error (.-message error)))))))) | ||
false))))) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#168