Class: Keydown::Slide

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, classnames = '') ⇒ Slide

Returns a new instance of Slide.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/keydown/slide.rb', line 8

def initialize(text, classnames = '')
  @content = text
  @notes = ''
  @codemap = {}
  @background_image = {}

  @classnames = []
  classnames.split(' ').inject(@classnames) do |css_classnames, name|
    css_classnames << name
    css_classnames
  end

  extract_notes!
  extract_content!
  extract_code!
  extract_background_image!
  highlight_code!
end

Instance Attribute Details

#background_imageObject (readonly)

Returns the value of attribute background_image.



6
7
8
# File 'lib/keydown/slide.rb', line 6

def background_image
  @background_image
end

#contentObject (readonly)

Returns the value of attribute content.



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

def content
  @content
end

#notesObject (readonly)

Returns the value of attribute notes.



5
6
7
# File 'lib/keydown/slide.rb', line 5

def notes
  @notes
end

Instance Method Details

#background_attribution_classnamesObject



44
45
46
47
48
# File 'lib/keydown/slide.rb', line 44

def background_attribution_classnames
  return [] unless background_image[:attribution_text] || background_image[:service]

  ['attribution', background_image[:service]].join(' ')
end

#classnamesObject



27
28
29
# File 'lib/keydown/slide.rb', line 27

def classnames
  @classnames.length > 0 ? { :class => @classnames.join(' ') } : {}
end

#container_classnamesObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/keydown/slide.rb', line 31

def container_classnames
  @names ||= begin
    names = ['slide']

    unless @background_image.empty?
      names << 'full-background'
      names << @background_image[:classname]
    end

    names.join(' ')
  end
end

#to_htmlObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/keydown/slide.rb', line 50

def to_html
  require 'tilt'
  require 'rdiscount'

  markdown = RDiscount.new(@content)
  context = OpenStruct.new(:html_content => markdown.to_html,
                           :container_classnames => container_classnames,
                           :classnames => classnames,
                           :background_attribution_classnames => background_attribution_classnames,
                           :background_image => background_image)

  slide = Tilt.new(File.join(Tasks.template_dir, 'slide.html.haml'))
  slide.render(context)
end