rodolfo 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/rodolfo +9 -15
- data/lib/rodolfo.rb +27 -4
- 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: df5eaa2a01e993da8484f0bacefab3f22d88e889
|
4
|
+
data.tar.gz: d341e4fde1ce38d657948dc78b24cb47fd3d929c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2221a3f3c72fe1e136081b75a36e046639d3edeec121c7af9d41e31db1cdb62089455c34c7d38b63b2fafd1095fbcfb7c69a3324a2087b461bcd06baf43578b6
|
7
|
+
data.tar.gz: 6cd22910b4f65fe478f709bbf52c1b4448ff0b604fd0c0b25050d9bfc11f2328d21a2a10a983fcd959f7d7f965951316add168d5e46c3afff25ece2c51e22ec0
|
data/bin/rodolfo
CHANGED
@@ -8,8 +8,7 @@ require File.join(root_path, 'lib', 'rodolfo.rb')
|
|
8
8
|
|
9
9
|
opts = Slop.parse do |o|
|
10
10
|
o.string '-t', '--template', 'template name'
|
11
|
-
o.
|
12
|
-
o.on '--schema', 'print the json schema'
|
11
|
+
o.on '--skip-validation', 'skip json schema validation'
|
13
12
|
o.on '--version', 'print the version' do
|
14
13
|
STDOUT.write Rodolfo::VERSION
|
15
14
|
exit 0
|
@@ -21,19 +20,14 @@ unless opts[:template]
|
|
21
20
|
exit 1
|
22
21
|
end
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
if opts[:schema]
|
27
|
-
STDOUT.write package.schema
|
28
|
-
exit 0
|
29
|
-
end
|
30
|
-
|
31
|
-
json_data = $stdin.tty? ? nil : $stdin.read
|
23
|
+
json_data = $stdin.tty? ? {} : $stdin.read
|
32
24
|
data = JSON.parse(json_data, symbolize_names: true)
|
33
|
-
|
25
|
+
package = Rodolfo::Package.new opts[:template], data
|
34
26
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
STDOUT.write bytes
|
27
|
+
unless opts.skip_validation? || package.valid?
|
28
|
+
STDOUT.write JSON.dump(package.validation_errors)
|
29
|
+
exit 2
|
39
30
|
end
|
31
|
+
|
32
|
+
STDOUT.write package.make
|
33
|
+
exit 0
|
data/lib/rodolfo.rb
CHANGED
@@ -1,15 +1,27 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'json-schema'
|
1
3
|
require 'pathname'
|
2
4
|
require 'prawn'
|
3
5
|
require 'prawn/measurements'
|
4
6
|
require 'prawn/measurement_extensions'
|
5
7
|
require 'prawn/table'
|
6
8
|
|
9
|
+
##
|
10
|
+
# Create PDFs from the CLI using Prawn
|
7
11
|
module Rodolfo
|
8
|
-
VERSION = '0.0.
|
12
|
+
VERSION = '0.0.5'.freeze
|
9
13
|
|
14
|
+
##
|
15
|
+
# Represents a filesystem folder which should contain
|
16
|
+
# - schema.json to perform the validation
|
17
|
+
# - data.json as example data
|
18
|
+
# - template.rb the pdf generator itself
|
19
|
+
#
|
20
|
+
# It handles methods for manipulate those files and the pdf generation
|
10
21
|
class Package
|
11
|
-
def initialize(path)
|
22
|
+
def initialize(path, data)
|
12
23
|
@path = Pathname.new(path).absolute? ? path : File.join(Dir.pwd, path)
|
24
|
+
@data = data
|
13
25
|
@json_file_path = File.join @path, 'schema.json'
|
14
26
|
@template_file_path = File.join @path, 'template'
|
15
27
|
end
|
@@ -18,9 +30,20 @@ module Rodolfo
|
|
18
30
|
@json_schema ||= File.read @json_file_path
|
19
31
|
end
|
20
32
|
|
21
|
-
def
|
33
|
+
def valid?
|
34
|
+
args = schema, @data, { errors_as_objects: true }
|
35
|
+
@validation_errors = JSON::Validator.fully_validate(*args)
|
36
|
+
@validation_errors.empty?
|
37
|
+
end
|
38
|
+
|
39
|
+
def validation_errors
|
40
|
+
valid? unless @validation_errors
|
41
|
+
@validation_errors
|
42
|
+
end
|
43
|
+
|
44
|
+
def make
|
22
45
|
require @template_file_path
|
23
|
-
Rodolfo::Template.new(data).render
|
46
|
+
Rodolfo::Template.new(@data).render
|
24
47
|
end
|
25
48
|
end
|
26
49
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rodolfo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Initios
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Create pdfs with Prawn
|
14
14
|
email: dev@initios.com
|