class Showoff::Compiler::Downloads

adds file download link processing

Public Class Methods

enableFiles(index) click to toggle source
# 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) click to toggle source
# 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) click to toggle source

Convention that index 0 represents files that are always available and every other index represents files whose visibility will be triggered on that slide.

[
  {
    :enabled => false,
    :slides  => [
                  {:slidenum => num, :source => name, :file => file},
                  {:slidenum => num, :source => name, :file => file},
                ],
  },
  {
    :enabled => false,
    :slides  => [
                  {:slidenum => num, :source => name, :file => file},
                  {:slidenum => num, :source => name, :file => file},
                ],
  },
]
# 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) click to toggle source

Scan for file download links and move them to the state storage.

@param doc [Nokogiri::HTML::DocumentFragment]

The slide document

@return [Nokogiri::HTML::DocumentFragment]

The slide DOM with download links removed.

@todo Should .download change meaning to ‘make available on this slide’?

@see

https://github.com/puppetlabs/showoff/blob/3f43754c84f97be4284bb34f9bc7c42175d45226/lib/showoff.rb#L1056-L1073
# File lib/showoff/compiler/downloads.rb, line 16
def self.scanForFiles!(doc, options)
  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, options[:name], file)
      when 'p', 'prev', 'previous'
        self.pushFile(current-1, current, options[:name], file)
      when 'c', 'curr', 'current'
        self.pushFile(current, current, options[:name], file)
      when 'n', 'next'
        self.pushFile(current+1, current, options[:name], file)
      end
    end

    container.remove
  end

  doc
end