ejs-patched 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +20 -0
- data/README.md +38 -0
- data/lib/ejs.rb +107 -0
- metadata +62 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 40bb3022a9e30bcc3169ae6ee99bc8f80da7e89a
|
4
|
+
data.tar.gz: 69b8b8eb4ac13eb69833329ae29fdb7a464dfa41
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '069fa4e67c8f231ba771c4e96b7329539771316834f29362d6301667a4a4daeb3c14733e10ddf35486b42f45612774c29bcfaedb08d538b64c12b670ddd4f317'
|
7
|
+
data.tar.gz: ab936a2407618a204716642cefc8ba5902bbc1d84ab133233cf79a3bdbfee8729a486277ced05d2441648fa6310d855cd0ef0203e8a3378654457ab93f141345
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Sam Stephenson
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
EJS (Embedded JavaScript) template compiler for Ruby
|
2
|
+
====================================================
|
3
|
+
|
4
|
+
EJS templates embed JavaScript code inside `<% ... %>` tags, much like
|
5
|
+
ERB. This library is a port of
|
6
|
+
[Underscore.js](http://documentcloud.github.com/underscore/)'s
|
7
|
+
[`_.template`
|
8
|
+
function](http://documentcloud.github.com/underscore/#template) to
|
9
|
+
Ruby, and strives to maintain the same syntax and semantics.
|
10
|
+
|
11
|
+
Pass an EJS template to `EJS.compile` to generate a JavaScript
|
12
|
+
function:
|
13
|
+
|
14
|
+
EJS.compile("Hello <%= name %>")
|
15
|
+
# => "function(obj){...}"
|
16
|
+
|
17
|
+
Invoke the function in a JavaScript environment to produce a string
|
18
|
+
value. You can pass an optional object specifying local variables for
|
19
|
+
template evaluation.
|
20
|
+
|
21
|
+
The EJS tag syntax is as follows:
|
22
|
+
|
23
|
+
* Unescaped buffering with `<%- code %>`
|
24
|
+
* Escapes html by default with `<%= code %>`
|
25
|
+
* Unbuffered code for conditionals etc `<% code %>`
|
26
|
+
|
27
|
+
If you have the [ExecJS](https://github.com/sstephenson/execjs/)
|
28
|
+
library and a suitable JavaScript runtime installed, you can pass a
|
29
|
+
template and an optional hash of local variables to `EJS.evaluate`:
|
30
|
+
|
31
|
+
EJS.evaluate("Hello <%= name %>", :name => "world")
|
32
|
+
# => "Hello world"
|
33
|
+
|
34
|
+
-----
|
35
|
+
|
36
|
+
© 2012 Sam Stephenson
|
37
|
+
|
38
|
+
Released under the MIT license
|
data/lib/ejs.rb
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
# EJS (Embedded JavaScript) template compiler for Ruby
|
2
|
+
# This is a port of Underscore.js' `_.template` function:
|
3
|
+
# http://documentcloud.github.com/underscore/
|
4
|
+
|
5
|
+
module EJS
|
6
|
+
JS_UNESCAPES = {
|
7
|
+
'\\' => '\\',
|
8
|
+
"'" => "'",
|
9
|
+
'r' => "\r",
|
10
|
+
'n' => "\n",
|
11
|
+
't' => "\t",
|
12
|
+
'u2028' => "\u2028",
|
13
|
+
'u2029' => "\u2029"
|
14
|
+
}
|
15
|
+
JS_ESCAPES = JS_UNESCAPES.invert
|
16
|
+
JS_ESCAPE_PATTERN = Regexp.union(JS_ESCAPES.keys)
|
17
|
+
JS_UNESCAPE_PATTERN = /\\(#{Regexp.union(JS_UNESCAPES.keys)})/
|
18
|
+
|
19
|
+
class << self
|
20
|
+
attr_accessor :escape_pattern
|
21
|
+
attr_accessor :evaluation_pattern
|
22
|
+
attr_accessor :interpolation_pattern
|
23
|
+
|
24
|
+
# Compiles an EJS template to a JavaScript function. The compiled
|
25
|
+
# function takes an optional argument, an object specifying local
|
26
|
+
# variables in the template. You can optionally pass the
|
27
|
+
# `:evaluation_pattern` and `:interpolation_pattern` options to
|
28
|
+
# `compile` if you want to specify a different tag syntax for the
|
29
|
+
# template.
|
30
|
+
#
|
31
|
+
# EJS.compile("Hello <%= name %>")
|
32
|
+
# # => "function(obj){...}"
|
33
|
+
#
|
34
|
+
def compile(source, options = {})
|
35
|
+
source = source.dup
|
36
|
+
|
37
|
+
js_escape!(source)
|
38
|
+
replace_escape_tags!(source, options)
|
39
|
+
replace_interpolation_tags!(source, options)
|
40
|
+
replace_evaluation_tags!(source, options)
|
41
|
+
"function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};" +
|
42
|
+
"with(obj||{}){__p.push('#{source}');}return __p.join('');}"
|
43
|
+
end
|
44
|
+
|
45
|
+
# Evaluates an EJS template with the given local variables and
|
46
|
+
# compiler options. You will need the ExecJS
|
47
|
+
# (https://github.com/sstephenson/execjs/) library and a
|
48
|
+
# JavaScript runtime available.
|
49
|
+
#
|
50
|
+
# EJS.evaluate("Hello <%= name %>", :name => "world")
|
51
|
+
# # => "Hello world"
|
52
|
+
#
|
53
|
+
def evaluate(template, locals = {}, options = {})
|
54
|
+
require "execjs"
|
55
|
+
context = ExecJS.compile("var evaluate = #{compile(template, options)}")
|
56
|
+
context.call("evaluate", locals)
|
57
|
+
end
|
58
|
+
|
59
|
+
protected
|
60
|
+
def js_escape!(source)
|
61
|
+
source.gsub!(JS_ESCAPE_PATTERN) { |match| '\\' + JS_ESCAPES[match] }
|
62
|
+
source
|
63
|
+
end
|
64
|
+
|
65
|
+
def js_unescape!(source)
|
66
|
+
source.gsub!(JS_UNESCAPE_PATTERN) { |match| JS_UNESCAPES[match[1..-1]] }
|
67
|
+
source
|
68
|
+
end
|
69
|
+
|
70
|
+
def replace_escape_tags!(source, options)
|
71
|
+
source.gsub!(options[:escape_pattern] || escape_pattern) do
|
72
|
+
"',#{coerce_to_string_function}(#{js_unescape!($1)})#{escape_function},'"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def replace_evaluation_tags!(source, options)
|
77
|
+
source.gsub!(options[:evaluation_pattern] || evaluation_pattern) do
|
78
|
+
"'); #{js_unescape!($1)}; __p.push('"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def replace_interpolation_tags!(source, options)
|
83
|
+
source.gsub!(options[:interpolation_pattern] || interpolation_pattern) do
|
84
|
+
"', #{js_unescape!($1)},'"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def coerce_to_string_function
|
89
|
+
"function(s) {" +
|
90
|
+
"return (s === null || typeof(s) === 'undefined') ? '' : ('' + s);" +
|
91
|
+
"}"
|
92
|
+
end
|
93
|
+
|
94
|
+
def escape_function
|
95
|
+
".replace(/&/g, '&')" +
|
96
|
+
".replace(/</g, '<')" +
|
97
|
+
".replace(/>/g, '>')" +
|
98
|
+
".replace(/\"/g, '"')" +
|
99
|
+
".replace(/'/g, ''')" +
|
100
|
+
".replace(/\\//g,'/')"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
self.escape_pattern = /<%=([\s\S]+?)%>/
|
105
|
+
self.evaluation_pattern = /<%([\s\S]+?)%>/
|
106
|
+
self.interpolation_pattern = /<%-([\s\S]+?)%>/
|
107
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ejs-patched
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sam Stephenson
|
8
|
+
- Jimmie Elvenmark
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2018-01-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: execjs
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0.4'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0.4'
|
28
|
+
description: Compile and evaluate EJS (Embedded JavaScript) templates from Ruby.
|
29
|
+
email:
|
30
|
+
- sstephenson@gmail.com
|
31
|
+
- flugsio@gmail.com
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- LICENSE
|
37
|
+
- README.md
|
38
|
+
- lib/ejs.rb
|
39
|
+
homepage: https://github.com/flugsio/ruby-ejs-patched/
|
40
|
+
licenses: []
|
41
|
+
metadata: {}
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 2.6.14
|
59
|
+
signing_key:
|
60
|
+
specification_version: 4
|
61
|
+
summary: EJS (Embedded JavaScript) template compiler
|
62
|
+
test_files: []
|