Class: Showoff::Presentation::Slide

Inherits:
Object
  • Object
show all
Defined in:
lib/showoff/presentation/slide.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, content, context = {}) ⇒ Slide

Returns a new instance of Slide.



6
7
8
9
10
11
12
# File 'lib/showoff/presentation/slide.rb', line 6

def initialize(options, content, context={})
  @markdown   = content
  @transition = 'none'
  @classes    = []
  setOptions!(options)
  setContext!(context)
end

Instance Attribute Details

#backgroundObject (readonly)

Returns the value of attribute background.



4
5
6
# File 'lib/showoff/presentation/slide.rb', line 4

def background
  @background
end

#classesObject (readonly)

Returns the value of attribute classes.



4
5
6
# File 'lib/showoff/presentation/slide.rb', line 4

def classes
  @classes
end

#formObject (readonly)

Returns the value of attribute form.



4
5
6
# File 'lib/showoff/presentation/slide.rb', line 4

def form
  @form
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/showoff/presentation/slide.rb', line 4

def id
  @id
end

#markdownObject (readonly)

Returns the value of attribute markdown.



4
5
6
# File 'lib/showoff/presentation/slide.rb', line 4

def markdown
  @markdown
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/showoff/presentation/slide.rb', line 4

def name
  @name
end

#refObject (readonly)

Returns the value of attribute ref.



4
5
6
# File 'lib/showoff/presentation/slide.rb', line 4

def ref
  @ref
end

#sectionObject (readonly)

Returns the value of attribute section.



4
5
6
# File 'lib/showoff/presentation/slide.rb', line 4

def section
  @section
end

#section_titleObject (readonly)

Returns the value of attribute section_title.



4
5
6
# File 'lib/showoff/presentation/slide.rb', line 4

def section_title
  @section_title
end

#seqObject (readonly)

Returns the value of attribute seq.



4
5
6
# File 'lib/showoff/presentation/slide.rb', line 4

def seq
  @seq
end

#transitionObject (readonly)

Returns the value of attribute transition.



4
5
6
# File 'lib/showoff/presentation/slide.rb', line 4

def transition
  @transition
end

Instance Method Details

#renderObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/showoff/presentation/slide.rb', line 14

def render
  Showoff::State.increment(:slide_count)
  options = { :form => @form,
              :name => @name,
              :seq  => @seq,
            }

  content, notes = Showoff::Compiler.new(options).render(@markdown)

  # if a template file has been specified for this slide, load from disk and render it
  # @todo How many people are actually using these limited templates?!
  if tpl_file = Showoff::Config.get('template', @template)
    template = File.read(tpl_file)
    content  = template.gsub(/~~~CONTENT~~~/, content)
  end

  ERB.new(File.read(File.join(Showoff::GEMROOT, 'views','slide.erb')), nil, '-').result(binding)
end

#setContext!(context) ⇒ Object

currently a mishmash of passed in context and calculated valued extracted from classes



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
# File 'lib/showoff/presentation/slide.rb', line 77

def setContext!(context)
  @section = context[:section] || 'main'
  @name    = context[:name].chomp('.md')
  @seq     = context[:seq]

  #TODO: this should be in options
  # extract id from classes if set, or default to the HTML sanitized name
  @classes.delete_if { |x| x =~ /^#([\w-]+)/ && @id = $1 }
  @id ||= @name.dup.gsub(/[^-A-Za-z0-9_]/, '_')
  @id << seq.to_s if @seq

  # provide an href for the slide. If we've got multiple slides in this file, we'll have a sequence number
  # include that sequence number to index directly into that content
  @ref = @seq ? "#{@name}:#{@seq.to_s}" : @name

  #TODO: this should be in options
  # extract transition from classes, or default to 'none'
  @classes.delete_if { |x| x =~ /^transition=(.+)/ && @transition = $1 }

  #TODO: this should be in options
  # extract form id from classes, or default to nil
  @classes.delete_if { |x| x =~ /^form=(.+)/ && @form = $1 }

  # Extract a section title from subsection slides and add it to state so that it
  # can be carried forward to subsequent slides until a new section title is discovered.
  # @see
  #     https://github.com/puppetlabs/showoff/blob/3f43754c84f97be4284bb34f9bc7c42175d45226/lib/showoff.rb#L499-L508
  if @classes.include? 'subsection'
    matches = @markdown.match(/#+ *(.*?)#*$/)
    @section_title = matches[1] || @section
    Showoff::State.set(:section_title, @section_title)
  else
    @section_title = Showoff::State.get(:section_title) || @section
  end
end

#setOptions!(options) ⇒ Object

options are key=value elements within the [] brackets



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
# File 'lib/showoff/presentation/slide.rb', line 44

def setOptions!(options)
  return unless options
  return unless matches = options.match(/(\[(.*?)\])?(.*)/)

  if matches[2]
    matches[2].split(",").each do |element|
      key, val = element.split("=")
      case key
      when 'tpl', 'template'
        @template = val
      when 'bg', 'background'
        @background = val
      # For legacy reasons, the options below may also be specified in classes.
      # Currently that takes priority.
      # @todo: better define the difference between options and classes.
      when 'form'
        @form = val
      when 'id'
        @id = val
      when 'transition'
        @transition = val
      else
        Showoff::Logger.warn "Unknown slide option: #{key}=#{val}"
      end
    end
  end

  if matches[3]
    @classes = matches[3].split
  end
end

#slideClassesObject

This is a list of classes that we want applied only to content, and not to the slide, typically so that overly aggressive selectors don’t match more than they should.



38
39
40
41
# File 'lib/showoff/presentation/slide.rb', line 38

def slideClasses
  blacklist = ['bigtext']
  @classes.reject { |klass| blacklist.include? klass }
end