show_off_pdf 0.0.2.pre → 0.0.3.pre

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -5,15 +5,55 @@ Using Markdown Prawn, showoff2pdf will try to convert
5
5
  a ShowOff presentation into a sensible PDF document
6
6
  ready to print.
7
7
 
8
+ At the moment it supports the following features:
9
+
10
+ * Bulleted Lists
11
+ * Ordered lists
12
+ * Images (local and remote)
13
+ * Multiple levels of headings
14
+ * Bold, Italic and Underline text
15
+
16
+ With partial (and in progress) support for:
17
+
18
+ * Code blocks
19
+ * Commandline argument
20
+ * Formatting / Alignment
21
+
22
+ Requirements
23
+ ------------
24
+
25
+ Requires the latest <tt>Prawn</tt> and also requires
26
+ <tt>ShowOff</tt>.
27
+
28
+ Prawn is used to generate the PDFs and ShowOff itself
29
+ is used to read the configuration information from the
30
+ slideshow and pull in its content from each section.
31
+
32
+
8
33
  Installation
9
34
  ------------
10
35
 
11
- $ sudo gem install show_off_pdf --pre
36
+ $ sudo gem install prawn --pre
37
+ $ sudo gem install show_off_pdf --pre showoff
12
38
 
13
39
  Usage
14
40
  -----
15
41
 
16
- $ cd ./show_off_presentation
42
+ $ cd /path/to/show_off_presentation
17
43
  $ showoff2pdf > presentation.pdf
18
44
 
19
- That's it
45
+ Known Issues
46
+ ------------
47
+
48
+ The following known issues are being worked on
49
+
50
+ * Detecting and dealing with code blocks is sketchy
51
+ and inconsistant.
52
+ * Detecting and dealing with commandline blocks is
53
+ sketchy and inconsistant.
54
+
55
+ Bugs
56
+ ----
57
+
58
+ Please open an issue here if you encounter a problem with
59
+ using showoff2pdf.
data/bin/showoff2pdf CHANGED
@@ -4,10 +4,17 @@ require File.dirname(__FILE__) + '/../show_off_pdf'
4
4
  paths = []
5
5
  images = []
6
6
  ShowOffUtils.showoff_sections.each do |section|
7
- paths << Dir.glob(File.expand_path("./#{section}/*.{md,mdown}"))
7
+ paths << Dir.glob(File.expand_path("./#{section}/**/*.{md,mdown}"))
8
8
  images << Dir.glob(File.expand_path("./#{section}/**/*.{png,jpg,jpeg}"))
9
9
  end
10
10
  paths.flatten!
11
11
  images.flatten!
12
12
  ImageFragment._image_assets = images
13
+
14
+ # If we set this, then it'll automatically preshrink
15
+ # images to 80% of their size before attempting to
16
+ # scale them.
17
+ #
18
+ ImageFragment._page_image_ratio = 0.8
19
+
13
20
  puts ShowoffSlideStream.new(paths).to_pdf.render
data/example.pdf CHANGED
Binary file
@@ -2,6 +2,15 @@ require 'net/http'
2
2
  require 'tmpdir'
3
3
 
4
4
  class ImageFragment < MarkdownFragment
5
+
6
+ def self._page_image_ratio=(value)
7
+ @@_page_image_ratio = value
8
+ end
9
+
10
+ def self._page_image_ratio
11
+ @@_page_image_ratio
12
+ end
13
+
5
14
  def self._image_assets=(value)
6
15
  @@_image_assets = value
7
16
  end
@@ -35,7 +44,8 @@ class ImageFragment < MarkdownFragment
35
44
  width = JPEG.new(file_path).width
36
45
  height = JPEG.new(file_path).height
37
46
  end
38
- pdf_object.image file_path, :width => width, :height => height, :scale => 0.8
47
+ width,height = best_fit(width, height, pdf_object)
48
+ pdf_object.image file_path , :fit => [ width, height], :position => :center
39
49
  end
40
50
 
41
51
  private
@@ -44,6 +54,64 @@ class ImageFragment < MarkdownFragment
44
54
  !/^(http:|https:)/.match(@content.first).nil?
45
55
  end
46
56
 
57
+ # Calculate the width and height to best fit the
58
+ # image on the page.
59
+ #
60
+ def best_fit(width, height, pdf)
61
+ ph = pdf.bounds.height - page_padding
62
+ pw = pdf.bounds.width - page_padding
63
+ return [width, height] if height <= ph && width <= pw
64
+
65
+ if ImageFragment._page_image_ratio
66
+ iw = width * ImageFragment._page_image_ratio
67
+ ih = height * ImageFragment._page_image_ratio
68
+ else
69
+ iw = width
70
+ ih = height
71
+ end
72
+ iw = pixels_to_points(iw)
73
+ ih = pixels_to_points(ih)
74
+
75
+ if ih <= ph && iw <= pw
76
+ return [iw, ih]
77
+ elsif ih > ph
78
+ r = height / width
79
+ ih = (ih - (page_padding * 2))
80
+ iw = ih * r
81
+ elsif iw > pw
82
+ r = width / height
83
+ iw = (iw - (page_padding * 2))
84
+ ih = iw * r
85
+ else
86
+ puts "SHOULD NEXT GET HERE"
87
+ exit(-1)
88
+ end
89
+ return [iw, ih]
90
+ end
91
+
92
+ # Work out the page padding later, for not assume that
93
+ # it's 20.
94
+ #
95
+ def page_padding
96
+ 20
97
+ end
98
+
99
+
100
+ # Very rough way to convert pixels to points, by
101
+ # assuming the we're at 96 DPI. This isn't the most
102
+ # ideal method, but it should be good enough for
103
+ # sizing images to fit on page correctly.
104
+ #
105
+ def pixels_to_points(pixels)
106
+ pixels * 72 / 96
107
+ end
108
+
109
+ # Very rough reversal ov the above
110
+ #
111
+ def points_to_pixels(points)
112
+ points / 72 * 96
113
+ end
114
+
47
115
  end
48
116
 
49
117
  class JPEG
@@ -1,6 +1,22 @@
1
1
  class ShowOffSlide
2
2
  attr_accessor :components, :content
3
-
3
+
4
+ SHOWOFF_SLIDE_TYPES = [
5
+ 'subsection',
6
+ 'commandline',
7
+ 'incremental',
8
+ 'center',
9
+ 'command',
10
+ 'small',
11
+ 'full-page',
12
+ 'bullets',
13
+ 'smbullets',
14
+ 'code',
15
+ 'smaller',
16
+ 'execute',
17
+ 'transition='
18
+ ]
19
+
4
20
  def initialize(content = '', options = {})
5
21
  @components = []
6
22
  @options = { :size => 'A4', :layout => :landscape }.merge(options)
@@ -17,7 +33,17 @@ class ShowOffSlide
17
33
  private
18
34
 
19
35
  def parse
20
-
36
+ # Get rid of leading \n characters
37
+ #
38
+ @content.gsub!(/^(\n)*/,'')
39
+
40
+ # Skip aparently blank slides
41
+ #
42
+ return if @content.empty?
43
+
44
+ # Pull out presenter notes for displaying at the bottom
45
+ # of the page
46
+ #
21
47
  s =/(\s)?.notes\s(.*)(\n)?/.match(@content)
22
48
  if !s.nil?
23
49
  @slide_notes = $2
@@ -25,10 +51,9 @@ class ShowOffSlide
25
51
  else
26
52
  @slide_notes = nil
27
53
  end
28
-
54
+
29
55
  sp = MarkdownPrawn::StringParser.new(@content)
30
56
  sp.parse!
31
- #@components << ParagraphFragment.new([@content])
32
57
  @components = sp.document_structure
33
58
  if @slide_notes
34
59
  @components << PresenterNotesFragment.new([@slide_notes])
data/show_off_pdf.gemspec CHANGED
@@ -11,7 +11,7 @@ TXT
11
11
 
12
12
  Gem::Specification.new do |spec|
13
13
  spec.name = "show_off_pdf"
14
- spec.version = '0.0.2.pre'
14
+ spec.version = '0.0.3.pre'
15
15
  spec.platform = Gem::Platform::RUBY
16
16
  spec.files = Dir.glob("{bin,lib,.}/**/**/*") +
17
17
  ["show_off_pdf.rb","README.md","COPYING.md",'LICENSE', "show_off_pdf.gemspec"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: show_off_pdf
3
3
  version: !ruby/object:Gem::Version
4
- hash: 961915980
4
+ hash: 961915976
5
5
  prerelease: true
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
9
+ - 3
10
10
  - pre
11
- version: 0.0.2.pre
11
+ version: 0.0.3.pre
12
12
  platform: ruby
13
13
  authors:
14
14
  - Ryan Stenhouse
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-12-09 00:00:00 +00:00
19
+ date: 2010-12-10 00:00:00 +00:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency