slideshow 0.7.8 → 0.8

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.
@@ -1,6 +1,13 @@
1
+ === 0.8 / 2009-03-14
2
+
3
+ * Added -f/--fetch URI option; lets you fetch templates from the internet
4
+ * Added -l/--list option; list all installed templates
5
+ * Added -c/--config PATH option; lets you set config folder (default is ~/.slideshow)
6
+ * Moved S5 v11 blank package out of core/gem
7
+
1
8
  === 0.7.8 / 2009-03-09
2
9
 
3
- * Adding SLIDESHOWOPT env variable; lets you set default command line options (e.g. -o slides)
10
+ * Added SLIDESHOWOPT env variable; lets you set default command line options (e.g. -o slides)
4
11
  * Using Hoe Rake tasks to manage gem; adding required files and build script
5
12
  * Move templates folder to top-level (out of lib/)
6
13
  * Minor code clean-up
@@ -28,22 +28,6 @@ templates/s5/print.css
28
28
  templates/s5/s5-core.css
29
29
  templates/s5/slides.js
30
30
  templates/s5/style.css.erb
31
- templates/s5blank.txt.gen
32
- templates/s5blank.txt.sample
33
- templates/s5blank/blank.textile
34
- templates/s5blank/footer.html.erb
35
- templates/s5blank/header.html.erb
36
- templates/s5blank/ui/default/blank.gif
37
- templates/s5blank/ui/default/bodybg.gif
38
- templates/s5blank/ui/default/framing.css
39
- templates/s5blank/ui/default/iepngfix.htc
40
- templates/s5blank/ui/default/opera.css
41
- templates/s5blank/ui/default/outline.css
42
- templates/s5blank/ui/default/pretty.css
43
- templates/s5blank/ui/default/print.css
44
- templates/s5blank/ui/default/s5-core.css
45
- templates/s5blank/ui/default/slides.css
46
- templates/s5blank/ui/default/slides.js
47
31
  templates/s6.txt
48
32
  templates/s6.txt.gen
49
33
  templates/s6.txt.sample
data/README.txt CHANGED
@@ -14,22 +14,35 @@ The Slide Show (S9) project also collects and welcomes themes and ships
14
14
  == SYNOPSIS:
15
15
 
16
16
  Usage: slideshow [options] name
17
-
17
+ -o, --output PATH Output Path
18
+ -g, --generate Generate Slide Show Templates
19
+ -t, --template MANIFEST Template Manifest
20
+ --s5 S5-Compatible Slide Show (same as -t s5.txt)
21
+ --fullerscreen FullerScreen-Compatible Slide Show (same as -t fullerscreen.txt)
22
+ -f, --fetch URI Fetch Templates
23
+ -c, --config PATH Configuration Path (default is ~/.slideshow)
24
+ -l, --list List Installed Templates
25
+ -v, --verbose Show debug trace
26
+ -h, --help Show this message
27
+
18
28
  Examples:
19
29
 
20
30
  slideshow microformats
21
31
  slideshow microformats.textile
22
- slideshow -s5 microformats # S5 compatible
23
- slideshow -f microformats # FullerScreen compatible
24
- slideshow -o slides microformats # Output slideshow to slides folder
32
+ slideshow -o slides microformats # Output slideshow to slides folder
33
+ slideshow --s5 microformats # Use S5-compatible slide show templates
34
+ slideshow --fullerscreen microformats # Use FullerScreen-compatible slide show templates
25
35
 
26
36
  More examles:
27
37
 
28
- slideshow -g # Generate slide show templates
29
- slideshow -g -s5 # Generate S5 compatible slide show templates
30
- slideshow -g -f # Generate FullerScreen compatible slide show templates
38
+ slideshow -g # Generate slide show templates
39
+ slideshow -g --s5 # Generate S5 compatible slide show templates
40
+ slideshow -g --fullerscreen # Generate FullerScreen compatible slide show templates
41
+
42
+ slideshow -l # List installed slide show templates
43
+ slideshow -f s5blank # Fetch (install) S5 blank starter template from internet
44
+ slideshow -t s5blank.txt microformats # Use your own slide show templates (e.g. s5blank.txt)
31
45
 
32
- slideshow -t s3.txt microformats # Use custom slide show templates
33
46
 
34
47
  == REQUIREMENTS:
35
48
 
@@ -10,6 +10,8 @@ require 'logger'
10
10
  require 'fileutils'
11
11
  require 'ftools'
12
12
  require 'pp'
13
+ require 'uri'
14
+ require 'net/http'
13
15
 
14
16
  # required gems
15
17
  require 'redcloth'
@@ -20,7 +22,7 @@ require 'slideshow/gen'
20
22
 
21
23
  module Slideshow
22
24
 
23
- VERSION = '0.7.8'
25
+ VERSION = '0.8'
24
26
 
25
27
  def Slideshow.main
26
28
 
@@ -22,40 +22,21 @@ class Gen
22
22
  [ 'bluecloth', lambda { |content| BlueCloth.new( content ).to_html } ]
23
23
  ]
24
24
 
25
- BUILTIN_MANIFESTS = [ 'fullerscreen.txt', 'fullerscreen.txt.gen',
26
- 's5.txt', 's5.txt.gen',
27
- 's6.txt', 's6.txt.gen',
28
- 's5blank.txt.gen' ]
29
-
30
25
  def initialize
31
26
  @logger = Logger.new(STDOUT)
32
27
  @logger.level = Logger::INFO
33
28
  @opts = Opts.new
34
29
  end
35
30
 
36
- # replace w/ attr_reader :logger, :opts ??
37
-
38
- def logger
39
- @logger
40
- end
41
-
42
- def opts
43
- @opts
44
- end
31
+ attr_reader :logger, :opts
32
+ attr_reader :session # give helpers/plugins a session-like hash
45
33
 
46
34
  def headers
47
35
  # give access to helpers to opts with a different name
48
36
  @opts
49
37
  end
50
-
51
- def session
52
- # give helpers/plugins a session-like hash
53
- @session
54
- end
55
-
56
- def markup_type
57
- @markup_type # :textile, :markdown
58
- end
38
+
39
+ attr_reader :markup_type # :textile, :markdown
59
40
 
60
41
  def load_markdown_libs
61
42
  # check for available markdown libs/gems
@@ -108,29 +89,30 @@ class Gen
108
89
  "local cache of stylesheets for syntax highlighting and more."
109
90
  return false
110
91
  else
111
- return File.join(home, 'slideshow')
92
+ return File.join(home, '.slideshow')
112
93
  end
113
94
  end
114
-
115
- def load_manifest( path )
95
+
96
+ def config_dir
97
+ unless @config_dir # first time? calculate config_dir value to "cache"
98
+
99
+ if opts.config_path
100
+ @config_dir = opts.config_path
101
+ else
102
+ @config_dir = cache_dir
103
+ end
116
104
 
117
- # check if file exists (if yes use custom template package!) - allows you to override builtin package with same name
118
- if BUILTIN_MANIFESTS.include?( path ) && !File.exists?( path )
119
- templatesdir = "#{File.dirname( LIB_PATH )}/templates"
120
- logger.debug "use builtin template package"
121
- logger.debug "templatesdir=#{templatesdir}"
122
- filename = "#{templatesdir}/#{path}"
123
- else
124
- templatesdir = File.dirname( path )
125
- logger.debug "use custom template package"
126
- logger.debug "templatesdir=#{templatesdir}"
127
- filename = path
105
+ # make sure path exists
106
+ File.makedirs( @config_dir ) unless File.directory? @config_dir
128
107
  end
129
-
108
+
109
+ @config_dir
110
+ end
111
+
112
+ def load_manifest_core( path )
130
113
  manifest = []
131
- puts " Loading template manifest #{filename}..."
132
114
 
133
- File.open( filename ).readlines.each_with_index do |line,i|
115
+ File.open( path ).readlines.each_with_index do |line,i|
134
116
  case line
135
117
  when /^\s*$/
136
118
  # skip empty lines
@@ -142,13 +124,7 @@ class Gen
142
124
 
143
125
  # add source for shortcuts (assumes relative path; if not issue warning/error)
144
126
  values << values[0] if values.size == 1
145
-
146
- # normalize all source paths (1..-1) /make full path/add template dir
147
- (1..values.size-1).each do |i|
148
- values[i] = "#{templatesdir}/#{values[i]}"
149
- logger.debug " path[#{i}]=>#{values[i]}<"
150
- end
151
-
127
+
152
128
  manifest << values
153
129
  end
154
130
  end
@@ -156,6 +132,79 @@ class Gen
156
132
  manifest
157
133
  end
158
134
 
135
+ def load_manifest( path )
136
+
137
+ filename = path
138
+
139
+ puts " Loading template manifest #{filename}..."
140
+ manifest = load_manifest_core( filename )
141
+
142
+ # post-processing
143
+ # normalize all source paths (1..-1) /make full path/add template dir
144
+
145
+ templatesdir = File.dirname( path )
146
+ logger.debug "templatesdir=#{templatesdir}"
147
+
148
+ manifest.each do |values|
149
+ (1..values.size-1).each do |i|
150
+ values[i] = "#{templatesdir}/#{values[i]}"
151
+ logger.debug " path[#{i}]=>#{values[i]}<"
152
+ end
153
+ end
154
+
155
+ manifest
156
+ end
157
+
158
+ def find_manifests( patterns )
159
+ manifests = []
160
+
161
+ patterns.each do |pattern|
162
+ pattern.gsub!( '\\', '/') # normalize path; make sure all path use / only
163
+ logger.debug "Checking #{pattern}"
164
+ Dir.glob( pattern ) do |file|
165
+ logger.debug " Found manifest: #{file}"
166
+ manifests << [ File.basename( file ), file ]
167
+ end
168
+ end
169
+
170
+ manifests
171
+ end
172
+
173
+ def installed_generator_manifests
174
+ # 1) search gem/templates
175
+
176
+ builtin_patterns = [
177
+ "#{File.dirname( LIB_PATH )}/templates/*.txt.gen"
178
+ ]
179
+
180
+ find_manifests( builtin_patterns )
181
+ end
182
+
183
+ def installed_template_manifests
184
+ # 1) search ./templates
185
+ # 2) search config_dir/templates
186
+ # 3) search gem/templates
187
+
188
+ builtin_patterns = [
189
+ "#{File.dirname( LIB_PATH )}/templates/*.txt"
190
+ ]
191
+ config_patterns = [
192
+ "#{config_dir}/templates/*.txt",
193
+ "#{config_dir}/templates/*/*.txt"
194
+ ]
195
+ current_patterns = [
196
+ "templates/*.txt",
197
+ "templates/*/*.txt"
198
+ ]
199
+
200
+ patterns = []
201
+ patterns += current_patterns unless LIB_PATH == File.expand_path( 'lib' ) # don't include working dir if we test code from repo (don't include slideshow/templates)
202
+ patterns += config_patterns
203
+ patterns += builtin_patterns
204
+
205
+ find_manifests( patterns )
206
+ end
207
+
159
208
  def load_template( path )
160
209
  puts " Loading template #{path}..."
161
210
  return File.read( path )
@@ -192,10 +241,112 @@ class Gen
192
241
  File.makedirs( dest_path ) unless File.directory? dest_path
193
242
  dest_full
194
243
  end
244
+
245
+
246
+ def fetch_file( dest, src )
247
+ logger.debug "fetch( dest: #{dest}, src: #{src})"
248
+
249
+ uri = URI.parse( src )
250
+
251
+ # todo: add our own agent HTTP header for identification?
252
+ response = Net::HTTP.get_response( uri )
253
+
254
+ unless response.code == '200' # note: responsoe.code is a string
255
+ msg = "#{response.code} #{response.message}"
256
+ puts "*** error: #{msg}"
257
+ return # todo: throw StandardException?
258
+ end
259
+
260
+ logger.debug " content_type: #{response.content_type}, content_length: #{response.content_length}"
261
+
262
+ # check for content type; use 'wb' for images
263
+ if response.content_type =~ /image/
264
+ logger.debug ' switching to binary'
265
+ flags = 'wb'
266
+ else
267
+ flags = 'w'
268
+ end
269
+
270
+ File.open( dest, flags ) do |f|
271
+ f.write( response.body )
272
+ end
273
+ end
274
+
275
+
276
+ def fetch_slideshow_templates
277
+ logger.debug "fetch_uri=#{opts.fetch_uri}"
278
+
279
+ src = opts.fetch_uri
280
+ # src = 'http://github.com/geraldb/slideshow/raw/d98e5b02b87ee66485431b1bee8fb6378297bfe4/code/templates/fullerscreen.txt'
281
+ # src = 'http://github.com/geraldb/sandbox/raw/13d4fec0908fbfcc456b74dfe2f88621614b5244/s5blank/s5blank.txt'
282
+ uri = URI.parse( src )
283
+
284
+ logger.debug "host: #{uri.host}, port: #{uri.port}, path: #{uri.path}"
285
+
286
+ dirname = File.dirname( uri.path )
287
+ basename = File.basename( uri.path, '.*' ) # e.g. fullerscreen (without extension)
288
+ filename = File.basename( uri.path ) # e.g. fullerscreen.txt (with extension)
289
+
290
+ logger.debug "dirname: #{dirname}"
291
+ logger.debug "basename: #{basename}, filename: #{filename}"
292
+
293
+ dlbase = "http://#{uri.host}:#{uri.port}#{dirname}"
294
+ pkgpath = File.expand_path( "#{config_dir}/templates/#{basename}" )
295
+
296
+ logger.debug "dlpath: #{dlbase}"
297
+ logger.debug "pkgpath: #{pkgpath}"
298
+
299
+ File.makedirs( pkgpath ) unless File.directory? pkgpath
300
+
301
+ puts "Fetching template package '#{basename}'"
302
+ puts " : from '#{dlbase}'"
303
+ puts " : saving to '#{pkgpath}'"
304
+
305
+ # download manifest
306
+ dest = "#{pkgpath}/#{filename}"
307
+
308
+ puts " Downloading manifest '#{filename}'..."
309
+
310
+ fetch_file( dest, src )
311
+
312
+ manifest = load_manifest_core( dest )
313
+
314
+ # download templates listed in manifest
315
+ manifest.each do |values|
316
+ values[1..-1].each do |file|
317
+
318
+ dest = "#{pkgpath}/#{file}"
319
+
320
+ # make sure path exists
321
+ destpath = File.dirname( dest )
322
+ File.makedirs( destpath ) unless File.directory? destpath
323
+
324
+ src = "#{dlbase}/#{file}"
325
+
326
+ puts " Downloading template '#{file}'..."
327
+ fetch_file( dest, src )
328
+ end
329
+ end
330
+ puts "Done."
331
+ end
195
332
 
196
333
  def create_slideshow_templates
197
- logger.debug "manifest=#{opts.manifest}.gen"
198
- manifest = load_manifest( opts.manifest+".gen" )
334
+
335
+ manifest_name = opts.manifest
336
+ logger.debug "manifest=#{manifest_name}"
337
+
338
+ manifests = installed_generator_manifests
339
+
340
+ # check for builtin generator manifests
341
+ matches = manifests.select { |m| m[0] == manifest_name+".gen" }
342
+
343
+ if matches.empty?
344
+ puts "*** error: unknown template manifest '#{manifest_name}'"
345
+ # todo: list installed manifests
346
+ exit 2
347
+ end
348
+
349
+ manifest = load_manifest( matches[0][1] )
199
350
 
200
351
  # expand output path in current dir and make sure output path exists
201
352
  outpath = File.expand_path( opts.output_path )
@@ -212,13 +363,40 @@ class Gen
212
363
 
213
364
  puts "Done."
214
365
  end
366
+
367
+ def list_slideshow_templates
368
+ manifests = installed_template_manifests
369
+
370
+ puts ''
371
+ puts 'Installed templates include:'
372
+
373
+ manifests.each do |manifest|
374
+ puts " #{manifest[0]} (#{manifest[1]})"
375
+ end
376
+ end
215
377
 
216
378
  def create_slideshow( fn )
217
379
 
218
- logger.debug "manifest=#{opts.manifest}"
219
- manifest = load_manifest( opts.manifest )
220
- # pp manifest
221
-
380
+ manifest_path_or_name = opts.manifest
381
+ logger.debug "manifest=#{manifest_path_or_name}"
382
+
383
+ # check if file exists (if yes use custom template package!) - allows you to override builtin package with same name
384
+ if File.exists?( manifest_path_or_name )
385
+ manifest = load_manifest( manifest_path_or_name )
386
+ else
387
+ # check for builtin manifests
388
+ manifests = installed_template_manifests
389
+ matches = manifests.select { |m| m[0] == manifest_path_or_name }
390
+
391
+ if matches.empty?
392
+ puts "*** error: unknown template manifest '#{manifest_path_or_name}'"
393
+ # todo: list installed manifests
394
+ exit 2
395
+ end
396
+
397
+ manifest = load_manifest( matches[0][1] )
398
+ end
399
+
222
400
  # expand output path in current dir and make sure output path exists
223
401
  outpath = File.expand_path( opts.output_path )
224
402
  logger.debug "outpath=#{outpath}"
@@ -382,23 +560,20 @@ class Gen
382
560
  end
383
561
 
384
562
  def load_plugins
563
+
564
+ patterns = []
565
+ patterns << "#{config_dir}/lib/**/*.rb"
566
+ patterns << 'lib/**/*.rb' unless LIB_PATH == File.expand_path( 'lib' ) # don't include lib if we are in repo (don't include slideshow/lib)
385
567
 
386
- # use lib folder unless we're in our very own folder
387
- # (that already uses lib for its core functionality), thus, use plugins instead
388
- if( LIB_PATH == File.expand_path( 'lib' ) )
389
- pattern = 'plugins/**/*.rb'
390
- else
391
- pattern = 'lib/**/*.rb'
392
- end
393
-
394
- logger.debug "pattern=#{pattern}"
395
-
396
- Dir.glob( pattern ) do |plugin|
397
- begin
398
- puts "Loading plugins in '#{plugin}'..."
399
- require( plugin )
400
- rescue Exception => e
401
- puts "** error: failed loading plugins in '#{plugin}': #{e}"
568
+ patterns.each do |pattern|
569
+ pattern.gsub!( '\\', '/') # normalize path; make sure all path use / only
570
+ Dir.glob( pattern ) do |plugin|
571
+ begin
572
+ puts "Loading plugins in '#{plugin}'..."
573
+ require( plugin )
574
+ rescue Exception => e
575
+ puts "** error: failed loading plugins in '#{plugin}': #{e}"
576
+ end
402
577
  end
403
578
  end
404
579
  end
@@ -413,7 +588,7 @@ def run( args )
413
588
 
414
589
  cmd.on( '-g', '--generate', 'Generate Slide Show Templates' ) { opts.put( 'generate', true ) }
415
590
 
416
- cmd.on( "-t", "--template TEMPLATE", "Template Manifest" ) do |t|
591
+ cmd.on( "-t", "--template MANIFEST", "Template Manifest" ) do |t|
417
592
  # todo: do some checks on passed in template argument
418
593
  opts.put( 'manifest', t )
419
594
  end
@@ -429,6 +604,16 @@ def run( args )
429
604
 
430
605
  # ?? cmd.on( '-i', '--include PATH', 'Load Path' ) { |s| opts.put( 'include', s ) }
431
606
 
607
+ cmd.on( '-f', '--fetch URI', 'Fetch Templates' ) do |u|
608
+ opts.put( 'fetch_uri', u )
609
+ end
610
+
611
+ cmd.on( '-c', '--config PATH', 'Configuration Path (default is ~/.slideshow)' ) do |p|
612
+ opts.put( 'config_path', p )
613
+ end
614
+
615
+ cmd.on( '-l', '--list', 'List Installed Templates' ) { opts.put( 'list', true ) }
616
+
432
617
  # todo: find different letter for debug trace switch (use v for version?)
433
618
  cmd.on( "-v", "--verbose", "Show debug trace" ) do
434
619
  logger.datetime_format = "%H:%H:%S"
@@ -452,10 +637,10 @@ def run( args )
452
637
  puts " slideshow -g # Generate slide show templates"
453
638
  puts " slideshow -g --s5 # Generate S5 compatible slide show templates"
454
639
  puts " slideshow -g --fullerscreen # Generate FullerScreen compatible slide show templates"
455
- puts " slideshow -g -t s5blank.txt # Generate S5 blank starter templates"
456
- puts
457
- puts " slideshow -t s3.txt microformats # Use your own slide show templates (e.g. s3.txt)"
458
640
  puts
641
+ puts " slideshow -l # List installed slide show templates"
642
+ puts " slideshow -f s5blank # Fetch (install) S5 blank starter template from internet"
643
+ puts " slideshow -t s5blank.txt microformats # Use your own slide show templates (e.g. s5blank.txt)"
459
644
  puts
460
645
  puts "Further information:"
461
646
  puts " http://slideshow.rubyforge.org"
@@ -467,8 +652,12 @@ def run( args )
467
652
 
468
653
  puts "Slide Show (S9) Version: #{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
469
654
 
470
- if opts.generate?
655
+ if opts.list?
656
+ list_slideshow_templates
657
+ elsif opts.generate?
471
658
  create_slideshow_templates
659
+ elsif opts.fetch?
660
+ fetch_slideshow_templates
472
661
  else
473
662
  load_markdown_libs
474
663
  load_plugins # check for optional plugins/extension in ./lib folder