elegant 1.1.0 → 1.2.0
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 +4 -4
- data/.travis.yml +1 -1
- data/CHANGELOG.md +5 -0
- data/bin/elegant +59 -36
- data/elegant.gemspec +1 -1
- data/lib/elegant/document.rb +2 -2
- data/lib/elegant/footer.rb +2 -3
- data/lib/elegant/header.rb +9 -3
- data/lib/elegant/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2e7cd7cced97c061f7a69326ed86bc86be3f443
|
4
|
+
data.tar.gz: d4f2e63d066cc775673f4959a0d909d9a2cd18e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0aed6189b36da2bd4b9add5999f11f757f4eae33abe67fe543b1534fffea0f9e32fd325357dcd9286afb24842f7c21c0c264fcdc70c7fa99befb73605ac2c46
|
7
|
+
data.tar.gz: 1160b31beb3d9d7feac865ab4af73e34a197a7d106e05a3a6346a91e957bf9689e00bf525eabdea3ffdf63dd2fe12530fa22b30490ce8ac66180f1a32add3233
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,11 @@ For more information about changelogs, check
|
|
6
6
|
[Keep a Changelog](http://keepachangelog.com) and
|
7
7
|
[Vandamme](http://tech-angels.github.io/vandamme).
|
8
8
|
|
9
|
+
## 1.2.0 - 2016.01.21
|
10
|
+
|
11
|
+
* [ENHANCEMENT] White background below the logo
|
12
|
+
* [ENHANCEMENT] Add inline-format to footer text (allows for links)
|
13
|
+
|
9
14
|
## 1.1.0 - 2015.11.12
|
10
15
|
|
11
16
|
* [ENHANCEMENT] Taller title (now has room for two lines)
|
data/bin/elegant
CHANGED
@@ -7,13 +7,41 @@ rescue LoadError
|
|
7
7
|
require 'elegant'
|
8
8
|
end
|
9
9
|
|
10
|
+
|
11
|
+
#####################
|
12
|
+
|
13
|
+
def asset(path)
|
14
|
+
File.expand_path "../../tmp/#{path}", __FILE__
|
15
|
+
end
|
16
|
+
|
17
|
+
def ttf(family)
|
18
|
+
{normal: asset("#{family}-Regular.ttf"), bold: asset("#{family}-Bold.ttf")}
|
19
|
+
end
|
20
|
+
|
21
|
+
Elegant.configure do |config|
|
22
|
+
config.author = 'Fullscreen'
|
23
|
+
config.creator = 'Channel+'
|
24
|
+
config.producer = 'Channel+ by Fullscreen'
|
25
|
+
config.watermark = asset 'images/logo.png'
|
26
|
+
config.fonts = {
|
27
|
+
'Helvetica' => ttf('fonts/HelveticaWorld'),
|
28
|
+
'Sans Serif' => ttf('fonts/ProximaNova'),
|
29
|
+
'Fallback' => ttf('fonts/ArialUnicode'),
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
#####################
|
34
|
+
|
35
|
+
def icon_for(name)
|
36
|
+
asset "images/icons/#{name}.png"
|
37
|
+
end
|
38
|
+
|
10
39
|
class Section
|
11
40
|
attr_accessor :title, :page, :alignment
|
12
41
|
def initialize(title:, page:, alignment:)
|
13
42
|
@title, @page, @alignment = title, page, alignment
|
14
43
|
end
|
15
44
|
|
16
|
-
attr_accessor :document
|
17
45
|
include Prawn::View
|
18
46
|
def render_to(pdf)
|
19
47
|
@document = pdf
|
@@ -22,11 +50,7 @@ class Section
|
|
22
50
|
|
23
51
|
def render
|
24
52
|
header
|
25
|
-
|
26
|
-
bounding_box [0, cursor], width: bounds.width, height: 170 do
|
27
|
-
stroke_bounds
|
28
|
-
end
|
29
|
-
|
53
|
+
body
|
30
54
|
footer
|
31
55
|
end
|
32
56
|
|
@@ -38,10 +62,16 @@ private
|
|
38
62
|
end
|
39
63
|
|
40
64
|
move_down 10
|
41
|
-
formatted_text_box [
|
65
|
+
formatted_text_box [header_text_box], height: 15, at: [0, cursor]
|
42
66
|
move_down 30 # 15 of the float box, and 15 real
|
43
67
|
end
|
44
68
|
|
69
|
+
def body
|
70
|
+
bounding_box [0, cursor], width: bounds.width, height: 170 do
|
71
|
+
stroke_bounds
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
45
75
|
def footer
|
46
76
|
unless alignment == :bottom
|
47
77
|
document.move_down 25
|
@@ -52,6 +82,17 @@ private
|
|
52
82
|
def sans_serif
|
53
83
|
'Sans Serif' if document.font_families['Sans Serif']
|
54
84
|
end
|
85
|
+
|
86
|
+
def header_text_box
|
87
|
+
{
|
88
|
+
text: title.upcase,
|
89
|
+
font: sans_serif,
|
90
|
+
styles: [:bold],
|
91
|
+
valign: :center,
|
92
|
+
color: '556270',
|
93
|
+
size: 14
|
94
|
+
}
|
95
|
+
end
|
55
96
|
end
|
56
97
|
|
57
98
|
sections = [
|
@@ -62,38 +103,20 @@ sections = [
|
|
62
103
|
Section.new(title: 'Month over month view tracking', page: 2, alignment: :middle),
|
63
104
|
]
|
64
105
|
|
65
|
-
|
66
|
-
{normal: ttf("#{family}-Regular"), bold: ttf("#{family}-Bold")}
|
67
|
-
end
|
106
|
+
#####################
|
68
107
|
|
69
|
-
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
def png(basename)
|
74
|
-
asset "images/#{basename}.png"
|
75
|
-
end
|
76
|
-
|
77
|
-
def asset(path)
|
78
|
-
File.expand_path "../../tmp/#{path}", __FILE__
|
79
|
-
end
|
80
|
-
|
81
|
-
fonts = {}.tap do |families|
|
82
|
-
families['Helvetica'] = font_files_for 'HelveticaWorld'
|
83
|
-
families['Fallback'] = font_files_for 'ArialUnicode'
|
84
|
-
families['Sans Serif'] = font_files_for 'ProximaNova'
|
85
|
-
end
|
86
|
-
|
87
|
-
company_logo = png('logo')
|
88
|
-
company_name = 'Fullscreen'
|
89
|
-
title = 'March 2015'
|
90
|
-
thumbnail = png('thumbnail')
|
91
|
-
footer = "Report for channelpl.us (2015/02/12 – 2015/10/12)"
|
108
|
+
header = {text: 'March 2015', logo: {url: asset('images/thumbnail.png')}}
|
109
|
+
footer = {text: "Report for <link href='https://www.channelpl.us'>Channel+</link> (2015/02/12 – 2015/10/12)"}
|
92
110
|
|
93
111
|
filename = 'elegant.pdf'
|
94
112
|
|
95
|
-
Elegant::Document.new(
|
96
|
-
sections.each
|
113
|
+
Elegant::Document.new(header: header, footer: footer) do |pdf|
|
114
|
+
sections.each do |section|
|
115
|
+
section.render_to pdf
|
116
|
+
if pdf.cursor != 15.0 && section.alignment == :bottom
|
117
|
+
p "CURSOR #{pdf.cursor}"
|
118
|
+
end
|
119
|
+
end
|
97
120
|
end.render_file filename
|
98
121
|
|
99
|
-
`open #{filename}`
|
122
|
+
`open #{filename}`
|
data/elegant.gemspec
CHANGED
@@ -26,6 +26,6 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_development_dependency 'prawn-manual_builder', '~> 0.2.0'
|
27
27
|
spec.add_development_dependency 'rake', '~> 10.0'
|
28
28
|
spec.add_development_dependency 'rspec', '~> 3.3'
|
29
|
-
spec.add_development_dependency 'coveralls', '~> 0.8.
|
29
|
+
spec.add_development_dependency 'coveralls', '~> 0.8.10'
|
30
30
|
spec.add_development_dependency 'pry-nav', '~> 0.2.4'
|
31
31
|
end
|
data/lib/elegant/document.rb
CHANGED
@@ -16,8 +16,8 @@ module Elegant
|
|
16
16
|
# (a Hash with a :url key with the location of the logo image and
|
17
17
|
# optional :width and :height, which default to 50x50).
|
18
18
|
# @option options [Hash] :footer ({}) The options for the footer. Accepted
|
19
|
-
# values are :text (the text in the bottom-center of the page
|
20
|
-
#
|
19
|
+
# values are :text (the text in the bottom-center of the page which may
|
20
|
+
# include a link which will be formatted inline).
|
21
21
|
# @see http://www.rubydoc.info/gems/prawn/Prawn/Document
|
22
22
|
def initialize(options = {}, &block)
|
23
23
|
options = options.dup
|
data/lib/elegant/footer.rb
CHANGED
@@ -5,7 +5,7 @@ module Elegant
|
|
5
5
|
|
6
6
|
def initialize(document, options = {})
|
7
7
|
@document = document
|
8
|
-
@text
|
8
|
+
@text = options[:text]
|
9
9
|
end
|
10
10
|
|
11
11
|
# Draws in the header of each page a horizontal line, the name of the
|
@@ -28,13 +28,12 @@ module Elegant
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def render_text
|
31
|
-
text = @url ? "<link href='#{@url}'>#{@text}</link>" : @text
|
32
31
|
left = 50
|
33
32
|
options = {size: 7, align: :center, valign: :top, inline_format: true}
|
34
33
|
options[:at] = [left, -6]
|
35
34
|
options[:width] = bounds.width - 2 * left
|
36
35
|
options[:height] = 10
|
37
|
-
text_box text, options
|
36
|
+
text_box @text, options
|
38
37
|
end
|
39
38
|
|
40
39
|
def render_page_number
|
data/lib/elegant/header.rb
CHANGED
@@ -16,7 +16,7 @@ module Elegant
|
|
16
16
|
repeat(:all) do
|
17
17
|
render_watermark
|
18
18
|
stroke_horizontal_rule
|
19
|
-
render_logo
|
19
|
+
render_logo
|
20
20
|
render_heading
|
21
21
|
end
|
22
22
|
end
|
@@ -44,7 +44,7 @@ module Elegant
|
|
44
44
|
def render_logo
|
45
45
|
float do
|
46
46
|
render_logo_frame
|
47
|
-
render_logo_image
|
47
|
+
render_logo_image if @logo[:url]
|
48
48
|
end if @logo
|
49
49
|
end
|
50
50
|
|
@@ -54,7 +54,13 @@ module Elegant
|
|
54
54
|
height = @logo_height + line_width
|
55
55
|
left = bounds.right - width - 0.5 * line_width
|
56
56
|
top = bounds.top + 0.5 * height
|
57
|
-
bounding_box([left, top], width: width, height: height)
|
57
|
+
bounding_box([left, top], width: width, height: height) do
|
58
|
+
old_color = self.fill_color
|
59
|
+
fill_color 'FFFFFF'
|
60
|
+
fill_rectangle [0, height], width, height
|
61
|
+
fill_color old_color
|
62
|
+
stroke_bounds
|
63
|
+
end
|
58
64
|
end
|
59
65
|
|
60
66
|
# Renders the actual image as the logo in the top-right corner.
|
data/lib/elegant/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elegant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- claudiob
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: prawn
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.8.
|
89
|
+
version: 0.8.10
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.8.
|
96
|
+
version: 0.8.10
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: pry-nav
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -159,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
159
|
version: '0'
|
160
160
|
requirements: []
|
161
161
|
rubyforge_project:
|
162
|
-
rubygems_version: 2.
|
162
|
+
rubygems_version: 2.5.1
|
163
163
|
signing_key:
|
164
164
|
specification_version: 4
|
165
165
|
summary: An elegant layout for PDF reports generated in Ruby.
|