keydown 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,365 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Keydown::Slide do
4
+ before :each do
5
+ module Keydown
6
+ class Tasks
7
+ def self.template_dir
8
+ File.join(Keydown::Tasks.source_root, 'templates', 'rocks')
9
+ end
10
+ end
11
+ end
12
+ end
13
+
14
+ shared_examples_for 'extracting slide data' do
15
+
16
+ it "should set the CSS classnames" do
17
+ @slide.classnames.should == @classnames
18
+ end
19
+
20
+ it "should extract the slide content" do
21
+ @slide.content.should match(/^# A Slide/)
22
+ @slide.content.should match(/With some text/)
23
+ end
24
+
25
+ it "should remove the notes from the content" do
26
+ @slide.content.should_not match(/a simple note/)
27
+ end
28
+
29
+ it "should extract the notes" do
30
+ @slide.notes.should match(/a simple note/)
31
+ end
32
+ end
33
+
34
+ shared_examples_for "generating HTML" do
35
+ it "should assign the classname(s) to the section" do
36
+ @doc.css(@slide_selector).should_not be_nil
37
+ end
38
+
39
+ it "should convert the content via Markdown" do
40
+ @doc.css('section h1').text.should == 'A Slide'
41
+ end
42
+
43
+ it "should not include the notes in the HTML" do
44
+ @doc.css('section p').each do |node|
45
+ node.text.should_not match(/!NOTES/)
46
+ end
47
+ end
48
+ end
49
+
50
+ shared_examples_for "Pygmentizing code fragments" do
51
+ it "should colorize the code fragments" do
52
+ @doc.css('.highlight').length.should == 1
53
+ end
54
+ end
55
+
56
+ describe 'without a CSS classname' do
57
+ before :each do
58
+ @slide_text = <<-SLIDE
59
+
60
+ # A Slide
61
+ With some text
62
+
63
+ !NOTES
64
+ a simple note
65
+ SLIDE
66
+
67
+ @classnames = ''
68
+ @slide = Keydown::Slide.new(@slide_text)
69
+ end
70
+
71
+ it_should_behave_like "extracting slide data"
72
+
73
+ describe "when generating HTML" do
74
+ before :each do
75
+ @html = @slide.to_html
76
+ @doc = Nokogiri(@html)
77
+ @slide_selector = "section"
78
+ end
79
+
80
+ it_should_behave_like "generating HTML"
81
+ end
82
+ end
83
+
84
+ describe "with a single CSS classname" do
85
+ before :each do
86
+ @slide_text = <<-SLIDE
87
+
88
+ # A Slide
89
+ With some text
90
+
91
+ !NOTES
92
+ a simple note
93
+ SLIDE
94
+
95
+ @classnames = 'foo'
96
+ @slide = Keydown::Slide.new(@slide_text, 'foo')
97
+ end
98
+
99
+ it_should_behave_like "extracting slide data"
100
+
101
+ describe "when generating HTML" do
102
+ before :each do
103
+ @html = @slide.to_html
104
+ @doc = Nokogiri(@html)
105
+ @slide_selector = "section.#{@classnames}"
106
+ end
107
+
108
+ it_should_behave_like "generating HTML"
109
+ end
110
+ end
111
+
112
+ describe "with multiple CSS classnames" do
113
+ before :each do
114
+ @slide_text = <<-SLIDE
115
+
116
+ # A Slide
117
+ With some text
118
+
119
+ !NOTES
120
+ a simple note
121
+ SLIDE
122
+
123
+ @classnames = 'foo bar'
124
+ @slide = Keydown::Slide.new(@slide_text, 'foo bar')
125
+
126
+ end
127
+
128
+ it_should_behave_like "extracting slide data"
129
+
130
+ describe "generating HTML" do
131
+ before :each do
132
+ @html = @slide.to_html
133
+ @doc = Nokogiri(@html)
134
+ @slide_selector = "section.#{@classnames}"
135
+ end
136
+ it_should_behave_like "generating HTML"
137
+ end
138
+ end
139
+
140
+ describe "without a note" do
141
+ before :each do
142
+ @slide_text = <<-SLIDE
143
+
144
+ # A Slide
145
+ With some text
146
+ SLIDE
147
+
148
+ @classnames = ''
149
+ @slide = Keydown::Slide.new(@slide_text)
150
+ end
151
+
152
+ it "should set the CSS classnames" do
153
+ @slide.classnames.should == @classnames
154
+ end
155
+
156
+ it "should extract the slide content" do
157
+ @slide.content.should match(/^# A Slide/)
158
+ @slide.content.should match(/With some text/)
159
+ end
160
+
161
+ describe "when generating HTML" do
162
+ before :each do
163
+ @html = @slide.to_html
164
+ @doc = Nokogiri(@html)
165
+ @slide_selector = "section"
166
+ end
167
+
168
+ it_should_behave_like "generating HTML"
169
+ end
170
+ end
171
+
172
+ describe "with code to higlight" do
173
+
174
+ describe "using the Slidedown syntax" do
175
+ before :each do
176
+ @slide_text = <<-SLIDE
177
+
178
+ # A Slide
179
+ With some text
180
+
181
+ @@@ ruby
182
+ def a_method(options)
183
+ puts "I can has options " + options
184
+ end
185
+ @@@
186
+ !NOTES
187
+ a simple note
188
+
189
+ SLIDE
190
+
191
+ @classnames = ''
192
+ template_dir = File.join(Keydown::Tasks.source_root, 'templates', 'rocks')
193
+ @slide = Keydown::Slide.new(@slide_text)
194
+ end
195
+
196
+ it_should_behave_like "extracting slide data"
197
+
198
+ describe "when generating HTML" do
199
+ before :each do
200
+ @html = @slide.to_html
201
+ @doc = Nokogiri(@html)
202
+ @slide_selector = "section"
203
+ end
204
+
205
+ it_should_behave_like "generating HTML"
206
+
207
+ it_should_behave_like "Pygmentizing code fragments"
208
+ end
209
+ end
210
+
211
+ describe "using the Github markup syntax" do
212
+ before :each do
213
+ @slide_text = <<-SLIDE
214
+
215
+ # A Slide
216
+ With some text
217
+
218
+ ``` ruby
219
+ def a_method(options)
220
+ puts "I can has options " + options
221
+ end
222
+ ```
223
+ !NOTES
224
+ a simple note
225
+
226
+ SLIDE
227
+
228
+ @classnames = ''
229
+ @slide = Keydown::Slide.new(@slide_text)
230
+ end
231
+
232
+ it_should_behave_like "extracting slide data"
233
+
234
+ describe "when generating HTML" do
235
+ before :each do
236
+ @html = @slide.to_html
237
+ @doc = Nokogiri(@html)
238
+ @slide_selector = "section"
239
+ end
240
+
241
+ it_should_behave_like "generating HTML"
242
+ it_should_behave_like "Pygmentizing code fragments"
243
+ end
244
+ end
245
+ end
246
+
247
+ describe "with an image for a full-bleed background" do
248
+ before(:each) do
249
+ @slide_text = <<-SLIDE
250
+
251
+ # A Slide
252
+ With some text
253
+
254
+ }}} images/my_background.png
255
+
256
+ !NOTES
257
+ a simple note
258
+
259
+ SLIDE
260
+
261
+ @classnames = ''
262
+ @slide = Keydown::Slide.new(@slide_text.chomp)
263
+ end
264
+
265
+ it_should_behave_like "extracting slide data"
266
+
267
+ describe "when generating HTML" do
268
+ before :each do
269
+ @html = @slide.to_html
270
+ @doc = Nokogiri(@html)
271
+ @slide_selector = "section"
272
+ @slide_container = @doc.css('div.slide')[0]
273
+ end
274
+
275
+ it_should_behave_like "generating HTML"
276
+
277
+ it "should remove any declaration of a background image" do
278
+ @doc.css(@slide_selector)[0].content.should_not match(/\}\}\}\s+images\/my_background\.png/)
279
+ end
280
+
281
+ it "should save off the background image info for use when generating the HTML" do
282
+ @slide.background_image.should == {:classname => 'my_background', :path => 'images/my_background.png'}
283
+ end
284
+
285
+ it "should add the full-background class to the containing div" do
286
+ @slide_container['class'].split(' ').should include('full-background')
287
+ end
288
+
289
+ it "should add the background image class to the containing div" do
290
+ @slide_container['class'].split(' ').should include('my_background')
291
+ end
292
+
293
+ end
294
+ end
295
+
296
+ describe "with an image for a full-bleed background with a Flickr attribution" do
297
+ before(:each) do
298
+ @slide_text = <<-SLIDE
299
+
300
+ # A Slide
301
+ With some text
302
+
303
+ }}} images/my_background.png::cprsize::flickr::http://flickr.com/1234
304
+
305
+ !NOTES
306
+ a simple note
307
+
308
+ SLIDE
309
+
310
+ @classnames = ''
311
+ @slide = Keydown::Slide.new(@slide_text.chomp)
312
+ end
313
+
314
+ it_should_behave_like "extracting slide data"
315
+
316
+ describe "when generating HTML" do
317
+ before :each do
318
+ @html = @slide.to_html
319
+ @doc = Nokogiri(@html)
320
+ @slide_selector = "section"
321
+ @slide_container = @doc.css('div.slide')[0]
322
+ end
323
+
324
+ it_should_behave_like "generating HTML"
325
+
326
+ it "should remove any declaration of a background image" do
327
+ @doc.css(@slide_selector)[0].content.should_not match(/\}\}\}\s+images\/my_background\.png/)
328
+ end
329
+
330
+ it "should save off the background image info for use when generating the HTML" do
331
+ @slide.background_image[:classname].should == 'my_background'
332
+ @slide.background_image[:path].should == 'images/my_background.png'
333
+ @slide.background_image[:service].should == 'flickr'
334
+ @slide.background_image[:attribution_text].should == 'cprsize'
335
+ @slide.background_image[:attribution_link].should == 'http://flickr.com/1234'
336
+ end
337
+
338
+ it "should add the full-background class to the containing div" do
339
+ @slide_container['class'].split(' ').should include('full-background')
340
+ end
341
+
342
+ it "should add the background image class to the containing div" do
343
+ @slide_container['class'].split(' ').should include('my_background')
344
+ end
345
+
346
+ describe "it makes an attribution element that" do
347
+ before(:each) do
348
+ @attribution = @doc.css('.attribution')[0]
349
+ end
350
+
351
+ it "should have the specified CSS class" do
352
+ @attribution['class'].split(' ').should include('flickr')
353
+ end
354
+
355
+ it "should have the specified text" do
356
+ @attribution.content.should match(/cprsize/)
357
+ end
358
+
359
+ it "should have the specified link" do
360
+ @attribution.css('a')[0]['href'].should match('http://flickr.com/1234')
361
+ end
362
+ end
363
+ end
364
+ end
365
+ end
@@ -0,0 +1,133 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Keydown::SlideDeck do
4
+
5
+ shared_examples_for "finding slides" do
6
+ describe "when building slides" do
7
+
8
+ it "should find the document's title" do
9
+ @deck.title.should == "Kermit the Frog Says..."
10
+ end
11
+
12
+ it "should find all the slides in the markdown" do
13
+ @deck.slides.length.should == 3
14
+ end
15
+ end
16
+ end
17
+
18
+
19
+ before :each do
20
+ module Keydown
21
+ class Tasks
22
+ def self.template_dir
23
+ File.join(Keydown::Tasks.source_root, 'templates', 'rocks')
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ describe "with a title" do
30
+ before :each do
31
+ @slides_text = <<-SLIDES
32
+ # Kermit the Frog Says...
33
+
34
+ !SLIDE
35
+
36
+ # This Presentation
37
+
38
+ !NOTE
39
+
40
+ I think this should be ignored
41
+
42
+ !SLIDE foo
43
+
44
+ # Is Brought to You By
45
+
46
+ !NOTE
47
+
48
+ and this
49
+
50
+ !SLIDE foo bar
51
+
52
+ # The Letter Q
53
+
54
+ SLIDES
55
+
56
+ @deck = Keydown::SlideDeck.new(@slides_text)
57
+ end
58
+
59
+ it_should_behave_like "finding slides"
60
+
61
+ describe "when generating HTML" do
62
+ before :each do
63
+ @html = @deck.to_html
64
+ @doc = Nokogiri(@html)
65
+ end
66
+
67
+ it "should set the document's title" do
68
+ @doc.css('title').text.should == "Kermit the Frog Says..."
69
+ end
70
+
71
+ it "should generate the correct number of slides" do
72
+ @doc.css('div.slide').length.should == 4
73
+ end
74
+
75
+ it "should set the CSS classnames of each slide" do
76
+ slides = @doc.css('div.slide section')
77
+
78
+ slides[0]['class'].should == 'middle' # config/start slide
79
+ slides[1]['class'].should == nil
80
+ slides[2]['class'].should == 'foo'
81
+ slides[3]['class'].should == 'foo bar'
82
+ end
83
+ end
84
+ end
85
+
86
+ describe "with a background image" do
87
+ before :each do
88
+ @slides_text = <<-SLIDES
89
+ # Kermit the Frog Says...
90
+
91
+ !SLIDE
92
+
93
+ # This Presentation
94
+
95
+ }}} images/my_background.png
96
+
97
+ !SLIDE foo
98
+
99
+ # Is Brought to You By
100
+
101
+ !NOTE
102
+
103
+ and this
104
+
105
+ !SLIDE foo bar
106
+
107
+ # The Letter Q
108
+ SLIDES
109
+
110
+ @deck = Keydown::SlideDeck.new(@slides_text)
111
+ end
112
+
113
+ it_should_behave_like "finding slides"
114
+
115
+ describe "when generating HTML" do
116
+ before(:each) do
117
+ @html = @deck.to_html
118
+ @doc = Nokogiri(@html)
119
+ @slide_with_background = @doc.css('div.slide')[1]
120
+ end
121
+
122
+ it "should add the full-bleed background CSS classname to any slide that specifies a background" do
123
+ @slide_with_background['class'].split(' ').should include('full-background')
124
+ end
125
+
126
+ it "should add a custom classname to a slide that specifies a background" do
127
+ @slide_with_background['class'].split(' ').should include('my_background')
128
+ end
129
+ end
130
+
131
+
132
+ end
133
+ end