acts_as_pdf 0.1.1

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
+ SHA1:
3
+ metadata.gz: 8097fa288bd2b41f23f8f0a86893384c646055a4
4
+ data.tar.gz: 164a123197257f6cc6c86cd70648aba91d6bf823
5
+ SHA512:
6
+ metadata.gz: 84e077731a89b240b753f198b76072896d242864d02d3e10718868b28f5a9d8cb5fc0132fad0f4c76a9cc4efc5bb3d6ba403b2c34acde798f79fe27878f34742
7
+ data.tar.gz: d14abcbade8ba83e3ba6227e83d99731b1958384e80687cd092c05b9e8476a750d750f644043f0863f33dbba135cbd9319b4aee91267d4c3eadfb346b9f1563a
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 oren
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
+ # ActsAsPdf
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 'acts_as_pdf'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install acts_as_pdf
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](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,33 @@
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 = 'ActsAsPdf'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ require 'bundler/gem_tasks'
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'test'
28
+ t.pattern = 'test/**/*_test.rb'
29
+ t.verbose = false
30
+ end
31
+
32
+
33
+ task default: :test
@@ -0,0 +1,3 @@
1
+ module ActsAsPdf
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,51 @@
1
+ module ActsAsPdf
2
+ extend ActiveSupport::Concern
3
+
4
+ @@pdf_options = Hash.new { |hash, key| hash[key] = Hash.new { |hash, key| hash[key] = Hash.new } }
5
+ cattr_accessor :pdf_options
6
+
7
+ def md_pdf args = []
8
+ hash = self.send(ActsAsPdf.pdf_options[self.class.to_s.downcase][:opts][:method], *args) rescue {}
9
+ output = md_to_pdf
10
+
11
+ font_size = ActsAsPdf.pdf_options[self.class.to_s.downcase][:opts][:font_size] || '10'
12
+
13
+ hash.each { |k, v| output.gsub!(k.to_s, v.to_s) }
14
+ '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">' + "<style type = 'text/css'> body { font-family: 'Futura'; font-size: #{font_size}; line-height:180%; }</style>" + output
15
+ end
16
+
17
+ def md_to_pdf
18
+ pipeline = ::HTML::Pipeline.new [
19
+ ::HTML::Pipeline::MarkdownFilter
20
+ ]
21
+ result = pipeline.call self.send(ActsAsPdf.pdf_options[self.class.to_s.downcase][:field]).gsub(/[\n|^ ][ |\t]+/){ |m| m.gsub(/ |\t/, '&nbsp;') }.gsub("\n", "<br>")
22
+ result[:output].to_s
23
+ end
24
+
25
+ def preview params
26
+ return self unless params[:preview]
27
+
28
+ model_name = self.class.to_s.downcase.to_sym
29
+ field_name = ActsAsPdf.pdf_options[self.class.to_s.downcase][:field]
30
+
31
+ model = self.class.new
32
+ model.send("#{field_name}=", params[model_name][field_name])
33
+ model
34
+ end
35
+
36
+ def generate_pdf params, args = []
37
+ convention = self.preview params
38
+ WickedPdf.new.pdf_from_string(convention.md_pdf(args))
39
+ end
40
+
41
+ module ClassMethods
42
+
43
+ def acts_as_pdf field, opts = {}
44
+ ActsAsPdf.pdf_options[self.to_s.downcase][:opts] = opts
45
+ ActsAsPdf.pdf_options[self.to_s.downcase][:field] = field
46
+ end
47
+
48
+ end
49
+ end
50
+
51
+ ActiveRecord::Base.send(:include, ActsAsPdf)
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :acts_as_pdf do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acts_as_pdf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Oren Carta-Lag
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-09-15 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Description of ActsAsPdf.
14
+ email:
15
+ - oren.carta-lag@hotmail.fr
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - MIT-LICENSE
21
+ - README.md
22
+ - Rakefile
23
+ - lib/acts_as_pdf.rb
24
+ - lib/acts_as_pdf/version.rb
25
+ - lib/tasks/acts_as_pdf_tasks.rake
26
+ homepage: http://rubygems.org/gems/acts_as_pdf
27
+ licenses:
28
+ - MIT
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 2.6.12
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: A simple markdown to pdf gem
50
+ test_files: []