rodolfo 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/rodolfo +14 -8
  3. data/lib/rodolfo.rb +13 -24
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 773520f2d80304bcc6c699ff1f767b5e59264026
4
- data.tar.gz: 405f21606fa584c43c1b5b8dc7082a30c5afabe5
3
+ metadata.gz: 721c332031a996a570c5084587a12caa636cec6b
4
+ data.tar.gz: 5f1857ff5e61f6cdc3af3493706b8834de5a7faa
5
5
  SHA512:
6
- metadata.gz: 0a489720dadbfdf746154c590636b8848cf81f3c33dd54284b09fe2f3f51cbfb042d4e466184a6c07e71885910e4fe1f2c421c3bedc0faa5b996e654bcb53d4a
7
- data.tar.gz: 4f13e0b3dc02b3d4e77c7f3a6ef289af66df69273e56668699a2c52a5ccbc0b333bff0d3be173220cbfc3b9ca47208c5ce6987d1f14c10e4c8dbc4f0f11a676b
6
+ metadata.gz: cf72f7910018f6a6b41b369bbe8c59fbf0cfc14745dac772407558b86762f577a21dc8e6a62a92b7e44254beb2fab79897d2e48ef2e1273d06f805505d2cd870
7
+ data.tar.gz: c1cd4c02b2d7eddfb204fe59de0c4015d6c4e4f4ba687c4708e432b5499e43699d919f7af0d31201b8986d18dc467411c192078c879debdc3e8f5ec2fae32565
data/bin/rodolfo CHANGED
@@ -9,22 +9,28 @@ require File.join(root_path, 'lib', 'rodolfo.rb')
9
9
  opts = Slop.parse do |o|
10
10
  o.string '-t', '--template', 'template name'
11
11
  o.string '-o', '--output', 'output pdf (optional, you can use stdout instead)'
12
+ o.on '--schema', 'print the json schema'
12
13
  o.on '--version', 'print the version' do
13
- puts Slop::VERSION
14
- exit
14
+ STDOUT.write Rodolfo::VERSION
15
+ exit 0
15
16
  end
16
17
  end
17
18
 
18
- json_data = $stdin.tty? ? nil : $stdin.read
19
-
20
- unless json_data && opts[:template]
21
- puts 'Missing json data throught stdin' unless json_data
19
+ unless opts[:template]
22
20
  puts opts
23
- exit
21
+ exit 1
22
+ end
23
+
24
+ package = Rodolfo::Package.new(opts[:template])
25
+
26
+ if opts[:schema]
27
+ STDOUT.write package.schema
28
+ exit 0
24
29
  end
25
30
 
31
+ json_data = $stdin.tty? ? nil : $stdin.read
26
32
  data = JSON.parse(json_data, symbolize_names: true)
27
- bytes = Rodolfo::Pdf.new(opts[:template]).make data
33
+ bytes = package.make data
28
34
 
29
35
  if opts[:output]
30
36
  open(opts[:output], 'wb') { |f| f.puts bytes }
data/lib/rodolfo.rb CHANGED
@@ -1,38 +1,27 @@
1
- module Rodolfo
2
- class Pdf
3
- def initialize(path)
4
- @package = TemplatePackage.new path
5
- end
6
-
7
- def schema
8
- @package.schema
9
- end
10
-
11
- def make(data)
12
- require 'prawn'
13
- require 'prawn/measurements'
14
- require 'prawn/measurement_extensions'
15
- require 'prawn/table'
1
+ require 'pathname'
2
+ require 'prawn'
3
+ require 'prawn/measurements'
4
+ require 'prawn/measurement_extensions'
5
+ require 'prawn/table'
16
6
 
17
- p = @package.proc_maker(data)
18
- Prawn::Document.new(&p).render
19
- end
20
- end
7
+ module Rodolfo
8
+ VERSION = '0.0.3'.freeze
21
9
 
22
- class TemplatePackage
10
+ class Package
23
11
  def initialize(path)
24
- @path = path
12
+ @path = Pathname.new(path).absolute? ? path : File.join(Dir.pwd, path)
25
13
  @json_file_path = File.join @path, 'schema.json'
26
- @template_file_path = File.join @path, 'template.rb'
14
+ @template_file_path = File.join @path, 'template'
27
15
  end
28
16
 
29
17
  def schema
30
18
  @json_schema ||= File.read @json_file_path
31
19
  end
32
20
 
33
- def proc_maker(data)
21
+ def make(data)
34
22
  require @template_file_path
35
- Rodolfo.make_proc data
23
+ p = Rodolfo::Template.new data
24
+ Prawn::Document.new(&p).render
36
25
  end
37
26
  end
38
27
  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.2
4
+ version: 0.0.3
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-14 00:00:00.000000000 Z
11
+ date: 2016-10-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Create pdfs with Prawn
14
14
  email: dev@initios.com