thecore_download_documents 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 87ed58e84808a0fc8352525fdc1804a93af6f814f72e12bad5ec3b9444d7e1fb
4
+ data.tar.gz: 41f4f03b4542ecafe1bf9334df5c9d0d756833895722e2396d04e9d062a52e9b
5
+ SHA512:
6
+ metadata.gz: 0aff66c1b5607b0526babd4b45be81d7e7823fa2d7f8718d5efacccb96fe071b49555a63ec9e9982eda78c166863192a4f23d71e8cabece0587ac1f6dc9b540e
7
+ data.tar.gz: 6961139180317a745c93f0273d9f1eb49083ca48735baed8c6628ed097bb2fed9cf666f0d4e742bc0447316d4213f76c99b70ca5c7bd457003d56e95e7d4ce1f
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2019 Gabriele Tassoni
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,28 @@
1
+ # ThecoreDownloadDocuments
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'thecore_download_documents'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install thecore_download_documents
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'ThecoreDownloadDocuments'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ require 'bundler/gem_tasks'
18
+
19
+ require 'rake/testtask'
20
+
21
+ Rake::TestTask.new(:test) do |t|
22
+ t.libs << 'test'
23
+ t.pattern = 'test/**/*_test.rb'
24
+ t.verbose = false
25
+ end
26
+
27
+ task default: :test
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :thecore_download_documents do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,54 @@
1
+ require "thecore_download_documents/railtie"
2
+
3
+ require 'thecore'
4
+ require "prawn"
5
+ require "prawn/table"
6
+ require 'csv'
7
+ module ThecoreDownloadDocuments
8
+ # Your code goes here...
9
+ def self.pdf_table header, footer, rows, table_headers, filename
10
+ pdf = Prawn::Document.new page_layout: :landscape, page_size: "A4"
11
+ pdf.repeat :all do
12
+ # Header
13
+ pdf.bounding_box [pdf.bounds.left, pdf.bounds.top], width: pdf.bounds.width do
14
+ pdf.float do
15
+ pdf.text (header[:left] || ""), size: 8, align: :left
16
+ end
17
+ pdf.float do
18
+ pdf.text (header[:center] || ""), size: 8, align: :center
19
+ end
20
+ pdf.text (header[:right] || ""), size: 8, align: :right
21
+ end
22
+ # Footer
23
+ pdf.bounding_box [pdf.bounds.left, pdf.bounds.bottom + 18], width: pdf.bounds.width do
24
+ pdf.float do
25
+ pdf.text (footer[:left] || ""), size: 8, align: :left
26
+ end
27
+ pdf.float do
28
+ pdf.text (footer[:center] || ""), size: 8, align: :center
29
+ end
30
+ pdf.text (footer[:right] || ""), size: 8, align: :right
31
+ end
32
+ end
33
+
34
+ # Create another box that is placed on the page after our footer is
35
+ pdf.bounding_box [pdf.bounds.left, pdf.bounds.top-8], width: pdf.bounds.width, height: pdf.bounds.height - 16 do
36
+ #Generate the rest of your PDF content here
37
+ pdf.table rows.unshift(table_headers), header: true do |table| table.row(0).font_style = :bold end
38
+ end
39
+
40
+ return pdf.render, {filename: "#{filename}.pdf", type: "application/pdf"}
41
+ end
42
+
43
+ def self.csv_table rows, table_headers, filename
44
+ csv = CSV.generate do |row|
45
+ row << table_headers
46
+ row << ["another", "row"]
47
+ rows.each do |r|
48
+ row << r.values
49
+ end
50
+ end
51
+
52
+ return csv, {filename: "#{filename}.csv", type: "text/csv"}
53
+ end
54
+ end
@@ -0,0 +1,4 @@
1
+ module ThecoreDownloadDocuments
2
+ class Railtie < ::Rails::Railtie
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module ThecoreDownloadDocuments
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thecore_download_documents
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gabriele Tassoni
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-09-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Some helper methods to create pdfs and csvs ina a simple, tabellar notation.
14
+ for PDF you can also add an header and a footer to each page.
15
+ email:
16
+ - gabriele.tassoni@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - MIT-LICENSE
22
+ - README.md
23
+ - Rakefile
24
+ - lib/tasks/thecore_download_documents_tasks.rake
25
+ - lib/thecore_download_documents.rb
26
+ - lib/thecore_download_documents/railtie.rb
27
+ - lib/thecore_download_documents/version.rb
28
+ homepage: https://github.com/gabrieletassoni/thecore_download_documents
29
+ licenses:
30
+ - MIT
31
+ metadata: {}
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubygems_version: 3.0.6
48
+ signing_key:
49
+ specification_version: 4
50
+ summary: Common methods to help exporting to csv, pdf documents.
51
+ test_files: []