Class: Wingtips::Slide

Inherits:
Object
  • Object
show all
Includes:
Shoes::Highlighter::Markup
Defined in:
lib/wingtips/slide.rb

Constant Summary collapse

IMAGES_DIRECTORY =
'images/'
CODE_DIRECTORY =
'code/'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Slide

Returns a new instance of Slide.



19
20
21
22
23
# File 'lib/wingtips/slide.rb', line 19

def initialize(app)
  @app = app
  @effects = []
  after_initialize
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &blk) ⇒ Object

copied from the URL implementation… weird but I want to have classes not methods for this



41
42
43
44
45
46
47
# File 'lib/wingtips/slide.rb', line 41

def method_missing(method, *args, &blk)
  if app_should_handle_method? method
    app.send(method, *args, &blk)
  else
    super
  end
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



17
18
19
# File 'lib/wingtips/slide.rb', line 17

def app
  @app
end

Instance Method Details

#add_demo_as_effect(string, &block) ⇒ Object



79
80
81
# File 'lib/wingtips/slide.rb', line 79

def add_demo_as_effect(string, &block)
  add_effect do demo(string, &block) end
end

#add_effect(&effect) ⇒ Object



83
84
85
# File 'lib/wingtips/slide.rb', line 83

def add_effect(&effect)
  @effects << effect
end

#after_initializeObject



171
172
173
# File 'lib/wingtips/slide.rb', line 171

def after_initialize
  # subclasses if an after hook is needed
end

#append(&blk) ⇒ Object



35
36
37
# File 'lib/wingtips/slide.rb', line 35

def append(&blk)
  @main_slot.append &blk
end

#bullet(string) ⇒ Object



93
94
95
# File 'lib/wingtips/slide.rb', line 93

def bullet(string)
  para '    • ' + string, size: BULLET_POINT_SIZE
end

#center_horizontally(element) ⇒ Object



159
160
161
# File 'lib/wingtips/slide.rb', line 159

def center_horizontally(element)
  element.left = @app.width / 2 - element.width / 2
end

#centered_enormous_text(string, opts = {}) ⇒ Object



152
153
154
155
156
157
# File 'lib/wingtips/slide.rb', line 152

def centered_enormous_text(string, opts={})
  para string, defaulted_options(opts,
                                 align: 'center',
                                 size: ENORMOUS_SIZE,
                                 margin_top: 50)
end

#centered_huge_text(string, opts = {}) ⇒ Object



145
146
147
148
149
150
# File 'lib/wingtips/slide.rb', line 145

def centered_huge_text(string, opts={})
  para string, defaulted_options(opts,
                                 align: 'center',
                                 size: VERY_BIG_SIZE,
                                 margin_top: 50)
end

#centered_subtitle(string, opts = {}) ⇒ Object



138
139
140
141
142
143
# File 'lib/wingtips/slide.rb', line 138

def centered_subtitle(string, opts={})
  para string, defaulted_options(opts,
                                 align: 'center',
                                 size: BULLET_POINT_SIZE,
                                 margin_top: 50)
end

#centered_title(string, opts = {}) ⇒ Object



131
132
133
134
135
136
# File 'lib/wingtips/slide.rb', line 131

def centered_title(string, opts={})
  para string, defaulted_options(opts,
                                 align: 'center',
                                 size: VERY_BIG_SIZE,
                                 margin_top: 50)
end

#code(string, demo_as_effect = false, &block) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/wingtips/slide.rb', line 49

def code(string, demo_as_effect = false, &block)
  source = source_from string
  source = source.split("\n").map{|line| '     ' + line}.join("\n")
  highlighted_code = para *highlight(source), size: CODE_SIZE
  add_demo_as_effect(source, &block) if demo_as_effect
  highlighted_code
end

#contentObject



25
26
27
# File 'lib/wingtips/slide.rb', line 25

def content
  # implemented by subclasses
end

#defaulted_options(passed, defaults = {}) ⇒ Object



163
164
165
166
167
168
169
# File 'lib/wingtips/slide.rb', line 163

def defaulted_options(passed, defaults={})
  results = defaults.merge(passed)
  if results[:vertical_align] == 'center'
    results[:margin_top] = height/2 - 100
  end
  results
end

#demo(string) {|last_app| ... } ⇒ Object

Yields:

  • (last_app)


57
58
59
60
61
62
63
64
65
66
67
# File 'lib/wingtips/slide.rb', line 57

def demo(string, &block)
  source = source_from string
  eval source

  last_app = Shoes.apps.last
  last_app.keypress do |key|
    last_app.quit if key == :control_w
  end

  yield last_app if block_given?
end

#effects_left?Boolean

Returns:

  • (Boolean)


175
176
177
# File 'lib/wingtips/slide.rb', line 175

def effects_left?
  !@effects.empty?
end

#empty_lineObject



97
98
99
# File 'lib/wingtips/slide.rb', line 97

def empty_line
  para ' ', size: BULLET_POINT_SIZE
end

#fullscreen_image(path) ⇒ Object



110
111
112
113
114
115
116
# File 'lib/wingtips/slide.rb', line 110

def fullscreen_image(path)
  img = image path
  height_ratio = height.to_r/img.height
  width_ratio = width.to_r/img.width
  scale_image_by img, [width_ratio, height_ratio].max
  img
end

#fully_shown_image(path, additional_height = 0) ⇒ Object



118
119
120
121
122
123
124
# File 'lib/wingtips/slide.rb', line 118

def fully_shown_image(path, additional_height = 0)
  img = image path
  height_ratio = (height - additional_height).to_r/img.height
  width_ratio = width.to_r/img.width
  scale_image_by img, [width_ratio, height_ratio].min
  img
end

#headline(string) ⇒ Object



87
88
89
90
91
# File 'lib/wingtips/slide.rb', line 87

def headline(string)
  text = title '  ' + string, size: HEADLINE_SIZE
  empty_line
  text
end

#image(path, *args) ⇒ Object



101
102
103
# File 'lib/wingtips/slide.rb', line 101

def image(path, *args)
  app.image(image_path(path), *args)
end

#image_path(path) ⇒ Object



105
106
107
108
# File 'lib/wingtips/slide.rb', line 105

def image_path(path)
  path = find_file_in(path, [IMAGES_DIRECTORY])
  File.expand_path(path)
end

#scale_image_by(img, ratio) ⇒ Object



126
127
128
129
# File 'lib/wingtips/slide.rb', line 126

def scale_image_by(img, ratio)
  img.width = (img.width * ratio).to_i
  img.height = (img.height * ratio).to_i
end

#showObject



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

def show
  @main_slot = stack height: app.height do
    content
  end
end

#source_from(string) ⇒ Object



69
70
71
72
73
74
75
76
77
# File 'lib/wingtips/slide.rb', line 69

def source_from(string)
  file_path = find_file_in(string, [CODE_DIRECTORY])

  if file_path
    File.read file_path
  else
    string
  end
end

#trigger_effectObject



179
180
181
182
# File 'lib/wingtips/slide.rb', line 179

def trigger_effect
  effect = @effects.shift
  @main_slot.append &effect
end