Class: PresentationMaker

Inherits:
Wee::Component
  • Object
show all
Defined in:
lib/wee-pm/presentation_maker.rb

Constant Summary collapse

AREA_COLS =
90
DEFAULT_CONVERTER =
HtmlConverter

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ PresentationMaker

Returns a new instance of PresentationMaker.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/wee-pm/presentation_maker.rb', line 9

def initialize(filename)
  super()
  @filename = filename
  @presentation = 
  if File.exists? @filename
    Presentation.from_string(File.read(@filename))
  else
    Presentation.new
  end

  if @presentation.slides.empty?
    @presentation.slides << Slide.new
  end

  @presentation.slides.each do |sl|
    sl.converter = DEFAULT_CONVERTER 
  end

  @edit_mode = false

  @show_title_page = true
end

Instance Method Details

#add_new_slide_afterObject



104
105
106
107
# File 'lib/wee-pm/presentation_maker.rb', line 104

def add_new_slide_after
  @current_slide_index += 1
  add_new_slide_before
end

#add_new_slide_beforeObject


Actions: Edit




95
96
97
98
99
100
101
102
# File 'lib/wee-pm/presentation_maker.rb', line 95

def add_new_slide_before
  index = @current_slide_index
  @presentation.slides[index,0] = Slide.new {|s| 
    s.title = @current_slide.title
    s.converter = DEFAULT_CONVERTER
  }
  select_slide(index)
end

#delete_current_slideObject



109
110
111
112
113
# File 'lib/wee-pm/presentation_maker.rb', line 109

def delete_current_slide
  return if @presentation.slides.size <= 1
  @presentation.slides.delete_at(@current_slide_index)
  select_slide([@current_slide_index, @presentation.slides.size-1].min)
end

#move_current_slide_downObject



123
124
125
126
127
128
129
# File 'lib/wee-pm/presentation_maker.rb', line 123

def move_current_slide_down
  sl = @presentation.slides
  ci = @current_slide_index
  return if ci >= sl.size-1
  sl[ci+1], sl[ci] = sl[ci], sl[ci+1]
  select_slide(ci+1)
end

#move_current_slide_upObject



115
116
117
118
119
120
121
# File 'lib/wee-pm/presentation_maker.rb', line 115

def move_current_slide_up
  sl = @presentation.slides
  ci = @current_slide_index
  return if ci <= 0
  sl[ci-1], sl[ci] = sl[ci], sl[ci-1]
  select_slide(ci-1)
end

#next_slide_or_overlayObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/wee-pm/presentation_maker.rb', line 54

def next_slide_or_overlay
  if @show_title_page
    @show_title_page = false
    select_slide(0)
  elsif @current_overlay >= @current_slide.number_of_overlays
    if @current_slide_index < @presentation.slides.size-1
      select_slide(@current_slide_index + 1)
    else
      # TODO: show End-Box
    end
  else
    @current_overlay += 1
  end

  unless @step_mode 
    @current_overlay = @current_slide.number_of_overlays
  end
end

#prev_slide_or_overlayObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/wee-pm/presentation_maker.rb', line 73

def prev_slide_or_overlay
  # we are already on the first page -> do nothing!
  return if @show_title_page

  if @step_mode
    @current_overlay -= 1
    return if @current_overlay >= 0
  end

  @current_slide_index -= 1
  if @current_slide_index < 0
    show_title_page()
  else
    select_slide(@current_slide_index)
    @current_overlay = @current_slide.number_of_overlays 
  end
end

#renderObject


Rendering




147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/wee-pm/presentation_maker.rb', line 147

def render
  r.html do
    r.head do
      r.title("Presentation Maker #{ @filename }")
      r.style(@presentation.style)
      if @current_slide
        r.style(@current_slide.style)
      end
    end

    body = r.body

    #if not @edit_mode
    #  body.onclick(javascript_action {||next_slide_or_overlay})
    #end

    body.with do

      if not @edit_mode
        page_down = r.url_for_callback(proc {
          next_slide_or_overlay()
        })
        page_up = r.url_for_callback(proc {
          prev_slide_or_overlay()
        })
        toggle_mode_url = r.url_for_callback(proc {
          toggle_mode()
        })
        toggle_step_mode_url = r.url_for_callback(proc {
          toggle_step_mode()
        })

        r << %{
          <script>
          document.onkeypress = function(ev) {
            switch (ev.keyCode) {
            case 101: /* 'e' */
              document.location.href='#{ toggle_mode_url }';
              return false;
            case 115: /* 's' */
              document.location.href='#{ toggle_step_mode_url }';
              return false;
            case 34: /* page down */
              document.location.href='#{ page_down }';
              return false;
            case 33: /* page up */
              document.location.href='#{ page_up }';
              return false;
            };
            return true;
          };
          </script>
        }
      end

      r.span.id("navibutton").with do 
        r.anchor.callback { toggle_mode }.with do
          r.space(2)
        end
      end
      render_body
    end
  end
end

#render_bodyObject



368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
# File 'lib/wee-pm/presentation_maker.rb', line 368

def render_body
  if not @edit_mode
    render_slide
  else
    r.table do
      r.table_row do

        r.table_data.valign('top').with do 
          render_navi
        end

        r.table_data.valign('top').with do
          render_slide
        end

      end
    end
  end
end

#render_naviObject



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/wee-pm/presentation_maker.rb', line 235

def render_navi
  r.div.id('naviframe').with do
    r.anchor.callback{toggle_mode}.with { r.text('Hide') }

    r.text(" | ")

    r.anchor.callback { toggle_step_mode }.with do
      r.text('Change into Full-Slide mode') if @step_mode
      r.text('Change into Step mode') if !@step_mode
    end

    r.text(" | ")
    r.anchor.callback{save_presentation}.with { r.text('Save presentation') }
    r.hr

    r.text("Presentation: ")
    if @show_title_page
      r.text(@presentation.title)
    else
      r.anchor.callback{show_title_page}.with { r.text(@presentation.title) }
    end
    r.break

    render_outline

    r.hr

    if @show_title_page
      render_title_edit
    else
      render_slide_edit
    end
  end
end

#render_outlineObject



340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
# File 'lib/wee-pm/presentation_maker.rb', line 340

def render_outline
  r.ol {
    @presentation.slides.each_with_index do |slide, i|
      r.li do
        if i == @current_slide_index
          r.bold slide.title
          r.break

          (0 .. @current_slide.number_of_overlays).each do |j|
            if j == @current_overlay
              r.text "#{ j+1 }"
            else
              r.anchor.callback { @current_overlay = j }.with {
                r.text "#{ j+1 }"
              }
            end
            r.space
          end
        else
          r.anchor.callback { select_slide(i); show_all_overlays() }.with {
            r.text slide.title
          }
        end
      end
    end
  }
end

#render_slideObject



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/wee-pm/presentation_maker.rb', line 212

def render_slide
  if @show_title_page
    r.div.id('titlepage').css_class('slide').with do
      r.h1.onclick(javascript_action {||next_slide_or_overlay}).
        with(@presentation.title)

      r.div.id('author_email').with do
        r.text @presentation.author
        r.text(" (")
        r.anchor.href("mailto:#{ @presentation.email }").with(@presentation.email)
        r.text(")")
      end

    end
  elsif @current_slide
    r.div.id('slides').css_class('slide').  with do
      r.h1.onclick(javascript_action {||next_slide_or_overlay}).
        with(@current_slide.title)
      @current_slide.render_on(r, @current_overlay) 
    end
  end
end

#render_slide_editObject



296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
# File 'lib/wee-pm/presentation_maker.rb', line 296

def render_slide_edit
  r.ul do 
    r.li {
      r.text('Add new slide ')
      r.anchor.callback{add_new_slide_before}.with { r.text('before') }; r.text(' / ')
      r.anchor.callback{add_new_slide_after}.with { r.text('after') }; r.space
      r.text('current')
    }
    r.li {
      r.text('Current slide: ')
      r.anchor.callback{move_current_slide_up}.with { r.text('move up') }; r.text(' / ')
      r.anchor.callback{move_current_slide_down}.with { r.text('move down') }; r.text(' / ')
      r.anchor.callback{delete_current_slide}.with { r.text('delete') }
    }
  end

  r.hr

  r.paragraph
  r.form do
    r.submit_button.value('Update').callback { @current_overlay = @current_slide.number_of_overlays }
    r.space

    r.text "Title: "
    r.text_input.size(35).callback {|c| @current_slide.title = c.to_s}.value(@current_slide.title)

    r.paragraph
    r.text_area.cols(AREA_COLS).rows(30).callback {|c| @current_slide.content = c.to_s}.with(@current_slide.content)

    r.paragraph
    r.text "Annotations:"
    r.break
    r.text_area.cols(AREA_COLS).rows(10).callback {|c| @current_slide.annotations = c.to_s}.
      with(@current_slide.annotations)

    r.paragraph
    r.text "Style:"
    r.break
    r.text_area.cols(AREA_COLS).rows(10).callback {|c| @current_slide.style = c.to_s}.
      with(@current_slide.style)

  end
end

#render_title_editObject



270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
# File 'lib/wee-pm/presentation_maker.rb', line 270

def render_title_edit
  r.form do
    r.submit_button.value('Update')

    r.table.with do
      %w(title author email).each do |f| 
        r.table_row.with do
          r.table_data("#{ f.capitalize }: ")
          r.table_data.with {
            r.text_input.size(35).
              callback {|c| @presentation.send("#{ f }=", c.to_s) }.
              value(@presentation.send("#{ f }"))
          }
        end
      end
   end # table

   r.paragraph
   r.text("Style:")
   r.break
   r.text_area.cols(AREA_COLS).rows(10).callback {|c| @presentation.style = c.to_s}.
     with(@presentation.style)

  end
end

#save_presentationObject



131
132
133
# File 'lib/wee-pm/presentation_maker.rb', line 131

def save_presentation
  @presentation.save(@filename)
end

#select_slide(index) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/wee-pm/presentation_maker.rb', line 42

def select_slide(index)
  @show_title_page = false

  @current_slide_index = index
  @current_slide = @presentation.slides[@current_slide_index]
  @current_overlay = 0
end

#show_all_overlaysObject



50
51
52
# File 'lib/wee-pm/presentation_maker.rb', line 50

def show_all_overlays
  @current_overlay = @current_slide.number_of_overlays
end

#show_title_pageObject


Actions: Show




37
38
39
40
# File 'lib/wee-pm/presentation_maker.rb', line 37

def show_title_page
  @show_title_page = true
  @current_slide_index = @current_slide = @current_overlay = nil
end

#toggle_modeObject



135
136
137
# File 'lib/wee-pm/presentation_maker.rb', line 135

def toggle_mode
  @edit_mode = !@edit_mode
end

#toggle_step_modeObject



139
140
141
# File 'lib/wee-pm/presentation_maker.rb', line 139

def toggle_step_mode
  @step_mode = !@step_mode
end