rails_pdf 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff4ea451dd985532dd06ad6f39077f72d2548f079e7a6b08137d9188af7d6093
4
- data.tar.gz: c5e975d26cbd6325574ddb882f28d123abb2805f2da34c9426d1632427298fbf
3
+ metadata.gz: a742b7784d9de2ff96b957b3d56b2e581f50a9f3391e671a42a3b47ebb9af05e
4
+ data.tar.gz: 759a0f0cacce237ce67b4e90fbcfd30b108435d8eabd4ee86cc32a8b55526563
5
5
  SHA512:
6
- metadata.gz: ea72f4697bd60be620899bcd99918563d6fcb88d1ba3c715907e74745d0ef6aeff4e6715e16d8c978cb304eecdef22eff98a5a88de5208bdfd4893eb4f6a8f6f
7
- data.tar.gz: dc7dff507f0cc393f73a85b712f0c750ceb06211d55157ee60005100f9633c30c45112d9b8d976d35e6ae8425c54bec24dfc16373d34e6e64a7f4ee165093e3f
6
+ metadata.gz: 2adec1532786547cf080cea01439344dbb4cdb86c0820b17aaf3b2958c61b01247e85601c16201e7056047eec2752db844d646bfeb4a66ca08a5a955ba2b073d
7
+ data.tar.gz: 4e075625279ddfb16639f4eae52aeecbdd497697b768b4036f6061ea3977101684ab3e0366e792105a950815075561a80427da62850764e9cde6bc842b70f2d8
data/README.md CHANGED
@@ -19,7 +19,7 @@ It's uses [ReLaXedJS](https://github.com/RelaxedJS/ReLaXed) tool, which is wrapp
19
19
 
20
20
  The idea of this gem is to separate logic of PDF creation from regular Rails views/controllers. Make it independent and easy to maintain.
21
21
 
22
- ## Template starters
22
+ ## Template starters (build-it with generator)
23
23
 
24
24
  _If you want to contribute and add more templates - it' very easy to do. See #Templates section of this doc._
25
25
 
@@ -44,6 +44,20 @@ _If you want to contribute and add more templates - it' very easy to do. See #Te
44
44
  Template: <a href="https://github.com/igorkasyanchuk/rails_pdf/blob/master/lib/generators/rails_pdf/templates/chart1/chart.pug.erb">chart1</a>
45
45
  </td>
46
46
  </tr>
47
+ <tr>
48
+ <td width="25%">
49
+ <a href="https://github.com/igorkasyanchuk/rails_pdf/blob/master/docs/report_4.png">
50
+ <img src="https://github.com/igorkasyanchuk/rails_pdf/blob/master/docs/report_4_thumb.png?raw=true" />
51
+ </a>
52
+ Template: <a href="https://github.com/igorkasyanchuk/rails_pdf/blob/master/lib/generators/rails_pdf/templates/products/index.pug.erb">products</a>
53
+ </td>
54
+ <td width="25%">
55
+ </td>
56
+ <td width="25%">
57
+ </td>
58
+ <td width="25%">
59
+ </td>
60
+ </tr>
47
61
  </table>
48
62
 
49
63
  ## Usage
@@ -97,6 +111,20 @@ RailsPDF.template("report/chart.pug.erb").render_to_tempfile('report.pdf') # Tem
97
111
 
98
112
  With ERB files you can use App code (like models, etc). For example you can iterate over @users and output in PDF.
99
113
 
114
+ ### JS/CSS/Images
115
+
116
+ Basically you need to put an absolute path to asset or remote URL (for example on CDN. but local files works faster).
117
+
118
+ ```slim
119
+ style
120
+ include:scss <%= Rails.root %>/app/pdf/report/stylesheets/invoice.scss
121
+
122
+ img(src="<%= Rails.root %>/app/pdf/shared/images/rails_pdf.png")
123
+
124
+ script(src='<%= Rails.root %>/app/pdf/shared/javascripts/Chart.bundle.min.js')
125
+ ```
126
+
127
+
100
128
  ## Installation
101
129
 
102
130
  Installation of gem is very simple, it's just requires one additional step to install RelaxedJS tool which is using Chrome headless.
@@ -134,13 +162,13 @@ $ bundle
134
162
  - if you are using bootstrap and you want to use columns - include bootstrap.print.css and use styles from it.
135
163
  - if you are using Charts.js and you want to clear and readable text put in options: `devicePixelRatio: 3,`
136
164
  - you can define size of page using in SCSS:
137
- ```
165
+ ```scss
138
166
  // A4
139
167
  $page-width: 8.27in;
140
168
  $page-height: 11.69in;
141
169
  ```
142
170
  - if you want to add header/footer (sample: lib/generators/rails_pdf/templates/simple_invoice/invoice.pug.erb)
143
- ```
171
+ ```pug
144
172
  h1 My document
145
173
  p some paragraph
146
174
 
@@ -184,6 +212,7 @@ $ bundle
184
212
  - check support for older Rails (should work but check is needed)
185
213
  - check embedding in emails
186
214
  - maybe add ability to save webpage by url or HTML snippet to PDF, e.g. `RailsPDF.url("http://google.com").render_to_file("google.com.pdf")`
215
+ - better gem logo :)
187
216
 
188
217
  ## Production
189
218
 
@@ -1,7 +1,7 @@
1
1
  class RailsPdfGenerator < Rails::Generators::NamedBase
2
2
  source_root File.expand_path('templates', __dir__)
3
3
 
4
- TYPES = ["basic_invoice", "chart1", "simple_invoice", "new"]
4
+ TYPES = ["basic_invoice", "chart1", "simple_invoice", "new", "products"]
5
5
 
6
6
  def create_helper_file
7
7
  report = args[0]
@@ -27,6 +27,8 @@ class RailsPdfGenerator < Rails::Generators::NamedBase
27
27
  gsub_file "app/pdf/#{report}/invoice.pug.erb", '<%= report %>', report
28
28
  when 'chart1'
29
29
  gsub_file "app/pdf/#{report}/chart.pug.erb", '<%= report %>', report
30
+ when 'products'
31
+ gsub_file "app/pdf/#{report}/index.pug.erb", '<%= report %>', report
30
32
  end
31
33
 
32
34
  directory "mixins", "app/pdf/mixins"
@@ -0,0 +1,53 @@
1
+ link(href="<%= Rails.root %>/app/pdf/shared/stylesheets/font-awesome/style.css" rel="stylesheet")
2
+ link(href="<%= Rails.root %>/app/pdf/shared/stylesheets/bootstrap/bootstrap.min.css" rel="stylesheet")
3
+ link(href="<%= Rails.root %>/app/pdf/shared/stylesheets/bootstrap/bootstrap.print.css" rel="stylesheet")
4
+ link(href="<%= Rails.root %>/app/pdf/<%= report %>/stylesheets/template.css" rel="stylesheet")
5
+
6
+ .container
7
+ .row
8
+ .col-md-12
9
+ h1 Sales Report 2019
10
+ p Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam velit urna, tincidunt vel mauris sit amet, dictum fermentum diam. Integer dignissim lorem ante, eget ultrices libero tincidunt at. Integer ut elit volutpat mauris suscipit tempus eget a ipsum. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam mattis nisl vel tellus bibendum, eu vulputate ligula semper. Nulla varius nulla sit amet nisl rhoncus dapibus.
11
+ table.table.table-bordered
12
+ thead
13
+ tr
14
+ th SKU
15
+ th Title
16
+ th East
17
+ th West
18
+ th North
19
+ th South
20
+ th Estimated $
21
+ tbody
22
+ <% 200.times do %>
23
+ tr
24
+ td <%= link_to rand(1_000_000).to_s.rjust(8, "0"), '#' %>
25
+ td <%= ['Phone', 'Computer', 'Laptop', 'PC', 'Beer'].sample %>
26
+ td.text-success <%= rand(100) %>
27
+ td.text-success <%= rand(100) %>
28
+ td.text-danger <%= rand(100) %>
29
+ td.text-danger <%= rand(100) %>
30
+ td <%= number_to_currency rand(10000), precision: 0 %>
31
+ <% end %>
32
+
33
+
34
+ template#page-footer
35
+ style(type='text/css').
36
+ .pdfheader {
37
+ font-size: 9px;
38
+ color: #555;
39
+ font-family: Helvetica;
40
+ font-weight: normal;
41
+ width: 1000px;
42
+ border-top: 1px solid #ccc;
43
+ margin-left: 10%;
44
+ margin-right: 10%;
45
+ padding-top: 1mm;
46
+ margin-bottom: -1mm;
47
+ text-align: center;
48
+ }
49
+ .pageNumber {
50
+ color: red;
51
+ }
52
+
53
+ .pdfheader Page #[span.pageNumber] / #[span.totalPages]
@@ -0,0 +1,7 @@
1
+ @page {
2
+ size: 8.27in 11.69in;
3
+ -relaxed-page-width: 8.27in;
4
+ -relaxed-page-height: 11.69in;
5
+ margin: 0.5in 0.2in;
6
+ margin-bottom: 1in;
7
+ }
@@ -1,3 +1,3 @@
1
1
  module RailsPDF
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_pdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Kasyanchuk
@@ -73,6 +73,8 @@ files:
73
73
  - lib/generators/rails_pdf/templates/layouts/application.pug.erb
74
74
  - lib/generators/rails_pdf/templates/mixins/mixin.pug
75
75
  - lib/generators/rails_pdf/templates/new/file.pug.erb
76
+ - lib/generators/rails_pdf/templates/products/index.pug.erb
77
+ - lib/generators/rails_pdf/templates/products/stylesheets/template.css
76
78
  - lib/generators/rails_pdf/templates/shared/images/rails_pdf.png
77
79
  - lib/generators/rails_pdf/templates/shared/javascripts/Chart.bundle.min.js
78
80
  - lib/generators/rails_pdf/templates/shared/stylesheets/bootstrap/bootstrap.min.css
@@ -120,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
122
  - !ruby/object:Gem::Version
121
123
  version: '0'
122
124
  requirements: []
123
- rubygems_version: 3.0.1
125
+ rubygems_version: 3.0.2
124
126
  signing_key:
125
127
  specification_version: 4
126
128
  summary: Reliable way to generate PDF files of any complexity.