pea 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/pea.rb +23 -15
- metadata +5 -5
data/lib/pea.rb
CHANGED
|
@@ -1,32 +1,40 @@
|
|
|
1
1
|
class Pea
|
|
2
2
|
|
|
3
|
-
attr_accessor :file_contents, :hash, :
|
|
3
|
+
attr_accessor :file_contents, :file, :hash, :rendered
|
|
4
4
|
|
|
5
5
|
def initialize(file = nil)
|
|
6
|
-
self.open_and_read_file(file)
|
|
7
6
|
end
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
|
|
9
|
+
def read(file)
|
|
10
|
+
|
|
11
|
+
@file = File.new file, "r"
|
|
12
|
+
|
|
10
13
|
if !file.empty?
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
@file_contents << line
|
|
14
|
+
file_contents = ""
|
|
15
|
+
while line = @file.gets
|
|
16
|
+
file_contents << line
|
|
15
17
|
end
|
|
16
18
|
end
|
|
19
|
+
|
|
20
|
+
@contents = file_contents
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def read_static(static_contents)
|
|
24
|
+
@contents = static_contents
|
|
17
25
|
end
|
|
18
26
|
|
|
19
|
-
def
|
|
27
|
+
def render(hash)
|
|
28
|
+
@hash = hash
|
|
29
|
+
|
|
20
30
|
@hash.each do |key, value|
|
|
21
|
-
|
|
31
|
+
unless value.nil?
|
|
32
|
+
@contents = @contents.gsub(/\{#{Regexp.escape(key)}\}/, value)
|
|
33
|
+
end
|
|
22
34
|
end
|
|
23
35
|
|
|
24
|
-
@
|
|
25
|
-
end
|
|
36
|
+
@rendered = @contents
|
|
26
37
|
|
|
27
|
-
|
|
28
|
-
self.open_and_read_file(file)
|
|
29
|
-
@hash = hash
|
|
30
|
-
self.replaced
|
|
38
|
+
@rendered
|
|
31
39
|
end
|
|
32
40
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pea
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 0.1.0
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,11 +9,11 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2013-02-08 00:00:00.000000000 Z
|
|
13
13
|
dependencies: []
|
|
14
14
|
description: You can simply provide Pea with a file and a hash of values and pea will
|
|
15
15
|
return the contents of the file with the hash keys replaced with the values
|
|
16
|
-
email:
|
|
16
|
+
email: andyhmltn@gmail.com
|
|
17
17
|
executables: []
|
|
18
18
|
extensions: []
|
|
19
19
|
extra_rdoc_files: []
|
|
@@ -39,8 +39,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
39
39
|
version: '0'
|
|
40
40
|
requirements: []
|
|
41
41
|
rubyforge_project:
|
|
42
|
-
rubygems_version: 1.8.
|
|
42
|
+
rubygems_version: 1.8.24
|
|
43
43
|
signing_key:
|
|
44
44
|
specification_version: 3
|
|
45
|
-
summary:
|
|
45
|
+
summary: A very simple templating library!
|
|
46
46
|
test_files: []
|