aptible-prawn-helpers 0.0.1

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
+ SHA1:
3
+ metadata.gz: 6fcf4c0f2c0766f4bac83d94c32776be5f4cf5d4
4
+ data.tar.gz: 97a1d03444899f1085d6eb70285aa24d01b4db9b
5
+ SHA512:
6
+ metadata.gz: 4f72cfd5cda59c3a65a7194ec6689b20dfb618617d3a0b4bbc282870f55efb2d4ffed6a4e565ed0068fb68f057b0a32b8240123ddaf6430fc5b2139e3839154a
7
+ data.tar.gz: a058a66dd2c7f06aa19f348235328a030a95ea30ae0394a8754725e9de0f7d68b2731aedf559083a5f33bb48e38baa825ec1ea207dbb6bd28dd708b7503855bf
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ rvm:
2
+ - 2.0.0
3
+ - jruby
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in aptible-auth.gemspec
4
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Aptible, Inc.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # ![](https://raw.github.com/aptible/straptible/master/lib/straptible/rails/templates/public.api/icon-60px.png) Aptible::DocumentHelpers
2
+
3
+ Include `Aptible::DocumentHelpers` in your `Prawn::Document` for easy Aptible-styled PDF generation.
4
+
5
+ # Installation
6
+
7
+ Add `aptible-prawn-helpers` to your Gemfile
8
+
9
+ ```
10
+ gem 'aptible-prawn-helpers'
11
+
12
+ ```
13
+ and install the gem with `bundle install`.
14
+
15
+ # Usage
16
+
17
+ To load the helpers, just include the module in your `Prawn::Document` definition:
18
+
19
+ ```
20
+ class AptibleDocument < Prawn::Document
21
+ include Aptible::DocumentHelpers
22
+ end
23
+ ```
24
+
25
+ [<img src="https://s.gravatar.com/avatar/9b58236204e844e3181e43e05ddb0809?s=60" style="border-radius: 50%;" alt="@sandersonet" />](https://github.com/sandersonet)
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'aptible/tasks'
4
+ Aptible::Tasks.load_tasks
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'English'
6
+ require 'aptible/document_helpers/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'aptible-prawn-helpers'
10
+ spec.version = Aptible::DocumentHelpers::VERSION
11
+ spec.authors = ['Skylar Anderson', 'Chas Ballew']
12
+ spec.email = ['skylar@aptible.com', 'chas@aptible.com']
13
+ spec.description = 'Prawn Document Helpers'
14
+ spec.summary = 'Prawn Document Helpers'
15
+ spec.homepage = 'https://github.com/aptible/aptible-prawn-helpers'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files`.split($RS)
19
+ spec.test_files = spec.files.grep(/^spec\//)
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.3'
23
+ spec.add_development_dependency 'aptible-tasks', '>= 0.2.0'
24
+ spec.add_development_dependency 'rake'
25
+ spec.add_development_dependency 'rspec', '~> 2.0'
26
+ spec.add_development_dependency 'pry'
27
+ end
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,18 @@
1
+ module Aptible
2
+ module DocumentHelpers
3
+ module ChangeLayoutFormat
4
+ def change_layout_format(format)
5
+ case format
6
+ when :portrait
7
+ start_new_page(layout: :portrait)
8
+ on_page_create
9
+ when :landscape
10
+ start_new_page(layout: :landscape)
11
+ # push the current page
12
+ @landscape_pages.push(page_number)
13
+ # push additional pages in the watermark hook
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,29 @@
1
+ module Aptible
2
+ module DocumentHelpers
3
+ module FontLoader
4
+ # rubocop:disable MethodLength
5
+ def load_fonts
6
+ font_families.update(
7
+ 'Georgia' => {
8
+ normal: 'data/fonts/Georgia.ttf',
9
+ italic: 'data/fonts/Georgia Italic.ttf',
10
+ bold: 'data/fonts/Georgia Bold.ttf',
11
+ bold_italic: 'data/fonts/Georgia Bold Italic.ttf'
12
+ }
13
+ )
14
+ font_families.update(
15
+ 'Proxima Nova' => {
16
+ normal: 'data/fonts/proxima_nova.ttf',
17
+ italic: 'data/fonts/proxima_nova_italic.ttf',
18
+ light: 'data/fonts/proxima_nova_light.ttf',
19
+ light_italic: 'data/fonts/proxima_nova_light_italic.ttf',
20
+ bold: 'data/fonts/proxima_nova_bold.ttf',
21
+ bold_italic: 'data/fonts/proxima_nova_bold_italic.ttf'
22
+ }
23
+ )
24
+ font 'Georgia'
25
+ end
26
+ # rubocop:enable MethodLength
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,23 @@
1
+ module Aptible
2
+ module DocumentHelpers
3
+ module Footer
4
+ # rubocop:disable MethodLength
5
+ def footer
6
+ options = {
7
+ at: [0, -10],
8
+ color: '999999',
9
+ size: 10,
10
+ page_filter: ->(page) { page != 1 }
11
+ }
12
+ font 'Proxima Nova'
13
+ number_pages "#{@document.organization_name}", options
14
+ number_pages 'NIST SP 800-30 Rev 1 Risk Analysis',
15
+ options.merge(at: [0, -22])
16
+ number_pages 'Prepared with assistance from Aptible',
17
+ options.merge(at: [0, -34])
18
+ font 'Georgia'
19
+ end
20
+ # rubocop:enable MethodLength
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,48 @@
1
+ module Aptible
2
+ module DocumentHelpers
3
+ module Header
4
+ # rubocop:disable MethodLength
5
+ def header(title, options = {})
6
+ header_box do
7
+ formatted_text [{
8
+ text: title,
9
+ color: '003366',
10
+ size: 30,
11
+ styles: [:bold],
12
+ font: 'Proxima Nova'
13
+ }],
14
+ valign: :center
15
+ add_dest title, dest_fit
16
+ end
17
+
18
+ closed = options[:closed] || false
19
+ outline.define do
20
+ section(title, destination: page_number, closed: closed) do
21
+ end
22
+ end
23
+ end
24
+
25
+ def header_box(&block)
26
+ box_margin = 36
27
+ background_color = 'eef6fe'
28
+ reset_default_font_color = '333333'
29
+
30
+ bounding_box([-bounds.absolute_left, cursor + 50],
31
+ width: bounds.absolute_left + bounds.absolute_right,
32
+ height: box_margin * 2) do
33
+ fill_color background_color
34
+ fill_rectangle(
35
+ [bounds.left, bounds.top],
36
+ bounds.right,
37
+ bounds.top - bounds.bottom
38
+ )
39
+ fill_color reset_default_font_color
40
+ # pass the block and render the text
41
+ indent(50, &block)
42
+ end
43
+ # move_down(20)
44
+ end
45
+ # rubocop:enable MethodLength
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,43 @@
1
+ module Aptible
2
+ module DocumentHelpers
3
+ module PageNumbers
4
+ # rubocop:disable MethodLength
5
+ def page_numbers
6
+ # Number portrait pages pages
7
+ font 'Proxima Nova'
8
+ string = 'Page <page>'
9
+ options = {
10
+ at: [bounds.right - 150, -22],
11
+ width: 150,
12
+ align: :right,
13
+ start_count_at: 1,
14
+ size: 10,
15
+ color: '999999',
16
+ page_filter: lambda do |page|
17
+ (!page.in?(1..2)) &&
18
+ (!page.in?(@landscape_pages))
19
+ end
20
+ }
21
+ number_pages string, options
22
+
23
+ return unless @landscape_pages.any?
24
+
25
+ # Number landscape pages
26
+ options = {
27
+ at: [bounds.right + 25, -22],
28
+ width: 150,
29
+ align: :right,
30
+ start_count_at: @landscape_pages[0] - 2,
31
+ size: 10,
32
+ color: '999999',
33
+ page_filter: lambda do |page|
34
+ page.in?(@landscape_pages)
35
+ end
36
+ }
37
+ number_pages string, options
38
+ font 'Georgia'
39
+ end
40
+ # rubocop:enable MethodLength
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,34 @@
1
+ module Aptible
2
+ module DocumentHelpers
3
+ module PrettyTable
4
+ # rubocop:disable MethodLength
5
+ def pretty_table(data, col_widths, options = {})
6
+ font_size 11
7
+
8
+ # Widths should add to 510 for portrait, 690 for landscape
9
+
10
+ table_options = {
11
+ header: true,
12
+ column_widths: col_widths,
13
+ cell_style: { inline_format: true }
14
+ }
15
+
16
+ table(data, table_options) do
17
+ cells.padding = 8
18
+ cells.border_color = '999999'
19
+ row(0).background_color = 'ffcc99'
20
+ row(0).font_style = :bold
21
+ row(0).valign = :center
22
+
23
+ centering_option = options[:col_center] || ''
24
+ column(centering_option).align = :center unless centering_option == ''
25
+
26
+ bolding_option = options[:col_bold] || ''
27
+ column(bolding_option).font_style = :bold unless bolding_option == ''
28
+ end
29
+ font_size 12
30
+ end
31
+ # rubocop:enable MethodLength
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,28 @@
1
+ module Aptible
2
+ module DocumentHelpers
3
+ module SubsectionHeadings
4
+ # rubocop:disable MethodLength
5
+ def subsection_heading(heading_title, section_title)
6
+ move_down 20
7
+ formatted_text [
8
+ text: heading_title,
9
+ anchor: heading_title,
10
+ font: 'Proxima Nova',
11
+ size: 20,
12
+ styles: [:bold],
13
+ color: '003366'
14
+ ]
15
+
16
+ move_down 10
17
+
18
+ outline.add_subsection_to(section_title) do
19
+ # Add references for PDF navigation
20
+ outline.section(title: heading_title, destination: page_number)
21
+ # Add page titles and numbers for Table of Contents
22
+ outline.page(title: heading_title, destination: page_number)
23
+ end
24
+ end
25
+ # rubocop:enable MethodLength
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,53 @@
1
+ module Aptible
2
+ module DocumentHelpers
3
+ module TableOfContents
4
+ # rubocop:disable MethodLength
5
+ def table_of_contents
6
+ go_to_page 2
7
+ fill_color '333333'
8
+ font('Proxima Nova')
9
+ header_box do
10
+ font('Proxima Nova', size: 30, style: :bold) do
11
+ text('Table of Contents', valign: :center, color: '003366')
12
+ end
13
+ end
14
+ # text 'Table of Contents', size: 27.812, style: :bold, align: :center
15
+ move_down(15)
16
+
17
+ font('Proxima Nova', size: 13) do
18
+ column_box([0, cursor], columns: 2, width: bounds.width) do
19
+ last_title ||= ''
20
+ # don't bump the first heading
21
+ bump_heading = false
22
+ outline.items.keys.each do |key|
23
+ # Section headings are strings
24
+ if key.class == String
25
+ if key != last_title
26
+ move_down(3) if bump_heading
27
+ text key,
28
+ style: :bold,
29
+ leading: 3
30
+ move_down(2)
31
+ end
32
+ # bump each one after the first
33
+ bump_heading = true
34
+ else
35
+ # Page references are hashes
36
+ last_title = key.fetch(:title)
37
+ indent(40) do
38
+ text "#{key.fetch(:title)}" \
39
+ "#{@nbsp}–#{@nbsp}" \
40
+ "p.#{@nbsp}#{key.fetch(:destination) - 2 }",
41
+ style: :italic,
42
+ size: 11,
43
+ indent_paragraphs: -20
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ # rubocop:enable MethodLength
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,5 @@
1
+ module Aptible
2
+ module DocumentHelpers
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,56 @@
1
+ module Aptible
2
+ module DocumentHelpers
3
+ module Watermark
4
+ # rubocop:disable MethodLength
5
+ def watermarked(stamp_type = 'CONFIDENTIAL', format = :portrait, &block)
6
+ # Tying the definition to the current format helps ensure
7
+ # the watermark is created with the right margin boxes
8
+ define_watermarks(format)
9
+
10
+ stamp_name = "#{stamp_type} - #{format}"
11
+
12
+ # Watermark the current page
13
+ stamp stamp_name
14
+
15
+ # Watermark additional pages
16
+ on_page_create do
17
+ stamp stamp_name
18
+ @landscape_pages.push(page_number) if format == :landscape
19
+ end
20
+ yield if block_given?
21
+ # clears the callback
22
+ on_page_create
23
+ end
24
+
25
+ def define_watermarks(format = :portrait)
26
+ @defined_formats ||= []
27
+ # Catch strings
28
+ format = format.to_sym
29
+ return if @defined_formats.include?(format)
30
+
31
+ case format
32
+ when :portrait
33
+ create_confidential_stamp(48, 0, -60, format)
34
+ when :landscape
35
+ create_confidential_stamp(15, 130, 70, format)
36
+ end
37
+ @defined_formats << format
38
+ end
39
+
40
+ def create_confidential_stamp(rotation, main_y_pos, sub_y_pos, format)
41
+ create_stamp("CONFIDENTIAL - #{format}") do
42
+ rotate(rotation, origin: [0, 0]) do
43
+ fill_color 'f3f3f3'
44
+ font('Proxima Nova', style: :bold, size: 100) do
45
+ draw_text 'CONFIDENTIAL', at: [40, main_y_pos]
46
+ end
47
+ font('Proxima Nova', style: :normal, size: 70) do
48
+ draw_text 'Do Not Distribute', at: [130, sub_y_pos]
49
+ end
50
+ end
51
+ end
52
+ end
53
+ # rubocop:enable MethodLength
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,23 @@
1
+ require 'aptible/document_helpers/change_layout_format'
2
+ require 'aptible/document_helpers/font_loader'
3
+ require 'aptible/document_helpers/footer'
4
+ require 'aptible/document_helpers/header'
5
+ require 'aptible/document_helpers/page_numbers'
6
+ require 'aptible/document_helpers/pretty_table'
7
+ require 'aptible/document_helpers/subsection_headings'
8
+ require 'aptible/document_helpers/table_of_contents'
9
+ require 'aptible/document_helpers/watermark'
10
+
11
+ module Aptible
12
+ module DocumentHelpers
13
+ include Aptible::DocumentHelpers::FontLoader
14
+ include Aptible::DocumentHelpers::Header
15
+ include Aptible::DocumentHelpers::Footer
16
+ include Aptible::DocumentHelpers::PageNumbers
17
+ include Aptible::DocumentHelpers::SubsectionHeadings
18
+ include Aptible::DocumentHelpers::PrettyTable
19
+ include Aptible::DocumentHelpers::Watermark
20
+ include Aptible::DocumentHelpers::ChangeLayoutFormat
21
+ include Aptible::DocumentHelpers::TableOfContents
22
+ end
23
+ end
data/spec/.keep ADDED
File without changes
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aptible-prawn-helpers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Skylar Anderson
8
+ - Chas Ballew
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-11-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '1.3'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '1.3'
28
+ - !ruby/object:Gem::Dependency
29
+ name: aptible-tasks
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: 0.2.0
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: 0.2.0
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: '2.0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '2.0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: pry
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ description: Prawn Document Helpers
85
+ email:
86
+ - skylar@aptible.com
87
+ - chas@aptible.com
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - .gitignore
93
+ - .rspec
94
+ - .travis.yml
95
+ - Gemfile
96
+ - LICENSE.md
97
+ - README.md
98
+ - Rakefile
99
+ - aptible-prawn-helpers.gemspec
100
+ - data/fonts/Georgia Bold Italic.ttf
101
+ - data/fonts/Georgia Bold.ttf
102
+ - data/fonts/Georgia Italic.ttf
103
+ - data/fonts/Georgia.ttf
104
+ - data/fonts/proxima_nova.ttf
105
+ - data/fonts/proxima_nova_bold.ttf
106
+ - data/fonts/proxima_nova_bold_italic.ttf
107
+ - data/fonts/proxima_nova_italic.ttf
108
+ - data/fonts/proxima_nova_light.ttf
109
+ - data/fonts/proxima_nova_light_italic.ttf
110
+ - lib/aptible/document_helpers.rb
111
+ - lib/aptible/document_helpers/change_layout_format.rb
112
+ - lib/aptible/document_helpers/font_loader.rb
113
+ - lib/aptible/document_helpers/footer.rb
114
+ - lib/aptible/document_helpers/header.rb
115
+ - lib/aptible/document_helpers/page_numbers.rb
116
+ - lib/aptible/document_helpers/pretty_table.rb
117
+ - lib/aptible/document_helpers/subsection_headings.rb
118
+ - lib/aptible/document_helpers/table_of_contents.rb
119
+ - lib/aptible/document_helpers/version.rb
120
+ - lib/aptible/document_helpers/watermark.rb
121
+ - spec/.keep
122
+ homepage: https://github.com/aptible/aptible-prawn-helpers
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.2.2
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: Prawn Document Helpers
146
+ test_files:
147
+ - spec/.keep