tp 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.cane +5 -0
- data/.travis.yml +1 -1
- data/Gemfile +2 -0
- data/Guardfile +4 -1
- data/Rakefile +8 -3
- data/Readme.md +2 -2
- data/bin/tp +3 -1
- data/lib/coderay/prawn_encoder.rb +39 -0
- data/lib/keyboard.rb +28 -16
- data/lib/tp.rb +4 -0
- data/lib/tp/cli.rb +27 -0
- data/lib/tp/presenter.rb +11 -1
- data/lib/tp/publisher/pdf.rb +85 -0
- data/lib/tp/slide.rb +13 -5
- data/lib/tp/slide/bulleted.rb +29 -6
- data/lib/tp/slide/code.rb +41 -8
- data/lib/tp/slide/header_only.rb +10 -1
- data/lib/tp/slide/paragraph.rb +20 -1
- data/lib/tp/slide_deck.rb +15 -12
- data/lib/tp/version.rb +1 -1
- data/slides.md +6 -2
- data/spec/lib/tp/cli_spec.rb +57 -0
- data/spec/lib/tp/coderay/prawn_encoder_spec.rb +21 -0
- data/spec/lib/tp/publisher/pdf_spec.rb +11 -0
- data/spec/lib/tp/slide/bulleted_spec.rb +19 -4
- data/spec/lib/tp/slide/code_spec.rb +5 -2
- data/spec/lib/tp/slide/header_only_spec.rb +2 -2
- data/spec/lib/tp/slide/paragraph_spec.rb +2 -2
- data/spec/spec_helper.rb +2 -2
- data/tp.gemspec +6 -1
- metadata +92 -2
data/.cane
ADDED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Guardfile
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
-
guard
|
1
|
+
guard :rspec, env: { skip_coverage: true } do
|
2
2
|
watch(%r{^spec/.+_spec\.rb$})
|
3
3
|
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
4
4
|
watch('spec/spec_helper.rb') { "spec" }
|
5
5
|
end
|
6
6
|
|
7
|
+
guard :cane do
|
8
|
+
watch(/.*\.rb/)
|
9
|
+
end
|
data/Rakefile
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
|
+
require 'cane/rake_task'
|
2
3
|
require 'rspec/core/rake_task'
|
3
4
|
|
4
|
-
|
5
|
-
task default: :spec
|
5
|
+
task default: :ci
|
6
6
|
|
7
|
-
|
7
|
+
task :ci do
|
8
|
+
Rake::Task[:spec].invoke
|
9
|
+
Rake::Task[:cane].invoke
|
10
|
+
end
|
11
|
+
|
12
|
+
Cane::RakeTask.new
|
8
13
|
RSpec::Core::RakeTask.new
|
data/Readme.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# tp
|
2
|
-
[![Build Status](https://
|
2
|
+
[![Build Status](https://travis-ci.org/justincampbell/tp.png?branch=master)](https://travis-ci.org/justincampbell/tp)
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/tp.png)](http://badge.fury.io/rb/tp)
|
4
|
-
[![Code Climate](https://codeclimate.com/
|
4
|
+
[![Code Climate](https://codeclimate.com/github/justincampbell/tp.png)](https://codeclimate.com/github/justincampbell/tp)
|
5
5
|
|
6
6
|
![Demo](https://s3.amazonaws.com/justincampbell/tp.gif)
|
7
7
|
|
data/bin/tp
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
require "coderay"
|
2
|
+
|
3
|
+
class PrawnEncoder < CodeRay::Encoders::Encoder
|
4
|
+
register_for :to_prawn
|
5
|
+
|
6
|
+
COLORS = {
|
7
|
+
default: "E6E1DC",
|
8
|
+
comment: "BC9458",
|
9
|
+
constant: "DA4939",
|
10
|
+
instance_variable: "D0D0FF",
|
11
|
+
integer: "56D65E",
|
12
|
+
float: "56D65E",
|
13
|
+
inline_delimiter: "EF804F",
|
14
|
+
keyword: "CC7833",
|
15
|
+
method: "FFC66D",
|
16
|
+
string: "A5C261",
|
17
|
+
symbol: "6D9CBE"
|
18
|
+
}
|
19
|
+
|
20
|
+
def setup(options)
|
21
|
+
super
|
22
|
+
@out = []
|
23
|
+
@open = []
|
24
|
+
end
|
25
|
+
|
26
|
+
def text_token(text, kind)
|
27
|
+
color = COLORS[kind] || COLORS[@open.last] || COLORS[:default]
|
28
|
+
|
29
|
+
@out << {:text => text, :color => color}
|
30
|
+
end
|
31
|
+
|
32
|
+
def begin_group(kind)
|
33
|
+
@open << kind
|
34
|
+
end
|
35
|
+
|
36
|
+
def end_group(kind)
|
37
|
+
@open.pop
|
38
|
+
end
|
39
|
+
end
|
data/lib/keyboard.rb
CHANGED
@@ -2,26 +2,15 @@ module Keyboard
|
|
2
2
|
extend self
|
3
3
|
|
4
4
|
def read
|
5
|
-
|
6
|
-
old_stty = `stty -g`
|
7
|
-
system "stty raw -echo"
|
8
|
-
|
9
|
-
chr = STDIN.getc.chr
|
5
|
+
chr = ""
|
10
6
|
|
11
|
-
|
12
|
-
|
13
|
-
chr = chr + STDIN.getc.chr
|
14
|
-
chr = chr + STDIN.getc.chr
|
15
|
-
}
|
7
|
+
with_stty "raw -echo" do
|
8
|
+
chr << STDIN.getc.chr
|
16
9
|
|
17
|
-
|
18
|
-
extra_thread.kill
|
19
|
-
end
|
20
|
-
ensure
|
21
|
-
system "stty #{old_stty}"
|
10
|
+
chr = extra_thread_trick(chr) if chr == "\e"
|
22
11
|
end
|
23
12
|
|
24
|
-
symbolize
|
13
|
+
symbolize(chr)
|
25
14
|
end
|
26
15
|
|
27
16
|
def wait_for_return
|
@@ -34,6 +23,29 @@ module Keyboard
|
|
34
23
|
|
35
24
|
private
|
36
25
|
|
26
|
+
def extra_thread_trick(chr)
|
27
|
+
extra_thread = Thread.new {
|
28
|
+
chr = chr + STDIN.getc.chr
|
29
|
+
chr = chr + STDIN.getc.chr
|
30
|
+
}
|
31
|
+
|
32
|
+
extra_thread.join 0.00001
|
33
|
+
extra_thread.kill
|
34
|
+
|
35
|
+
chr
|
36
|
+
end
|
37
|
+
|
38
|
+
def with_stty(options, &block)
|
39
|
+
begin
|
40
|
+
old_stty = `stty -g`
|
41
|
+
system "stty #{options}"
|
42
|
+
|
43
|
+
yield
|
44
|
+
ensure
|
45
|
+
system "stty #{old_stty}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
37
49
|
def symbolize(character)
|
38
50
|
case character
|
39
51
|
when " "
|
data/lib/tp.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
require 'coderay'
|
2
|
+
require 'coderay/prawn_encoder'
|
3
|
+
require 'thor'
|
2
4
|
|
3
5
|
require 'keyboard'
|
4
6
|
require 'screen'
|
5
7
|
require 'string'
|
8
|
+
require 'tp/cli'
|
6
9
|
require 'tp/presenter'
|
10
|
+
require 'tp/publisher/pdf'
|
7
11
|
require 'tp/renderer'
|
8
12
|
require 'tp/slide'
|
9
13
|
require 'tp/slide/bulleted'
|
data/lib/tp/cli.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module TP
|
2
|
+
class CLI < Thor
|
3
|
+
default_task :usage
|
4
|
+
|
5
|
+
desc "usage", "Display usage banner", hide: true
|
6
|
+
def usage
|
7
|
+
puts [
|
8
|
+
"Terminal Presenter #{TP::VERSION}",
|
9
|
+
"https://github.com/justincampbell/tp"
|
10
|
+
].join("\n")
|
11
|
+
|
12
|
+
puts "\n"
|
13
|
+
|
14
|
+
help
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "FILENAME", "Present a Markdown file in your terminal"
|
18
|
+
def present(filename)
|
19
|
+
TP::Presenter.new(File.read(filename)).present
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "pdf FILENAME [OUTPUT]", "Convert a Markdown slide deck to a PDF"
|
23
|
+
def pdf(filename, output = nil)
|
24
|
+
TP::Publisher::PDF.new(filename, output).publish
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/tp/presenter.rb
CHANGED
@@ -7,9 +7,17 @@ module TP
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def present
|
10
|
+
suggest_sizing
|
11
|
+
render_slides
|
12
|
+
clear_screen
|
13
|
+
end
|
14
|
+
|
15
|
+
def suggest_sizing
|
10
16
|
Screen.suggest slide_deck.width, slide_deck.height
|
11
17
|
Keyboard.wait_for_return
|
18
|
+
end
|
12
19
|
|
20
|
+
def render_slides
|
13
21
|
loop do
|
14
22
|
Renderer.new(slide_deck.current_frame).render
|
15
23
|
|
@@ -24,14 +32,16 @@ module TP
|
|
24
32
|
|
25
33
|
break if slide_deck.ended?
|
26
34
|
end
|
35
|
+
end
|
27
36
|
|
37
|
+
def clear_screen
|
28
38
|
Screen.clear!
|
29
39
|
end
|
30
40
|
|
31
41
|
def slides
|
32
42
|
result = markdown.split /^#/
|
33
43
|
result.reject! &:empty?
|
34
|
-
result.map! { |string| string
|
44
|
+
result.map! { |string| "##{string}" }
|
35
45
|
|
36
46
|
result.map { |string| SlideFactory.from_markdown string }
|
37
47
|
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require "prawn"
|
2
|
+
require "prawn/measurement_extensions"
|
3
|
+
|
4
|
+
module TP
|
5
|
+
module Publisher
|
6
|
+
class PDF
|
7
|
+
extend Forwardable
|
8
|
+
def_delegators :pdf,
|
9
|
+
:bounds,
|
10
|
+
:canvas,
|
11
|
+
:fill_color,
|
12
|
+
:fill_rectangle,
|
13
|
+
:font,
|
14
|
+
:font_size,
|
15
|
+
:render_file,
|
16
|
+
:start_new_page,
|
17
|
+
:text_box,
|
18
|
+
:width_of
|
19
|
+
|
20
|
+
attr_reader :input_filename
|
21
|
+
|
22
|
+
def initialize(input_filename, output_filename)
|
23
|
+
@input_filename = input_filename
|
24
|
+
@output_filename = output_filename
|
25
|
+
end
|
26
|
+
|
27
|
+
def publish
|
28
|
+
slides.each do |slide|
|
29
|
+
render_slide(slide)
|
30
|
+
end
|
31
|
+
|
32
|
+
render_file output_filename
|
33
|
+
end
|
34
|
+
|
35
|
+
def render_slide(slide)
|
36
|
+
new_page
|
37
|
+
|
38
|
+
slide.render_pdf(pdf)
|
39
|
+
end
|
40
|
+
|
41
|
+
def markdown
|
42
|
+
@markdown ||= File.read(input_filename)
|
43
|
+
end
|
44
|
+
|
45
|
+
def presenter
|
46
|
+
@presenter ||= Presenter.new(markdown)
|
47
|
+
end
|
48
|
+
|
49
|
+
def slides
|
50
|
+
presenter.slides
|
51
|
+
end
|
52
|
+
|
53
|
+
def output_filename
|
54
|
+
@output_filename || "#{input_filename.split('.').first}.pdf"
|
55
|
+
end
|
56
|
+
|
57
|
+
def pdf
|
58
|
+
@pdf ||= Prawn::Document.new(document_options)
|
59
|
+
end
|
60
|
+
|
61
|
+
def document_options
|
62
|
+
{
|
63
|
+
page_layout: :landscape,
|
64
|
+
optimize_objects: true,
|
65
|
+
skip_page_creation: true
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
def new_page
|
70
|
+
start_new_page
|
71
|
+
|
72
|
+
fill_color '111111'
|
73
|
+
|
74
|
+
canvas do
|
75
|
+
fill_rectangle [bounds.left, bounds.top], bounds.width, bounds.height
|
76
|
+
end
|
77
|
+
|
78
|
+
fill_color 'EEEEEE'
|
79
|
+
|
80
|
+
font "Helvetica"
|
81
|
+
font_size 1.in
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
data/lib/tp/slide.rb
CHANGED
@@ -22,23 +22,31 @@ module TP
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def frames
|
25
|
-
[
|
25
|
+
[render_terminal]
|
26
26
|
end
|
27
27
|
|
28
28
|
def lines
|
29
29
|
markdown.lines.to_a
|
30
30
|
end
|
31
31
|
|
32
|
-
def
|
33
|
-
|
32
|
+
def pdf_content_height(pdf)
|
33
|
+
pdf.bounds.height - pdf_header_height
|
34
34
|
end
|
35
35
|
|
36
|
-
def
|
37
|
-
|
36
|
+
def pdf_content_top_left(pdf)
|
37
|
+
[pdf.bounds.left, pdf.bounds.top - pdf_header_height]
|
38
|
+
end
|
39
|
+
|
40
|
+
def pdf_header_height
|
41
|
+
header != "" ? 1.in : 0
|
38
42
|
end
|
39
43
|
|
40
44
|
def height
|
41
45
|
lines.count
|
42
46
|
end
|
47
|
+
|
48
|
+
def hard_width?
|
49
|
+
true
|
50
|
+
end
|
43
51
|
end
|
44
52
|
end
|
data/lib/tp/slide/bulleted.rb
CHANGED
@@ -1,18 +1,41 @@
|
|
1
1
|
class TP::Slide::Bulleted < TP::Slide
|
2
|
-
BULLET = "\u2022
|
2
|
+
BULLET = "\u2022"
|
3
|
+
|
4
|
+
def render_pdf(pdf)
|
5
|
+
pdf.text_box header,
|
6
|
+
align: :center,
|
7
|
+
overflow: :shrink_to_fit,
|
8
|
+
single_line: true,
|
9
|
+
height: pdf_header_height,
|
10
|
+
size: pdf_header_height
|
11
|
+
|
12
|
+
pdf.text_box rendered_bullets,
|
13
|
+
at: pdf_content_top_left(pdf),
|
14
|
+
height: pdf_content_height(pdf),
|
15
|
+
overflow: :shrink_to_fit,
|
16
|
+
valign: :center
|
17
|
+
end
|
3
18
|
|
4
|
-
def
|
19
|
+
def render_terminal
|
5
20
|
frames.last
|
6
21
|
end
|
7
22
|
|
8
23
|
def width
|
9
24
|
header_length = header.length
|
10
|
-
longest_bullet = bullets.collect(&:length).max +
|
25
|
+
longest_bullet = bullets.collect(&:length).max + bullet_length
|
11
26
|
[header_length, longest_bullet].max
|
12
27
|
end
|
13
28
|
|
14
29
|
def bullets
|
15
|
-
content.lines.to_a.map { |line| line.gsub(
|
30
|
+
content.lines.to_a.map { |line| line.gsub(/^[\*|-]\s/, "").strip }
|
31
|
+
end
|
32
|
+
|
33
|
+
def bullet_length
|
34
|
+
BULLET.length + 1
|
35
|
+
end
|
36
|
+
|
37
|
+
def rendered_bullets
|
38
|
+
bullets.map { |text| "#{BULLET} #{text}" }.join("\n")
|
16
39
|
end
|
17
40
|
|
18
41
|
def frames
|
@@ -23,8 +46,8 @@ class TP::Slide::Bulleted < TP::Slide
|
|
23
46
|
|
24
47
|
@frames = [buffer.dup]
|
25
48
|
|
26
|
-
bullets.each do |
|
27
|
-
buffer << "#{BULLET} #{
|
49
|
+
bullets.each do |line|
|
50
|
+
buffer << "#{BULLET} #{line}\n"
|
28
51
|
@frames << buffer.dup
|
29
52
|
end
|
30
53
|
|
data/lib/tp/slide/code.rb
CHANGED
@@ -1,5 +1,41 @@
|
|
1
1
|
class TP::Slide::Code < TP::Slide
|
2
|
-
|
2
|
+
LANGUAGE_MAPPINGS = {
|
3
|
+
[nil] => 'text',
|
4
|
+
%w[clj] => 'clojure',
|
5
|
+
%w[objc] => 'cpp',
|
6
|
+
%w[rb] => 'ruby'
|
7
|
+
}
|
8
|
+
|
9
|
+
def render_pdf(pdf)
|
10
|
+
pdf.text_box header,
|
11
|
+
align: :center,
|
12
|
+
overflow: :shrink_to_fit,
|
13
|
+
single_line: true,
|
14
|
+
height: pdf_header_height,
|
15
|
+
size: pdf_header_height
|
16
|
+
|
17
|
+
pdf.font 'Courier' do
|
18
|
+
pdf.formatted_text_box prawn_code,
|
19
|
+
at: pdf_content_top_left(pdf),
|
20
|
+
height: pdf_content_height(pdf),
|
21
|
+
size: (pdf.bounds.width / maximum_line_length) * character_ratio(pdf),
|
22
|
+
valign: :center
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def character_ratio(pdf)
|
27
|
+
pdf.font_size / pdf.width_of("#")
|
28
|
+
end
|
29
|
+
|
30
|
+
def maximum_line_length
|
31
|
+
[code.lines.to_a.map { |line| line.rstrip.length }.max, 80].min
|
32
|
+
end
|
33
|
+
|
34
|
+
def prawn_code
|
35
|
+
CodeRay.scan(code.gsub(' ', Prawn::Text::NBSP), language).to_prawn
|
36
|
+
end
|
37
|
+
|
38
|
+
def render_terminal
|
3
39
|
centered_header +
|
4
40
|
"\n\n" +
|
5
41
|
highlighted_code
|
@@ -28,13 +64,10 @@ class TP::Slide::Code < TP::Slide
|
|
28
64
|
end
|
29
65
|
|
30
66
|
def language
|
31
|
-
|
32
|
-
|
33
|
-
when "clj" then "clojure"
|
34
|
-
when "objc" then "cpp"
|
35
|
-
when "rb" then "ruby"
|
36
|
-
else
|
37
|
-
raw_language
|
67
|
+
LANGUAGE_MAPPINGS.each do |keys, value|
|
68
|
+
return value if keys.include? raw_language
|
38
69
|
end
|
70
|
+
|
71
|
+
raw_language
|
39
72
|
end
|
40
73
|
end
|
data/lib/tp/slide/header_only.rb
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
class TP::Slide::HeaderOnly < TP::Slide
|
2
|
-
def
|
2
|
+
def render_pdf(pdf)
|
3
|
+
pdf.text_box header,
|
4
|
+
align: :center,
|
5
|
+
overflow: :shrink_to_fit,
|
6
|
+
single_line: true,
|
7
|
+
size: pdf.bounds.height,
|
8
|
+
valign: :center
|
9
|
+
end
|
10
|
+
|
11
|
+
def render_terminal
|
3
12
|
centered_header
|
4
13
|
end
|
5
14
|
|
data/lib/tp/slide/paragraph.rb
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
class TP::Slide::Paragraph < TP::Slide
|
2
|
-
def
|
2
|
+
def render_pdf(pdf)
|
3
|
+
pdf.text_box header,
|
4
|
+
align: :center,
|
5
|
+
overflow: :shrink_to_fit,
|
6
|
+
single_line: true,
|
7
|
+
height: pdf_header_height,
|
8
|
+
size: pdf_header_height
|
9
|
+
|
10
|
+
pdf.text_box paragraph,
|
11
|
+
at: pdf_content_top_left(pdf),
|
12
|
+
height: pdf_content_height(pdf),
|
13
|
+
overflow: :shrink_to_fit,
|
14
|
+
valign: :center
|
15
|
+
end
|
16
|
+
|
17
|
+
def render_terminal
|
3
18
|
centered_header +
|
4
19
|
"\n\n" +
|
5
20
|
paragraph
|
@@ -15,4 +30,8 @@ class TP::Slide::Paragraph < TP::Slide
|
|
15
30
|
def width
|
16
31
|
content.length
|
17
32
|
end
|
33
|
+
|
34
|
+
def hard_width?
|
35
|
+
false
|
36
|
+
end
|
18
37
|
end
|
data/lib/tp/slide_deck.rb
CHANGED
@@ -7,10 +7,6 @@ module TP
|
|
7
7
|
@slides = slides
|
8
8
|
end
|
9
9
|
|
10
|
-
def [](index)
|
11
|
-
frames[index]
|
12
|
-
end
|
13
|
-
|
14
10
|
def current
|
15
11
|
frames[cursor]
|
16
12
|
end
|
@@ -45,20 +41,27 @@ module TP
|
|
45
41
|
end
|
46
42
|
|
47
43
|
def width
|
48
|
-
|
49
|
-
|
50
|
-
if slides_without_paragraphs.empty?
|
51
|
-
[slides.collect(&:width).max, 80].min
|
44
|
+
if maximum_hard_width
|
45
|
+
[maximum_header_length, maximum_hard_width].max
|
52
46
|
else
|
53
|
-
[
|
54
|
-
slides.collect(&:header).map(&:length).max,
|
55
|
-
slides_without_paragraphs.collect(&:width).max
|
56
|
-
].max
|
47
|
+
[maximum_width, 80].min
|
57
48
|
end
|
58
49
|
end
|
59
50
|
|
60
51
|
def height
|
61
52
|
slides.collect(&:height).max
|
62
53
|
end
|
54
|
+
|
55
|
+
def maximum_header_length
|
56
|
+
slides.collect(&:header).map(&:length).max
|
57
|
+
end
|
58
|
+
|
59
|
+
def maximum_width
|
60
|
+
slides.collect(&:width).max
|
61
|
+
end
|
62
|
+
|
63
|
+
def maximum_hard_width
|
64
|
+
slides.select(&:hard_width?).collect(&:width).max
|
65
|
+
end
|
63
66
|
end
|
64
67
|
end
|
data/lib/tp/version.rb
CHANGED
data/slides.md
CHANGED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
require 'tmpdir'
|
5
|
+
|
6
|
+
describe TP::CLI do
|
7
|
+
subject { cli }
|
8
|
+
let(:cli) { klass.new }
|
9
|
+
|
10
|
+
let(:tmpdir) { Dir.mktmpdir }
|
11
|
+
let(:input_filename) { File.join(tmpdir, "slides.md") }
|
12
|
+
let(:slides) { File.read("slides.md") }
|
13
|
+
|
14
|
+
before do
|
15
|
+
File.open(input_filename, 'w') {|file| file.write slides }
|
16
|
+
end
|
17
|
+
|
18
|
+
after do
|
19
|
+
FileUtils.rm_rf tmpdir
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#usage" do
|
23
|
+
subject(:usage) { cli.usage }
|
24
|
+
|
25
|
+
it "displays a banner and help" do
|
26
|
+
cli.should_receive(:puts).exactly(2).times
|
27
|
+
cli.should_receive(:help)
|
28
|
+
|
29
|
+
usage
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#present" do
|
34
|
+
subject(:present) { cli.present(input_filename) }
|
35
|
+
|
36
|
+
before do
|
37
|
+
Keyboard.stub(:read).and_return(:return, :return, :backspace, 'q')
|
38
|
+
Screen.stub(:print)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "presents" do
|
42
|
+
present
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#pdf" do
|
47
|
+
subject(:pdf) { cli.pdf(input_filename, output_filename) }
|
48
|
+
|
49
|
+
let(:output_filename) { File.join(tmpdir, "slides.pdf") }
|
50
|
+
|
51
|
+
it "renders a PDF" do
|
52
|
+
pdf
|
53
|
+
|
54
|
+
File.exist?(output_filename).should be_true
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PrawnEncoder do
|
4
|
+
subject { prawn_encoder }
|
5
|
+
let(:prawn_encoder) { klass.new }
|
6
|
+
|
7
|
+
let(:options) { {} }
|
8
|
+
|
9
|
+
before do
|
10
|
+
prawn_encoder.setup(options)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "builds a prawn token" do
|
14
|
+
prawn_encoder.begin_group(:comment)
|
15
|
+
prawn_encoder.text_token("# test", nil).should == [{
|
16
|
+
text: "# test",
|
17
|
+
color: klass::COLORS[:comment]
|
18
|
+
}]
|
19
|
+
prawn_encoder.end_group(:comment)
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TP::Publisher::PDF do
|
4
|
+
subject { publisher }
|
5
|
+
let(:publisher) { klass.new(input_filename, output_filename) }
|
6
|
+
|
7
|
+
let(:input_filename) { "slides.md" }
|
8
|
+
let(:output_filename) { nil }
|
9
|
+
|
10
|
+
its(:output_filename) { should == "slides.pdf" }
|
11
|
+
end
|
@@ -3,6 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe TP::Slide::Bulleted do
|
4
4
|
subject { slide }
|
5
5
|
|
6
|
+
let(:bullet) { TP::Slide::Bulleted::BULLET }
|
6
7
|
let(:markdown) { "# Bullets\n\n* Bullet 1\n* Bullet 2" }
|
7
8
|
let(:slide) { klass.new markdown }
|
8
9
|
|
@@ -10,11 +11,19 @@ describe TP::Slide::Bulleted do
|
|
10
11
|
Screen.stub width: 20
|
11
12
|
end
|
12
13
|
|
14
|
+
its(:bullets) { should == ["Bullet 1", "Bullet 2"] }
|
15
|
+
|
13
16
|
its(:width) { should == 10 }
|
14
17
|
its(:height) { should == 4 }
|
15
18
|
|
16
|
-
|
17
|
-
|
19
|
+
context "with dash bullets" do
|
20
|
+
let(:markdown) { "# Bullets\n\n- Bullet 1\n- Bullet 2" }
|
21
|
+
|
22
|
+
its(:bullets) { should == ["Bullet 1", "Bullet 2"] }
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#render_terminal" do
|
26
|
+
subject(:lines) { slide.render_terminal.lines.to_a }
|
18
27
|
|
19
28
|
it { lines.count.should == 4 }
|
20
29
|
|
@@ -23,11 +32,17 @@ describe TP::Slide::Bulleted do
|
|
23
32
|
end
|
24
33
|
|
25
34
|
it "renders bullets" do
|
26
|
-
lines[2].should == "#{
|
27
|
-
lines[3].should == "#{
|
35
|
+
lines[2].should == "#{bullet} Bullet 1\n"
|
36
|
+
lines[3].should == "#{bullet} Bullet 2\n"
|
28
37
|
end
|
29
38
|
end
|
30
39
|
|
40
|
+
describe "#rendered_bullets" do
|
41
|
+
subject(:rendered_bullets) { slide.rendered_bullets }
|
42
|
+
|
43
|
+
it { should == "#{bullet} Bullet 1\n#{bullet} Bullet 2" }
|
44
|
+
end
|
45
|
+
|
31
46
|
describe "#frames" do
|
32
47
|
subject(:frames) { slide.frames }
|
33
48
|
|
@@ -16,6 +16,9 @@ describe TP::Slide::Code do
|
|
16
16
|
its(:code) { should == "class Thing\nend\n" }
|
17
17
|
its(:language) { should == "ruby" }
|
18
18
|
|
19
|
+
its(:maximum_line_length) { should == 11 }
|
20
|
+
its(:prawn_code) { should be_a Array }
|
21
|
+
|
19
22
|
describe "#highlighted_code" do
|
20
23
|
subject(:highlighted_code) { slide.highlighted_code }
|
21
24
|
|
@@ -34,8 +37,8 @@ describe TP::Slide::Code do
|
|
34
37
|
end
|
35
38
|
end
|
36
39
|
|
37
|
-
describe "#
|
38
|
-
subject(:
|
40
|
+
describe "#render_terminal" do
|
41
|
+
subject(:render_terminal) { slide.render_terminal }
|
39
42
|
|
40
43
|
before do
|
41
44
|
slide.stub highlighted_code: "Highlighted code"
|
@@ -13,8 +13,8 @@ describe TP::Slide::HeaderOnly do
|
|
13
13
|
its(:width) { should == 6 }
|
14
14
|
its(:height) { should == 1 }
|
15
15
|
|
16
|
-
describe "#
|
17
|
-
subject(:lines) { slide.
|
16
|
+
describe "#render_terminal" do
|
17
|
+
subject(:lines) { slide.render_terminal.lines.to_a }
|
18
18
|
|
19
19
|
it { lines.count.should == 1 }
|
20
20
|
|
@@ -13,8 +13,8 @@ describe TP::Slide::Paragraph do
|
|
13
13
|
its(:width) { should == 15 }
|
14
14
|
its(:height) { should == 3 }
|
15
15
|
|
16
|
-
describe "#
|
17
|
-
subject(:lines) { slide.
|
16
|
+
describe "#render_terminal" do
|
17
|
+
subject(:lines) { slide.render_terminal.lines.to_a }
|
18
18
|
|
19
19
|
it { lines.count.should == 3 }
|
20
20
|
|
data/spec/spec_helper.rb
CHANGED
@@ -4,7 +4,7 @@ require 'support/klass'
|
|
4
4
|
|
5
5
|
puts RUBY_DESCRIPTION
|
6
6
|
|
7
|
-
|
7
|
+
unless ENV['skip_coverage']
|
8
8
|
require 'simplecov'
|
9
9
|
SimpleCov.start
|
10
10
|
end
|
@@ -15,6 +15,6 @@ RSpec.configure do |config|
|
|
15
15
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
16
16
|
config.run_all_when_everything_filtered = true
|
17
17
|
config.filter_run :focus
|
18
|
-
config.order =
|
18
|
+
config.order = :random
|
19
19
|
end
|
20
20
|
|
data/tp.gemspec
CHANGED
@@ -20,9 +20,14 @@ Gem::Specification.new do |gem|
|
|
20
20
|
gem.require_paths = ["lib"]
|
21
21
|
|
22
22
|
gem.add_dependency "coderay", "~> 1.0"
|
23
|
+
gem.add_dependency "prawn", "~> 0.12"
|
24
|
+
gem.add_dependency "thor", "~> 0.17"
|
23
25
|
|
26
|
+
gem.add_development_dependency "cane"
|
27
|
+
gem.add_development_dependency "guard"
|
24
28
|
gem.add_development_dependency "guard-rspec"
|
29
|
+
gem.add_development_dependency "guard-cane"
|
25
30
|
gem.add_development_dependency "rake"
|
26
31
|
gem.add_development_dependency "rspec"
|
27
|
-
gem.add_development_dependency "simplecov" if RUBY_DESCRIPTION.start_with? "ruby
|
32
|
+
gem.add_development_dependency "simplecov" if RUBY_DESCRIPTION.start_with? "ruby"
|
28
33
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-02-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: coderay
|
@@ -27,6 +27,70 @@ dependencies:
|
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '1.0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: prawn
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0.12'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0.12'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: thor
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0.17'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.17'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: cane
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: guard
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
30
94
|
- !ruby/object:Gem::Dependency
|
31
95
|
name: guard-rspec
|
32
96
|
requirement: !ruby/object:Gem::Requirement
|
@@ -43,6 +107,22 @@ dependencies:
|
|
43
107
|
- - ! '>='
|
44
108
|
- !ruby/object:Gem::Version
|
45
109
|
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: guard-cane
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
46
126
|
- !ruby/object:Gem::Dependency
|
47
127
|
name: rake
|
48
128
|
requirement: !ruby/object:Gem::Requirement
|
@@ -99,6 +179,7 @@ executables:
|
|
99
179
|
extensions: []
|
100
180
|
extra_rdoc_files: []
|
101
181
|
files:
|
182
|
+
- .cane
|
102
183
|
- .gitignore
|
103
184
|
- .rspec
|
104
185
|
- .travis.yml
|
@@ -108,11 +189,14 @@ files:
|
|
108
189
|
- Rakefile
|
109
190
|
- Readme.md
|
110
191
|
- bin/tp
|
192
|
+
- lib/coderay/prawn_encoder.rb
|
111
193
|
- lib/keyboard.rb
|
112
194
|
- lib/screen.rb
|
113
195
|
- lib/string.rb
|
114
196
|
- lib/tp.rb
|
197
|
+
- lib/tp/cli.rb
|
115
198
|
- lib/tp/presenter.rb
|
199
|
+
- lib/tp/publisher/pdf.rb
|
116
200
|
- lib/tp/renderer.rb
|
117
201
|
- lib/tp/slide.rb
|
118
202
|
- lib/tp/slide/bulleted.rb
|
@@ -126,7 +210,10 @@ files:
|
|
126
210
|
- spec/lib/keyboard_spec.rb
|
127
211
|
- spec/lib/screen_spec.rb
|
128
212
|
- spec/lib/string_spec.rb
|
213
|
+
- spec/lib/tp/cli_spec.rb
|
214
|
+
- spec/lib/tp/coderay/prawn_encoder_spec.rb
|
129
215
|
- spec/lib/tp/presenter_spec.rb
|
216
|
+
- spec/lib/tp/publisher/pdf_spec.rb
|
130
217
|
- spec/lib/tp/slide/bulleted_spec.rb
|
131
218
|
- spec/lib/tp/slide/code_spec.rb
|
132
219
|
- spec/lib/tp/slide/header_only_spec.rb
|
@@ -166,7 +253,10 @@ test_files:
|
|
166
253
|
- spec/lib/keyboard_spec.rb
|
167
254
|
- spec/lib/screen_spec.rb
|
168
255
|
- spec/lib/string_spec.rb
|
256
|
+
- spec/lib/tp/cli_spec.rb
|
257
|
+
- spec/lib/tp/coderay/prawn_encoder_spec.rb
|
169
258
|
- spec/lib/tp/presenter_spec.rb
|
259
|
+
- spec/lib/tp/publisher/pdf_spec.rb
|
170
260
|
- spec/lib/tp/slide/bulleted_spec.rb
|
171
261
|
- spec/lib/tp/slide/code_spec.rb
|
172
262
|
- spec/lib/tp/slide/header_only_spec.rb
|