slideshow 0.6 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/slideshow.rb +540 -534
- metadata +2 -2
data/lib/slideshow.rb
CHANGED
@@ -1,535 +1,541 @@
|
|
1
|
-
require 'optparse'
|
2
|
-
require 'erb'
|
3
|
-
require 'redcloth'
|
4
|
-
require 'maruku'
|
5
|
-
require 'logger'
|
6
|
-
require 'fileutils'
|
7
|
-
require 'ftools'
|
8
|
-
require 'hpricot'
|
9
|
-
require 'uv'
|
10
|
-
|
11
|
-
|
12
|
-
module Slideshow
|
13
|
-
|
14
|
-
VERSION = '0.6'
|
15
|
-
|
16
|
-
class Params
|
17
|
-
|
18
|
-
def initialize( name, headers )
|
19
|
-
@svgname = "#{name}.svg"
|
20
|
-
@cssname = "#{name}.css"
|
21
|
-
@headers = headers
|
22
|
-
end
|
23
|
-
|
24
|
-
def params_binding
|
25
|
-
binding
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
# todo: split (command line) options and headers?
|
31
|
-
# e.g. share (command line) options between slide shows (but not headers?)
|
32
|
-
|
33
|
-
class Opts
|
34
|
-
|
35
|
-
def initialize
|
36
|
-
@hash = {}
|
37
|
-
end
|
38
|
-
|
39
|
-
def put( key, value )
|
40
|
-
key = key
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
def
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
def
|
130
|
-
|
131
|
-
end
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
@
|
167
|
-
end
|
168
|
-
|
169
|
-
def
|
170
|
-
@
|
171
|
-
end
|
172
|
-
|
173
|
-
def
|
174
|
-
|
175
|
-
end
|
176
|
-
|
177
|
-
def
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
end
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
#
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
#
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
#
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
content =
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
#
|
321
|
-
|
322
|
-
content.gsub!( "
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
content =
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
out
|
414
|
-
out
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
cmd.
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
puts
|
498
|
-
puts "
|
499
|
-
puts
|
500
|
-
puts
|
501
|
-
puts
|
502
|
-
puts "
|
503
|
-
puts " slideshow
|
504
|
-
puts " slideshow
|
505
|
-
puts " slideshow -
|
506
|
-
puts
|
507
|
-
puts
|
508
|
-
puts "
|
509
|
-
puts
|
510
|
-
puts "
|
511
|
-
puts "
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
end
|
532
|
-
|
533
|
-
end #
|
534
|
-
|
1
|
+
require 'optparse'
|
2
|
+
require 'erb'
|
3
|
+
require 'redcloth'
|
4
|
+
require 'maruku'
|
5
|
+
require 'logger'
|
6
|
+
require 'fileutils'
|
7
|
+
require 'ftools'
|
8
|
+
require 'hpricot'
|
9
|
+
require 'uv'
|
10
|
+
|
11
|
+
|
12
|
+
module Slideshow
|
13
|
+
|
14
|
+
VERSION = '0.6.1'
|
15
|
+
|
16
|
+
class Params
|
17
|
+
|
18
|
+
def initialize( name, headers )
|
19
|
+
@svgname = "#{name}.svg"
|
20
|
+
@cssname = "#{name}.css"
|
21
|
+
@headers = headers
|
22
|
+
end
|
23
|
+
|
24
|
+
def params_binding
|
25
|
+
binding
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
# todo: split (command line) options and headers?
|
31
|
+
# e.g. share (command line) options between slide shows (but not headers?)
|
32
|
+
|
33
|
+
class Opts
|
34
|
+
|
35
|
+
def initialize
|
36
|
+
@hash = {}
|
37
|
+
end
|
38
|
+
|
39
|
+
def put( key, value )
|
40
|
+
key = normalize_key( key )
|
41
|
+
setter = "#{key}=".to_sym
|
42
|
+
|
43
|
+
if respond_to? setter
|
44
|
+
send setter, value
|
45
|
+
else
|
46
|
+
@hash[ key ] = value
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def code_theme=( value )
|
51
|
+
@hash[ :code_theme ] = value.tr( '-', '_' )
|
52
|
+
end
|
53
|
+
|
54
|
+
def gradient=( value )
|
55
|
+
put_gradient( value, :theme, :color1, :color2 )
|
56
|
+
end
|
57
|
+
|
58
|
+
def gradient_colors=( value )
|
59
|
+
put_gradient( value, :color1, :color2 )
|
60
|
+
end
|
61
|
+
|
62
|
+
def gradient_color=( value )
|
63
|
+
put_gradient( value, :color1 )
|
64
|
+
end
|
65
|
+
|
66
|
+
def gradient_theme=( value )
|
67
|
+
put_gradient( value, :theme )
|
68
|
+
end
|
69
|
+
|
70
|
+
def []( key )
|
71
|
+
value = @hash[ normalize_key( key ) ]
|
72
|
+
if value.nil?
|
73
|
+
puts "** Warning: header '#{key}' undefined"
|
74
|
+
"- #{key} not found -"
|
75
|
+
else
|
76
|
+
value
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def generate?
|
81
|
+
get_boolean( 'generate', false )
|
82
|
+
end
|
83
|
+
|
84
|
+
def has_includes?
|
85
|
+
@hash[ :include ]
|
86
|
+
end
|
87
|
+
|
88
|
+
def includes
|
89
|
+
# fix: use os-agnostic delimiter (use : for Mac/Unix?)
|
90
|
+
has_includes? ? @hash[ :include ].split( ';' ) : []
|
91
|
+
end
|
92
|
+
|
93
|
+
def s5?
|
94
|
+
get_boolean( 's5', false )
|
95
|
+
end
|
96
|
+
|
97
|
+
def fullerscreen?
|
98
|
+
get_boolean( 'fuller', false ) || get_boolean( 'fullerscreen', false )
|
99
|
+
end
|
100
|
+
|
101
|
+
def code_theme
|
102
|
+
get( 'code-theme', DEFAULTS[ :code_theme ] )
|
103
|
+
end
|
104
|
+
|
105
|
+
def code_line_numbers?
|
106
|
+
get_boolean( 'code-line-numbers', DEFAULTS[ :code_line_numbers ] )
|
107
|
+
end
|
108
|
+
|
109
|
+
DEFAULTS =
|
110
|
+
{
|
111
|
+
:title => 'Untitled Slide Show',
|
112
|
+
:footer => '',
|
113
|
+
:subfooter => '',
|
114
|
+
:gradient_theme => 'dark',
|
115
|
+
:gradient_color1 => 'red',
|
116
|
+
:gradient_color2 => 'black',
|
117
|
+
:code_theme => 'amy',
|
118
|
+
:code_line_numbers => 'true'
|
119
|
+
}
|
120
|
+
|
121
|
+
def set_defaults
|
122
|
+
DEFAULTS.each_pair do | key, value |
|
123
|
+
@hash[ key ] = value if @hash[ key ].nil?
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
private
|
128
|
+
|
129
|
+
def normalize_key( key )
|
130
|
+
key.to_s.downcase.tr('-', '_').to_sym
|
131
|
+
end
|
132
|
+
|
133
|
+
# Assigns the given gradient-* keys to the values in the given string.
|
134
|
+
def put_gradient( string, *keys )
|
135
|
+
values = string.split( ' ' )
|
136
|
+
|
137
|
+
values.zip(keys).each do |v, k|
|
138
|
+
@hash[ normalize_key( "gradient-#{k}" ) ] = v.tr( '-', '_' )
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def get( key, default )
|
143
|
+
@hash.fetch( normalize_key(key), default )
|
144
|
+
end
|
145
|
+
|
146
|
+
def get_boolean( key, default )
|
147
|
+
value = @hash[ normalize_key( key ) ]
|
148
|
+
if value.nil?
|
149
|
+
default
|
150
|
+
else
|
151
|
+
(value == true || value =~ /true|yes|on/i) ? true : false
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
end # class Opts
|
156
|
+
|
157
|
+
|
158
|
+
class Gen
|
159
|
+
|
160
|
+
KNOWN_TEXTILE_EXTNAMES = [ '.textile', '.t' ]
|
161
|
+
KNOWN_MARKDOWN_EXTNAMES = [ '.markdown', '.mark', '.m', '.txt', '.text' ]
|
162
|
+
|
163
|
+
def initialize
|
164
|
+
@logger = Logger.new(STDOUT)
|
165
|
+
@logger.level = Logger::INFO
|
166
|
+
@opts = Opts.new
|
167
|
+
end
|
168
|
+
|
169
|
+
def logger
|
170
|
+
@logger
|
171
|
+
end
|
172
|
+
|
173
|
+
def opts
|
174
|
+
@opts
|
175
|
+
end
|
176
|
+
|
177
|
+
def cache_dir
|
178
|
+
PLATFORM =~ /win32/ ? win32_cache_dir : File.join(File.expand_path("~"), ".slideshow")
|
179
|
+
end
|
180
|
+
|
181
|
+
def win32_cache_dir
|
182
|
+
unless File.exists?(home = ENV['HOMEDRIVE'] + ENV['HOMEPATH'])
|
183
|
+
puts "No HOMEDRIVE or HOMEPATH environment variable. Set one to save a" +
|
184
|
+
"local cache of stylesheets for syntax highlighting and more."
|
185
|
+
return false
|
186
|
+
else
|
187
|
+
return File.join(home, 'slideshow')
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
def load_template( name, builtin )
|
192
|
+
|
193
|
+
if opts.has_includes?
|
194
|
+
opts.includes.each do |path|
|
195
|
+
logger.debug "File.exists? #{path}/#{name}"
|
196
|
+
|
197
|
+
if File.exists?( "#{path}/#{name}" ) then
|
198
|
+
puts "Loading custom template #{path}/#{name}..."
|
199
|
+
return File.read( "#{path}/#{name}" )
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
# fallback load builtin template packaged with gem
|
205
|
+
load_builtin_template( builtin )
|
206
|
+
end
|
207
|
+
|
208
|
+
def load_builtin_template( name )
|
209
|
+
templatesdir = "#{File.dirname(__FILE__)}/templates"
|
210
|
+
logger.debug "templatesdir=#{templatesdir}"
|
211
|
+
|
212
|
+
File.read( "#{templatesdir}/#{name}" )
|
213
|
+
end
|
214
|
+
|
215
|
+
def render_template( content, b=TOPLEVEL_BINDING )
|
216
|
+
ERB.new( content ).result( b )
|
217
|
+
end
|
218
|
+
|
219
|
+
|
220
|
+
def create_slideshow_templates
|
221
|
+
|
222
|
+
files =
|
223
|
+
case
|
224
|
+
when opts.s5?
|
225
|
+
[[ 's5/header.html.erb', 'header.html.erb' ],
|
226
|
+
[ 's5/footer.html.erb', 'footer.html.erb' ],
|
227
|
+
[ 's5/style.css.erb', 'style.css.erb' ]]
|
228
|
+
when opts.fullerscreen? # use fullerscreen templates
|
229
|
+
[[ 'header.html.erb', 'header.html.erb' ],
|
230
|
+
[ 'footer.html.erb', 'footer.html.erb' ],
|
231
|
+
[ 'style.css.erb', 'style.css.erb' ]]
|
232
|
+
else # use default s6 templates
|
233
|
+
[[ 's6/header.html.erb', 'header.html.erb' ],
|
234
|
+
[ 's6/footer.html.erb', 'footer.html.erb' ],
|
235
|
+
[ 's6/style.css.erb', 'style.css.erb' ]]
|
236
|
+
end
|
237
|
+
|
238
|
+
# background theming shared between s5/s6/fullerscreen
|
239
|
+
files << [ 'gradient.svg.erb', 'gradient.svg.erb' ]
|
240
|
+
|
241
|
+
files.each do |file|
|
242
|
+
source = "#{File.dirname(__FILE__)}/templates/#{file[0]}"
|
243
|
+
dest = "#{file[1]}"
|
244
|
+
|
245
|
+
puts "Copying '#{source}' to '#{dest}'"
|
246
|
+
File.copy( source, dest )
|
247
|
+
end
|
248
|
+
|
249
|
+
puts "Done."
|
250
|
+
end
|
251
|
+
|
252
|
+
def create_slideshow( fn )
|
253
|
+
|
254
|
+
if opts.s5?
|
255
|
+
headerdoc = load_template( 'header.html.erb', 's5/header.html.erb' )
|
256
|
+
footerdoc = load_template( 'footer.html.erb', 's5/footer.html.erb' )
|
257
|
+
styledoc = load_template( 'style.css.erb', 's5/style.css.erb' )
|
258
|
+
elsif opts.fullerscreen? # use fullerscreen templates
|
259
|
+
headerdoc = load_template( 'header.html.erb', 'header.html.erb' )
|
260
|
+
footerdoc = load_template( 'footer.html.erb', 'footer.html.erb' )
|
261
|
+
styledoc = load_template( 'style.css.erb', 'style.css.erb' )
|
262
|
+
else # use default s6 templates
|
263
|
+
headerdoc = load_template( 'header.html.erb', 's6/header.html.erb' )
|
264
|
+
footerdoc = load_template( 'footer.html.erb', 's6/footer.html.erb' )
|
265
|
+
styledoc = load_template( 'style.css.erb', 's6/style.css.erb' )
|
266
|
+
end
|
267
|
+
|
268
|
+
# background theming shared between s5/s6/fullerscreen
|
269
|
+
gradientdoc = load_template( 'gradient.svg.erb', 'gradient.svg.erb' )
|
270
|
+
|
271
|
+
basename = File.basename( fn, '.*' )
|
272
|
+
extname = File.extname( fn )
|
273
|
+
|
274
|
+
known_extnames = KNOWN_TEXTILE_EXTNAMES + KNOWN_MARKDOWN_EXTNAMES
|
275
|
+
|
276
|
+
if extname.empty? then
|
277
|
+
extname = ".textile" # default to .textile
|
278
|
+
|
279
|
+
known_extnames.each do |e|
|
280
|
+
logger.debug "File.exists? #{basename}#{e}"
|
281
|
+
if File.exists?( "#{basename}#{e}" ) then
|
282
|
+
extname = e
|
283
|
+
logger.debug "extname=#{extname}"
|
284
|
+
break
|
285
|
+
end
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
inname = "#{basename}#{extname}"
|
290
|
+
outname = "#{basename}.html"
|
291
|
+
svgname = "#{basename}.svg"
|
292
|
+
cssname = "#{basename}.css"
|
293
|
+
|
294
|
+
logger.debug "inname=#{inname}"
|
295
|
+
|
296
|
+
content = File.read( inname )
|
297
|
+
|
298
|
+
# read source document
|
299
|
+
# strip leading optional headers (key/value pairs) including optional empty lines
|
300
|
+
|
301
|
+
read_headers = true
|
302
|
+
content = ""
|
303
|
+
|
304
|
+
File.open( inname ).readlines.each do |line|
|
305
|
+
if read_headers && line =~ /^\s*(\w[\w-]*)[ \t]*:[ \t]*(.*)/
|
306
|
+
key = $1.downcase
|
307
|
+
value = $2.strip
|
308
|
+
|
309
|
+
logger.debug " adding option: key=>#{key}< value=>#{value}<"
|
310
|
+
opts.put( key, value )
|
311
|
+
elsif line =~ /^\s*$/
|
312
|
+
content << line unless read_headers
|
313
|
+
else
|
314
|
+
read_headers = false
|
315
|
+
content << line
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
# run pre-filters (built-in macros)
|
320
|
+
# o replace {{{ w/ <pre class='code'>
|
321
|
+
# o replace }}} w/ </pre>
|
322
|
+
content.gsub!( "{{{{{{", "<pre class='code'>_S9BEGIN_" )
|
323
|
+
content.gsub!( "}}}}}}", "_S9END_</pre>" )
|
324
|
+
content.gsub!( "{{{", "<pre class='code'>" )
|
325
|
+
content.gsub!( "}}}", "</pre>" )
|
326
|
+
# restore escaped {{{}}} I'm sure there's a better way! Rubyize this! Anyone?
|
327
|
+
content.gsub!( "_S9BEGIN_", "{{{" )
|
328
|
+
content.gsub!( "_S9END_", "}}}" )
|
329
|
+
|
330
|
+
opts.set_defaults
|
331
|
+
|
332
|
+
params = Params.new( basename, opts )
|
333
|
+
|
334
|
+
puts "Preparing slideshow theme '#{svgname}'..."
|
335
|
+
|
336
|
+
out = File.new( svgname, "w+" )
|
337
|
+
out << render_template( gradientdoc, params.params_binding )
|
338
|
+
out.flush
|
339
|
+
out.close
|
340
|
+
|
341
|
+
puts "Preparing slideshow '#{outname}'..."
|
342
|
+
|
343
|
+
# convert light-weight markup to hypertext
|
344
|
+
|
345
|
+
if KNOWN_MARKDOWN_EXTNAMES.include?( extname )
|
346
|
+
content = Maruku.new( content, {:on_error => :raise} ).to_html
|
347
|
+
# old code: content = BlueCloth.new( content ).to_html
|
348
|
+
else
|
349
|
+
# turn off hard line breaks
|
350
|
+
# turn off span caps (see http://rubybook.ca/2008/08/16/redcloth)
|
351
|
+
red = RedCloth.new( content, [:no_span_caps] )
|
352
|
+
red.hard_breaks = false
|
353
|
+
content = red.to_html
|
354
|
+
end
|
355
|
+
|
356
|
+
|
357
|
+
# post-processing
|
358
|
+
|
359
|
+
slide_counter = 0
|
360
|
+
content2 = ''
|
361
|
+
|
362
|
+
# wrap h1's in slide divs; note use just <h1 since some processors add ids e.g. <h1 id='x'>
|
363
|
+
content.each_line do |line|
|
364
|
+
if line.include?( '<h1' ) then
|
365
|
+
content2 << "\n\n</div>" if slide_counter > 0
|
366
|
+
content2 << "<div class='slide'>\n\n"
|
367
|
+
slide_counter += 1
|
368
|
+
end
|
369
|
+
content2 << line
|
370
|
+
end
|
371
|
+
content2 << "\n\n</div>" if slide_counter > 0
|
372
|
+
|
373
|
+
## todo: run syntax highlighting before markup/textilize? lets us add textile to highlighted code?
|
374
|
+
## avoid undoing escaped entities?
|
375
|
+
|
376
|
+
include_code_stylesheet = false
|
377
|
+
# syntax highlight code
|
378
|
+
# todo: can the code handle escaped entities? e.g. >
|
379
|
+
doc = Hpricot(content2)
|
380
|
+
doc.search("pre.code, pre > code").each do |e|
|
381
|
+
if e.inner_html =~ /^\s*#!(\w+)/
|
382
|
+
lang = $1.downcase
|
383
|
+
if e.inner_html =~ /^\{\{\{/ # {{{ assumes escape/literal #!lang
|
384
|
+
# do nothing; next
|
385
|
+
logger.debug " skipping syntax highlighting using lang=#{lang}; assumimg escaped literal"
|
386
|
+
else
|
387
|
+
logger.debug " syntax highlighting using lang=#{lang}"
|
388
|
+
if Uv.syntaxes.include?(lang)
|
389
|
+
code = e.inner_html.sub(/^\s*#!\w+/, '').strip
|
390
|
+
|
391
|
+
code.gsub!( "<", "<" )
|
392
|
+
code.gsub!( ">", ">" )
|
393
|
+
code.gsub!( "&", "&" )
|
394
|
+
# todo: missing any other entities? use CGI::unescapeHTML?
|
395
|
+
logger.debug "code=>#{code}<"
|
396
|
+
|
397
|
+
code_highlighted = Uv.parse( code, "xhtml", lang, opts.code_line_numbers?, opts.code_theme )
|
398
|
+
# old code: e.inner_html = code_highlighted
|
399
|
+
# todo: is it ok to replace the pre.code enclosing element to avoid duplicates?
|
400
|
+
e.swap( code_highlighted )
|
401
|
+
include_code_stylesheet = true
|
402
|
+
end
|
403
|
+
end
|
404
|
+
end
|
405
|
+
end
|
406
|
+
|
407
|
+
content2 = doc.to_s
|
408
|
+
|
409
|
+
|
410
|
+
out = File.new( outname, "w+" )
|
411
|
+
out << render_template( headerdoc, params.params_binding )
|
412
|
+
out << content2
|
413
|
+
out << render_template( footerdoc, params.params_binding )
|
414
|
+
out.flush
|
415
|
+
out.close
|
416
|
+
|
417
|
+
puts "Preparing slideshow stylesheet '#{cssname}'..."
|
418
|
+
|
419
|
+
out = File.new( cssname, "w+" )
|
420
|
+
out << render_template( styledoc, params.params_binding )
|
421
|
+
|
422
|
+
if include_code_stylesheet
|
423
|
+
logger.debug "cache_dir=#{cache_dir}"
|
424
|
+
|
425
|
+
FileUtils.mkdir(cache_dir) unless File.exists?(cache_dir) if cache_dir
|
426
|
+
Uv.copy_files "xhtml", cache_dir
|
427
|
+
|
428
|
+
theme = opts.code_theme
|
429
|
+
|
430
|
+
theme_content = File.read( "#{cache_dir}/css/#{theme}.css" )
|
431
|
+
|
432
|
+
out << "/* styles for code syntax highlighting theme '#{theme}' */\n"
|
433
|
+
out << "\n"
|
434
|
+
out << theme_content
|
435
|
+
end
|
436
|
+
|
437
|
+
out.flush
|
438
|
+
out.close
|
439
|
+
|
440
|
+
|
441
|
+
if opts.s5?
|
442
|
+
# copy s5 machinery to s5 folder
|
443
|
+
# todo/fix: is there a better way to check if the dir exists?
|
444
|
+
Dir.mkdir( 's5' ) unless File.directory?( 's5' )
|
445
|
+
|
446
|
+
[ 'opera.css', 'outline.css', 'print.css', 's5-core.css', 'slides.js' ].each do |name|
|
447
|
+
|
448
|
+
source = "#{File.dirname(__FILE__)}/templates/s5/#{name}"
|
449
|
+
dest = "s5/#{name}"
|
450
|
+
|
451
|
+
logger.debug "copying '#{source} ' to '#{dest}'"
|
452
|
+
File.copy( source, dest )
|
453
|
+
end
|
454
|
+
elsif opts.fullerscreen?
|
455
|
+
# do nothing; slideshow machinery built into plugin (requires install!)
|
456
|
+
else
|
457
|
+
# copy s6 machinery to s6 folder
|
458
|
+
Dir.mkdir( 's6' ) unless File.directory?( 's6' )
|
459
|
+
|
460
|
+
[ 'outline.css', 'print.css', 'slides.css', 'slides.js', 'jquery.js' ].each do |name|
|
461
|
+
|
462
|
+
source = "#{File.dirname(__FILE__)}/templates/s6/#{name}"
|
463
|
+
dest = "s6/#{name}"
|
464
|
+
|
465
|
+
logger.debug "copying '#{source} ' to '#{dest}'"
|
466
|
+
File.copy( source, dest )
|
467
|
+
end
|
468
|
+
end
|
469
|
+
|
470
|
+
puts "Done."
|
471
|
+
end
|
472
|
+
|
473
|
+
|
474
|
+
def run( args )
|
475
|
+
|
476
|
+
opt=OptionParser.new do |cmd|
|
477
|
+
|
478
|
+
cmd.banner = "Usage: slideshow [options] name"
|
479
|
+
|
480
|
+
#todo/fix: use -s5 option without optional hack? possible with OptionParser package/lib?
|
481
|
+
# use -5 switch instead?
|
482
|
+
cmd.on( '-s[OPTIONAL]', '--s5', 'S5 Compatible Slide Show' ) { opts.put( 's5', true ) }
|
483
|
+
cmd.on( '-f[OPTIONAL]', '--fullerscreen', 'FullerScreen Compatible Slide Show' ) { opts.put( 'fuller', true ) }
|
484
|
+
# opts.on( "-s", "--style STYLE", "Select Stylesheet" ) { |s| $options[:style]=s }
|
485
|
+
# opts.on( "-v", "--version", "Show version" ) {}
|
486
|
+
|
487
|
+
cmd.on( '-g', '--generate', 'Generate Slide Show Templates' ) { opts.put( 'generate', true ) }
|
488
|
+
# use -d or -o to select output directory for slideshow or slideshow templates?
|
489
|
+
# cmd.on( '-d', '--directory DIRECTORY', 'Output Directory' ) { |s| opts.put( 'directory', s ) }
|
490
|
+
cmd.on( '-i', '--include PATH', 'Load Path' ) { |s| opts.put( 'include', s ) }
|
491
|
+
|
492
|
+
cmd.on( "-t", "--trace", "Show debug trace" ) {
|
493
|
+
logger.datetime_format = "%H:%H:%S"
|
494
|
+
logger.level = Logger::DEBUG
|
495
|
+
}
|
496
|
+
cmd.on_tail( "-h", "--help", "Show this message" ) {
|
497
|
+
puts
|
498
|
+
puts "Slide Show (S9) is a free web alternative to PowerPoint or KeyNote in Ruby"
|
499
|
+
puts
|
500
|
+
puts cmd.help
|
501
|
+
puts
|
502
|
+
puts "Examples:"
|
503
|
+
puts " slideshow microformats"
|
504
|
+
puts " slideshow microformats.textile"
|
505
|
+
puts " slideshow -s5 microformats # S5 compatible"
|
506
|
+
puts " slideshow -f microformats # FullerScreen compatible"
|
507
|
+
puts
|
508
|
+
puts "More examles:"
|
509
|
+
puts " slideshow -g # Generate slide show templates"
|
510
|
+
puts " slideshow -g -s5 # Generate S5 compatible slide show templates"
|
511
|
+
puts " slideshow -g -f # Generate FullerScreen compatible slide show templates"
|
512
|
+
puts
|
513
|
+
puts " slideshow -i . microformats # Use slide show templates in path ."
|
514
|
+
puts " slideshow -i . -s5 microformats # Use S5 compatible slide show templates in path ."
|
515
|
+
puts
|
516
|
+
puts "Further information:"
|
517
|
+
puts " http://slideshow.rubyforge.org"
|
518
|
+
exit
|
519
|
+
}
|
520
|
+
end
|
521
|
+
|
522
|
+
opt.parse!( args )
|
523
|
+
|
524
|
+
puts "Slide Show (S9) Version: #{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
|
525
|
+
|
526
|
+
if opts.generate?
|
527
|
+
create_slideshow_templates
|
528
|
+
else
|
529
|
+
args.each { |fn| create_slideshow( fn ) }
|
530
|
+
end
|
531
|
+
end
|
532
|
+
|
533
|
+
end # class Gen
|
534
|
+
|
535
|
+
def Slideshow.main
|
536
|
+
Gen.new.run(ARGV)
|
537
|
+
end
|
538
|
+
|
539
|
+
end # module Slideshow
|
540
|
+
|
535
541
|
Slideshow.main if __FILE__ == $0
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slideshow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-08-
|
12
|
+
date: 2008-08-30 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|