ruby-ejs 1.0.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ejs.rb +21 -9
  3. metadata +3 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 232f0b535162a8e22d9af9531aad70ec430854b1bfbbdf09748cac64169307c8
4
- data.tar.gz: 6e7a19b04327933e6c56961233cef0635b7c8d8def2d04a845a7b1697862ce07
3
+ metadata.gz: e6f2553149b74aaab5eccde973398291061768402d5dea28fb17913aa6343f1e
4
+ data.tar.gz: 6cd17fe9a3ed414bbfe7a762d5deb18067b295ffb744663a20e5ee598e97146c
5
5
  SHA512:
6
- metadata.gz: 29c23c1b84a8ce4383753b7f6ec562fad487c40f3111fb0180a5db51bb0b9a6910dd65fea44b646225042f2f7865758dfc08bdda8737d16f29507380568620e8
7
- data.tar.gz: 1758fe11dd541ea571a9c6a4a6e804dc06a698cebcebc589b13d42be2ab7dfe6f22d37fa57c47c76f1a0d1c98089a14936efefc548fccc7a5286d6cbf56ce630
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 << function_source(source, options)
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
- output << " " << segment << "\n"
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 << " __append(`" + segment.gsub("\\"){"\\\\"}.gsub(/\n/, '\\n').gsub(/\r/, '\\r') + "`);\n"
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
- output
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.1
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: 2018-07-11 00:00:00.000000000 Z
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
- rubyforge_project:
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