elegant 0.0.0 → 1.0.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: 36b854e581ccff601af3015dd4b19c25f095202f
4
- data.tar.gz: 4b4444ebe31e9ab1359ed1c6432e9ed4a279d083
3
+ metadata.gz: 49d380d40dfac8ce477d00db75bc1604695432a3
4
+ data.tar.gz: 75459d4ca3def9cfe6a639196ea3285744282f74
5
5
  SHA512:
6
- metadata.gz: 969b386e87be5af551ed7e270fbe806731dc705c6de719743940051b9178b3b7b08fb30db2a99f4ce0bff50c66f8a931293804f235eff664fe191aa10392f00f
7
- data.tar.gz: 4d6ab0f39dca53487225356245da59e699ad411f99f2880b755ebaa90f4d852d89716c8679a05ec4f11bca31e6afce7d27bf8a1460a3cc9a1d28698ae70afd44
6
+ metadata.gz: 5591417ffb9d7fe2496f7c381fc35cea285c2339d886eca283d19cacdcf29c3b81b3a37d2c8a6d6b8ca8545e68ef2429a14f5095db9c83cb5aa67a62bf1bb09c
7
+ data.tar.gz: 5cf7843617579048f2f96f305b2c0e04ad3af0c18e2f7ed851da1838b3efd88336fcd473512bf024c10e4f6d6f40fc492007795aeed1e909cd81082dc0608482
data/.gitignore CHANGED
@@ -7,4 +7,6 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
- *.gem
10
+ elegant.pdf
11
+ example*.pdf
12
+ *.psd
data/.travis.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  language: ruby
2
+ cache: bundler
2
3
  rvm:
3
- - 2.2.3
4
- before_install: gem install bundler -v 1.10.6
4
+ - 2.1.0
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ For more information about changelogs, check
6
+ [Keep a Changelog](http://keepachangelog.com) and
7
+ [Vandamme](http://tech-angels.github.io/vandamme).
8
+
9
+ ## 1.0.0 - 2015.11.03
10
+
11
+ * [FEATURE] New `Elegant::Document` class with `title` method.
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015 claudiob
3
+ Copyright (c) 2015 Fullscreen, Inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the 'Software'), to deal
data/README.md CHANGED
@@ -1,41 +1,73 @@
1
- # Elegant
1
+ Elegant
2
+ =======
2
3
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/elegant`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+ Elegant provides a nice layout for PDF reports generated in Ruby.
4
5
 
5
- TODO: Delete this and the text above, and describe your gem
6
+ The **source code** is available on [GitHub](https://github.com/Fullscreen/elegant) and the **documentation** on [RubyDoc](http://www.rubydoc.info/github/Fullscreen/elegant/master/Elegant/Interface).
6
7
 
7
- ## Installation
8
+ [![Build Status](http://img.shields.io/travis/Fullscreen/elegant/master.svg)](https://travis-ci.org/Fullscreen/elegant)
9
+ [![Coverage Status](http://img.shields.io/coveralls/Fullscreen/elegant/master.svg)](https://coveralls.io/r/Fullscreen/elegant)
10
+ [![Dependency Status](http://img.shields.io/gemnasium/Fullscreen/elegant.svg)](https://gemnasium.com/Fullscreen/elegant)
11
+ [![Code Climate](http://img.shields.io/codeclimate/github/Fullscreen/elegant.svg)](https://codeclimate.com/github/Fullscreen/elegant)
12
+ [![Online docs](http://img.shields.io/badge/docs-✓-green.svg)](http://www.rubydoc.info/github/Fullscreen/elegant/master/Elegant)
13
+ [![Gem Version](http://img.shields.io/gem/v/elegant.svg)](http://rubygems.org/gems/elegant)
8
14
 
9
- Add this line to your application's Gemfile:
15
+ Elegant is a library built on top of [Prawn](http://prawnpdf.org) to generate PDF files in Ruby.
10
16
 
11
- ```ruby
12
- gem 'elegant'
13
- ```
17
+ Whereas Prawn creates PDF pages that are completely blank (letting users customize them at will),
18
+ Elegant comes with a nice layout that makes each page look… elegant! :wink:
19
+
20
+ How to use
21
+ ==========
14
22
 
15
- And then execute:
23
+ If you have never used [Prawn](http://prawnpdf.org/) to generate PDF files, you should first read [its manual](http://prawnpdf.org/manual.pdf).
16
24
 
17
- $ bundle
25
+ Using Elegant is as simple as replacing any instance of `Prawn::Document` with `Elegant::Document`:
18
26
 
19
- Or install it yourself as:
27
+ ```ruby
28
+ # with Prawn
29
+ Prawn::Document.new do
30
+ text 'Hello, World!'
31
+ end
32
+
33
+ # with Elegant
34
+ Elegant::Document.new do
35
+ text 'Hello, World!'
36
+ end
37
+
38
+ # with Elegant and extra options
39
+ header = {text: 'A report', logo: {url: 'http://lorempixel.com/500/500'}}
40
+ footer = {text: 'A link', url: 'http://www.example.com'}
41
+ Elegant::Document.new(header: header, footer: footer) do
42
+ title 'Welcome'
43
+ text 'Hello, world!'
44
+ end
45
+ ```
20
46
 
21
- $ gem install elegant
47
+ ![Prawn vs. Elegant](https://cloud.githubusercontent.com/assets/7408595/10898333/433a6072-817e-11e5-8c95-999c5629e84c.jpg)
22
48
 
23
- ## Usage
49
+ `Elegant::Document` accepts some options [... TODO ...]
24
50
 
25
- TODO: Write usage instructions here
51
+ How to install
52
+ ==============
26
53
 
27
- ## Development
54
+ Elegant requires **Ruby 2.1 or higher**.
28
55
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
56
+ To include in your project, add `gem 'elegant', ~> '1.0'` to the `Gemfile` file of your Ruby project.
30
57
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
58
+ How to generate the manual
59
+ ==========================
32
60
 
33
- ## Contributing
61
+ `rake manual`
34
62
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/elegant. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
63
+ How to contribute
64
+ =================
36
65
 
66
+ If you’ve made it this far in the README… thanks! :v:
67
+ Feel free to try it the gem, explore the code, and send issues or pull requests.
37
68
 
38
- ## License
69
+ All pull requests will have to make Travis and Code Climate happy in order to be accepted. :kissing_smiling_eyes:
39
70
 
40
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
71
+ You can also run the tests locally with `bundle exec rspec`.
41
72
 
73
+ Happy hacking!
data/Rakefile CHANGED
@@ -1 +1,9 @@
1
1
  require 'bundler/gem_tasks'
2
+
3
+ require "rspec/core/rake_task"
4
+ require "rspec/core/version"
5
+
6
+ desc "Run all examples"
7
+ RSpec::Core::RakeTask.new :spec
8
+
9
+ task default: [:spec]
data/bin/console CHANGED
@@ -1,14 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'bundler/setup'
4
- require 'elegant'
3
+ require "bundler/setup"
4
+ require "elegant"
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
8
8
 
9
9
  # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require 'pry'
11
- # Pry.elegantt
10
+ # require "pry"
11
+ # Pry.start
12
12
 
13
- require 'irb'
13
+ require "irb"
14
14
  IRB.start
data/bin/elegant ADDED
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'elegant'
5
+ rescue LoadError
6
+ require 'rubygems'
7
+ require 'elegant'
8
+ end
9
+
10
+ class Section
11
+ attr_accessor :title, :page, :alignment
12
+ def initialize(title:, page:, alignment:)
13
+ @title, @page, @alignment = title, page, alignment
14
+ end
15
+
16
+ attr_accessor :document
17
+ include Prawn::View
18
+ def render_to(pdf)
19
+ @document = pdf
20
+ render
21
+ end
22
+
23
+ def render
24
+ header
25
+
26
+ bounding_box [0, cursor], width: bounds.width, height: 170 do
27
+ stroke_bounds
28
+ end
29
+
30
+ footer
31
+ end
32
+
33
+ private
34
+
35
+ def header
36
+ if alignment == :top and page > 1
37
+ start_new_page
38
+ end
39
+
40
+ move_down 10
41
+ formatted_text_box [{text: title.upcase, font: sans_serif, styles: [:bold], valign: :center, color: '556270', size: 14}], height: 15, at: [0, cursor]
42
+ move_down 30 # 15 of the float box, and 15 real
43
+ end
44
+
45
+ def footer
46
+ unless alignment == :bottom
47
+ document.move_down 25
48
+ document.stroke_horizontal_rule
49
+ end
50
+ end
51
+
52
+ def sans_serif
53
+ 'Sans Serif' if document.font_families['Sans Serif']
54
+ end
55
+ end
56
+
57
+ sections = [
58
+ Section.new(title: 'Lifetime Metrics', page: 1, alignment: :top),
59
+ Section.new(title: 'Monetization', page: 1, alignment: :middle),
60
+ Section.new(title: 'Month over month view tracking', page: 1, alignment: :bottom),
61
+ Section.new(title: 'Lifetime Metrics', page: 2, alignment: :top),
62
+ Section.new(title: 'Month over month view tracking', page: 2, alignment: :middle),
63
+ ]
64
+
65
+ def font_files_for(family)
66
+ {normal: ttf("#{family}-Regular"), bold: ttf("#{family}-Bold")}
67
+ end
68
+
69
+ def ttf(basename)
70
+ asset "fonts/#{basename}.ttf"
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)"
92
+
93
+ filename = 'elegant.pdf'
94
+
95
+ Elegant::Document.new(fonts: fonts, title: title, company_logo: company_logo, thumbnail: thumbnail, footer: footer, company_name: company_name) do |pdf|
96
+ sections.each{|section| section.render_to pdf}
97
+ end.render_file filename
98
+
99
+ `open #{filename}`
data/elegant.gemspec CHANGED
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  lib = File.expand_path('../lib', __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'elegant/version'
@@ -9,16 +8,24 @@ Gem::Specification.new do |spec|
9
8
  spec.authors = ['claudiob']
10
9
  spec.email = ['claudiob@gmail.com']
11
10
 
12
- spec.summary = %q{:elegant:}
13
- spec.description = %q{:elegant: :elegant: :elegant:}
14
- spec.homepage = 'https://github.com/claudiob/elegant'
11
+ spec.summary = %q{An elegant layout for PDF reports generated in Ruby.}
12
+ spec.description = %q{Elegant expands Prawn providing a new class to generate new pages with an elegant layout.}
13
+ spec.homepage = 'https://github.com/Fullscreen/elegant'
15
14
  spec.license = 'MIT'
16
15
 
16
+ spec.required_ruby_version = '>= 2.1' # 2.0 does not have Array#to_h
17
+
17
18
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
19
  spec.bindir = 'exe'
19
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
21
  spec.require_paths = ['lib']
21
22
 
22
- spec.add_development_dependency 'bundler', '~> 1.10'
23
+ spec.add_dependency 'prawn', '~> 2.0'
24
+
25
+ spec.add_development_dependency 'pdf-inspector', '~> 1.2'
26
+ spec.add_development_dependency 'prawn-manual_builder', '~> 0.2.0'
23
27
  spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rspec', '~> 3.3'
29
+ spec.add_development_dependency 'coveralls', '~> 0.8.2'
30
+ spec.add_development_dependency 'pry-nav', '~> 0.2.4'
24
31
  end
@@ -0,0 +1,42 @@
1
+ require 'elegant/configuration'
2
+
3
+ module Elegant
4
+ # Provides methods to read and write global configuration settings.
5
+ #
6
+ # @example Set the author of PDF files to 'John Doe':
7
+ # Elegant.configure do |config|
8
+ # config.author = 'John Doe'
9
+ # end
10
+ #
11
+ module Config
12
+ # Yields the global configuration to the given block.
13
+ #
14
+ # @example
15
+ # Elegant.configure do |config|
16
+ # config.author = 'John Doe'
17
+ # end
18
+ #
19
+ # @yield [Elegant::Configuration] The global configuration.
20
+ def configure
21
+ yield configuration if block_given?
22
+ end
23
+
24
+ # Returns the global {Elegant::Models::Configuration} object.
25
+ #
26
+ # While this method _can_ be used to read and write configuration settings,
27
+ # it is easier to use {Elegant::Config#configure} Elegant.configure}.
28
+ #
29
+ # @example
30
+ # Elegant.configuration.author = 'John Doe'
31
+ #
32
+ # @return [Elegant::Configuration] The global configuration.
33
+ def configuration
34
+ @configuration ||= Elegant::Configuration.new
35
+ end
36
+ end
37
+
38
+ # @note Config is the only module auto-loaded in the Elegant module,
39
+ # in order to have a syntax as easy as Elegant.configure
40
+
41
+ extend Config
42
+ end
@@ -0,0 +1,49 @@
1
+ module Elegant
2
+ # Provides an object to store global configuration settings.
3
+ #
4
+ # This class is typically not used directly, but by calling
5
+ # {Elegant::Config#configure Elegant.configure}, which creates and updates a
6
+ # single instance of {Elegant::Configuration}.
7
+ #
8
+ # @example Set the author of PDF files to 'John Doe':
9
+ # Elegant.configure do |config|
10
+ # config.author = 'John Doe'
11
+ # end
12
+ #
13
+ # @see Elegant::Config for more examples.
14
+ class Configuration
15
+ # @return [String] the Author to store in the PDF metadata
16
+ attr_accessor :author
17
+
18
+ # @return [String] the Creator to store in the PDF metadata
19
+ attr_accessor :creator
20
+
21
+ # @return [String] the Producer to store in the PDF metadata
22
+ attr_accessor :producer
23
+
24
+ # @return [String] the path of an image to display on every page
25
+ attr_accessor :watermark
26
+
27
+ # @return [Array<Hash<Symbol, Hash<Symbol, String>] the fonts to use.
28
+ attr_accessor :fonts
29
+
30
+ def initialize
31
+ @author = 'Elegant'
32
+ @creator = 'Elegant'
33
+ @producer = 'Elegant'
34
+ @watermark = asset 'images/default_watermark.png'
35
+ @fonts = {'Sans Serif' => default_font, 'Fallback' => default_font}
36
+ end
37
+
38
+ private
39
+
40
+ def default_font
41
+ type = 'DejaVuSans'
42
+ {normal: asset("fonts/#{type}.ttf"), bold: asset("fonts/#{type}Bold.ttf")}
43
+ end
44
+
45
+ def asset(file)
46
+ File.expand_path "../#{file}", __FILE__
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,81 @@
1
+ require 'elegant/config'
2
+ require 'elegant/footer'
3
+ require 'elegant/header'
4
+ require 'elegant/typography'
5
+
6
+ module Elegant
7
+ # A wrapper around Prawn::Document that enforces an elegant layout, setting
8
+ # nice dimensions and margins so that each page can fit up to three sections
9
+ # of content properly aligned along the vertical axis.
10
+ class Document < ::Prawn::Document
11
+ # Creates a new Elegant Document.
12
+ # @param [Hash] options. All the options of Prawn::Document are
13
+ # available, plus the following extra options.
14
+ # @option options [Hash] :header ({}) The options for the header. Accepted
15
+ # values are :text (the title to write in the top-right corner) and :logo
16
+ # (a Hash with a :url key with the location of the logo image and
17
+ # optional :width and :height, which default to 50x50).
18
+ # @option options [Hash] :footer ({}) The options for the footer. Accepted
19
+ # values are :text (the text in the bottom-center of the page) and :url
20
+ # (to make that text a link to a URL).
21
+ # @see http://www.rubydoc.info/gems/prawn/Prawn/Document
22
+ def initialize(options = {}, &block)
23
+ options = options.dup
24
+ @header = Header.new self, options.delete(:header) {{}}
25
+ @footer = Footer.new self, options.delete(:footer) {{}}
26
+
27
+ super(with_elegant options) do
28
+ Typography.new(self).set_fonts
29
+ @header.render
30
+
31
+ if block
32
+ block.arity < 1 ? instance_eval(&block) : block[self]
33
+ end
34
+
35
+ @footer.render
36
+ end
37
+ end
38
+
39
+ # An additional method provided by Elegant::Document to render a title
40
+ # with an elegant font and padding above and below.
41
+ def title(text, options = {})
42
+ move_down 10
43
+
44
+ width = bounds.width - @header.title_padding
45
+ title = text_options.merge text: text.upcase, color: '556270', size: 14
46
+ options = {width: width, height: 15, at: [0, cursor]}
47
+ formatted_text_box [title], options
48
+
49
+ move_down 30
50
+ end
51
+
52
+ # Determines the total height occupied by the header
53
+ def header_height
54
+ 50
55
+ end
56
+
57
+ private
58
+
59
+ # Applies some elegant defaults to the options provided by the user. For
60
+ # instance forces the layout to be letter portrait, and set the metadata
61
+ # from the configuration if not explicitly provided.
62
+ def with_elegant(options)
63
+ options[:page_size] = 'LETTER'
64
+ options[:page_layout] = :portrait
65
+ options[:print_scaling] = :none
66
+ options[:top_margin] = (default_margin = 36) + header_height / 2
67
+ options[:info] = default_metadata.merge(options.fetch :info, {})
68
+ options
69
+ end
70
+
71
+ def default_metadata
72
+ %i(Author Creator Producer).map do |key|
73
+ [key, Elegant.configuration.public_send(key.to_s.downcase)]
74
+ end.to_h
75
+ end
76
+
77
+ def text_options
78
+ {font: 'Sans Serif', styles: [:bold]}
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,97 @@
1
+ Fonts are (c) Bitstream (see below). DejaVu changes are in public domain.
2
+ Glyphs imported from Arev fonts are (c) Tavmjong Bah (see below)
3
+
4
+ Bitstream Vera Fonts Copyright
5
+ ------------------------------
6
+
7
+ Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream Vera is
8
+ a trademark of Bitstream, Inc.
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of the fonts accompanying this license ("Fonts") and associated
12
+ documentation files (the "Font Software"), to reproduce and distribute the
13
+ Font Software, including without limitation the rights to use, copy, merge,
14
+ publish, distribute, and/or sell copies of the Font Software, and to permit
15
+ persons to whom the Font Software is furnished to do so, subject to the
16
+ following conditions:
17
+
18
+ The above copyright and trademark notices and this permission notice shall
19
+ be included in all copies of one or more of the Font Software typefaces.
20
+
21
+ The Font Software may be modified, altered, or added to, and in particular
22
+ the designs of glyphs or characters in the Fonts may be modified and
23
+ additional glyphs or characters may be added to the Fonts, only if the fonts
24
+ are renamed to names not containing either the words "Bitstream" or the word
25
+ "Vera".
26
+
27
+ This License becomes null and void to the extent applicable to Fonts or Font
28
+ Software that has been modified and is distributed under the "Bitstream
29
+ Vera" names.
30
+
31
+ The Font Software may be sold as part of a larger software package but no
32
+ copy of one or more of the Font Software typefaces may be sold by itself.
33
+
34
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
35
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY,
36
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT,
37
+ TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL BITSTREAM OR THE GNOME
38
+ FOUNDATION BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING
39
+ ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
40
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
41
+ THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE
42
+ FONT SOFTWARE.
43
+
44
+ Except as contained in this notice, the names of Gnome, the Gnome
45
+ Foundation, and Bitstream Inc., shall not be used in advertising or
46
+ otherwise to promote the sale, use or other dealings in this Font Software
47
+ without prior written authorization from the Gnome Foundation or Bitstream
48
+ Inc., respectively. For further information, contact: fonts at gnome dot
49
+ org.
50
+
51
+ Arev Fonts Copyright
52
+ ------------------------------
53
+
54
+ Copyright (c) 2006 by Tavmjong Bah. All Rights Reserved.
55
+
56
+ Permission is hereby granted, free of charge, to any person obtaining
57
+ a copy of the fonts accompanying this license ("Fonts") and
58
+ associated documentation files (the "Font Software"), to reproduce
59
+ and distribute the modifications to the Bitstream Vera Font Software,
60
+ including without limitation the rights to use, copy, merge, publish,
61
+ distribute, and/or sell copies of the Font Software, and to permit
62
+ persons to whom the Font Software is furnished to do so, subject to
63
+ the following conditions:
64
+
65
+ The above copyright and trademark notices and this permission notice
66
+ shall be included in all copies of one or more of the Font Software
67
+ typefaces.
68
+
69
+ The Font Software may be modified, altered, or added to, and in
70
+ particular the designs of glyphs or characters in the Fonts may be
71
+ modified and additional glyphs or characters may be added to the
72
+ Fonts, only if the fonts are renamed to names not containing either
73
+ the words "Tavmjong Bah" or the word "Arev".
74
+
75
+ This License becomes null and void to the extent applicable to Fonts
76
+ or Font Software that has been modified and is distributed under the
77
+ "Tavmjong Bah Arev" names.
78
+
79
+ The Font Software may be sold as part of a larger software package but
80
+ no copy of one or more of the Font Software typefaces may be sold by
81
+ itself.
82
+
83
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
84
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
85
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
86
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL
87
+ TAVMJONG BAH BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
88
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
89
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
90
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
91
+ OTHER DEALINGS IN THE FONT SOFTWARE.
92
+
93
+ Except as contained in this notice, the name of Tavmjong Bah shall not
94
+ be used in advertising or otherwise to promote the sale, use or other
95
+ dealings in this Font Software without prior written authorization
96
+ from Tavmjong Bah. For further information, contact: tavmjong @ free
97
+ . fr.
Binary file
@@ -0,0 +1,46 @@
1
+ require 'open-uri' # for open(http://...)
2
+ module Elegant
3
+ class Footer
4
+ include Prawn::View
5
+
6
+ def initialize(document, options = {})
7
+ @document = document
8
+ @text, @url = options.values_at :text, :url
9
+ end
10
+
11
+ # Draws in the header of each page a horizontal line, the name of the
12
+ # author, the title and the page number. The author must be provided in
13
+ # the configuration, and the title when initializing the document.
14
+ def render
15
+ repeat(:all) do
16
+ transparent(0.25) { stroke_horizontal_line 0, bounds.width, at: 0 }
17
+ render_author
18
+ render_text if @text
19
+ end
20
+ render_page_number
21
+ end
22
+
23
+ private
24
+
25
+ def render_author
26
+ options = {at: [0, -6], width: 50, height: 10, size: 7, valign: :top}
27
+ text_box Elegant.configuration.author, options
28
+ end
29
+
30
+ def render_text
31
+ text = @url ? "<link href='#{@url}'>#{@text}</link>" : @text
32
+ left = 50
33
+ options = {size: 7, align: :center, valign: :top, inline_format: true}
34
+ options[:at] = [left, -6]
35
+ options[:width] = bounds.width - 2 * left
36
+ options[:height] = 10
37
+ text_box text, options
38
+ end
39
+
40
+ def render_page_number
41
+ options = {width: 50, height: 10, size: 7, align: :right, valign: :top}
42
+ options[:at] = [bounds.width - options[:width], -6]
43
+ number_pages "Page <page>", options
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,91 @@
1
+ require 'open-uri' # for open(http://...)
2
+ module Elegant
3
+ class Header
4
+ include Prawn::View
5
+
6
+ def initialize(document, options = {})
7
+ @document = document
8
+ @text, @logo = options.values_at :text, :logo
9
+ @logo_width = @logo.fetch(:width, 50) if @logo
10
+ @logo_height = @logo.fetch(:height, 50) if @logo
11
+ end
12
+
13
+ # Draws in the header of each page a watermark logo (provided via the
14
+ # configuration), a horizontal line, a title and an image for the content.
15
+ def render
16
+ repeat(:all) do
17
+ render_watermark
18
+ stroke_horizontal_rule
19
+ render_logo if @logo
20
+ render_heading
21
+ end
22
+ end
23
+
24
+ # Sets the right padding for title based on whether the page has a logo
25
+ # or not.
26
+ def title_padding
27
+ @logo_width ? @logo_width + (margin = 7) : 0
28
+ end
29
+
30
+ private
31
+
32
+ # Renders a watermark at the top-left corner of each page. The watermark
33
+ # must be provided via configuration.
34
+ def render_watermark
35
+ image = Elegant.configuration.watermark
36
+ height = (document.header_height * 0.25).ceil
37
+ y = bounds.top + (document.header_height * 0.375).floor
38
+ image image, at: [0, y], height: height.ceil
39
+ end
40
+
41
+
42
+ # Renders an image in the top-right corner of each page. The image must be
43
+ # provided when initializing the document.
44
+ def render_logo
45
+ float do
46
+ render_logo_frame
47
+ render_logo_image
48
+ end if @logo
49
+ end
50
+
51
+ # Renders a frame around the logo in the top-right corner.
52
+ def render_logo_frame(options = {})
53
+ width = @logo_width + line_width
54
+ height = @logo_height + line_width
55
+ left = bounds.right - width - 0.5 * line_width
56
+ top = bounds.top + 0.5 * height
57
+ bounding_box([left, top], width: width, height: height) {stroke_bounds}
58
+ end
59
+
60
+ # Renders the actual image as the logo in the top-right corner.
61
+ def render_logo_image
62
+ left = bounds.right - @logo_width - line_width
63
+ top = bounds.top + @logo_height / 2
64
+ options = {width: @logo_width, height: @logo_height, at: [left, top]}
65
+ image open(@logo[:url]), options
66
+ rescue OpenURI::HTTPError, OpenSSL::SSL::SSLError, SocketError
67
+ end
68
+
69
+ # Writes the heading for the document in the top-right corner of each page,
70
+ # to the left of the logo. The heading must be provided when initializing
71
+ # the document.
72
+ def render_heading
73
+ transparent(0.25) do
74
+ font('Sans Serif', style: :bold) {text_box @text, heading_options}
75
+ end if @text
76
+ end
77
+
78
+ def heading_options(options = {})
79
+ left = 25
80
+ width = (@logo_width || 0) + 2 * line_width + (margin = 5)
81
+ options[:valign] = :center
82
+ options[:align] = :right
83
+ options[:size] = 17
84
+ options[:overflow] = :shrink_to_fit
85
+ options[:width] = bounds.width - width - left
86
+ options[:height] = document.header_height / 2.0
87
+ options[:at] = [left, bounds.top + options[:height]]
88
+ options
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,17 @@
1
+ module Elegant
2
+ class Typography
3
+ include Prawn::View
4
+
5
+ def initialize(document, options = {})
6
+ @document = document
7
+ end
8
+
9
+ # Set the fonts for the document. Fonts are provided via configuration and
10
+ # a 'Fallback' font must be set to be used for special characters. A
11
+ # 'Sans Serif' font is also required for titles and headers.
12
+ def set_fonts
13
+ font_families.update Elegant.configuration.fonts
14
+ fallback_fonts ['Fallback']
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module Elegant
2
- VERSION = '0.0.0'
2
+ VERSION = '1.0.0'
3
3
  end
data/lib/elegant.rb CHANGED
@@ -1,5 +1,7 @@
1
- require 'elegant/version'
1
+ require 'prawn'
2
+ require 'elegant/document'
2
3
 
4
+ # Provides Elegant::Document, a wrapper around Prawn::Document to initialize
5
+ # PDF pages with an elegant layout.
3
6
  module Elegant
4
- # Your code goes here...
5
7
  end
metadata CHANGED
@@ -1,29 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elegant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - claudiob
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-20 00:00:00.000000000 Z
11
+ date: 2015-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: prawn
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.10'
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pdf-inspector
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: prawn-manual_builder
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.2.0
20
48
  type: :development
21
49
  prerelease: false
22
50
  version_requirements: !ruby/object:Gem::Requirement
23
51
  requirements:
24
52
  - - "~>"
25
53
  - !ruby/object:Gem::Version
26
- version: '1.10'
54
+ version: 0.2.0
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: rake
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -38,7 +66,50 @@ dependencies:
38
66
  - - "~>"
39
67
  - !ruby/object:Gem::Version
40
68
  version: '10.0'
41
- description: ":elegant: :elegant: :elegant:"
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: coveralls
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.8.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.8.2
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-nav
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.2.4
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.2.4
111
+ description: Elegant expands Prawn providing a new class to generate new pages with
112
+ an elegant layout.
42
113
  email:
43
114
  - claudiob@gmail.com
44
115
  executables: []
@@ -47,17 +118,28 @@ extra_rdoc_files: []
47
118
  files:
48
119
  - ".gitignore"
49
120
  - ".travis.yml"
121
+ - CHANGELOG.md
50
122
  - Gemfile
51
- - LICENSE.txt
123
+ - MIT-LICENSE
52
124
  - README.md
53
125
  - Rakefile
54
126
  - bin/console
55
- - bin/dhh
127
+ - bin/elegant
56
128
  - bin/setup
57
129
  - elegant.gemspec
58
130
  - lib/elegant.rb
131
+ - lib/elegant/config.rb
132
+ - lib/elegant/configuration.rb
133
+ - lib/elegant/document.rb
134
+ - lib/elegant/fonts/DejaVuLicense.txt
135
+ - lib/elegant/fonts/DejaVuSans.ttf
136
+ - lib/elegant/fonts/DejaVuSansBold.ttf
137
+ - lib/elegant/footer.rb
138
+ - lib/elegant/header.rb
139
+ - lib/elegant/images/default_watermark.png
140
+ - lib/elegant/typography.rb
59
141
  - lib/elegant/version.rb
60
- homepage: https://github.com/claudiob/elegant
142
+ homepage: https://github.com/Fullscreen/elegant
61
143
  licenses:
62
144
  - MIT
63
145
  metadata: {}
@@ -69,7 +151,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
69
151
  requirements:
70
152
  - - ">="
71
153
  - !ruby/object:Gem::Version
72
- version: '0'
154
+ version: '2.1'
73
155
  required_rubygems_version: !ruby/object:Gem::Requirement
74
156
  requirements:
75
157
  - - ">="
@@ -80,6 +162,5 @@ rubyforge_project:
80
162
  rubygems_version: 2.4.5.1
81
163
  signing_key:
82
164
  specification_version: 4
83
- summary: ":elegant:"
165
+ summary: An elegant layout for PDF reports generated in Ruby.
84
166
  test_files: []
85
- has_rdoc:
data/bin/dhh DELETED
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'elegant'