presentify 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +44 -0
- data/Rakefile +2 -0
- data/bin/presentify +14 -0
- data/lib/presentify.rb +48 -0
- data/lib/presentify/colorifer.rb +61 -0
- data/lib/presentify/keyboard.rb +57 -0
- data/lib/presentify/printer.rb +52 -0
- data/lib/presentify/screen.rb +13 -0
- data/lib/presentify/slide.rb +20 -0
- data/lib/presentify/version.rb +3 -0
- data/presentify.gemspec +22 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 28cd07e853a795de01b666cf461e41489270c8ab
|
4
|
+
data.tar.gz: ab509c81637ecfd8c7e7760731686764d22fefb5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 85168038fc278b9fc8863629f59872596b30f0158d2c708f26df3e62bdfa5de98f314dab496c757e5cba61183c0ec4ff13a08732e358a774cdc3fb59a098f991
|
7
|
+
data.tar.gz: 3c00c54dd45318557703874cdc0becc47250caf7e099f1aa9bff9003f4b75aa3baa69975b602aed984b6fd13063e4538f3c416a489bc5d98eecdcb421ac4b147
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Nikolay Nemshilov
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Presentify
|
2
|
+
|
3
|
+
Is a little ruby gem that turns a folder of ruby scripts into
|
4
|
+
a CLI based presentation, where one can show and run the code.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
$ gem install presentify
|
9
|
+
|
10
|
+
## Slides
|
11
|
+
|
12
|
+
Any folder with numerical filenames
|
13
|
+
|
14
|
+
slides/
|
15
|
+
1.rb
|
16
|
+
2.rb
|
17
|
+
...
|
18
|
+
|
19
|
+
Every slide should have a header comment with the slide title and
|
20
|
+
some ruby code to show / run
|
21
|
+
|
22
|
+
# Slide Title
|
23
|
+
|
24
|
+
print "Hello world!"
|
25
|
+
|
26
|
+
## Running and navigating
|
27
|
+
|
28
|
+
You can start your presentation by running the `presentify` command
|
29
|
+
with the argument that points to your slides folder
|
30
|
+
|
31
|
+
$ presentify slides
|
32
|
+
|
33
|
+
Once it starts, use the arrow keys to switch between slides and code/demo modes
|
34
|
+
|
35
|
+
* `up` - show the code
|
36
|
+
* `down` - run the code
|
37
|
+
* `left` - previous slide
|
38
|
+
* `right` - next slide
|
39
|
+
|
40
|
+
## License & Copyright
|
41
|
+
|
42
|
+
All code in this library is licensed under the terms of the MIT License
|
43
|
+
|
44
|
+
Copyright (C) 2014 Nikolay Nemshilov
|
data/Rakefile
ADDED
data/bin/presentify
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
lib = File.dirname(__FILE__) + "/../lib"
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require "presentify"
|
7
|
+
|
8
|
+
if ! ARGV[0]
|
9
|
+
puts "Please specify a directory"
|
10
|
+
elsif ! File.exists?(ARGV[0])
|
11
|
+
puts "Can't find the '#{ARGV[0]}' directory"
|
12
|
+
else
|
13
|
+
Presentify.new ARGV[0]
|
14
|
+
end
|
data/lib/presentify.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require "presentify/slide"
|
2
|
+
require "presentify/screen"
|
3
|
+
require "presentify/printer"
|
4
|
+
require "presentify/keyboard"
|
5
|
+
require "presentify/colorifer"
|
6
|
+
|
7
|
+
class Presentify
|
8
|
+
def initialize(directory, start_page=1)
|
9
|
+
@page = start_page
|
10
|
+
@slides = read(directory)
|
11
|
+
@printer = Printer.new
|
12
|
+
|
13
|
+
show_code @page
|
14
|
+
|
15
|
+
Keyboard.new do |keyboard|
|
16
|
+
keyboard.on(:up) { show_code }
|
17
|
+
keyboard.on(:down) { show_demo }
|
18
|
+
keyboard.on(:left) { show_prev }
|
19
|
+
keyboard.on(:right) { show_next }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def show_next
|
24
|
+
show_code @page += 1 if @slides.size > @page + 1
|
25
|
+
end
|
26
|
+
|
27
|
+
def show_prev
|
28
|
+
show_code @page -= 1 if @page > 1
|
29
|
+
end
|
30
|
+
|
31
|
+
def show_code(page=@page)
|
32
|
+
@printer.show @slides[@page = page]
|
33
|
+
end
|
34
|
+
|
35
|
+
def show_demo(page=@page)
|
36
|
+
@printer.demo @slides[@page = page]
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def read(directory)
|
42
|
+
[nil] + (1..999).map do |num|
|
43
|
+
if File.exists?("#{directory}/#{num}.rb")
|
44
|
+
Slide.new(File.read("#{directory}/#{num}.rb"))
|
45
|
+
end
|
46
|
+
end.compact
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
class Presentify
|
2
|
+
class Colorifer
|
3
|
+
RED = 1
|
4
|
+
GREEN = 2
|
5
|
+
YELLOW = 3
|
6
|
+
BLUE = 4
|
7
|
+
MAGENTA = 5
|
8
|
+
CYAN = 6
|
9
|
+
WHITE = 7
|
10
|
+
|
11
|
+
CONSTANTS_RE = /true|false|nil/
|
12
|
+
SINGLE_STRINGS_RE = /('|").*?((?![\\])\1)/
|
13
|
+
MUTLTI_STRINGS_RE = /%(Q|w)[\{\[]([\s\S]*?)[\]\}]/m
|
14
|
+
KEYWORDS_RE = /while|do|end|sleep|puts|print/
|
15
|
+
METHOD_CALLS_RE = /\.[a-z_]+/
|
16
|
+
ESCAPE_CODES_RE = /\\(r|b|n|(e\[[\d\;]+(m|A)))/
|
17
|
+
INTERPOLATIONS_RE = /\#\{.+?\}/
|
18
|
+
|
19
|
+
def colorify(code)
|
20
|
+
#code = code.gsub NUMBERS_RE, "\e[3#{RED}m\\2\e[0m\\3"
|
21
|
+
|
22
|
+
replacify code.dup, {
|
23
|
+
CONSTANTS_RE => RED,
|
24
|
+
ESCAPE_CODES_RE => YELLOW,
|
25
|
+
INTERPOLATIONS_RE => YELLOW,
|
26
|
+
MUTLTI_STRINGS_RE => GREEN,
|
27
|
+
SINGLE_STRINGS_RE => GREEN,
|
28
|
+
KEYWORDS_RE => MAGENTA,
|
29
|
+
METHOD_CALLS_RE => CYAN
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def replacify(code, res)
|
36
|
+
stash = []
|
37
|
+
|
38
|
+
# applying colors
|
39
|
+
res.each do |re, color|
|
40
|
+
while code.match(re)
|
41
|
+
match = $&.dup
|
42
|
+
code.sub! match, placeholder(stash.size)
|
43
|
+
replacement = "\e[3#{color}m#{match}\e[0m"
|
44
|
+
replacement << "\e[3#{GREEN}m" if re == ESCAPE_CODES_RE || re == INTERPOLATIONS_RE
|
45
|
+
stash << replacement
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# rollback
|
50
|
+
while entry = stash.pop
|
51
|
+
code.sub! placeholder(stash.size), entry
|
52
|
+
end
|
53
|
+
|
54
|
+
code
|
55
|
+
end
|
56
|
+
|
57
|
+
def placeholder(num)
|
58
|
+
"-----placeholder-#{num}----"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
class Presentify
|
2
|
+
class Keyboard
|
3
|
+
def initialize(&block)
|
4
|
+
@listeners = []
|
5
|
+
block.call(self)
|
6
|
+
Thread.new { watch_keyboard }.join
|
7
|
+
end
|
8
|
+
|
9
|
+
def on(key, &block)
|
10
|
+
@listeners << [key, block]
|
11
|
+
end
|
12
|
+
|
13
|
+
def trigger(key)
|
14
|
+
@listeners.each do |entry|
|
15
|
+
if entry[0] == key
|
16
|
+
entry[1].call
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def watch_keyboard
|
24
|
+
while true
|
25
|
+
case ch = read_key
|
26
|
+
when "\e[A" then trigger :up
|
27
|
+
when "\e[B" then trigger :down
|
28
|
+
when "\e[C" then trigger :right
|
29
|
+
when "\e[D" then trigger :left
|
30
|
+
when "\r", "\n" then trigger :enter
|
31
|
+
when "\e", "\u0003" then system("clear") && exit(0)
|
32
|
+
# else puts "You pressed: #{ch.inspect}\n"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def read_key
|
38
|
+
old_state = `stty -g`
|
39
|
+
`stty raw -echo`
|
40
|
+
|
41
|
+
c = STDIN.getc.chr
|
42
|
+
|
43
|
+
if c == "\e" # reading escape sequences
|
44
|
+
extra_thread = Thread.new do
|
45
|
+
c += STDIN.getc.chr + STDIN.getc.chr
|
46
|
+
end
|
47
|
+
extra_thread.join(0.001)
|
48
|
+
extra_thread.kill
|
49
|
+
end
|
50
|
+
|
51
|
+
c
|
52
|
+
|
53
|
+
ensure
|
54
|
+
`stty #{old_state}`
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
class Presentify
|
2
|
+
class Printer
|
3
|
+
def initialize
|
4
|
+
@screen = Screen.new
|
5
|
+
@colorifer = Colorifer.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def show(slide)
|
9
|
+
load_up slide do
|
10
|
+
print_title
|
11
|
+
print_code
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def demo(slide)
|
16
|
+
load_up slide do
|
17
|
+
print_title
|
18
|
+
@demo_thread = Thread.new do
|
19
|
+
eval slide.code
|
20
|
+
end
|
21
|
+
@demo_thread.join(0.01)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def load_up(slide, &block)
|
28
|
+
@demo_thread.kill if @demo_thread
|
29
|
+
@screen.clear
|
30
|
+
@current_slide = slide
|
31
|
+
|
32
|
+
block.call
|
33
|
+
end
|
34
|
+
|
35
|
+
def print_title
|
36
|
+
print "\e[33m== #{@current_slide.head} ==\e[0m\n\n"
|
37
|
+
end
|
38
|
+
|
39
|
+
def print_code
|
40
|
+
code = @colorifer.colorify(@current_slide.code)
|
41
|
+
print "#{code}\n\n\n"
|
42
|
+
end
|
43
|
+
|
44
|
+
def puts(str)
|
45
|
+
STDOUT.puts str.gsub("\n", "\n\r")
|
46
|
+
end
|
47
|
+
|
48
|
+
def print(str)
|
49
|
+
STDOUT.print str.gsub("\n", "\n\r")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class Presentify
|
2
|
+
class Slide
|
3
|
+
attr_reader :head, :code
|
4
|
+
|
5
|
+
def initialize(content)
|
6
|
+
@head, @code = parse(content)
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
HEAD_RE = /\A#([^\n]+)\n/
|
12
|
+
CODE_RE = /\A#[^\n]+\n([\s\S]+)/
|
13
|
+
|
14
|
+
def parse(content)
|
15
|
+
[HEAD_RE, CODE_RE].map do |re|
|
16
|
+
content.scan(re)[0][0].strip
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/presentify.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'presentify/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "presentify"
|
8
|
+
spec.version = Presentify::VERSION
|
9
|
+
spec.authors = ["Nikolay Nemshilov"]
|
10
|
+
spec.email = ["nemshilov@gmail.com"]
|
11
|
+
spec.summary = %q{Turns a folder with ruby files into a CLI presentation.}
|
12
|
+
spec.description = %q{Turns a folder with ruby files into a CLI presentation. For real.}
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: presentify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nikolay Nemshilov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Turns a folder with ruby files into a CLI presentation. For real.
|
42
|
+
email:
|
43
|
+
- nemshilov@gmail.com
|
44
|
+
executables:
|
45
|
+
- presentify
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/presentify
|
55
|
+
- lib/presentify.rb
|
56
|
+
- lib/presentify/colorifer.rb
|
57
|
+
- lib/presentify/keyboard.rb
|
58
|
+
- lib/presentify/printer.rb
|
59
|
+
- lib/presentify/screen.rb
|
60
|
+
- lib/presentify/slide.rb
|
61
|
+
- lib/presentify/version.rb
|
62
|
+
- presentify.gemspec
|
63
|
+
homepage:
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata: {}
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.2.2
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: Turns a folder with ruby files into a CLI presentation.
|
87
|
+
test_files: []
|