Module: JavaScriptTemplateLiterals
- Defined in:
- lib/javascript_template_literals.rb,
lib/javascript_template_literals/version.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- VERSION =
"0.1.0"
Class Method Summary collapse
Class Method Details
.interpolate(b, str) ⇒ Object
7 8 9 |
# File 'lib/javascript_template_literals.rb', line 7 def self.interpolate(b, str) str.gsub(/\$\{([^\}]*)\}/) { b.eval($1) } end |
.template_arguments(b, str) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/javascript_template_literals.rb', line 11 def self.template_arguments(b, str) strings = [] exps = [] loop do h, _, str = str.partition(/\$\{([^\}]*)\}/) strings << h break unless $1 exps << b.eval($1) end [strings, *exps] end |