tp 0.0.1 → 0.0.2
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.
- data/.travis.yml +9 -0
- data/Readme.md +24 -0
- data/bin/tp +1 -1
- data/lib/keyboard.rb +7 -0
- data/lib/screen.rb +15 -0
- data/lib/tp/presenter.rb +48 -0
- data/lib/tp/slide.rb +33 -0
- data/lib/tp/version.rb +1 -1
- data/lib/tp.rb +5 -13
- data/spec/lib/keyboard_spec.rb +15 -0
- data/spec/lib/screen_spec.rb +31 -0
- data/spec/lib/tp/presenter_spec.rb +35 -0
- data/spec/lib/tp/slide_spec.rb +57 -0
- data/spec/lib/tp_spec.rb +2 -15
- metadata +15 -2
- data/README.md +0 -29
data/.travis.yml
ADDED
data/Readme.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# tp [](https://secure.travis-ci.org/JustinCampbell/tp) [](https://codeclimate.com/github/JustinCampbell/tp)
|
2
|
+
|
3
|
+
Terminal Presenter
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'tp'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install tp
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```sh
|
22
|
+
tp presentation.md
|
23
|
+
```
|
24
|
+
|
data/bin/tp
CHANGED
data/lib/keyboard.rb
ADDED
data/lib/screen.rb
ADDED
data/lib/tp/presenter.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
module TP
|
2
|
+
class Presenter
|
3
|
+
attr_accessor :markdown
|
4
|
+
|
5
|
+
def initialize(markdown)
|
6
|
+
self.markdown = markdown
|
7
|
+
end
|
8
|
+
|
9
|
+
def present
|
10
|
+
slides.each do |slide|
|
11
|
+
Screen.clear!
|
12
|
+
show_slide slide
|
13
|
+
Keyboard.wait_for_enter
|
14
|
+
end
|
15
|
+
|
16
|
+
Screen.clear!
|
17
|
+
end
|
18
|
+
|
19
|
+
def slides
|
20
|
+
result = markdown.split /^# /
|
21
|
+
result.reject! &:empty?
|
22
|
+
result.map! { |string| string.prepend "#" }
|
23
|
+
|
24
|
+
result.map { |string| Slide.new string }
|
25
|
+
end
|
26
|
+
|
27
|
+
def show_slide(slide)
|
28
|
+
buffer = slide.header.center Screen.width
|
29
|
+
|
30
|
+
if slide.body
|
31
|
+
buffer << "\n\n"
|
32
|
+
|
33
|
+
if slide.paragraph
|
34
|
+
buffer << slide.paragraph.center(Screen.width)
|
35
|
+
else
|
36
|
+
slide.bullets.each { |string| buffer << "#{bullet}#{string}\n" }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
print buffer
|
41
|
+
end
|
42
|
+
|
43
|
+
def bullet
|
44
|
+
"\u2022 "
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
data/lib/tp/slide.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
module TP
|
2
|
+
class Slide
|
3
|
+
attr_accessor :markdown
|
4
|
+
|
5
|
+
def initialize(markdown)
|
6
|
+
self.markdown = markdown.strip
|
7
|
+
end
|
8
|
+
|
9
|
+
def header
|
10
|
+
match = markdown.match /^#\s*(.+)(?:\n)*/
|
11
|
+
|
12
|
+
match[1] if match
|
13
|
+
end
|
14
|
+
|
15
|
+
def body
|
16
|
+
match = markdown.match /^#\s*.+\n\n(.*)/m
|
17
|
+
|
18
|
+
match[1] if match
|
19
|
+
end
|
20
|
+
|
21
|
+
def bullets
|
22
|
+
return unless body
|
23
|
+
|
24
|
+
result = body.scan(/^\*\s+(.+)/).flatten
|
25
|
+
|
26
|
+
result if result.any?
|
27
|
+
end
|
28
|
+
|
29
|
+
def paragraph
|
30
|
+
body unless bullets
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/tp/version.rb
CHANGED
data/lib/tp.rb
CHANGED
@@ -1,15 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require 'keyboard'
|
2
|
+
require 'screen'
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
slides = markdown.split(/^# /).keep_if { |string| string != "" }.map { |string| "# " + string }
|
4
|
+
require 'tp/presenter'
|
5
|
+
require 'tp/slide'
|
6
|
+
require 'tp/version'
|
7
7
|
|
8
|
-
slides.each do |slide|
|
9
|
-
print "\e[2J\e[f"
|
10
|
-
puts slide
|
11
|
-
$stdin.gets
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'keyboard'
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Keyboard do
|
6
|
+
describe ".wait_for_enter" do
|
7
|
+
subject(:wait_for_enter) { klass.wait_for_enter }
|
8
|
+
|
9
|
+
it "waits for enter" do
|
10
|
+
$stdin.should_receive :gets
|
11
|
+
|
12
|
+
wait_for_enter
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'screen'
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Screen do
|
6
|
+
describe ".clear!" do
|
7
|
+
subject(:clear!) { klass.clear! }
|
8
|
+
|
9
|
+
it "clears the screen" do
|
10
|
+
Screen.should_receive(:print).with("\e[2J\e[f")
|
11
|
+
|
12
|
+
clear!
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe ".height" do
|
17
|
+
subject(:height) { klass.height }
|
18
|
+
|
19
|
+
it "returns the height" do
|
20
|
+
height.should be_nonzero
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe ".width" do
|
25
|
+
subject(:width) { klass.width }
|
26
|
+
|
27
|
+
it "returns the width" do
|
28
|
+
width.should be_nonzero
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TP::Presenter do
|
4
|
+
subject(:presenter) { klass.new markdown }
|
5
|
+
|
6
|
+
let(:markdown) {
|
7
|
+
<<-MD.gsub(/^ {6}/, '')
|
8
|
+
# Header by itself
|
9
|
+
|
10
|
+
# Bullets
|
11
|
+
|
12
|
+
* Bullet 1
|
13
|
+
* Bullet 2
|
14
|
+
|
15
|
+
# Paragraph
|
16
|
+
|
17
|
+
This is a really long paragraph. Kinda.
|
18
|
+
MD
|
19
|
+
}
|
20
|
+
|
21
|
+
before :each do
|
22
|
+
Screen.stub width: 20, height: 20
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#present" do
|
26
|
+
it "works" do
|
27
|
+
Keyboard.should_receive(:wait_for_enter).exactly(3).times
|
28
|
+
Screen.should_receive(:clear!).exactly(4).times
|
29
|
+
|
30
|
+
presenter.should_receive(:print).exactly(3).times
|
31
|
+
|
32
|
+
presenter.present
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TP::Slide do
|
4
|
+
subject(:slide) { klass.new markdown }
|
5
|
+
|
6
|
+
let(:markdown) {
|
7
|
+
"# First Slide\n\n* Bullet 1\n* Bullet 2"
|
8
|
+
}
|
9
|
+
|
10
|
+
its(:markdown) { should == markdown }
|
11
|
+
|
12
|
+
context "with bullets" do
|
13
|
+
let(:markdown) {
|
14
|
+
"# First Slide\n\n* Bullet 1\n* Bullet 2"
|
15
|
+
}
|
16
|
+
|
17
|
+
its(:header) { should == "First Slide" }
|
18
|
+
its(:body) { should == "* Bullet 1\n* Bullet 2" }
|
19
|
+
|
20
|
+
its(:bullets) { should =~ ["Bullet 1", "Bullet 2"] }
|
21
|
+
its(:paragraph) { should be_nil }
|
22
|
+
end
|
23
|
+
|
24
|
+
context "with a paragraph" do
|
25
|
+
let(:markdown) {
|
26
|
+
"# First Slide\n\nThis is a paragraph of text"
|
27
|
+
}
|
28
|
+
|
29
|
+
its(:header) { should == "First Slide" }
|
30
|
+
its(:body) { should == "This is a paragraph of text" }
|
31
|
+
|
32
|
+
its(:bullets) { should be_nil }
|
33
|
+
its(:paragraph) { should == "This is a paragraph of text" }
|
34
|
+
end
|
35
|
+
|
36
|
+
context "with just a header" do
|
37
|
+
let(:markdown) {
|
38
|
+
"# First Slide"
|
39
|
+
}
|
40
|
+
|
41
|
+
its(:header) { should == "First Slide" }
|
42
|
+
its(:body) { should be_nil }
|
43
|
+
|
44
|
+
its(:bullets) { should be_nil }
|
45
|
+
its(:paragraph) { should be_nil }
|
46
|
+
end
|
47
|
+
|
48
|
+
context "with trailing newlines" do
|
49
|
+
let(:markdown) {
|
50
|
+
"# First Slide\n\n* Bullet 1\n* Bullet 2\n\n"
|
51
|
+
}
|
52
|
+
|
53
|
+
it "strips whitespace" do
|
54
|
+
slide.markdown.should == "# First Slide\n\n* Bullet 1\n* Bullet 2"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/spec/lib/tp_spec.rb
CHANGED
@@ -1,18 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe TP
|
4
|
-
|
5
|
-
subject(:present) { klass.present markdown }
|
6
|
-
let(:markdown) {
|
7
|
-
"# First Slide\n\n* Bullet 1\n* Bullet 2\n\n# Second Slide"
|
8
|
-
}
|
9
|
-
|
10
|
-
it "works" do
|
11
|
-
klass.should_receive(:print).twice
|
12
|
-
klass.should_receive(:puts).twice
|
13
|
-
$stdin.should_receive(:gets).twice
|
14
|
-
|
15
|
-
present
|
16
|
-
end
|
17
|
-
end
|
3
|
+
describe TP do
|
4
|
+
it { klass.should be_a Module }
|
18
5
|
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.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -85,14 +85,23 @@ extra_rdoc_files: []
|
|
85
85
|
files:
|
86
86
|
- .gitignore
|
87
87
|
- .rspec
|
88
|
+
- .travis.yml
|
88
89
|
- Gemfile
|
89
90
|
- Guardfile
|
90
91
|
- LICENSE.txt
|
91
|
-
- README.md
|
92
92
|
- Rakefile
|
93
|
+
- Readme.md
|
93
94
|
- bin/tp
|
95
|
+
- lib/keyboard.rb
|
96
|
+
- lib/screen.rb
|
94
97
|
- lib/tp.rb
|
98
|
+
- lib/tp/presenter.rb
|
99
|
+
- lib/tp/slide.rb
|
95
100
|
- lib/tp/version.rb
|
101
|
+
- spec/lib/keyboard_spec.rb
|
102
|
+
- spec/lib/screen_spec.rb
|
103
|
+
- spec/lib/tp/presenter_spec.rb
|
104
|
+
- spec/lib/tp/slide_spec.rb
|
96
105
|
- spec/lib/tp_spec.rb
|
97
106
|
- spec/spec_helper.rb
|
98
107
|
- spec/support/klass.rb
|
@@ -122,6 +131,10 @@ signing_key:
|
|
122
131
|
specification_version: 3
|
123
132
|
summary: tp
|
124
133
|
test_files:
|
134
|
+
- spec/lib/keyboard_spec.rb
|
135
|
+
- spec/lib/screen_spec.rb
|
136
|
+
- spec/lib/tp/presenter_spec.rb
|
137
|
+
- spec/lib/tp/slide_spec.rb
|
125
138
|
- spec/lib/tp_spec.rb
|
126
139
|
- spec/spec_helper.rb
|
127
140
|
- spec/support/klass.rb
|
data/README.md
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# Tp
|
2
|
-
|
3
|
-
TODO: Write a gem description
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
gem 'tp'
|
10
|
-
|
11
|
-
And then execute:
|
12
|
-
|
13
|
-
$ bundle
|
14
|
-
|
15
|
-
Or install it yourself as:
|
16
|
-
|
17
|
-
$ gem install tp
|
18
|
-
|
19
|
-
## Usage
|
20
|
-
|
21
|
-
TODO: Write usage instructions here
|
22
|
-
|
23
|
-
## Contributing
|
24
|
-
|
25
|
-
1. Fork it
|
26
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
-
5. Create new Pull Request
|