alego_pdf 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: af1c4d29195fc9f0cc0648b710923a8e63bf63c6e7d48feaf9373bf76ae7c536
4
+ data.tar.gz: f67c101c414c719d10c695504ca4454d1e3c41924304c3c4b30d6dd96d184bde
5
+ SHA512:
6
+ metadata.gz: 998a826b0368b40fa1a1d43964f241dc2229d8423096a73f25d930b9ae49cfaa4ab15369dcd28da21dc2d4f7599500c84b0572d1654549f3d752121c288af071
7
+ data.tar.gz: 40f26d1de7c0cbd1b0b07df2b7136a4d9defa0405017960de99d007b35a2f39b9d300f38d62e0b75577a5bf192024c24256f8f43e375dd47f2222b60af95adc2
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /.idea
10
+ /log/*.log
11
+ /test/dummy/db/*.sqlite3
12
+ /test/dummy/db/*.sqlite3-journal
13
+ /test/dummy/log/*.log
14
+ /test/dummy/node_modules/
15
+ /test/dummy/yarn-error.log
16
+ /test/dummy/storage/
17
+ /test/dummy/tmp/
18
+ /vendor/*
data/.gitlab-ci.yml ADDED
@@ -0,0 +1,28 @@
1
+ stages:
2
+ - build
3
+
4
+ #testes:
5
+ # stage: test
6
+ # script:
7
+ # - echo "Executanto testes automatizados"
8
+ # - export RAILS_ENV="test"
9
+ # - rbenv install -s
10
+ # - if ! rbenv which bundle; then gem install bundler --no-ri --no-rdoc; rbenv rehash; fi
11
+ # - bundle install
12
+ # - rspec spec
13
+ # tags:
14
+ # - tester
15
+
16
+ build:
17
+ stage: build
18
+ script:
19
+ - if ! rbenv shell 2.7.3; then rbenv install -s 2.7.3; rbenv rehash; fi
20
+ - if ! rbenv which bundle; then gem install bundler --no-ri --no-rdoc; rbenv rehash; fi
21
+ - bundle install
22
+ - rake build
23
+ - rake release
24
+ # - rake force_release
25
+ only:
26
+ - /^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}$/
27
+ tags:
28
+ - deployer
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.3
data/CHANGELOG ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in alego_pdf.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,112 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ alego_pdf (1.0.0)
5
+ factory_bot_rails
6
+ hexapdf
7
+ open-uri
8
+ rspec-rails
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ actionpack (7.0.3.1)
14
+ actionview (= 7.0.3.1)
15
+ activesupport (= 7.0.3.1)
16
+ rack (~> 2.0, >= 2.2.0)
17
+ rack-test (>= 0.6.3)
18
+ rails-dom-testing (~> 2.0)
19
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
20
+ actionview (7.0.3.1)
21
+ activesupport (= 7.0.3.1)
22
+ builder (~> 3.1)
23
+ erubi (~> 1.4)
24
+ rails-dom-testing (~> 2.0)
25
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
26
+ activesupport (7.0.3.1)
27
+ concurrent-ruby (~> 1.0, >= 1.0.2)
28
+ i18n (>= 1.6, < 2)
29
+ minitest (>= 5.1)
30
+ tzinfo (~> 2.0)
31
+ builder (3.2.4)
32
+ cmdparse (3.0.7)
33
+ concurrent-ruby (1.1.10)
34
+ crass (1.0.6)
35
+ date (3.2.2)
36
+ diff-lcs (1.5.0)
37
+ erubi (1.11.0)
38
+ factory_bot (6.2.1)
39
+ activesupport (>= 5.0.0)
40
+ factory_bot_rails (6.2.0)
41
+ factory_bot (~> 6.2.0)
42
+ railties (>= 5.0.0)
43
+ geom2d (0.3.1)
44
+ hexapdf (0.24.2)
45
+ cmdparse (~> 3.0, >= 3.0.3)
46
+ geom2d (~> 0.3)
47
+ i18n (1.12.0)
48
+ concurrent-ruby (~> 1.0)
49
+ loofah (2.18.0)
50
+ crass (~> 1.0.2)
51
+ nokogiri (>= 1.5.9)
52
+ method_source (1.0.0)
53
+ minitest (5.16.3)
54
+ nokogiri (1.13.8-x86_64-darwin)
55
+ racc (~> 1.4)
56
+ open-uri (0.2.0)
57
+ stringio
58
+ time
59
+ uri
60
+ racc (1.6.0)
61
+ rack (2.2.4)
62
+ rack-test (2.0.2)
63
+ rack (>= 1.3)
64
+ rails-dom-testing (2.0.3)
65
+ activesupport (>= 4.2.0)
66
+ nokogiri (>= 1.6)
67
+ rails-html-sanitizer (1.4.3)
68
+ loofah (~> 2.3)
69
+ railties (7.0.3.1)
70
+ actionpack (= 7.0.3.1)
71
+ activesupport (= 7.0.3.1)
72
+ method_source
73
+ rake (>= 12.2)
74
+ thor (~> 1.0)
75
+ zeitwerk (~> 2.5)
76
+ rake (12.3.3)
77
+ rspec-core (3.11.0)
78
+ rspec-support (~> 3.11.0)
79
+ rspec-expectations (3.11.0)
80
+ diff-lcs (>= 1.2.0, < 2.0)
81
+ rspec-support (~> 3.11.0)
82
+ rspec-mocks (3.11.1)
83
+ diff-lcs (>= 1.2.0, < 2.0)
84
+ rspec-support (~> 3.11.0)
85
+ rspec-rails (5.1.2)
86
+ actionpack (>= 5.2)
87
+ activesupport (>= 5.2)
88
+ railties (>= 5.2)
89
+ rspec-core (~> 3.10)
90
+ rspec-expectations (~> 3.10)
91
+ rspec-mocks (~> 3.10)
92
+ rspec-support (~> 3.10)
93
+ rspec-support (3.11.0)
94
+ stringio (3.0.2)
95
+ thor (1.2.1)
96
+ time (0.2.0)
97
+ date
98
+ tzinfo (2.0.5)
99
+ concurrent-ruby (~> 1.0)
100
+ uri (0.11.0)
101
+ zeitwerk (2.6.0)
102
+
103
+ PLATFORMS
104
+ x86_64-darwin-19
105
+
106
+ DEPENDENCIES
107
+ alego_pdf!
108
+ bundler
109
+ rake (~> 12.0)
110
+
111
+ BUNDLED WITH
112
+ 2.2.21
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2018 Rodrigo de Sá
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # AlegoPdf
2
+ Gem responsável por juntar 1 ou mais PDF's no mesmo arquivo
3
+
4
+ ## Instalação
5
+ Adicione esta linha no seu Gemfile:
6
+
7
+ ```ruby
8
+ gem 'alego_pdf'
9
+ ```
10
+
11
+ #### Desenvolvimento
12
+ Para desenvolvimento, use no seu gemfile o seguinte código:
13
+
14
+ ```ruby
15
+ gem 'alego_shared', path: '../alego_shared'
16
+ ```
17
+
18
+ E execute:
19
+
20
+ $ bundle install
21
+
22
+ Ou instale isto você mesmo usando o comando:
23
+
24
+ $ gem install alego_pdf
25
+
26
+ ## Uso
27
+ A gem 'alego_pdf' depende da gem 'hexapdf' para fazer a juntada de arquivos.
28
+ Veja mais sobre a gem 'hexapdf' no Github: https://github.com/gettalong/hexapdf
29
+ A gem 'alego_pdf' faz a leitura dos arquivos via URI e Tempfile e a gem 'hexapdf' junta-os. Veja o exemplo na gem alego_pdf:
30
+
31
+ ```
32
+ def call
33
+ target = HexaPDF::Document.new
34
+
35
+ # filepaths é um array com as url's dos arquivos
36
+ filepaths.each do |filepath|
37
+ uri = URI.parse(filepath).open(&:read) # leitura do arquivo
38
+ tempfile = Tempfile.new
39
+ tempfile.write(uri.force_encoding('UTF-8')) # escrita no arquivo Tempfile
40
+ tempfile.close # fecha o arquivo
41
+
42
+ pdf = HexaPDF::Document.open(tempfile)
43
+ pdf.pages.each { |page| target.pages << target.import(page) } # junta os arquivos em um novo HexaPDF
44
+ end
45
+
46
+ target.write(filename, optimize: true)
47
+ end
48
+ ```
49
+
50
+ Após instalar a gem 'alego_pdf', deve buscar a URL dos arquivos e passar estas URL's como parâmetro. Veja o exemplo a seguir:
51
+
52
+ ```
53
+ def merge_arquivos
54
+ # O atributo "arquivo_url" deve ser a url onde o arquivo está armazenado.
55
+ # Exemplo: https://spiderminio-dev.al.go.leg.br:9000/portal-rails/uploads/transparencia/organograma/arquivo/1/Manual_do_stimuus_-_6_Instalando_o_esti%CC%81mulo_no_seu_aplicativo.pdf?X-Amz-Expires=600&X-Amz-Date=20220909T165125Z&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=BUjuSkJYyf0wzRmG%2F20220909%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-SignedHeaders=host&X-Amz-Signature=791bbc7db8aac7bd0c61dc7a60d04ec3d39f6d63d60f9d971383c97b55e9815a
56
+
57
+ filepaths = Model.order('id desc').map(&:arquivo_url)
58
+
59
+ respond_to do |format|
60
+ format.html
61
+ format.pdf do
62
+ filename = 'tmp/arquivos.pdf'
63
+ AlegoPdf::Merging.new(filepaths, filename).call
64
+
65
+ pdf_filename = File.join(Rails.root, filename)
66
+ send_file(pdf_filename, filename: 'merge-arquivos.pdf', type: 'application/pdf')
67
+ end
68
+ end
69
+ end
70
+ ```
71
+
72
+ ## Contribuição
73
+
74
+ Relatórios de bugs e pull requests são bem-vindos no GitLab em https://gitlab.al.go.leg.br/sistemas/gem/alego_pdf.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task default: :spec
data/alego_pdf.gemspec ADDED
@@ -0,0 +1,41 @@
1
+ require_relative 'lib/alego_pdf/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'alego_pdf'
5
+ spec.version = AlegoPdf::VERSION
6
+ spec.authors = ['Rodrigo de Sá']
7
+ spec.email = ['rodrigo.sa@al.go.leg.br']
8
+ spec.homepage = 'https://gitlab.al.go.leg.br/gem/alego_pdf'
9
+ spec.summary = 'Summary of AlegoPdf.'
10
+ spec.description = 'Description of AlegoPdf.'
11
+ spec.license = 'MIT'
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
13
+
14
+ begin
15
+ s.metadata['allowed_push_host'] = ENV['GEM_SERVER'] || ''
16
+ rescue StandardError
17
+ end
18
+
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ # spec.metadata['source_code_uri'] = 'TODO: Put your gems public repo URL here.'
21
+ # spec.metadata['changelog_uri'] = 'TODO: Put your gems CHANGELOG.md URL here.'
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ end
28
+
29
+ spec.bindir = 'exe'
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ['lib']
32
+
33
+ spec.add_development_dependency 'bundler' # , '~> 1.2', '>= 1.2.0'
34
+ spec.add_development_dependency 'rake' # , "~> 11.2.2"
35
+
36
+ spec.add_runtime_dependency 'factory_bot_rails' # , "~> 4.4.1"
37
+
38
+ spec.add_dependency 'hexapdf' # , "~> 0.24.0"
39
+ spec.add_dependency 'open-uri' # , "~> 0.2.0"
40
+ spec.add_dependency 'rspec-rails' # , "~> 3.0.0.beta"
41
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'alego_pdf'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ require 'hexapdf'
2
+ require 'open-uri'
3
+
4
+ module AlegoPdf
5
+ class Merging
6
+ attr_reader :filepaths, :filename
7
+
8
+ def initialize(filepaths, filename)
9
+ @filepaths = filepaths
10
+ @filename = filename
11
+ end
12
+
13
+ def call
14
+ target = HexaPDF::Document.new
15
+
16
+ filepaths.each do |filepath|
17
+ uri = URI.parse(filepath).open(&:read)
18
+ tempfile = Tempfile.new
19
+ tempfile.write(uri.force_encoding('UTF-8'))
20
+ tempfile.close
21
+
22
+ pdf = HexaPDF::Document.open(tempfile)
23
+ pdf.pages.each { |page| target.pages << target.import(page) }
24
+ end
25
+
26
+ target.write(filename, optimize: true)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module AlegoPdf
2
+ VERSION = '1.0.0'
3
+ end
data/lib/alego_pdf.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'alego_pdf/version'
2
+ require 'alego_pdf/merging'
3
+
4
+ require 'hexapdf'
5
+ require 'open-uri'
6
+ require 'factory_bot_rails'
7
+
8
+ module AlegoPdf
9
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alego_pdf
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Rodrigo de Sá
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-09-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: factory_bot_rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: hexapdf
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: open-uri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Description of AlegoPdf.
98
+ email:
99
+ - rodrigo.sa@al.go.leg.br
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".gitlab-ci.yml"
106
+ - ".ruby-version"
107
+ - CHANGELOG
108
+ - Gemfile
109
+ - Gemfile.lock
110
+ - MIT-LICENSE
111
+ - README.md
112
+ - Rakefile
113
+ - alego_pdf.gemspec
114
+ - bin/console
115
+ - bin/setup
116
+ - lib/alego_pdf.rb
117
+ - lib/alego_pdf/merging.rb
118
+ - lib/alego_pdf/version.rb
119
+ homepage: https://gitlab.al.go.leg.br/gem/alego_pdf
120
+ licenses:
121
+ - MIT
122
+ metadata:
123
+ homepage_uri: https://gitlab.al.go.leg.br/gem/alego_pdf
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: 2.5.0
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubygems_version: 3.1.6
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Summary of AlegoPdf.
143
+ test_files: []