showoff 0.15.1 → 0.15.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a67f806a8e4ea968733805e72b6976820aa1c04b
4
- data.tar.gz: fe179fae4f9ed586414d33b200d764324e400317
3
+ metadata.gz: 4fcc16c52c78d5e9c2d0f6b8fed009584e8b4558
4
+ data.tar.gz: 43d18be95f74b4690bb096733d821a87a9e09cb5
5
5
  SHA512:
6
- metadata.gz: c502bc0616a0a208399adf5d0ab51488ba6230f1ccaf04a872167742932be04750130f3708f6e71f76eab20a9e61392357721957e8f1077b189985cf01b7d23a
7
- data.tar.gz: 6ae5577782baf360c4c412ad1ff9654648eb1e12f06cf94ac7c8661246ff4a3b412b60eac043b0dceb90055bb87ae0b01c208b618e27b145d2b48ca83aae86f5
6
+ metadata.gz: 9c671f6d44ce601953d7e2a1882535c5d0141459033801a2fbe869a0d1a7998f792e9faa486cdff2d8888575bc53872af56064d667e459952a4fcee2e0240f07
7
+ data.tar.gz: 8330b2398adb6bfaf6a51e8358c4f6095bffd489a1e57c825c7e7f4da7199b36900eb83fdb10296f0a6e47b618a808f485b0f09adf6a4ea6a5ef1806b9e06603
data/lib/showoff.rb CHANGED
@@ -114,6 +114,14 @@ class ShowOff < Sinatra::Application
114
114
  settings.showoff_config['locked'] ||= Array.new
115
115
  end
116
116
 
117
+ # default code parsers (for executable code blocks)
118
+ settings.showoff_config['parsers'] ||= {}
119
+ settings.showoff_config['parsers']['perl'] ||= 'perl'
120
+ settings.showoff_config['parsers']['puppet'] ||= 'puppet apply --color=false'
121
+ settings.showoff_config['parsers']['python'] ||= 'python'
122
+ settings.showoff_config['parsers']['ruby'] ||= 'ruby'
123
+ settings.showoff_config['parsers']['shell'] ||= 'sh'
124
+
117
125
  # default code validators
118
126
  settings.showoff_config['validators'] ||= {}
119
127
  settings.showoff_config['validators']['perl'] ||= 'perl -cw'
@@ -226,7 +234,7 @@ class ShowOff < Sinatra::Application
226
234
  files = if File.directory? section
227
235
  Dir.glob("#{section}/**/*").sort
228
236
  else
229
- [section]
237
+ Array(section)
230
238
  end
231
239
  @logger.debug files
232
240
  files
@@ -1320,30 +1328,27 @@ class ShowOff < Sinatra::Application
1320
1328
  get '/execute/:lang' do |lang|
1321
1329
  return 'Run showoff with -x or --executecode to enable code execution' unless @execute
1322
1330
 
1323
- code = get_code_from_slide(params[:path], params[:index])
1331
+ code = get_code_from_slide(params[:path], params[:index])
1332
+ parser = settings.showoff_config['parsers'][lang]
1333
+
1334
+ return "No parser for #{lang}" unless parser
1324
1335
 
1325
1336
  require 'timeout'
1326
1337
  require 'open3' # for 1.8 compatibility :/
1327
1338
  begin
1328
1339
  Timeout::timeout(settings.showoff_config['timeout']) do
1329
- case lang
1330
- when 'ruby'
1331
- eval(code).to_s
1332
- when 'shell'
1333
- %x(#{code})
1334
- when 'puppet'
1335
- stdout, err = Open3.capture2('puppet', 'apply', '--color=false', '-e', code)
1336
- stdout
1337
- when 'python'
1338
- stdout, err = Open3.capture2('python', '-c', code)
1339
- stdout
1340
- when 'perl'
1341
- stdout, err = Open3.capture2('perl', '-e', code)
1342
- stdout
1343
- when 'null'
1344
- code
1345
- else
1346
- "No exec handler for #{lang}"
1340
+ # write out a tempfile to make it simpler for end users to add custom language parser
1341
+ Tempfile.open('showoff-execution') do |f|
1342
+ File.write(f.path, code)
1343
+ @logger.debug "Evaluating: #{parser} #{f.path}"
1344
+ output, status = Open3.capture2e("#{parser} #{f.path}")
1345
+
1346
+ unless status.success?
1347
+ @logger.warn "Command execution failed for #{params[:path]}[#{params[:index]}]"
1348
+ @logger.warn output
1349
+ end
1350
+
1351
+ output
1347
1352
  end
1348
1353
  end
1349
1354
  rescue => e
@@ -1,3 +1,3 @@
1
1
  # No namespace here since ShowOff is a class and I'd have to inherit from
2
2
  # Sinatra::Application (which we don't want to load here)
3
- SHOWOFF_VERSION = '0.15.1'
3
+ SHOWOFF_VERSION = '0.15.2'
data/lib/showoff_utils.rb CHANGED
@@ -130,7 +130,7 @@ class ShowOffUtils
130
130
  next
131
131
 
132
132
  elsif validator
133
- # write out a tempfile because many validators require files to with
133
+ # write out a tempfile because many validators require files to work with
134
134
  Tempfile.open('showoff-validation') do |f|
135
135
  File.write(f.path, code)
136
136
  unless system("#{validator} #{f.path}", :out => File::NULL, :err => File::NULL)
@@ -409,27 +409,57 @@ class ShowOffUtils
409
409
  logger.level = Logger::WARN
410
410
  end
411
411
 
412
- index = File.join(dir, ShowOffUtils.presentation_config_file)
413
- sections = nil
412
+ index = File.join(dir, ShowOffUtils.presentation_config_file)
413
+ sections = ["."] # default boring showoff.json
414
+
414
415
  if File.exist?(index)
415
- data = JSON.parse(File.read(index))
416
- logger.debug data
417
- if data.is_a?(Hash)
418
- sections = data['sections']
419
- else
420
- sections = data
421
- end
422
- sections = sections.map do |s|
423
- if s.is_a? Hash
424
- s['section']
416
+ begin
417
+ data = JSON.parse(File.read(index))
418
+ logger.debug data
419
+ if data.is_a?(Hash)
420
+ sections = data['sections'] if data.include? 'sections'
425
421
  else
426
- s
422
+ sections = data
423
+ end
424
+
425
+ # each entry in sections can be:
426
+ # - "filename.md"
427
+ # - { "section": "filename.md" }
428
+ # - { "section": [ "array.md, "of.md, "files.md"] }
429
+ # - { "include": "sections.json" }
430
+ sections = sections.map do |entry|
431
+ next entry if entry.is_a? String
432
+ next nil unless entry.is_a? Hash
433
+
434
+ next entry['section'] if entry.include? 'section'
435
+
436
+ section = nil
437
+ if entry.include? 'include'
438
+ file = entry['include']
439
+ path = File.dirname(file)
440
+ data = JSON.parse(File.read(file))
441
+ if data.is_a? Array
442
+ if path == '.'
443
+ section = data
444
+ else
445
+ section = data.map do |source|
446
+ "#{path}/#{source}"
447
+ end
448
+ end
449
+ end
450
+ end
451
+
452
+ section
427
453
  end
454
+ rescue => e
455
+ logger.error "There was a problem with the presentation file #{index}"
456
+ logger.error e.message
457
+ logger.debug e.backtrace
458
+ sections = []
428
459
  end
429
- else
430
- sections = ["."] # if there's no showoff.json file, make a boring one
431
460
  end
432
- sections
461
+
462
+ sections.flatten.compact
433
463
  end
434
464
 
435
465
  def self.showoff_title(dir = '.')
@@ -44,9 +44,6 @@ pre code {
44
44
  /* explicitly size parent elements so the screen blanker works */
45
45
  html, body{
46
46
  height:100%;
47
- }
48
-
49
- body {
50
47
  margin:0;
51
48
  padding:0;
52
49
  overflow: hidden;
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: showoff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.1
4
+ version: 0.15.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Chacon
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-11-20 00:00:00.000000000 Z
12
+ date: 2016-12-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra