Class: Wingtips::Slide
- Inherits:
-
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
-
#add_demo_as_effect(string, &block) ⇒ Object
-
#add_effect(&effect) ⇒ Object
-
#after_initialize ⇒ Object
-
#append(&blk) ⇒ Object
-
#bullet(string) ⇒ Object
-
#center_horizontally(element) ⇒ Object
-
#centered_enormous_text(string, opts = {}) ⇒ Object
-
#centered_huge_text(string, opts = {}) ⇒ Object
-
#centered_subtitle(string, opts = {}) ⇒ Object
-
#centered_title(string, opts = {}) ⇒ Object
-
#code(string, demo_as_effect = false, options = {}, &block) ⇒ Object
-
#content ⇒ Object
-
#defaulted_options(passed, defaults = {}) ⇒ Object
-
#demo(string) {|last_app| ... } ⇒ Object
-
#effects_left? ⇒ Boolean
-
#empty_line ⇒ Object
-
#fullscreen_image(path) ⇒ Object
-
#fully_shown_image(path, additional_height = 0) ⇒ Object
-
#headline(string) ⇒ Object
-
#image(path, *args) ⇒ Object
-
#image_path(path) ⇒ Object
-
#initialize(app, wingtips_options = {}) ⇒ Slide
constructor
-
#method_missing(method, *args, &blk) ⇒ Object
copied from the URL implementation…
-
#scale_image_by(img, ratio) ⇒ Object
-
#show ⇒ Object
-
#source_from(string) ⇒ Object
-
#trigger_effect ⇒ Object
Constructor Details
#initialize(app, wingtips_options = {}) ⇒ Slide
Returns a new instance of Slide.
19
20
21
22
23
24
|
# File 'lib/wingtips/slide.rb', line 19
def initialize(app, wingtips_options = {})
@app = app
@effects = []
@background_color = wingtips_options[:background_color]
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
43
44
45
46
47
48
49
|
# File 'lib/wingtips/slide.rb', line 43
def method_missing(method, *args, &blk)
if app_should_handle_method? method
app.send(method, *args, &blk)
else
super
end
end
|
Instance Attribute Details
#app ⇒ Object
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
82
83
84
|
# File 'lib/wingtips/slide.rb', line 82
def add_demo_as_effect(string, &block)
add_effect do demo(string, &block) end
end
|
#add_effect(&effect) ⇒ Object
86
87
88
|
# File 'lib/wingtips/slide.rb', line 86
def add_effect(&effect)
@effects << effect
end
|
#after_initialize ⇒ Object
175
176
177
|
# File 'lib/wingtips/slide.rb', line 175
def after_initialize
end
|
#append(&blk) ⇒ Object
37
38
39
|
# File 'lib/wingtips/slide.rb', line 37
def append(&blk)
@main_slot.append &blk
end
|
#bullet(string) ⇒ Object
96
97
98
|
# File 'lib/wingtips/slide.rb', line 96
def bullet(string)
para ' • ' + string, size: BULLET_POINT_SIZE
end
|
#center_horizontally(element) ⇒ Object
163
164
165
|
# File 'lib/wingtips/slide.rb', line 163
def center_horizontally(element)
element.left = @app.width / 2 - element.width / 2
end
|
#centered_enormous_text(string, opts = {}) ⇒ Object
156
157
158
159
160
161
|
# File 'lib/wingtips/slide.rb', line 156
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
149
150
151
152
153
154
|
# File 'lib/wingtips/slide.rb', line 149
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
142
143
144
145
146
147
|
# File 'lib/wingtips/slide.rb', line 142
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
135
136
137
138
139
140
|
# File 'lib/wingtips/slide.rb', line 135
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, options = {}, &block) ⇒ Object
51
52
53
54
55
56
57
58
|
# File 'lib/wingtips/slide.rb', line 51
def code(string, demo_as_effect = false, options = {}, &block)
source = source_from string
source = source.split("\n").map{|line| ' ' + line}.join("\n")
opts = {size: CODE_SIZE}.merge options
highlighted_code = para *highlight(source, nil, @app.code_highlighting), opts
add_demo_as_effect(source, &block) if demo_as_effect
highlighted_code
end
|
#content ⇒ Object
26
27
28
|
# File 'lib/wingtips/slide.rb', line 26
def content
end
|
#defaulted_options(passed, defaults = {}) ⇒ Object
167
168
169
170
171
172
173
|
# File 'lib/wingtips/slide.rb', line 167
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
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/wingtips/slide.rb', line 60
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
179
180
181
|
# File 'lib/wingtips/slide.rb', line 179
def effects_left?
!@effects.empty?
end
|
#empty_line ⇒ Object
100
101
102
|
# File 'lib/wingtips/slide.rb', line 100
def empty_line
para ' ', size: BULLET_POINT_SIZE
end
|
#fullscreen_image(path) ⇒ Object
113
114
115
116
117
118
119
|
# File 'lib/wingtips/slide.rb', line 113
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
121
122
123
124
125
126
127
|
# File 'lib/wingtips/slide.rb', line 121
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
90
91
92
93
94
|
# File 'lib/wingtips/slide.rb', line 90
def headline(string)
text = title ' ' + string, size: HEADLINE_SIZE
empty_line
text
end
|
#image(path, *args) ⇒ Object
104
105
106
|
# File 'lib/wingtips/slide.rb', line 104
def image(path, *args)
app.image(image_path(path), *args)
end
|
#image_path(path) ⇒ Object
108
109
110
111
|
# File 'lib/wingtips/slide.rb', line 108
def image_path(path)
path = find_file_in(path, [IMAGES_DIRECTORY])
File.expand_path(path)
end
|
#scale_image_by(img, ratio) ⇒ Object
129
130
131
132
133
|
# File 'lib/wingtips/slide.rb', line 129
def scale_image_by(img, ratio)
img.width = (img.width * ratio).to_i
img.height = (img.height * ratio).to_i
img
end
|
#show ⇒ Object
30
31
32
33
34
35
|
# File 'lib/wingtips/slide.rb', line 30
def show
@main_slot = stack height: app.height do
background @background_color if @background_color
content
end
end
|
#source_from(string) ⇒ Object
72
73
74
75
76
77
78
79
80
|
# File 'lib/wingtips/slide.rb', line 72
def source_from(string)
file_path = find_file_in(string, [CODE_DIRECTORY])
if file_path
File.read file_path
else
string
end
end
|
#trigger_effect ⇒ Object
183
184
185
186
|
# File 'lib/wingtips/slide.rb', line 183
def trigger_effect
effect = @effects.shift
@main_slot.append &effect
end
|