Class: Wingtips::Configuration

Inherits:
Object
  • Object
show all
Includes:
DSL
Defined in:
lib/wingtips/configuration.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DSL

#slide

Constructor Details

#initialize(path) ⇒ Configuration

Returns a new instance of Configuration.



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

def initialize(path)
  self.class.current = self
  @wingtips_options = {
    app: {
      title:      'Presentation',
      fullscreen: true
    },
    templates: {}
  }


  full_path = File.expand_path(path)
  load_options(full_path)
  load_templates full_path
  load_named_slides full_path

  # the empty slide at the start is needed as otherwise the dimensions
  # of the first slide are most likely messed up
  @slide_classes = [Wingtips::Slide]

  self.instance_eval(File.read(full_path))
end

Class Attribute Details

.currentObject

Returns the value of attribute current.



72
73
74
# File 'lib/wingtips/configuration.rb', line 72

def current
  @current
end

Instance Attribute Details

#slide_classesObject (readonly)

Returns the value of attribute slide_classes.



5
6
7
# File 'lib/wingtips/configuration.rb', line 5

def slide_classes
  @slide_classes
end

Instance Method Details

#app_optionsObject



51
52
53
# File 'lib/wingtips/configuration.rb', line 51

def app_options
  @wingtips_options[:app]
end

#load_options(full_path) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/wingtips/configuration.rb', line 30

def load_options(full_path)
  begin
    @allow_unnamed_slides = true
    self.instance_eval(File.read(full_path))
  rescue NameError
    @allow_unnamed_slides = false
    # expected to hit the first slide class and then abort evaling
    # the config file. This is necessary so we can have the options at the
    # beginning of the config file while they are needed in the tamplates
    # for instance. So what happens is:
    # 1. read config (options should be on top)
    # 2. error upon encountering the first class, continue in initialize
    # 3. Load slides and templates (while options are already loaded)
    # 4. eval the config file again (options are read again, shouldn't be
    #   a problem). This time no error as slide and template classes are
    #   loaded
    # Yes there could be a separate options file, but it didn't feel right
    # to have a config and an options file
  end
end

#slides(*slide_classes) ⇒ Object



63
64
65
# File 'lib/wingtips/configuration.rb', line 63

def slides(*slide_classes)
  @slide_classes.concat(slide_classes)
end

#template_optionsObject



55
56
57
# File 'lib/wingtips/configuration.rb', line 55

def template_options
  @wingtips_options[:templates]
end

#unnamed_slides_allowed?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/wingtips/configuration.rb', line 67

def unnamed_slides_allowed?
  @allow_unnamed_slides
end

#wingtips_options(opts = {}) ⇒ Object



59
60
61
# File 'lib/wingtips/configuration.rb', line 59

def wingtips_options(opts={})
  HashUtils.deep_merge! @wingtips_options, opts
end