sablon 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -1
- data/bin/sablon +9 -4
- data/lib/sablon/version.rb +1 -1
- data/test/executable_test.rb +13 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f0de4c805cae97f7a2a68f2b82d081c7f5a6aac
|
4
|
+
data.tar.gz: 7083c6d868050f33ef08de6c0c698f9fdece86f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da8799eeef32b9142c69edd505a9609b57097306f0f2e452a5e541d31bbcaad7e16c28ffee420ac18d646ec46ab67cd323b7b8b7e72876372f1f408cd0cd0fce
|
7
|
+
data.tar.gz: 42f093e8db992ceff780d931a3cd7170349f3498c2c81de58539492253207eb7e4d747fb888ada796279dfe1982e261f852be8c88574a914f7588490a6254b49
|
data/README.md
CHANGED
@@ -115,7 +115,10 @@ The usage is as follows:
|
|
115
115
|
cat <context path>.json | sablon <template path> <output path>
|
116
116
|
```
|
117
117
|
|
118
|
-
|
118
|
+
If no `<output path>` is given, the document will be printed to stdout.
|
119
|
+
|
120
|
+
|
121
|
+
Have a look at [this test](test/executable_test.rb) for examples.
|
119
122
|
|
120
123
|
### Examples
|
121
124
|
|
data/bin/sablon
CHANGED
@@ -3,17 +3,22 @@
|
|
3
3
|
require 'sablon'
|
4
4
|
require 'json'
|
5
5
|
|
6
|
-
if ARGV.size
|
6
|
+
if ARGV.size < 1
|
7
7
|
puts <<-HELP
|
8
|
-
cat <context path> | sablon <template path> <output path>
|
8
|
+
cat <context path> | sablon <template path> [<output path>]
|
9
9
|
HELP
|
10
10
|
exit
|
11
11
|
end
|
12
12
|
|
13
13
|
template_path = File.expand_path(ARGV[0])
|
14
|
-
output_path = File.expand_path(ARGV[1])
|
15
14
|
context_json = STDIN.readlines.join
|
16
15
|
context = JSON.parse(context_json)
|
17
16
|
|
18
17
|
template = Sablon.template(template_path)
|
19
|
-
|
18
|
+
|
19
|
+
if !ARGV[1].nil? && !ARGV[1].empty?
|
20
|
+
output_path = File.expand_path(ARGV[1])
|
21
|
+
template.render_to_file(output_path, context)
|
22
|
+
else
|
23
|
+
$stdout.print template.render_to_string(context)
|
24
|
+
end
|
data/lib/sablon/version.rb
CHANGED
data/test/executable_test.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
1
|
require "test_helper"
|
3
2
|
|
4
3
|
class ExecutableTest < Sablon::TestCase
|
@@ -8,15 +7,23 @@ class ExecutableTest < Sablon::TestCase
|
|
8
7
|
super
|
9
8
|
@base_path = Pathname.new(File.expand_path("../", __FILE__))
|
10
9
|
@output_path = @base_path + "sandbox/shopping_list.docx"
|
10
|
+
@template_path = @base_path + "fixtures/shopping_list_template.docx"
|
11
|
+
@context_path = @base_path + "fixtures/shopping_list_context.json"
|
12
|
+
@executable_path = @base_path + '../bin/sablon'
|
11
13
|
end
|
12
14
|
|
13
|
-
def
|
14
|
-
|
15
|
-
|
15
|
+
def teardown
|
16
|
+
@output_path.delete if @output_path.exist?
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_generate_document_from_template_output_to_file
|
20
|
+
`cat #{@context_path} | #{@executable_path} #{@template_path} #{@output_path}`
|
16
21
|
|
17
|
-
|
22
|
+
assert_docx_equal @base_path + "fixtures/shopping_list_sample.docx", @output_path
|
23
|
+
end
|
18
24
|
|
19
|
-
|
25
|
+
def test_generate_document_from_template_output_to_stdout
|
26
|
+
`cat #{@context_path} | #{@executable_path} #{@template_path} > #{@output_path}`
|
20
27
|
|
21
28
|
assert_docx_equal @base_path + "fixtures/shopping_list_sample.docx", @output_path
|
22
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sablon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yves Senn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|