slidedown 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -4,8 +4,7 @@ Generate slides with Markdown
4
4
 
5
5
  ## Usage
6
6
 
7
- Write your talk. Currently, the syntax highlight lexer defaults to Ruby.
8
- Adding support for specifying languages is in the TODOs.
7
+ Write your talk.
9
8
 
10
9
  !SLIDE
11
10
 
@@ -35,7 +34,7 @@ Generate the output:
35
34
 
36
35
  ### Custom Styles
37
36
 
38
- To add custom styles to your slides, just create stylesheets in the same directory as your presentation's markdown file:
37
+ To add custom styles to your slides, just create stylesheets in the same directory as your presentation markdown file:
39
38
 
40
39
  | - presentation-directory
41
40
  | - slides.md
@@ -43,28 +42,41 @@ To add custom styles to your slides, just create stylesheets in the same directo
43
42
 
44
43
  The additional styles will be added to your generated slides.
45
44
 
45
+ ## Navigation
46
+
47
+ Give your presentation!
48
+
49
+ * left, right arrows to navigate through slides
50
+ * esc to go home
51
+
46
52
  ## Syntax Highlighting
47
53
 
48
- slidedown syntax highlighting works just like Lighthouse's:
54
+ For Ruby:
49
55
 
50
56
  @@@ ruby
51
- def foo
52
- :bar
53
- end
57
+ def foo
58
+ :bar
59
+ end
54
60
  @@@
55
61
 
56
- Or for JavaScript
62
+ For Javascript
57
63
 
58
64
  @@@ js
59
- function foo() {
60
- return 'bar';
61
- }
65
+ function foo() {
66
+ return 'bar';
67
+ }
68
+ @@@
69
+
70
+ For ERb:
71
+
72
+ @@@ rhtml
73
+ <%= @post.created_at.to_s(:fancy) %>
62
74
  @@@
63
75
 
64
76
  ### Requirements
65
77
 
66
- * RDiscount
67
78
  * Nokogiri
79
+ * makers-mark
68
80
  * pygments (for syntax highlighting)
69
81
 
70
82
  ## Todo
@@ -100,4 +112,4 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
100
112
  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
101
113
  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
102
114
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
103
- OTHER DEALINGS IN THE SOFTWARE.
115
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -9,7 +9,7 @@ $SILENT = true
9
9
 
10
10
  class SlideDown
11
11
  USAGE = "The SlideDown command line interface takes a .md (Markdown) file as its only required argument. It will convert the file to HTML in standard out. Options:
12
- -t, --template [TEMPLATE] the .erb files in /templates directory. Default is -t default, which prints stylesheets and javascripts inline. The import template uses link and script tags."
12
+ -t, --template [TEMPLATE] the .erb files in /templates directory. Default is -t default, which prints stylesheets and javascripts inline. The import template uses link and script tags. This can also accept an absolute path for templates outside the /templates directory."
13
13
 
14
14
  attr_accessor :stylesheets, :title
15
15
  attr_reader :classes
@@ -63,9 +63,13 @@ class SlideDown
63
63
  end
64
64
 
65
65
  def render(name)
66
- directory = File.join(File.dirname(__FILE__), "..", "templates")
67
- path = File.join(directory, "#{name}.erb")
68
- template = File.read(path)
66
+ if is_absolute_path?(name)
67
+ template = File.read("#{name}.erb")
68
+ else
69
+ directory = File.join(File.dirname(__FILE__), "..", "templates")
70
+ path = File.join(directory, "#{name}.erb")
71
+ template = File.read(path)
72
+ end
69
73
  ERB.new(template).result(binding)
70
74
  end
71
75
 
@@ -79,7 +83,7 @@ class SlideDown
79
83
  Dir[Dir.pwd + '/*.stylesheets']
80
84
  end
81
85
 
82
- def jabascripts
86
+ def javascripts
83
87
  Dir[Dir.pwd + '/*.javascripts'].map { |path| File.read(path) }
84
88
  end
85
89
 
@@ -100,4 +104,8 @@ class SlideDown
100
104
  ''
101
105
  end
102
106
  end
107
+
108
+ def is_absolute_path?(path)
109
+ path == File.expand_path(path)
110
+ end
103
111
  end
@@ -0,0 +1,64 @@
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
+ require 'tempfile'
3
+ require 'ftools'
4
+
5
+ describe 'slidedown commandline tool' do
6
+ include TestHelp
7
+
8
+ it "converts MD to HTML" do
9
+ run_slidedown
10
+ result_file_content.should == reference_file_content
11
+ end
12
+
13
+ it "accepts -t template-filename" do
14
+ run_slidedown("-t import")
15
+ result_file_content.should == reference_file_content("slides-import")
16
+ end
17
+
18
+ it "defaults to default template" do
19
+ run_slidedown("-t default")
20
+ result_file_content.should == reference_file_content
21
+ end
22
+
23
+ it "accepts -t /full/path/to/template-filename" do
24
+ import_template_path = File.join(root_path, 'templates', 'import.erb')
25
+ other_template_path = Tempfile.new("slidedown-template").path
26
+ File.copy(import_template_path, "#{other_template_path}.erb")
27
+
28
+ run_slidedown("-t #{other_template_path}")
29
+
30
+ result_file_content.should == reference_file_content("slides-import")
31
+ end
32
+
33
+ def run_slidedown(opts = "")
34
+ `#{slidedown_path} #{source_path} #{opts} > #{result_file_path}`
35
+ end
36
+
37
+ def slidedown_path
38
+ File.join(root_path, 'bin', 'slidedown')
39
+ end
40
+
41
+ def source_path
42
+ File.join(root_path, 'example', 'slides.md')
43
+ end
44
+
45
+ def root_path
46
+ File.join(File.dirname(__FILE__), '..')
47
+ end
48
+
49
+ def reference_file_content(basename = 'slides')
50
+ open(reference_file_path(basename)).read
51
+ end
52
+
53
+ def reference_file_path(basename = 'slides')
54
+ File.join(root_path, 'example', "#{basename}.html")
55
+ end
56
+
57
+ def result_file_content
58
+ open(result_file_path).read
59
+ end
60
+
61
+ def result_file_path
62
+ @result_file_path_for_current_test ||= Tempfile.new("slidedown-specs").path
63
+ end
64
+ end
@@ -0,0 +1,20 @@
1
+ $LOAD_PATH << File.join(File.dirname(__FILE__), *%w[.. lib])
2
+
3
+ require 'rubygems'
4
+ require 'nokogiri'
5
+ require 'spec'
6
+ require File.join(File.dirname(__FILE__), *%w[.. lib slidedown])
7
+
8
+ module TestHelp
9
+ def slide(*args)
10
+ Slide.new(@markdown, *args)
11
+ end
12
+
13
+ def slidedown
14
+ SlideDown.new(@markdown)
15
+ end
16
+
17
+ def with_markdown(markdown)
18
+ @markdown = markdown.gsub(/^\s*\|/, '')
19
+ end
20
+ end
@@ -0,0 +1,37 @@
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
+
3
+ describe 'SlideDown' do
4
+ include TestHelp
5
+
6
+ it 'has text' do
7
+ with_markdown <<-MD
8
+ |# foo
9
+ MD
10
+ slide.text.should include('# foo')
11
+ end
12
+
13
+ it 'gets class names' do
14
+ with_markdown <<-MD
15
+ |# foo
16
+ MD
17
+ slide('code').classes.should == ['code']
18
+ end
19
+
20
+ it 'gets html' do
21
+ with_markdown <<-MD
22
+ |# foo
23
+ MD
24
+ Nokogiri(slide.html).at('h1').text.should == 'foo'
25
+ end
26
+
27
+ it 'syntax highlights' do
28
+ with_markdown <<-MD
29
+ |@@@ ruby
30
+ | def foo
31
+ | :bar
32
+ | end
33
+ |@@@
34
+ MD
35
+ Nokogiri(slide.html).at('.code.ruby').should_not be_nil
36
+ end
37
+ end
@@ -0,0 +1,87 @@
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
+
3
+ describe 'SlideDown' do
4
+ include TestHelp
5
+
6
+ it 'finds slides' do
7
+ with_markdown <<-MD
8
+ |# First
9
+ |
10
+ |!SLIDE
11
+ |
12
+ |# Second
13
+ MD
14
+ slidedown.slides.length.should == 2
15
+ end
16
+
17
+ it 'generates HTML from markdown' do
18
+ with_markdown <<-MD
19
+ |!SLIDE
20
+ |# The title
21
+ |!SLIDE
22
+ MD
23
+ Nokogiri::HTML(slidedown.render('default')).at('h1').should_not be_nil
24
+ end
25
+
26
+ it 'adds class names to slides' do
27
+ with_markdown <<-MD
28
+ |# This is the title
29
+ |!SLIDE awesome
30
+ |# The title
31
+ MD
32
+ second_slide = Nokogiri::HTML(slidedown.render('default')).search('#track > div')[1]
33
+ second_slide['class'].should include('awesome')
34
+ end
35
+
36
+ it 'ignores content after !NOTES declaration' do
37
+ with_markdown <<-MD
38
+ |# The Title
39
+ |!NOTES
40
+ |# Some Notes
41
+ |!SLIDE
42
+ |# Another Title
43
+ |!NOTES
44
+ |# More Notes
45
+ |!SLIDE
46
+ |# Yet Another Title
47
+ MD
48
+
49
+ slidedown.slides.length.should == 3
50
+
51
+ first_slide = Nokogiri::HTML(slidedown.render('default')).search('#track > div')[0].content
52
+ second_slide = Nokogiri::HTML(slidedown.render('default')).search('#track > div')[1].content
53
+
54
+ first_slide.should_not include('Some Notes')
55
+ second_slide.should_not include('More Notes')
56
+ end
57
+
58
+ # this one is hard
59
+ it 'allows custom lexer' do
60
+ with_markdown <<-MD
61
+ |@@@ js
62
+ | (function() { })();
63
+ |@@@
64
+ MD
65
+ # slidedown.render('default')
66
+ Nokogiri(slidedown.render('default')).at('.highlight.js').should_not be_nil
67
+ end
68
+
69
+ it 'links css files' do
70
+ stylesheets = ["reset.css", "my.css"]
71
+ doggles = SlideDown.new("# doggles", :stylesheets => stylesheets)
72
+
73
+ stylesheets.each do |stylesheet|
74
+ Nokogiri(doggles.render('default')).at("link[rel='stylesheet'][href='#{stylesheet}']").should_not be_nil
75
+ end
76
+ end
77
+
78
+ it 'has a default title' do
79
+ with_markdown("# broccoli")
80
+ Nokogiri(slidedown.render('default')).at("title").text.should == "Slides"
81
+ end
82
+
83
+ it 'can be given a custom title' do
84
+ broccoli = SlideDown.new("# broccoli", :title => "Choppin")
85
+ Nokogiri(broccoli.render('default')).at("title").text.should == "Choppin"
86
+ end
87
+ end
@@ -19,13 +19,16 @@
19
19
  <script type="text/javascript" charset="utf-8">
20
20
  <%= read('javascripts/slides.js') %>
21
21
  </script>
22
- <% jabascripts.each do |jaba| %>
22
+ <% javascripts.each do |javascript| %>
23
23
  <script type="text/javascript" charset="utf-8">
24
- <%= jaba %>
24
+ <%= javascript %>
25
25
  </script>
26
26
  <% end %>
27
27
  </head>
28
28
  <body>
29
+ <div id="instructions">
30
+ Use the left/right arrow keys to navigate.
31
+ </div>
29
32
  <div id="slides">
30
33
  <div id="track">
31
34
  <% slides.each_with_index do |slide, idx| %>
@@ -4,43 +4,43 @@
4
4
  var allSlides = function() {
5
5
  return $('#slides #track > div');
6
6
  }
7
-
7
+
8
8
  var slideDimensions = function() {
9
9
  return {
10
10
  width: $(window).width(),
11
11
  height: $(window).height()
12
12
  }
13
13
  }
14
-
14
+
15
15
  var getIndex = function() {
16
16
  var index = document.location.hash.split('#')[1];
17
17
  return Number(index);
18
18
  }
19
-
19
+
20
20
  var setIndex = function(idx) {
21
21
  var newSlide = '#slide-' + idx;
22
22
  if ($(newSlide).size() < 1) { return false; }
23
23
  document.location.hash = '#' + idx;
24
24
  }
25
-
25
+
26
26
  var setSlideDimensions = function() {
27
27
  var dimensions = slideDimensions();
28
-
28
+
29
29
  $('#slides').height(dimensions.height);
30
30
  $('#slides').width(dimensions.width);
31
-
31
+
32
32
  allSlides().height(dimensions.height);
33
33
  allSlides().width(dimensions.width);
34
34
  }
35
-
35
+
36
36
  var showCurrentSlide = function() {
37
37
  var dimensions = slideDimensions();
38
38
  var index = getIndex();
39
39
  var offset = (index || 0) * dimensions.width;
40
-
40
+
41
41
  $('#track').animate({ marginLeft: '-' + offset + 'px' }, 200);
42
42
  }
43
-
43
+
44
44
  var verticalAlign = function() {
45
45
  var dimensions = slideDimensions();
46
46
  var margin = (dimensions.height - $(this).height()) / 2;
@@ -54,34 +54,42 @@
54
54
  overflow: 'hidden',
55
55
  fontSize: '26px'
56
56
  });
57
-
57
+
58
58
  allSlides().find('.content').each(verticalAlign);
59
59
  }
60
-
60
+
61
61
  var adjustSlides = function() {
62
62
  var dimensions = slideDimensions();
63
-
63
+
64
64
  setSlideDimensions();
65
65
  showCurrentSlide();
66
66
 
67
67
  formatGist();
68
68
  }
69
-
69
+
70
70
  var move = function(event) {
71
71
  var DIRECTIONS = {
72
- 37: -1, // ARROW LEFT
73
- 39: 1, // ARROW RIGHT
74
- 32: 1, // SPACE BAR
75
- 13: 1, // RETURN
72
+ 37: -1, // ARROW LEFT
73
+ 39: 1, // ARROW RIGHT
74
+ 32: 1, // SPACE BAR
75
+ 13: 1, // RETURN
76
+ 27: 'home', // ESCAPE
76
77
  left: -1,
77
78
  right: 1
78
79
  }
79
-
80
+
80
81
  if (dir = DIRECTIONS[event.which || event]) {
81
- setIndex(getIndex() + dir);
82
+ if (dir == 'home') {
83
+ event.preventDefault();
84
+ event.stopPropagation();
85
+ location.href = '/';
86
+ } else {
87
+ $('#instructions').slideUp(100);
88
+ setIndex(getIndex() + dir);
89
+ }
82
90
  }
83
91
  }
84
-
92
+
85
93
  function clickMove(e) {
86
94
  if (e.pageX < ($(window).width() / 2)) {
87
95
  move('left');
@@ -89,7 +97,11 @@
89
97
  move('right');
90
98
  }
91
99
  }
92
-
100
+
101
+ function hideInstructions() {
102
+ $('#instructions').slideUp(200);
103
+ }
104
+
93
105
  $(window).bind('resize', function() { adjustSlides(); });
94
106
  $(document).bind('keydown', move);
95
107
  $(document).bind('hash.changed', adjustSlides);
@@ -100,5 +112,7 @@
100
112
  if (document.location.search.indexOf('notes') == 1) {
101
113
  $('.notes').show();
102
114
  }
115
+
116
+ window.setTimeout(hideInstructions, 3000);
103
117
  });
104
- })(jQuery);
118
+ })(jQuery);
@@ -8,6 +8,7 @@ body {
8
8
  font-size: 38px;
9
9
  color: #111;
10
10
  background: #fff;
11
+ overflow: hidden;
11
12
  }
12
13
 
13
14
  pre {
@@ -26,6 +27,17 @@ ul {
26
27
  padding: 0 0 0 1em;
27
28
  }
28
29
 
30
+ #instructions {
31
+ position: absolute;
32
+ width: 99%;
33
+ text-align: center;
34
+ background: #ffd;
35
+ font-size: 20px;
36
+ padding: 10px;
37
+ font-weight: bold;
38
+ border-bottom: 1px solid #ff0;
39
+ }
40
+
29
41
  #slides {
30
42
  overflow: hidden;
31
43
  text-align: left;
@@ -112,4 +124,4 @@ ul {
112
124
  .code .vc { color: #008080 } /* Name.Variable.Class */
113
125
  .code .vg { color: #008080 } /* Name.Variable.Global */
114
126
  .code .vi { color: #008080 } /* Name.Variable.Instance */
115
- .code .il { color: #009999 } /* Literal.Number.Integer.Long */
127
+ .code .il { color: #009999 } /* Literal.Number.Integer.Long */
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slidedown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - Pat Nakajima
@@ -10,37 +15,41 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2009-03-10 00:00:00 -04:00
18
+ date: 2009-09-24 00:00:00 -04:00
14
19
  default_executable: slidedown
15
20
  dependencies:
16
21
  - !ruby/object:Gem::Dependency
17
22
  name: makers-mark
18
- type: :runtime
19
- version_requirement:
20
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
21
25
  requirements:
22
26
  - - ">="
23
27
  - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
24
30
  version: "0"
25
- version:
31
+ type: :runtime
32
+ version_requirements: *id001
26
33
  - !ruby/object:Gem::Dependency
27
34
  name: nokogiri
28
- type: :runtime
29
- version_requirement:
30
- version_requirements: !ruby/object:Gem::Requirement
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
31
37
  requirements:
32
38
  - - ">="
33
39
  - !ruby/object:Gem::Version
40
+ segments:
41
+ - 0
34
42
  version: "0"
35
- version:
43
+ type: :runtime
44
+ version_requirements: *id002
36
45
  description:
37
46
  email:
38
47
  executables:
39
48
  - slidedown
40
49
  extensions: []
41
50
 
42
- extra_rdoc_files: []
43
-
51
+ extra_rdoc_files:
52
+ - README.md
44
53
  files:
45
54
  - README.md
46
55
  - bin/slidedown
@@ -55,13 +64,17 @@ files:
55
64
  - templates/stylesheets/screen.css
56
65
  - templates/stylesheets/slides.css
57
66
  - vendor/albino.rb
67
+ - spec/commandline_spec.rb
68
+ - spec/helper.rb
69
+ - spec/slide_spec.rb
70
+ - spec/slidedown_spec.rb
58
71
  has_rdoc: true
59
- homepage:
72
+ homepage: http://github.com/nakajima/slidedown
60
73
  licenses: []
61
74
 
62
75
  post_install_message:
63
- rdoc_options: []
64
-
76
+ rdoc_options:
77
+ - --charset=UTF-8
65
78
  require_paths:
66
79
  - lib
67
80
  - vendor
@@ -69,20 +82,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
69
82
  requirements:
70
83
  - - ">="
71
84
  - !ruby/object:Gem::Version
85
+ segments:
86
+ - 0
72
87
  version: "0"
73
- version:
74
88
  required_rubygems_version: !ruby/object:Gem::Requirement
75
89
  requirements:
76
90
  - - ">="
77
91
  - !ruby/object:Gem::Version
92
+ segments:
93
+ - 0
78
94
  version: "0"
79
- version:
80
95
  requirements: []
81
96
 
82
97
  rubyforge_project:
83
- rubygems_version: 1.3.3
98
+ rubygems_version: 1.3.6
84
99
  signing_key:
85
100
  specification_version: 2
86
101
  summary: Create slides with Markdown
87
- test_files: []
88
-
102
+ test_files:
103
+ - spec/commandline_spec.rb
104
+ - spec/helper.rb
105
+ - spec/slide_spec.rb
106
+ - spec/slidedown_spec.rb