on 492ae2f help sign in
180 lines 3.7 kB history raw
1### `++earn`
3Purl to tape
5Parses a [`++purl`]() `pul` to a [`++tape`]().
7Accepts
8-------
10`pul` is a `++purl`.
12Produces
13--------
15A `++tape`.
17Source
18------
20 ++ earn :: purl to tape
21 |^ |= pul=purl
22 ^- tape
23 :(weld (head p.pul) "/" (body q.pul) (tail r.pul))
24 ::
26Examples
27--------
29 ~zod/main=> (earn [| ~ [%| .127.0.0.1]] [~ ~] ~)
30 "http://127.0.0.1/"
31 ~zod/main=> (earn [| ~ `/com/google/www] [~ ~] ~)
32 "http://www.google.com/"
33 ~zod/main=> (earn [& ~ `/com/google/www] [~ ~] ~)
34 "https://www.google.com/"
35 ~zod/main=> (earn [& `200 `/com/google/www] [~ ~] ~)
36 "https://www.google.com:200/"
37 ~zod/main=> (earn [& `200 `/com/google/www] [~ /search] ~)
38 "https://www.google.com:200/search"
39 ~zod/main=> (earn [& ~ `/com/google/www] [`%html /search] ~)
40 "https://www.google.com/search"
41 ~zod/main=> (earn [& ~ `/com/google/www] [~ /search] [%q 'urbit'] ~)
42 "https://www.google.com/search?q=urbit"
43 ~zod/main=> (earn [& ~ `/com/google/www] [~ /search] [%q 'urbit escaping?'] ~)
44 "https://www.google.com/search?q=urbit%20escaping%3F"
46### `++body`
48Render URL path
50Renders URL path `pok` as a [`++tape`]().
52Accepts
53-------
55`pok` is a [`++pork`]().
57Produces
58--------
60A `++tape`.
62Source
63------
65 ++ body
66 |= pok=pork ^- tape
67 ?~ q.pok ~
68 |-
69 =+ seg=(trip i.q.pok)
70 ?~ t.q.pok
71 ?~(p.pok seg (welp seg '.' (trip u.p.pok)))
72 (welp seg '/' $(q.pok t.q.pok))
73 ::
75Examples
76--------
78 ~zod/main=> (body:earn ~ /foo/mol/lok)
79 "foo/mol/lok"
80 ~zod/main=> (body:earn `%htm /foo/mol/lok)
81 "foo/mol/lok.htm"
82 ~zod/main=> (body:earn `%htm /)
83 ""
85### `++head`
87Render URL beginning
89Renders a `++hart`, usually the beginning of a URL, as the [`++tape`]()
90of a traditional URL.
92Accepts
93-------
95`har` is a `++heart`.
97Produces
98--------
100A `++tape`.
102Source
103------
105 ++ head
106 |= har=hart
107 ^- tape
108 ;: weld
109 ?:(&(p.har !=([& /localhost] r.har)) "https://" "http://")
110 ::
111 ?- -.r.har
112 | (trip (rsh 3 1 (scot %if p.r.har)))
113 & =+ rit=(flop p.r.har)
114 |- ^- tape
115 ?~(rit ~ (weld (trip i.rit) ?~(t.rit "" `tape`['.' $(rit t.rit)])))
116 ==
117 ::
118 ?~(q.har ~ `tape`[':' (trip (rsh 3 2 (scot %ui u.q.har)))])
119 ==
120 ::
122Examples
123--------
125 ~zod/main=> (head:earn | ~ %| .127.0.0.1)
126 "http://127.0.0.1"
127 ~zod/main=> (head:earn & ~ %| .127.0.0.1)
128 "https://127.0.0.1"
129 ~zod/main=> (head:earn & [~ 8.080] %| .127.0.0.1)
130 "https://127.0.0.1:8080"
131 ~zod/main=> (head:earn & [~ 8.080] %& /com/google/www)
132 "https://www.google.com:8080"
134### `++tail`
136Render query string
138Renders a [`++quay`](), a query string in hoon, to the [`++tape`]() of a
139traditional query string.
141Accepts
142-------
144`kay` is a `++quay`.
146Produces
147--------
149A `++tape`.
151Source
152------
154 ++ tail
155 |= kay=quay
156 ^- tape
157 ?: =(~ kay) ~
158 :- '?'
159 |- ^- tape
160 ?~ kay ~
161 ;: weld
162 (urle (trip p.i.kay))
163 "="
164 (urle (trip q.i.kay))
165 ?~(t.kay ~ `tape`['&' $(kay t.kay)])
166 ==
167 --
168 ::
170Examples
171--------
173 ~zod/main=> (tail:earn ~)
174 ""
175 ~zod/main=> (tail:earn [%ask 'bid'] ~)
176 "?ask=bid"
177 ~zod/main=> (tail:earn [%ask 'bid'] [%make 'well'] ~)
178 "?ask=bid&make=well"