pptxt 0.2.5 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/pptxt +82 -55
- data/lib/pptxt/error/file_not_found.rb +7 -0
- data/lib/pptxt/error/{missing_dependency_error.rb → missing_dependency.rb} +0 -0
- data/lib/pptxt/error/{unknown_xml_error.rb → unknown_xml.rb} +0 -0
- data/lib/pptxt/error.rb +3 -2
- data/lib/pptxt/slide.rb +0 -2
- data/lib/pptxt.rb +11 -10
- data/lib/string.rb +12 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99b2795bb271e491d3bbb26302ef6b341703d10e
|
4
|
+
data.tar.gz: 60446a3049884f34f742a4af348a1b740db8e791
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6d16dedcbd36c8879a90f462edd1f1cc47680b6b292ec504ce7b7f6d05f85e0fc8067cc33effb2b0c63d23e104e38a907e35582aae42fb577b961c11b82adf1
|
7
|
+
data.tar.gz: e39933584b5a43c330218589bfbd6b94755ba3e374f5385fc1373793f8da9cccc0e226ca7d52092b9f0585051d4efd2227fc498e1fe1c42e094dc894c819d11e
|
data/bin/pptxt
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
require "colorize"
|
3
4
|
require "io/wait"
|
4
5
|
require "optparse"
|
5
6
|
require "pathname"
|
@@ -11,7 +12,7 @@ class PPtxtExit
|
|
11
12
|
INVALID_ARGUMENT = 2
|
12
13
|
MISSING_ARGUMENT = 3
|
13
14
|
EXTRA_ARGUMENTS = 4
|
14
|
-
|
15
|
+
EXCEPTION = 5
|
15
16
|
end
|
16
17
|
|
17
18
|
def parse(args)
|
@@ -20,6 +21,7 @@ def parse(args)
|
|
20
21
|
options["git"] = false
|
21
22
|
options["pptx"] = nil
|
22
23
|
options["slideshow"] = false
|
24
|
+
options["verbose"] = false
|
23
25
|
|
24
26
|
parser = OptionParser.new do |opts|
|
25
27
|
opts.banner = "Usage: #{File.basename($0)} [OPTIONS] <pptx>"
|
@@ -58,6 +60,14 @@ def parse(args)
|
|
58
60
|
opts.on("-s", "--slideshow", "Display as slideshow") do
|
59
61
|
options["slideshow"] = true
|
60
62
|
end
|
63
|
+
|
64
|
+
opts.on(
|
65
|
+
"-v",
|
66
|
+
"--verbose",
|
67
|
+
"Show backtrace when error occurs"
|
68
|
+
) do
|
69
|
+
options["verbose"] = true
|
70
|
+
end
|
61
71
|
end
|
62
72
|
|
63
73
|
begin
|
@@ -84,15 +94,8 @@ def parse(args)
|
|
84
94
|
exit PPtxtExit::EXTRA_ARGUMENTS
|
85
95
|
end
|
86
96
|
|
87
|
-
if (!Pathname.new(args[0]).expand_path.exist?)
|
88
|
-
puts "#{args[0]} does not exist!"
|
89
|
-
exit PPtxtExit::FILE_DOES_NOT_EXIST
|
90
|
-
end
|
91
|
-
|
92
97
|
options["pptx"] = args[0].strip
|
93
|
-
if (options["pptx"] == "/dev/null")
|
94
|
-
exit PPtxtExit::GOOD
|
95
|
-
end
|
98
|
+
exit PPtxtExit::GOOD if (options["pptx"] == "/dev/null")
|
96
99
|
|
97
100
|
return options
|
98
101
|
end
|
@@ -100,59 +103,83 @@ end
|
|
100
103
|
# Parse CLI args
|
101
104
|
options = parse(ARGV)
|
102
105
|
|
103
|
-
|
104
|
-
|
106
|
+
begin
|
107
|
+
# Get slides
|
108
|
+
slides = PPtxt.new(options["pptx"]).slides
|
109
|
+
|
110
|
+
if (!options["slideshow"])
|
111
|
+
# Loop through slides
|
112
|
+
slides.each do |slide|
|
113
|
+
if (options["detailed"])
|
114
|
+
puts slide.detailed
|
115
|
+
elsif (options["git"])
|
116
|
+
puts slide.diffable
|
117
|
+
puts
|
118
|
+
else
|
119
|
+
puts slide
|
120
|
+
puts
|
121
|
+
end
|
122
|
+
end
|
123
|
+
else
|
124
|
+
quit = false
|
125
|
+
count = 0
|
126
|
+
|
127
|
+
while (!quit)
|
128
|
+
slide = slides[count]
|
105
129
|
|
106
|
-
|
107
|
-
|
108
|
-
slides.each do |slide|
|
109
|
-
if (options["detailed"])
|
110
|
-
puts slide.detailed
|
111
|
-
elsif (options["git"])
|
112
|
-
puts slide.diffable
|
130
|
+
# Make it human readable and parse
|
131
|
+
system("clear")
|
113
132
|
puts
|
114
|
-
else
|
115
133
|
puts slide
|
116
134
|
puts
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
puts
|
131
|
-
puts "j:Next k:Previous q:Quit"
|
132
|
-
|
133
|
-
answer = nil
|
134
|
-
while (!answer)
|
135
|
-
begin
|
136
|
-
system("stty raw -echo")
|
137
|
-
if $stdin.ready?
|
138
|
-
answer = $stdin.getc.chr
|
139
|
-
else
|
140
|
-
sleep 0.1
|
135
|
+
puts "j:Next k:Previous q:Quit"
|
136
|
+
|
137
|
+
answer = nil
|
138
|
+
while (!answer)
|
139
|
+
begin
|
140
|
+
system("stty raw -echo")
|
141
|
+
if $stdin.ready?
|
142
|
+
answer = $stdin.getc.chr
|
143
|
+
else
|
144
|
+
sleep 0.1
|
145
|
+
end
|
146
|
+
ensure
|
147
|
+
system("stty -raw echo")
|
141
148
|
end
|
142
|
-
|
143
|
-
|
149
|
+
end
|
150
|
+
puts
|
151
|
+
|
152
|
+
case answer
|
153
|
+
when "j", "J"
|
154
|
+
count += 1 if (count < (slides.length - 1))
|
155
|
+
when "k", "K"
|
156
|
+
count -= 1 if (count > 0)
|
157
|
+
when "q", "Q", "\x03"
|
158
|
+
# Quit or ^C
|
159
|
+
quit = true
|
144
160
|
end
|
145
161
|
end
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
162
|
+
end
|
163
|
+
rescue Interrupt
|
164
|
+
# ^C
|
165
|
+
# Exit gracefully
|
166
|
+
rescue Errno::EPIPE
|
167
|
+
# Do nothing. This can happen if piping to another program such as
|
168
|
+
# less. Usually if less is closed before we're done with STDOUT.
|
169
|
+
rescue PPtxt::Error => e
|
170
|
+
puts e.message
|
171
|
+
exit PPtxtExit::EXCEPTION
|
172
|
+
rescue Exception => e
|
173
|
+
$stderr.puts "Oops! Looks like an error has occured! Maybe the " \
|
174
|
+
"message below will help. If not, you can use the " \
|
175
|
+
"--verbose flag to get a backtrace.".word_wrap
|
176
|
+
|
177
|
+
$stderr.puts e.message.white.on_red
|
178
|
+
if (options["verbose"])
|
179
|
+
e.backtrace.each do |line|
|
180
|
+
$stderr.puts line.light_yellow
|
156
181
|
end
|
157
182
|
end
|
183
|
+
exit PPtxtExit::EXCEPTION
|
158
184
|
end
|
185
|
+
exit PPtxtExit::GOOD
|
File without changes
|
File without changes
|
data/lib/pptxt/error.rb
CHANGED
data/lib/pptxt/slide.rb
CHANGED
data/lib/pptxt.rb
CHANGED
@@ -47,13 +47,15 @@ class PPtxt
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def create_slides
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
).split("\n")
|
50
|
+
if (ScoobyDoo.where_are_you("unzip").nil?)
|
51
|
+
raise PPtxt::Error::MissingDependency.new("unzip")
|
52
|
+
end
|
54
53
|
|
55
54
|
count = 0
|
56
|
-
|
55
|
+
%x(
|
56
|
+
unzip -l "#{@pptx}" | \grep -E "ppt/slides/[^_]" |
|
57
|
+
awk '{print $4}' | sort -k 1.17n
|
58
|
+
).split("\n").each do |slide|
|
57
59
|
xml = %x(unzip -qc "#{@pptx}" #{slide}).gsub("<", "\n<")
|
58
60
|
count += 1
|
59
61
|
@slides.push(PPtxtSlide.new(xml, count))
|
@@ -62,13 +64,12 @@ class PPtxt
|
|
62
64
|
private :create_slides
|
63
65
|
|
64
66
|
def initialize(pptx)
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
if (ScoobyDoo.where_are_you("unzip").nil?)
|
69
|
-
raise PPtxt::Error::MissingDependency.new("unzip")
|
67
|
+
if (!Pathname.new(pptx).expand_path.exist?)
|
68
|
+
raise PPtxt::Error::FileNotFound.new(pptx)
|
70
69
|
end
|
71
70
|
|
71
|
+
@pptx = pptx
|
72
|
+
@slides = Array.new
|
72
73
|
create_slides
|
73
74
|
end
|
74
75
|
end
|
data/lib/string.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# Modify String class to allow for rsplit and word wrap
|
2
|
+
class String
|
3
|
+
def rsplit(pattern)
|
4
|
+
ret = rpartition(pattern)
|
5
|
+
ret.delete_at(1)
|
6
|
+
return ret
|
7
|
+
end
|
8
|
+
|
9
|
+
def word_wrap(width = 80)
|
10
|
+
return scan(/\S.{0,#{width}}\S(?=\s|$)|\S+/).join("\n")
|
11
|
+
end
|
12
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pptxt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miles Whittaker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -62,9 +62,11 @@ files:
|
|
62
62
|
- bin/pptxt
|
63
63
|
- lib/pptxt.rb
|
64
64
|
- lib/pptxt/error.rb
|
65
|
-
- lib/pptxt/error/
|
66
|
-
- lib/pptxt/error/
|
65
|
+
- lib/pptxt/error/file_not_found.rb
|
66
|
+
- lib/pptxt/error/missing_dependency.rb
|
67
|
+
- lib/pptxt/error/unknown_xml.rb
|
67
68
|
- lib/pptxt/slide.rb
|
69
|
+
- lib/string.rb
|
68
70
|
homepage: https://mjwhitta.github.io/pptxt
|
69
71
|
licenses:
|
70
72
|
- GPL-3.0
|