javascript_template_literals 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +39 -0
- data/README.md +62 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/javascript_template_literals.gemspec +27 -0
- data/lib/javascript_template_literals.rb +33 -0
- data/lib/javascript_template_literals/version.rb +3 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6e57e0151670f1bda8d58f7a528a6dff9b4e7d863e37a94eca52f4f7c02c958a
|
4
|
+
data.tar.gz: 72239bf540148b4bdbeae67b97c093b189931f08b24d1b257289000704a62bb0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4746b096f781cbe7d96b81c7a245bf97f0102ddb38c84381776d5d4958c2a1ddbb2054ba2ff65ba6bd5aec9448150bf9499227732efa78277e69f4de885528f2
|
7
|
+
data.tar.gz: d4a8e27a9bd671f703aa3ad4866cf7b26d099bc9b554cea5503732595ef0eda210f263fb6887cac0ccf958153e83255dfea7ebd5b4eb38ba5d7ff317a8cc13f5
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
javascript_template_literals (0.1.0)
|
5
|
+
binding_of_caller
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
binding_of_caller (0.8.0)
|
11
|
+
debug_inspector (>= 0.0.1)
|
12
|
+
debug_inspector (0.0.3)
|
13
|
+
diff-lcs (1.3)
|
14
|
+
rake (10.5.0)
|
15
|
+
rspec (3.8.0)
|
16
|
+
rspec-core (~> 3.8.0)
|
17
|
+
rspec-expectations (~> 3.8.0)
|
18
|
+
rspec-mocks (~> 3.8.0)
|
19
|
+
rspec-core (3.8.0)
|
20
|
+
rspec-support (~> 3.8.0)
|
21
|
+
rspec-expectations (3.8.2)
|
22
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
23
|
+
rspec-support (~> 3.8.0)
|
24
|
+
rspec-mocks (3.8.0)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.8.0)
|
27
|
+
rspec-support (3.8.0)
|
28
|
+
|
29
|
+
PLATFORMS
|
30
|
+
ruby
|
31
|
+
|
32
|
+
DEPENDENCIES
|
33
|
+
bundler (~> 2.0)
|
34
|
+
javascript_template_literals!
|
35
|
+
rake (~> 10.0)
|
36
|
+
rspec (~> 3.0)
|
37
|
+
|
38
|
+
BUNDLED WITH
|
39
|
+
2.0.0
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# JavaScriptTemplateLiterals
|
2
|
+
|
3
|
+
Make #\`(string) works like JavaScript Template literals
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'javascript_template_literals'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install javascript_template_literals
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```rb
|
24
|
+
require "javascript_template_literals"
|
25
|
+
|
26
|
+
using JavaScriptTemplateLiterals
|
27
|
+
|
28
|
+
a = 5
|
29
|
+
b = 10
|
30
|
+
puts `Fifteen is ${a + b} and
|
31
|
+
not ${2 * a + b}.`
|
32
|
+
# Fifteen is 15 and
|
33
|
+
# not 20.
|
34
|
+
|
35
|
+
def my_tag((strings, person_exp, age_exp))
|
36
|
+
str0 = strings[0]
|
37
|
+
str1 = strings[1]
|
38
|
+
|
39
|
+
if age_exp > 99
|
40
|
+
age_str = "centenarian"
|
41
|
+
else
|
42
|
+
age_str = "youngster"
|
43
|
+
end
|
44
|
+
|
45
|
+
`${str0}${person_exp}${str1}${age_str}`
|
46
|
+
end
|
47
|
+
|
48
|
+
person = "Mike"
|
49
|
+
age = 28
|
50
|
+
puts my_tag`That ${ person } is a ${ age }`
|
51
|
+
# That Mike is a youngster
|
52
|
+
```
|
53
|
+
|
54
|
+
## Development
|
55
|
+
|
56
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
57
|
+
|
58
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
59
|
+
|
60
|
+
## Contributing
|
61
|
+
|
62
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/hanachin/javascript_template_literals.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "javascript_template_literals"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "javascript_template_literals/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "javascript_template_literals"
|
8
|
+
spec.version = JavaScriptTemplateLiterals::VERSION
|
9
|
+
spec.authors = ["Seiei Miyagi"]
|
10
|
+
spec.email = ["hanachin@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Make #`(string) works like JavaScript Template literals}
|
13
|
+
spec.homepage = "https://github.com/hanachin/javascript_template_literals"
|
14
|
+
# Specify which files should be added to the gem when it is released.
|
15
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
16
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
17
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_dependency "binding_of_caller"
|
24
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "javascript_template_literals/version"
|
2
|
+
require "binding_of_caller"
|
3
|
+
|
4
|
+
module JavaScriptTemplateLiterals
|
5
|
+
class Error < StandardError; end
|
6
|
+
|
7
|
+
def self.interpolate(b, str)
|
8
|
+
str.gsub(/\$\{([^\}]*)\}/) { b.eval($1) }
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.template_arguments(b, str)
|
12
|
+
strings = []
|
13
|
+
exps = []
|
14
|
+
loop do
|
15
|
+
h, _, str = str.partition(/\$\{([^\}]*)\}/)
|
16
|
+
strings << h
|
17
|
+
break unless $1
|
18
|
+
exps << b.eval($1)
|
19
|
+
end
|
20
|
+
[strings, *exps]
|
21
|
+
end
|
22
|
+
|
23
|
+
refine(Object) do
|
24
|
+
def `(str)
|
25
|
+
b = binding.of_caller(1)
|
26
|
+
JavaScriptTemplateLiterals.interpolate(b, str).tap do |ret|
|
27
|
+
ret.define_singleton_method(:to_ary) do
|
28
|
+
JavaScriptTemplateLiterals.template_arguments(b, str)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: javascript_template_literals
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Seiei Miyagi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-12-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: binding_of_caller
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- hanachin@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
85
|
+
- javascript_template_literals.gemspec
|
86
|
+
- lib/javascript_template_literals.rb
|
87
|
+
- lib/javascript_template_literals/version.rb
|
88
|
+
homepage: https://github.com/hanachin/javascript_template_literals
|
89
|
+
licenses: []
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.7.8
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: 'Make #`(string) works like JavaScript Template literals'
|
111
|
+
test_files: []
|