File tree Expand file tree Collapse file tree 2 files changed +20
-10
lines changed
apps/components_guide_web/lib/components_guide_web/templates/web_standards Expand file tree Collapse file tree 2 files changed +20
-10
lines changed Original file line number Diff line number Diff line change @@ -8,14 +8,6 @@ ComponentsGuideWeb.WebStandards.Live.URL
8
8
9
9
## JavaScript’s ` URL `
10
10
11
- ``` js
12
- const url = new URL (' https://example.org/songs?first=20&sortBy=releaseDate' );
13
- url .protocol ; // 'https:'
14
- url .hostname ; // 'example.org'
15
- url .origin ; // 'https://example.org'
16
- url .pathname ; // '/songs'
17
- ```
18
-
19
11
``` js
20
12
const root = new URL (' /' );
21
13
```
Original file line number Diff line number Diff line change @@ -111,19 +111,37 @@ defmodule ComponentsGuideWeb.WebStandards.Live.URL do
111
111
112
112
</form>
113
113
114
+ <section aria-labelledby=javascript-url-heading>
115
+ <h2 id=javascript-url-heading>JavaScript’s <code>URL</code></h2>
116
+
114
117
<pre class="language-js" phx-hook=PreCode><code>const url = new URL(
115
118
'<%= @state |> State.to_url() |> URI.to_string() %>'
116
119
);
117
120
url.protocol; // '<%= State.to_url(@state).scheme %>:'
118
121
url.host; // '<%= State.to_url(@state).host %>'
122
+ url.origin; // '<%= State.to_url(@state).scheme %>://<%= State.to_url(@state).host %>'
119
123
url.pathname; // '<%= State.to_url(@state).path %>'
120
124
121
125
url.search; // '?<%= State.to_url(@state).query %>'
122
126
const query = new URLSearchParams(url.search);
123
127
<%= for {key, value} <- State.get_query_vars(@state) do
124
- "query.get('#{key}'); // '#{value}'\n"
125
- end %>
128
+ "query.get('#{key}'); // '#{value}'"
129
+ end |> Enum.join("\n") %>
130
+ </code></pre>
131
+ </section>
132
+
133
+ <section aria-labelledby=swift-url-heading>
134
+ <h2 id=swift-url-heading>Swift’s <code>URL</code></h2>
135
+
136
+ <pre class="language-swift" phx-hook=PreCode><code>let url = URL(
137
+ string: "<%= @state |> State.to_url() |> URI.to_string() %>"
138
+ )!
139
+ url.scheme // Optional("<%= State.to_url(@state).scheme %>")
140
+ url.host // Optional("<%= State.to_url(@state).host %>")
141
+ url.path // "<%= State.to_url(@state).path %>"
142
+ url.query // Optional("<%= State.to_url(@state).query %>")
126
143
</code></pre>
144
+ </section>
127
145
"""
128
146
end
129
147
You can’t perform that action at this time.
0 commit comments