Class: Showoff::Compiler::Downloads
- Inherits:
-
Object
- Object
- Showoff::Compiler::Downloads
- Defined in:
- lib/showoff/compiler/downloads.rb
Overview
adds file download link processing
Class Method Summary collapse
- .enableFiles(index) ⇒ Object
- .getFiles(index) ⇒ Object
- .pushFile(index, current, source, file) ⇒ Object
-
.scanForFiles!(doc, options) ⇒ Nokogiri::HTML::DocumentFragment
Scan for file download links and move them to the state storage.
Class Method Details
.enableFiles(index) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/showoff/compiler/downloads.rb', line 73 def self.enableFiles(index) record = Showoff::State.getAtIndex(:downloads, index) return unless record record[:enabled] = true Showoff::State.setAtIndex(:downloads, index, record) end |
.getFiles(index) ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/showoff/compiler/downloads.rb', line 81 def self.getFiles(index) record = Showoff::State.getAtIndex(:downloads, index) if (record and record[:enabled]) record[:slides] else [] end end |
.pushFile(index, current, source, file) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/showoff/compiler/downloads.rb', line 64 def self.pushFile(index, current, source, file) record = Showoff::State.getAtIndex(:downloads, index) || {} record[:enabled] ||= false record[:slides] ||= [] record[:slides] << {:slidenum => current, :source => source, :file => file} Showoff::State.setAtIndex(:downloads, index, record) end |
.scanForFiles!(doc, options) ⇒ Nokogiri::HTML::DocumentFragment
TODO:
Should .download change meaning to ‘make available on this slide’?
Scan for file download links and move them to the state storage.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/showoff/compiler/downloads.rb', line 16 def self.scanForFiles!(doc, ) current = Showoff::State.get(:slide_count) doc.search('p.download').each do |container| links = container.text.gsub(/^\.download ?/, '') links.split("\n").each do |line| file, modifier = line.split modifier ||= 'next' # @todo Is this still the proper default? case modifier when 'a', 'all', 'always', 'now' self.pushFile(0, current, [:name], file) when 'p', 'prev', 'previous' self.pushFile(current-1, current, [:name], file) when 'c', 'curr', 'current' self.pushFile(current, current, [:name], file) when 'n', 'next' self.pushFile(current+1, current, [:name], file) end end container.remove end doc end |