acts_as_pdf 0.1.8 → 0.2.0

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
  SHA1:
3
- metadata.gz: efbe79bd33630df155fe1b5bcfd89a8a391cbba8
4
- data.tar.gz: cebab696e850ffdd6d6639223068a98806a5bdc6
3
+ metadata.gz: aed2d61006356c5a5f5c6d0da19e6f21ca9fc9c4
4
+ data.tar.gz: b0d5565e985ca90ae57ad4c4a61bbd52f713a7de
5
5
  SHA512:
6
- metadata.gz: a13f463951598559bac7fe74567d4b8645e42efc4c54f1a316dd259cf0aefc4c3417d39af7a7c232b7f40b10bcc790b9bb76aee856bf5730ac81c2d1b39ea63f
7
- data.tar.gz: 75ffa3127511b2105a5c01dd51192c858d82e7c49ea3646c6b032714875ed24b2f9b7ffe32d9adb9217d2077588ef8b99843ca8ee4b7db4832403b52465f6db8
6
+ metadata.gz: d309aa8dfa569a4bde034e1a46cce105097af7573765d9e085a2efd9824f416dfd27cfe74a2064d66f84eaaaf491dea8c3ab2dbace44d7fb2555c2c210f4dcb3
7
+ data.tar.gz: 327879b0182f060b69d799ba79cf832b3a8029e3de8792584e69e30336d0311b01527e9924cb9916d4ce8d63e6146002e73894904e9211a05d670db83884b414
data/README.md CHANGED
@@ -29,13 +29,19 @@ class Bill < ApplicationRecord
29
29
 
30
30
  def generate_bill user, company, obj # has many arguments or no one
31
31
  {
32
- "//COMPANY_NAME//": company.company_name,
33
- "//COMPANY_FULL_ADDRESS//": company.company_full_address,
34
- "//COMPANY_USER_POST//": company.company_user_post,
35
- "//USER_FIRST_NAME//": user.first_name,
36
- "//USER_LAST_NAME//": user.last_name,
37
- "//OBJECT_PRICE//": obj.salary,
38
- "//OBJECT_CURRENCY//": obj.currency
32
+ variables: {
33
+ "//COMPANY_NAME//": company.company_name,
34
+ "//COMPANY_FULL_ADDRESS//": company.company_full_address,
35
+ "//COMPANY_USER_POST//": company.company_user_post,
36
+ "//USER_FIRST_NAME//": user.first_name,
37
+ "//USER_LAST_NAME//": user.last_name,
38
+ "//OBJECT_PRICE//": obj.salary,
39
+ "//OBJECT_CURRENCY//": obj.currency
40
+ },
41
+ options: { # optional, only if you need footer or header
42
+ header: { font_size: 16, center: 'header' }
43
+ footer: { font_size: 10, center: 'footer'}
44
+ }
39
45
  }
40
46
  end
41
47
 
@@ -80,12 +86,12 @@ Now you can use it at runtime:
80
86
 
81
87
  **users_controller.rb**
82
88
  ```ruby
83
- class BillsController < ApplicationController
89
+ class UsersController < ApplicationController
84
90
 
85
91
  def after_buying_something
86
92
  bill = Bill.find(param[:bill_id])
87
93
  product = Product.find(param[:product_id])
88
- @pdf = bill.generate_bill(@user, product.company, product)
94
+ @pdf = bill.generate_pdf(params, [@user, product.company, product])
89
95
  end
90
96
  end
91
97
  ```
@@ -6,8 +6,12 @@ module ActsAsPdf
6
6
  @@pdf_options = {}
7
7
  cattr_accessor :pdf_options
8
8
 
9
+ def get_hash args
10
+ @hash ||= (self.send(ActsAsPdf.pdf_options[self.class.to_s.downcase][:opts][:method], *args) rescue {})
11
+ end
12
+
9
13
  def md_pdf args = []
10
- hash = self.send(ActsAsPdf.pdf_options[self.class.to_s.downcase][:opts][:method], *args) rescue {}
14
+ get_hash args
11
15
  output = md_to_pdf
12
16
 
13
17
  opts = ActsAsPdf.pdf_options[self.class.to_s.downcase][:opts]
@@ -15,7 +19,7 @@ module ActsAsPdf
15
19
  font_size = opts[:font_size] || '10'
16
20
  line_height = opts[:line_height] || '180%'
17
21
 
18
- hash.each { |k, v| output.gsub!(k.to_s, v.to_s) }
22
+ @hash[:variables].each { |k, v| output.gsub!(k.to_s, v.to_s) } if @hash.keys.include? :variables
19
23
  "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'> <style type = 'text/css'> body { font-family: #{font_name}; font-size: #{font_size}; line-height: #{line_height}; }</style> " + output
20
24
  end
21
25
 
@@ -43,8 +47,11 @@ module ActsAsPdf
43
47
  end
44
48
 
45
49
  def generate_pdf params, args = []
50
+ get_hash args
46
51
  model = self.preview params
47
- WickedPdf.new.pdf_from_string(model.md_pdf(args), ActsAsPdf.pdf_options[self.class.to_s.downcase][:opts])
52
+ opts = ActsAsPdf.pdf_options[self.class.to_s.downcase][:opts]
53
+ @hash[:options] = {} unless @hash[:options].present?
54
+ WickedPdf.new.pdf_from_string(model.md_pdf(args), opts.merge(@hash[:options]))
48
55
  end
49
56
 
50
57
  module ClassMethods
@@ -1,3 +1,3 @@
1
1
  module ActsAsPdf
2
- VERSION = '0.1.8'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -0,0 +1,3 @@
1
+ module ActsAsPdf
2
+ VERSION = '0.1.7'
3
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_pdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oren Carta-Lag
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-17 00:00:00.000000000 Z
11
+ date: 2018-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: html-pipeline
@@ -74,6 +74,7 @@ extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
76
  - lib/acts_as_pdf/version.rb
77
+ - lib/acts_as_pdf/version.rb~
77
78
  - lib/acts_as_pdf.rb
78
79
  - lib/preview_pdf.rb
79
80
  - lib/tasks/acts_as_pdf_tasks.rake