Current section

26 Versions

Jump to

Compare versions

5 files changed
+10 additions
-56 deletions
  @@ -53,7 +53,8 @@ export default class Renderer {
53 53 );
54 54
55 55 case "expression":
56 - return $.stringifyForInterpolation(dom.data[1].data[0]);
56 + // HTML escaping is done by Snabbdom
57 + return $.toText(dom.data[1].data[0]);
57 58
58 59 case "page":
59 60 return Renderer.renderDom(
  @@ -102,39 +103,12 @@ export default class Renderer {
102 103 return htmlVnode;
103 104 }
104 105
105 - // Based on stringify_for_interpolation/1
106 - static stringifyForInterpolation(value) {
107 - let text;
108 -
109 - if (Type.isAtom(value) || Type.isBinary(value) || Type.isNumber(value)) {
110 - text = $.toText(value);
111 - } else {
112 - let opts;
113 -
114 - if (Type.isMap(value)) {
115 - opts = Type.keywordList([
116 - [
117 - Type.atom("custom_options"),
118 - Type.keywordList([[Type.atom("sort_maps"), Type.boolean(true)]]),
119 - ],
120 - ]);
121 - } else {
122 - opts = Type.list();
123 - }
124 -
125 - text = Interpreter.inspect(value, opts);
126 - }
127 -
128 - return text;
129 - }
130 -
131 106 static toBitstring(term) {
132 107 return Type.isBitstring(term) ? term : Type.bitstring($.toText(term));
133 108 }
134 109
135 110 // Similar to Kernel.to_string/1
136 111 // (it is supposed to be a fast alternative to Kernel.to_string/1 for the client-side renderer only)
137 - // TODO: consider implementing consistency tests
138 112 // Deps: [String.Chars.to_string/1]
139 113 static toText(term) {
140 114 // Cases ordered by expected frequency (most common first)
  @@ -142,29 +116,18 @@ export default class Renderer {
142 116 case "atom":
143 117 return term.value === "nil" ? "" : term.value;
144 118
145 - // Some structs (which are maps) may have their own implementation of String.Chars protocol
146 - case "map":
147 - return Bitstring.toText(Elixir_String_Chars["to_string/1"](term));
148 -
149 119 case "bitstring":
150 - if (!Type.isBinary(term)) {
151 - Interpreter.raiseProtocolUndefinedError("String.Chars", term);
120 + if (Type.isBinary(term)) {
121 + return Bitstring.toText(term);
152 122 }
153 -
154 - return Bitstring.toText(term);
155 -
156 - // String.Chars protocol has special behaviour for lists, e.g. to_string([97, 98]) -> "ab"
157 - case "list":
158 - return Bitstring.toText(Elixir_String_Chars["to_string/1"](term));
123 + break;
159 124
160 125 case "integer":
161 - return term.value.toString();
162 -
163 126 case "float":
164 127 return term.value.toString();
165 128 }
166 129
167 - Interpreter.raiseProtocolUndefinedError("String.Chars", term);
130 + return Bitstring.toText(Elixir_String_Chars["to_string/1"](term));
168 131 }
169 132
170 133 static valueDomToBitstring(valueDom) {
  @@ -7,7 +7,7 @@
7 7 {<<"Sponsor">>,<<"https://github.com/sponsors/bartblast">>},
8 8 {<<"Website">>,<<"https://hologram.page">>}]}.
9 9 {<<"name">>,<<"hologram">>}.
10 - {<<"version">>,<<"0.6.3">>}.
10 + {<<"version">>,<<"0.6.4">>}.
11 11 {<<"description">>,
12 12 <<"Full stack isomorphic Elixir web framework that can be used on top of Phoenix.">>}.
13 13 {<<"elixir">>,<<"~> 1.0">>}.
  @@ -228,6 +228,7 @@ defmodule Hologram.Compiler do
228 228 "--minify",
229 229 "--outfile=#{output_bundle_path}",
230 230 "--sourcemap",
231 + "--sources-content=true",
231 232 "--target=es2021"
232 233 ]
  @@ -3,7 +3,6 @@ defmodule Hologram.Template.Renderer do
3 3
4 4 alias Hologram.Assets.ManifestCache, as: AssetManifestCache
5 5 alias Hologram.Assets.PageDigestRegistry
6 - alias Hologram.Commons.KernelUtils
7 6 alias Hologram.Commons.StringUtils
8 7 alias Hologram.Commons.Types, as: T
9 8 alias Hologram.Compiler.Encoder
  @@ -198,18 +197,9 @@ defmodule Hologram.Template.Renderer do
198 197 "&lt;script&gt;"
199 198 """
200 199 @spec stringify_for_interpolation(any) :: String.t()
201 - def stringify_for_interpolation(value)
202 -
203 - def stringify_for_interpolation(value)
204 - when is_atom(value) or is_binary(value) or is_number(value) do
205 - value
206 - |> to_string()
207 - |> HtmlEntities.encode()
208 - end
209 -
210 200 def stringify_for_interpolation(value) do
211 201 value
212 - |> KernelUtils.inspect()
202 + |> to_string()
213 203 |> HtmlEntities.encode()
214 204 end
  @@ -2,7 +2,7 @@
2 2 defmodule Hologram.MixProject do
3 3 use Mix.Project
4 4
5 - @version "0.6.3"
5 + @version "0.6.4"
6 6
7 7 # Copied from Hologram.Commons.SystemUtils
8 8 @windows_exec_suffixes [".bat", ".cmd", ".exe"]