Class: RevealCK::PresentationDSL

Inherits:
Object
  • Object
show all
Includes:
Retrieve
Defined in:
lib/reveal-ck/presentation_dsl.rb

Overview

Public: A PresentationDSL defines the DSL behind a presentation. It also knows how to load file containing the DSL.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Retrieve

included, #retrieve

Constructor Details

#initialize(args) ⇒ PresentationDSL

Returns a new instance of PresentationDSL.



11
12
13
14
# File 'lib/reveal-ck/presentation_dsl.rb', line 11

def initialize(args)
  @slides = []
  @config = retrieve(:config, args)
end

Instance Attribute Details

#author(author) ⇒ Object (readonly)

Returns the value of attribute author.



8
9
10
# File 'lib/reveal-ck/presentation_dsl.rb', line 8

def author
  @author
end

#configObject (readonly)

Returns the value of attribute config.



9
10
11
# File 'lib/reveal-ck/presentation_dsl.rb', line 9

def config
  @config
end

#theme(theme) ⇒ Object (readonly)

Rubocop doesn’t like trivial accessors, but docile breaks if trivial accessors are used. rubocop:disable TrivialAccessors



19
20
21
# File 'lib/reveal-ck/presentation_dsl.rb', line 19

def theme
  @theme
end

#title(title) ⇒ Object (readonly)

Returns the value of attribute title.



8
9
10
# File 'lib/reveal-ck/presentation_dsl.rb', line 8

def title
  @title
end

#transition(transition) ⇒ Object (readonly)

Returns the value of attribute transition.



8
9
10
# File 'lib/reveal-ck/presentation_dsl.rb', line 8

def transition
  @transition
end

Class Method Details

.load(args) ⇒ Object



66
67
68
69
70
71
# File 'lib/reveal-ck/presentation_dsl.rb', line 66

def self.load(args)
  file, config = retrieve(:file, args), retrieve(:config, args)
  builder = PresentationDSL.new config: config
  contents = File.open(file).read
  builder.instance_eval(contents)
end

Instance Method Details

#buildObject



50
51
52
53
54
55
56
57
58
# File 'lib/reveal-ck/presentation_dsl.rb', line 50

def build
  presentation = RevealCK::Presentation.new config: config
  presentation.theme = @theme if @theme
  presentation.transition = @transition if @transition
  presentation.author = @author if @author
  presentation.title = @title if @title
  @slides.each { |slide| presentation.add slide }
  presentation
end

#contents_of(path) ⇒ Object



46
47
48
# File 'lib/reveal-ck/presentation_dsl.rb', line 46

def contents_of(path)
  File.open(path).read
end

#presentation(&block) ⇒ Object



62
63
64
# File 'lib/reveal-ck/presentation_dsl.rb', line 62

def presentation(&block)
  Docile.dsl_eval(self, &block).build
end

#revealjs_config(key, value) ⇒ Object

rubocop:enable TrivialAccessors



36
37
38
# File 'lib/reveal-ck/presentation_dsl.rb', line 36

def revealjs_config(key, value)
  config.revealjs_config[key] = value
end

#slide(template, variables = {}) ⇒ Object



40
41
42
43
44
# File 'lib/reveal-ck/presentation_dsl.rb', line 40

def slide(template, variables = {})
  variables[:template] = template
  variables[:config] = @config
  @slides << RevealCK::Slide.new(variables)
end