tp 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Readme.md +42 -10
- data/lib/tp/presenter.rb +5 -32
- data/lib/tp/renderer.rb +36 -0
- data/lib/tp/slide.rb +10 -5
- data/lib/tp/slide_deck.rb +5 -0
- data/lib/tp/version.rb +1 -1
- data/lib/tp.rb +1 -0
- data/slides.md +45 -0
- data/spec/lib/tp/presenter_spec.rb +1 -3
- data/spec/lib/tp/slide_spec.rb +12 -0
- data/spec/spec_helper.rb +2 -0
- data/tp.gemspec +1 -1
- metadata +5 -3
data/Readme.md
CHANGED
@@ -1,24 +1,56 @@
|
|
1
1
|
# tp [![Build Status](https://secure.travis-ci.org/JustinCampbell/tp.png)](https://secure.travis-ci.org/JustinCampbell/tp) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/JustinCampbell/tp)
|
2
2
|
|
3
|
+
![Screenshot](http://f.cl.ly/items/0P0V2l2q381S3m3J0p0U/Screen%20Shot%202012-08-14%20at%207.52.52%20AM.png)
|
4
|
+
|
5
|
+
## Installation and Usage
|
6
|
+
|
7
|
+
```sh
|
8
|
+
gem install tp
|
9
|
+
tp slides.md
|
10
|
+
```
|
11
|
+
|
12
|
+
## Slide Deck
|
13
|
+
|
14
|
+
```md
|
15
|
+
# tp
|
16
|
+
|
17
|
+
# tp
|
18
|
+
|
3
19
|
Terminal Presenter
|
4
20
|
|
5
|
-
|
21
|
+
# tp
|
6
22
|
|
7
|
-
|
23
|
+
Presents Markdown in your terminal
|
8
24
|
|
9
|
-
|
25
|
+
# Installation
|
10
26
|
|
11
|
-
|
27
|
+
gem install tp
|
12
28
|
|
13
|
-
|
29
|
+
# Usage
|
14
30
|
|
15
|
-
|
31
|
+
tp slides.md
|
16
32
|
|
17
|
-
|
33
|
+
# Navigation
|
18
34
|
|
19
|
-
|
35
|
+
* Arrow keys
|
36
|
+
* Space/Enter/Backspace
|
37
|
+
* H,J,K,L (VIM)
|
38
|
+
* Q to quit
|
20
39
|
|
21
|
-
|
22
|
-
|
40
|
+
# Paragraphs
|
41
|
+
|
42
|
+
Short paragraphs are centered
|
43
|
+
|
44
|
+
# Paragraphs
|
45
|
+
|
46
|
+
Sometimes paragraphs are really really long and might wrap a few lines. It does it's best to wrap them logically. Also, they stay left-aligned.
|
47
|
+
|
48
|
+
# Contribute
|
49
|
+
|
50
|
+
JustinCampbell/tp
|
51
|
+
|
52
|
+
# Thanks!
|
53
|
+
|
54
|
+
@JustinCampbell
|
23
55
|
```
|
24
56
|
|
data/lib/tp/presenter.rb
CHANGED
@@ -11,18 +11,18 @@ module TP
|
|
11
11
|
Keyboard.wait_for_return
|
12
12
|
|
13
13
|
loop do
|
14
|
-
|
15
|
-
|
16
|
-
show_slide slide_deck.current or break
|
14
|
+
Renderer.new(slide_deck.current_slide).render
|
17
15
|
|
18
16
|
case Keyboard.read
|
19
|
-
when :right, :down, :space, :return, 'l', 'k'
|
17
|
+
when :right, :down, :space, :return, 'l', 'k', 'd', 's'
|
20
18
|
slide_deck.next
|
21
|
-
when :left, :up, :backspace, 'h', 'j'
|
19
|
+
when :left, :up, :backspace, 'h', 'j', 'a', 'w'
|
22
20
|
slide_deck.previous
|
23
21
|
when 'q'
|
24
22
|
break
|
25
23
|
end
|
24
|
+
|
25
|
+
break if slide_deck.ended?
|
26
26
|
end
|
27
27
|
|
28
28
|
Screen.clear!
|
@@ -39,33 +39,6 @@ module TP
|
|
39
39
|
def slide_deck
|
40
40
|
@slide_deck ||= SlideDeck.new slides
|
41
41
|
end
|
42
|
-
|
43
|
-
def show_slide(slide)
|
44
|
-
return unless slide
|
45
|
-
|
46
|
-
buffer = slide.header.center Screen.width
|
47
|
-
|
48
|
-
if slide.body
|
49
|
-
buffer << "\n\n"
|
50
|
-
|
51
|
-
if slide.paragraph
|
52
|
-
paragraph = slide.paragraph.wrap Screen.width
|
53
|
-
paragraph = paragraph.center Screen.width if paragraph.lines.one?
|
54
|
-
|
55
|
-
buffer << paragraph
|
56
|
-
else
|
57
|
-
slide.bullets.each { |string| buffer << "#{bullet}#{string}\n" }
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
print buffer
|
62
|
-
|
63
|
-
true
|
64
|
-
end
|
65
|
-
|
66
|
-
def bullet
|
67
|
-
"\u2022 "
|
68
|
-
end
|
69
42
|
end
|
70
43
|
end
|
71
44
|
|
data/lib/tp/renderer.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module TP
|
2
|
+
class Renderer
|
3
|
+
BULLET = "\u2022 "
|
4
|
+
|
5
|
+
attr_accessor :slide
|
6
|
+
|
7
|
+
def initialize(slide)
|
8
|
+
self.slide = slide
|
9
|
+
end
|
10
|
+
|
11
|
+
def render
|
12
|
+
Screen.clear!
|
13
|
+
|
14
|
+
return unless slide
|
15
|
+
|
16
|
+
buffer = slide.header.center Screen.width
|
17
|
+
|
18
|
+
if slide.body
|
19
|
+
buffer << "\n\n"
|
20
|
+
|
21
|
+
if slide.paragraph
|
22
|
+
paragraph = slide.paragraph.wrap Screen.width
|
23
|
+
paragraph = paragraph.center Screen.width if paragraph.lines.one?
|
24
|
+
|
25
|
+
buffer << paragraph
|
26
|
+
else
|
27
|
+
slide.bullets.each { |string| buffer << "#{BULLET}#{string}\n" }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
print buffer unless ENV['RUBY_ENV'] == 'test'
|
32
|
+
|
33
|
+
true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/tp/slide.rb
CHANGED
@@ -7,15 +7,14 @@ module TP
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def header
|
10
|
-
|
11
|
-
|
12
|
-
match[1] if match
|
10
|
+
line = lines.first
|
11
|
+
line[1, line.length - 1].to_s.strip
|
13
12
|
end
|
14
13
|
|
15
14
|
def body
|
16
|
-
|
15
|
+
result = lines[2, lines.count - 2]
|
17
16
|
|
18
|
-
|
17
|
+
result.join "" if result
|
19
18
|
end
|
20
19
|
|
21
20
|
def bullets
|
@@ -29,5 +28,11 @@ module TP
|
|
29
28
|
def paragraph
|
30
29
|
body unless bullets
|
31
30
|
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def lines
|
35
|
+
markdown.lines.to_a
|
36
|
+
end
|
32
37
|
end
|
33
38
|
end
|
data/lib/tp/slide_deck.rb
CHANGED
data/lib/tp/version.rb
CHANGED
data/lib/tp.rb
CHANGED
data/slides.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# tp
|
2
|
+
|
3
|
+
# tp
|
4
|
+
|
5
|
+
Terminal Presenter
|
6
|
+
|
7
|
+
# tp
|
8
|
+
|
9
|
+
Presents Markdown in your terminal
|
10
|
+
|
11
|
+
# Installation
|
12
|
+
|
13
|
+
gem install tp
|
14
|
+
|
15
|
+
# Usage
|
16
|
+
|
17
|
+
tp slides.md
|
18
|
+
|
19
|
+
# Navigation
|
20
|
+
|
21
|
+
* Arrow keys
|
22
|
+
* Space/Enter/Backspace
|
23
|
+
* H,J,K,L
|
24
|
+
* W,A,S,D
|
25
|
+
* Q to quit
|
26
|
+
|
27
|
+
# Paragraphs
|
28
|
+
|
29
|
+
Short paragraphs are centered
|
30
|
+
|
31
|
+
# Paragraphs
|
32
|
+
|
33
|
+
Sometimes paragraphs are really really long and might wrap a few lines. It does it's best to wrap them logically. Also, they stay left-aligned.
|
34
|
+
|
35
|
+
#
|
36
|
+
|
37
|
+
Headers can also be blank
|
38
|
+
|
39
|
+
# Contribute
|
40
|
+
|
41
|
+
JustinCampbell/tp
|
42
|
+
|
43
|
+
# Thanks!
|
44
|
+
|
45
|
+
@JustinCampbell
|
@@ -26,9 +26,7 @@ describe TP::Presenter do
|
|
26
26
|
describe "#present" do
|
27
27
|
it "works" do
|
28
28
|
Keyboard.should_receive(:wait_for_return).exactly(1).times
|
29
|
-
Screen.should_receive(:clear!).exactly(
|
30
|
-
|
31
|
-
presenter.should_receive(:print).exactly(3).times
|
29
|
+
Screen.should_receive(:clear!).exactly(4).times
|
32
30
|
|
33
31
|
presenter.present
|
34
32
|
end
|
data/spec/lib/tp/slide_spec.rb
CHANGED
@@ -45,6 +45,18 @@ describe TP::Slide do
|
|
45
45
|
its(:paragraph) { should be_nil }
|
46
46
|
end
|
47
47
|
|
48
|
+
context "with a blank header" do
|
49
|
+
let(:markdown) {
|
50
|
+
"#\n\nFirst Slide"
|
51
|
+
}
|
52
|
+
|
53
|
+
its(:header) { should be_empty }
|
54
|
+
its(:body) { should == "First Slide" }
|
55
|
+
|
56
|
+
its(:bullets) { should be_nil }
|
57
|
+
its(:paragraph) { should == "First Slide" }
|
58
|
+
end
|
59
|
+
|
48
60
|
context "with trailing newlines" do
|
49
61
|
let(:markdown) {
|
50
62
|
"# First Slide\n\n* Bullet 1\n* Bullet 2\n\n"
|
data/spec/spec_helper.rb
CHANGED
data/tp.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.email = ["justin@justincampbell.me"]
|
13
13
|
gem.description = "tp"
|
14
14
|
gem.summary = "tp"
|
15
|
-
gem.homepage = "http://github.com/
|
15
|
+
gem.homepage = "http://github.com/justincampbell/tp"
|
16
16
|
|
17
17
|
gem.files = `git ls-files`.split $/
|
18
18
|
gem.executables = gem.files.grep(%r{^bin/}).map { |file| File.basename file }
|
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.2.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: 2012-
|
12
|
+
date: 2012-11-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: guard-rspec
|
@@ -97,9 +97,11 @@ files:
|
|
97
97
|
- lib/string.rb
|
98
98
|
- lib/tp.rb
|
99
99
|
- lib/tp/presenter.rb
|
100
|
+
- lib/tp/renderer.rb
|
100
101
|
- lib/tp/slide.rb
|
101
102
|
- lib/tp/slide_deck.rb
|
102
103
|
- lib/tp/version.rb
|
104
|
+
- slides.md
|
103
105
|
- spec/lib/keyboard_spec.rb
|
104
106
|
- spec/lib/screen_spec.rb
|
105
107
|
- spec/lib/string_spec.rb
|
@@ -109,7 +111,7 @@ files:
|
|
109
111
|
- spec/spec_helper.rb
|
110
112
|
- spec/support/klass.rb
|
111
113
|
- tp.gemspec
|
112
|
-
homepage: http://github.com/
|
114
|
+
homepage: http://github.com/justincampbell/tp
|
113
115
|
licenses: []
|
114
116
|
post_install_message:
|
115
117
|
rdoc_options: []
|