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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODdkZGQ4MzYzNThlNTM4ZjRjODA2MWRmOTM1NGQzZDEwMTQ0OTgxNg==
4
+ ODM0ODQ3YjQ2OTBkYjIyMjkxMzFkMGNhMGI1NmQ4Y2FhODIwNjdlYw==
5
5
  data.tar.gz: !binary |-
6
- NjRiMTllODBjZWRlOTU4NjBjYWM2MWM5MWQ3NGVhZTJkNWQ5MjM1Ng==
6
+ NmQ4ZGRiZDAxZGQ1MDIwZmI3ZTA1NjE1ZjVhNmQ0NmZhZTlkMWU2NA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OWMxYWM1ZTczN2ZkMjE0MTY4MDk4YzRjMjhmYjIxOTMwZTBjODZhNzZlNjYx
10
- NGYwNDg2NjJmM2QwMTNlMzNjYzdiMmJmNzU4NWExZTc1NWQ4NjE3NzExYjM4
11
- ZTRhZjhlZGE0ZjgwOTU0ZTE0ODAxNDdkMGIzOWIwMDcwNjU4OTE=
9
+ YjYxZWFjZWM2OWZjNzhmZThkNTY5MmMzZjk2NzQ2MWUwYTc3ZmE0MjNjYmFi
10
+ ZWEzNGVhN2U3YWM2OTkyMmVlOGZlYjFjNzg1Y2Y1NzEzNTNiMTg2OTQ0NDVm
11
+ Njc0N2ZjMDIyMDkwNmVlOWNiYTExYWFmZjlmZDg2YWM3YjBlYWM=
12
12
  data.tar.gz: !binary |-
13
- NzRkZDA1NmYzMTc0N2U4NjgyZDVmODBiNWYzYjVjZmNkMThjYmQ1MDdjMjgz
14
- ZDU1MDcyZmVhN2JhMWNmYzdhMWNjMjdlMTFmZjdlNzMyYjgwZDk5YWE5NzJi
15
- ZTZkZDkxMDBjYmFlNDI5MzA3MGQ2MGM5ZjViN2FlZDczMTI5MTg=
13
+ ZjkwNWViYTdjNjU1YWJiYmVhNjQzMjMyYmVlZmRmYzI1YzgwMzg2MGY4MGY0
14
+ NmRiN2VlNTA0OGQ5ZDY0MzU0OWMyMTQ0M2VmNGU1ZmUyNmZjYmYxYmQ5MWNh
15
+ NDdiNWZhYzgxNmRmOGJhODc5NmZlYmI4ZDNkNGUxODU3NWRlYmM=
data/CHANGES CHANGED
@@ -14,4 +14,8 @@
14
14
 
15
15
  == Version 1.0.3
16
16
 
17
- * Bug fix.
17
+ * Bug fix.
18
+
19
+ == Version 1.0.4
20
+
21
+ * Bug fix, writing documentation.
data/README.md CHANGED
@@ -1,4 +1,75 @@
1
- text-interpolator
2
- =================
1
+ # Text Interpolator - Simple library for interpolation of variables inside the text.
3
2
 
4
- Simple library for interpolation of variables inside the text.
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
+ ```
@@ -1,3 +1,5 @@
1
+ require 'stringio'
2
+
1
3
  class TextInterpolator
2
4
 
3
5
  def interpolate object, env={}
@@ -1,3 +1,3 @@
1
1
  class TextInterpolator
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
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.3
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-04-29 00:00:00.000000000 Z
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