sablon 0.0.5 → 0.0.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f09a55daf98da6c52eb49e49e19291cdea0d1b11
4
- data.tar.gz: 2234c60fb99580f059f4f93ec46009b1b9af3727
3
+ metadata.gz: 0f0de4c805cae97f7a2a68f2b82d081c7f5a6aac
4
+ data.tar.gz: 7083c6d868050f33ef08de6c0c698f9fdece86f8
5
5
  SHA512:
6
- metadata.gz: e3bfbb49b514729e964717b14797c9af60a491e21f0abed165460c9c9f9987ad4da9040795369b0bd7ba8a1a299eaf279100c2c57135d3c91191b47bce9b65ec
7
- data.tar.gz: d88dd5dea55a11d726025b23709c112d979bd119df1524195f7f728c8eb5f64174b89a1ab96d6d9fa4b1d6bd85d634a536b7a477583c78de976386cbce02a637
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
- Have a look at [this test](test/executable_test.rb) for an example.
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 != 2
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
- template.render_to_file(output_path, context)
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
@@ -1,3 +1,3 @@
1
1
  module Sablon
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -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 test_generate_document_from_template
14
- template_path = @base_path + "fixtures/shopping_list_template.docx"
15
- context_path = @base_path + "fixtures/shopping_list_context.json"
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
- executable_path = @base_path + '../bin/sablon'
22
+ assert_docx_equal @base_path + "fixtures/shopping_list_sample.docx", @output_path
23
+ end
18
24
 
19
- `cat #{context_path} | #{executable_path} #{template_path} #{@output_path}`
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.5
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-02-26 00:00:00.000000000 Z
11
+ date: 2015-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri