ruby-ejs 1.0.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ejs.rb +21 -9
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6f2553149b74aaab5eccde973398291061768402d5dea28fb17913aa6343f1e
|
4
|
+
data.tar.gz: 6cd17fe9a3ed414bbfe7a762d5deb18067b295ffb744663a20e5ee598e97146c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 525cecf3021650777d0ccf269cb41010a6c1a3a433337655c8651f0eab786450c41e9fe7e2110daf58eb7784a1203510e948ff712252c19448c0ede5a066d052
|
7
|
+
data.tar.gz: 0bf8751b796b579f5125bb49a917367d2ed94e66ff325c521fc45e1778ef0048ca7b16e6e96be5f76501311045e0bcfe32e667ed98055d0ab409c2eae67d123d
|
data/lib/ejs.rb
CHANGED
@@ -42,8 +42,10 @@ module EJS
|
|
42
42
|
"import {escape} from 'ejs';\n"
|
43
43
|
end
|
44
44
|
|
45
|
+
fs = function_source(source, options)
|
46
|
+
output << fs[1]
|
45
47
|
output << "export default function (locals) {\n"
|
46
|
-
output <<
|
48
|
+
output << fs[0]
|
47
49
|
output << "}"
|
48
50
|
|
49
51
|
output
|
@@ -53,7 +55,7 @@ module EJS
|
|
53
55
|
options = default(options)
|
54
56
|
|
55
57
|
output = "function(locals, escape) {\n"
|
56
|
-
output << function_source(source, options)
|
58
|
+
output << function_source(source, options)[0]
|
57
59
|
output << "}"
|
58
60
|
output
|
59
61
|
end
|
@@ -222,12 +224,15 @@ module EJS
|
|
222
224
|
|
223
225
|
def function_source(source, options)
|
224
226
|
stack = []
|
227
|
+
imports = ""
|
225
228
|
output = " var __output = [], __append = __output.push.bind(__output);\n"
|
226
|
-
output << " with (locals || {}) {\n"
|
229
|
+
output << " with (locals || {}) {\n" unless options[:strict]
|
227
230
|
|
228
231
|
digest(source, options) do |segment, type, modifier|
|
229
232
|
if type == :js
|
230
|
-
if segment.match(/\A\s*\}/m)
|
233
|
+
if segment.match(/\A\s*\}.*\{\s*\Z/m)
|
234
|
+
output << " " << segment << "\n"
|
235
|
+
elsif segment.match(/\A\s*\}/m)
|
231
236
|
case stack.pop
|
232
237
|
when :escape
|
233
238
|
output << "\n return __output.join(\"\");\n"
|
@@ -257,18 +262,25 @@ module EJS
|
|
257
262
|
when :unescape
|
258
263
|
output << " __append(" << segment << ");\n"
|
259
264
|
else
|
260
|
-
|
265
|
+
if segment =~ /\A\s*import/
|
266
|
+
imports << segment.strip
|
267
|
+
imports << ';' unless segment =~ /;\s*\Z/
|
268
|
+
imports << "\n"
|
269
|
+
else
|
270
|
+
output << " " << segment << "\n"
|
271
|
+
end
|
261
272
|
end
|
262
273
|
end
|
263
274
|
elsif segment.length > 0
|
264
|
-
output <<
|
275
|
+
output << ' __append("' + segment.gsub("\\"){"\\\\"}.gsub(/\n/, '\\n').gsub(/\r/, '\\r').gsub('"', '\\"') + "\");\n"
|
265
276
|
end
|
266
277
|
end
|
267
278
|
|
268
|
-
output << " }\n"
|
279
|
+
output << " }\n" unless options[:strict]
|
269
280
|
output << " return __output.join(\"\");\n"
|
270
|
-
|
271
|
-
|
281
|
+
imports << "\n"
|
282
|
+
|
283
|
+
[output, imports]
|
272
284
|
end
|
273
285
|
|
274
286
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-ejs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Bracy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -111,8 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
111
|
- !ruby/object:Gem::Version
|
112
112
|
version: '0'
|
113
113
|
requirements: []
|
114
|
-
|
115
|
-
rubygems_version: 2.7.4
|
114
|
+
rubygems_version: 3.0.3
|
116
115
|
signing_key:
|
117
116
|
specification_version: 4
|
118
117
|
summary: EJS (Embedded JavaScript) template compiler
|