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.



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

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

  @codemap = CodeMap.build_from(text)
  @content = @codemap.mapped_text

  extract_notes!
  extract_content!
  extract_background_image!

  @classnames = Classnames.new('slide')
  @classnames.add(classnames)

  unless @background_image.empty?
    @classnames.add('full-background')
    @classnames.add(@background_image[:classname])
  end
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

#classnamesObject (readonly)

Returns the value of attribute classnames.



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

def classnames
  @classnames
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



29
30
31
32
33
# File 'lib/keydown/slide.rb', line 29

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

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

#to_htmlObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/keydown/slide.rb', line 35

def to_html
  require 'tilt'
  require 'rdiscount'

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

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

  @codemap.put_code_in html
end