ruby_it 0.2.0 → 0.3.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/examples/example4.rtxt +3 -0
- data/examples/example5.rtxt +2 -0
- data/lib/ruby_it/document.rb +13 -3
- data/lib/ruby_it.rb +1 -1
- data/spec/cli_spec.rb +40 -8
- metadata +4 -2
data/lib/ruby_it/document.rb
CHANGED
@@ -28,6 +28,9 @@ module RubyIt
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def result
|
31
|
+
#Giving The template file acces to the parent object
|
32
|
+
$parent = self ## <-- Global bad, but works for this
|
33
|
+
|
31
34
|
#Add params and template file text and clear white space
|
32
35
|
text = clean_whitespace( get_parameters + erb_text )
|
33
36
|
|
@@ -93,9 +96,16 @@ module RubyIt
|
|
93
96
|
|
94
97
|
def write
|
95
98
|
#write evaluated template to file:
|
96
|
-
File.
|
97
|
-
|
98
|
-
|
99
|
+
if ::File.writable? self.output or not ::File.exists? self.output
|
100
|
+
|
101
|
+
result = self.result
|
102
|
+
file_out = File.open( self.output, 'w' )
|
103
|
+
file_out << result
|
104
|
+
file_out.close
|
105
|
+
|
106
|
+
else
|
107
|
+
$stderr.puts "ERROR #{self.output} is not writable"
|
108
|
+
end
|
99
109
|
|
100
110
|
end
|
101
111
|
|
data/lib/ruby_it.rb
CHANGED
data/spec/cli_spec.rb
CHANGED
@@ -14,7 +14,6 @@ describe RubyIt do
|
|
14
14
|
generated_expected_text = "hello\nhello\nhello\n"
|
15
15
|
|
16
16
|
check_source_and_remove_gen( source, generated )
|
17
|
-
|
18
17
|
check_source_text( source, source_expected_text )
|
19
18
|
|
20
19
|
# run CLI (With blocking function)
|
@@ -31,7 +30,6 @@ describe RubyIt do
|
|
31
30
|
generated_expected_text = "Hello\nHello\nHello\n"
|
32
31
|
|
33
32
|
check_source_and_remove_gen( source, generated )
|
34
|
-
|
35
33
|
check_source_text( source, source_expected_text )
|
36
34
|
|
37
35
|
# run CLI (With blocking function)
|
@@ -48,7 +46,6 @@ describe RubyIt do
|
|
48
46
|
generated_expected_text = "Hello\nHello\nHello\nHello\nHello\n"
|
49
47
|
|
50
48
|
check_source_and_remove_gen( source, generated )
|
51
|
-
|
52
49
|
check_source_text( source, source_expected_text )
|
53
50
|
|
54
51
|
# run CLI (With blocking function)
|
@@ -56,6 +53,8 @@ describe RubyIt do
|
|
56
53
|
|
57
54
|
check_generated_text( generated, generated_expected_text )
|
58
55
|
end
|
56
|
+
|
57
|
+
|
59
58
|
it "evaluates command line parameters with different values '5'" do
|
60
59
|
source = "#{@prefix}/../examples/example3.rtxt"
|
61
60
|
generated = "#{@prefix}/../generated/example3.txt"
|
@@ -63,20 +62,52 @@ describe RubyIt do
|
|
63
62
|
generated_expected_text = "3\nHelloWorld\n"
|
64
63
|
|
65
64
|
check_source_and_remove_gen( source, generated )
|
66
|
-
|
67
65
|
check_source_text( source, source_expected_text )
|
66
|
+
#puts "#{@prefix}/../bin/ruby_it --config #{@prefix}/../examples/example3.conf --outpath #{@prefix}/../generated/ --file #{source}"
|
67
|
+
|
68
|
+
# run CLI (With blocking function)
|
69
|
+
do_and_report("#{@prefix}/../bin/ruby_it --config #{@prefix}/../examples/example3.conf --outpath #{@prefix}/../generated/ --file #{source}")
|
70
|
+
|
71
|
+
check_generated_text( generated, generated_expected_text )
|
72
|
+
end
|
68
73
|
|
69
74
|
|
70
|
-
puts "#{@prefix}/../bin/ruby_it --config #{@prefix}/../examples/example3.conf --outpath #{@prefix}/../generated/ --file #{source}"
|
71
75
|
|
72
|
-
|
76
|
+
it "Output is not writabe" do
|
77
|
+
source = "#{@prefix}/../examples/example4.rtxt"
|
78
|
+
generated = "#{@prefix}/../examples/example4.txt"
|
79
|
+
source_expected_text = ""
|
80
|
+
generated_expected_text = ""
|
81
|
+
|
82
|
+
# Create output and chmod to 000
|
83
|
+
::File.delete( generated ) if ::File.exists? generated
|
84
|
+
::File.open( generated, "w" ){ |f| f.write '' }
|
85
|
+
::File.chmod(0000, generated )
|
73
86
|
|
74
87
|
# run CLI (With blocking function)
|
75
|
-
|
88
|
+
require 'open3'
|
89
|
+
stdin, stdout, stderr = Open3.popen3("#{@prefix}/../bin/ruby_it --file #{source}")
|
76
90
|
|
77
|
-
|
91
|
+
stderr.readlines[0].strip.should == "ERROR #{generated} is not writable"
|
92
|
+
|
93
|
+
::File.delete( generated ) if ::File.exists? generated
|
78
94
|
end
|
95
|
+
|
96
|
+
|
97
|
+
it "Template Redirects output" do
|
98
|
+
source = "#{@prefix}/../examples/example5.rtxt"
|
99
|
+
generated = "#{@prefix}/../generated/example5.log"
|
100
|
+
source_expected_text = "<% $parent.out_filename = \"example5.log\" -%>\nExample 5 The template changes the output file.\n"
|
101
|
+
generated_expected_text = "Example 5 The template changes the output file.\n"
|
102
|
+
|
103
|
+
check_source_and_remove_gen( source, generated )
|
104
|
+
check_source_text( source, source_expected_text )
|
79
105
|
|
106
|
+
# run CLI (With blocking function)
|
107
|
+
do_and_report("#{@prefix}/../bin/ruby_it --outpath #{@prefix}/../generated/ --file #{source}")
|
108
|
+
|
109
|
+
check_generated_text( generated, generated_expected_text )
|
110
|
+
end
|
80
111
|
|
81
112
|
end
|
82
113
|
end
|
@@ -93,6 +124,7 @@ def do_and_report(command, report=false)
|
|
93
124
|
puts element
|
94
125
|
end
|
95
126
|
end
|
127
|
+
return g
|
96
128
|
end
|
97
129
|
|
98
130
|
def check_source_and_remove_gen( source, generated )
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_it
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-10-06 00:00:00.000000000 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
description: ! " Comand Line Interface (CLI) and Object class can be used to evaluate
|
@@ -26,6 +26,8 @@ files:
|
|
26
26
|
- examples/example2.txt
|
27
27
|
- examples/example3.conf
|
28
28
|
- examples/example3.rtxt
|
29
|
+
- examples/example4.rtxt
|
30
|
+
- examples/example5.rtxt
|
29
31
|
- examples/hello_erb.rtxt
|
30
32
|
- examples/hellos.rtxt
|
31
33
|
- examples/hellos.txt
|