rodolfo 0.0.2
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 +7 -0
 - data/bin/rodolfo +33 -0
 - data/lib/rodolfo.rb +38 -0
 - metadata +46 -0
 
    
        checksums.yaml
    ADDED
    
    | 
         @@ -0,0 +1,7 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ---
         
     | 
| 
      
 2 
     | 
    
         
            +
            SHA1:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 773520f2d80304bcc6c699ff1f767b5e59264026
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 405f21606fa584c43c1b5b8dc7082a30c5afabe5
         
     | 
| 
      
 5 
     | 
    
         
            +
            SHA512:
         
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 0a489720dadbfdf746154c590636b8848cf81f3c33dd54284b09fe2f3f51cbfb042d4e466184a6c07e71885910e4fe1f2c421c3bedc0faa5b996e654bcb53d4a
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 4f13e0b3dc02b3d4e77c7f3a6ef289af66df69273e56668699a2c52a5ccbc0b333bff0d3be173220cbfc3b9ca47208c5ce6987d1f14c10e4c8dbc4f0f11a676b
         
     | 
    
        data/bin/rodolfo
    ADDED
    
    | 
         @@ -0,0 +1,33 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #!/usr/bin/env ruby
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            root_path = File.dirname __dir__
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            require 'json'
         
     | 
| 
      
 6 
     | 
    
         
            +
            require 'slop'
         
     | 
| 
      
 7 
     | 
    
         
            +
            require File.join(root_path, 'lib', 'rodolfo.rb')
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            opts = Slop.parse do |o|
         
     | 
| 
      
 10 
     | 
    
         
            +
              o.string '-t', '--template', 'template name'
         
     | 
| 
      
 11 
     | 
    
         
            +
              o.string '-o', '--output', 'output pdf (optional, you can use stdout instead)'
         
     | 
| 
      
 12 
     | 
    
         
            +
              o.on '--version', 'print the version' do
         
     | 
| 
      
 13 
     | 
    
         
            +
                puts Slop::VERSION
         
     | 
| 
      
 14 
     | 
    
         
            +
                exit
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
            end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 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
         
     | 
| 
      
 22 
     | 
    
         
            +
              puts opts
         
     | 
| 
      
 23 
     | 
    
         
            +
              exit
         
     | 
| 
      
 24 
     | 
    
         
            +
            end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
            data = JSON.parse(json_data, symbolize_names: true)
         
     | 
| 
      
 27 
     | 
    
         
            +
            bytes = Rodolfo::Pdf.new(opts[:template]).make data
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
            if opts[:output]
         
     | 
| 
      
 30 
     | 
    
         
            +
              open(opts[:output], 'wb') { |f| f.puts bytes }
         
     | 
| 
      
 31 
     | 
    
         
            +
            else
         
     | 
| 
      
 32 
     | 
    
         
            +
              STDOUT.write bytes
         
     | 
| 
      
 33 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/rodolfo.rb
    ADDED
    
    | 
         @@ -0,0 +1,38 @@ 
     | 
|
| 
      
 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'
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                  p = @package.proc_maker(data)
         
     | 
| 
      
 18 
     | 
    
         
            +
                  Prawn::Document.new(&p).render
         
     | 
| 
      
 19 
     | 
    
         
            +
                end
         
     | 
| 
      
 20 
     | 
    
         
            +
              end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
              class TemplatePackage
         
     | 
| 
      
 23 
     | 
    
         
            +
                def initialize(path)
         
     | 
| 
      
 24 
     | 
    
         
            +
                  @path = path
         
     | 
| 
      
 25 
     | 
    
         
            +
                  @json_file_path = File.join @path, 'schema.json'
         
     | 
| 
      
 26 
     | 
    
         
            +
                  @template_file_path = File.join @path, 'template.rb'
         
     | 
| 
      
 27 
     | 
    
         
            +
                end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                def schema
         
     | 
| 
      
 30 
     | 
    
         
            +
                  @json_schema ||= File.read @json_file_path
         
     | 
| 
      
 31 
     | 
    
         
            +
                end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                def proc_maker(data)
         
     | 
| 
      
 34 
     | 
    
         
            +
                  require @template_file_path
         
     | 
| 
      
 35 
     | 
    
         
            +
                  Rodolfo.make_proc data
         
     | 
| 
      
 36 
     | 
    
         
            +
                end
         
     | 
| 
      
 37 
     | 
    
         
            +
              end
         
     | 
| 
      
 38 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,46 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: rodolfo
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.2
         
     | 
| 
      
 5 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 6 
     | 
    
         
            +
            authors:
         
     | 
| 
      
 7 
     | 
    
         
            +
            - Initios
         
     | 
| 
      
 8 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 9 
     | 
    
         
            +
            bindir: bin
         
     | 
| 
      
 10 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2016-10-14 00:00:00.000000000 Z
         
     | 
| 
      
 12 
     | 
    
         
            +
            dependencies: []
         
     | 
| 
      
 13 
     | 
    
         
            +
            description: Create pdfs with Prawn
         
     | 
| 
      
 14 
     | 
    
         
            +
            email: dev@initios.com
         
     | 
| 
      
 15 
     | 
    
         
            +
            executables:
         
     | 
| 
      
 16 
     | 
    
         
            +
            - rodolfo
         
     | 
| 
      
 17 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 18 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 19 
     | 
    
         
            +
            files:
         
     | 
| 
      
 20 
     | 
    
         
            +
            - bin/rodolfo
         
     | 
| 
      
 21 
     | 
    
         
            +
            - lib/rodolfo.rb
         
     | 
| 
      
 22 
     | 
    
         
            +
            homepage: https://github.com/initios/rodolfo
         
     | 
| 
      
 23 
     | 
    
         
            +
            licenses:
         
     | 
| 
      
 24 
     | 
    
         
            +
            - MIT
         
     | 
| 
      
 25 
     | 
    
         
            +
            metadata: {}
         
     | 
| 
      
 26 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
      
 27 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 28 
     | 
    
         
            +
            require_paths:
         
     | 
| 
      
 29 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 30 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 31 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 32 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 33 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 34 
     | 
    
         
            +
                  version: '2.0'
         
     | 
| 
      
 35 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 36 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 37 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 38 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 39 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 40 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 41 
     | 
    
         
            +
            rubyforge_project: 
         
     | 
| 
      
 42 
     | 
    
         
            +
            rubygems_version: 2.5.1
         
     | 
| 
      
 43 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 44 
     | 
    
         
            +
            specification_version: 4
         
     | 
| 
      
 45 
     | 
    
         
            +
            summary: rodolfo
         
     | 
| 
      
 46 
     | 
    
         
            +
            test_files: []
         
     |