text-interpolator 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGES +5 -1
- data/README.md +74 -3
- data/lib/text_interpolator/text_interpolator.rb +2 -0
- data/lib/text_interpolator/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ODM0ODQ3YjQ2OTBkYjIyMjkxMzFkMGNhMGI1NmQ4Y2FhODIwNjdlYw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NmQ4ZGRiZDAxZGQ1MDIwZmI3ZTA1NjE1ZjVhNmQ0NmZhZTlkMWU2NA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YjYxZWFjZWM2OWZjNzhmZThkNTY5MmMzZjk2NzQ2MWUwYTc3ZmE0MjNjYmFi
|
10
|
+
ZWEzNGVhN2U3YWM2OTkyMmVlOGZlYjFjNzg1Y2Y1NzEzNTNiMTg2OTQ0NDVm
|
11
|
+
Njc0N2ZjMDIyMDkwNmVlOWNiYTExYWFmZjlmZDg2YWM3YjBlYWM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZjkwNWViYTdjNjU1YWJiYmVhNjQzMjMyYmVlZmRmYzI1YzgwMzg2MGY4MGY0
|
14
|
+
NmRiN2VlNTA0OGQ5ZDY0MzU0OWMyMTQ0M2VmNGU1ZmUyNmZjYmYxYmQ5MWNh
|
15
|
+
NDdiNWZhYzgxNmRmOGJhODc5NmZlYmI4ZDNkNGUxODU3NWRlYmM=
|
data/CHANGES
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,75 @@
|
|
1
|
-
text
|
2
|
-
=================
|
1
|
+
# Text Interpolator - Simple library for interpolation of variables inside the text.
|
3
2
|
|
4
|
-
|
3
|
+
## Introduction
|
4
|
+
|
5
|
+
You have few options in ruby for variables interpolation:
|
6
|
+
|
7
|
+
- interpolation inside string:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
var1 = 'some value 1'
|
11
|
+
var2 = 'some value 2'
|
12
|
+
|
13
|
+
result = "We have var1: #{var1} and var2: #{var2}."
|
14
|
+
|
15
|
+
puts result # We have var1: some value 1 and var2: some value 2.
|
16
|
+
```
|
17
|
+
|
18
|
+
- interpolation inside file (with embedded ruby - erb):
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
# some_template.erb
|
22
|
+
|
23
|
+
We have var1: <%= var1 %> and var2: <%= var2%>.
|
24
|
+
|
25
|
+
# test.rb
|
26
|
+
|
27
|
+
require 'erb'
|
28
|
+
|
29
|
+
var1 = 'some value 1'
|
30
|
+
var2 = 'some value 2'
|
31
|
+
|
32
|
+
template = ERB.new(File.read("some_template.erb"))
|
33
|
+
|
34
|
+
result = template.result(binding)
|
35
|
+
|
36
|
+
puts result # We have var1: some value 1 and var2: some value 2.
|
37
|
+
```
|
38
|
+
|
39
|
+
This library can be used for interpolation inside file with string syntax.
|
40
|
+
|
41
|
+
In order to achieve it uses this ruby trick:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
env = {var1: 'some value 1', var2: 'some value 2'}
|
45
|
+
|
46
|
+
template = "We have var1: %{var1} and var2: %{var2}."
|
47
|
+
|
48
|
+
result = template % env
|
49
|
+
|
50
|
+
puts result # We have var1: some value 1 and var2: some value 2.
|
51
|
+
```
|
52
|
+
|
53
|
+
## Usage
|
54
|
+
|
55
|
+
It's straightforward:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
# some_template.txt
|
59
|
+
|
60
|
+
We have var1: #{var1} and var2: #{var2}.
|
61
|
+
|
62
|
+
# test.rb
|
63
|
+
|
64
|
+
require 'text_interpolator'
|
65
|
+
|
66
|
+
env ={var1: 'some value 1', var2: 'some value 2'}
|
67
|
+
|
68
|
+
template = File.read("some_template.txt")
|
69
|
+
|
70
|
+
text_interpolator = TextInterpolator.new
|
71
|
+
|
72
|
+
result = text_interpolator.interpolate template, env
|
73
|
+
|
74
|
+
puts result # We have var1: some value 1 and var2: some value 2.
|
75
|
+
```
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: text-interpolator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Shvets
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gemspec_deps_gen
|