dancroak-slidedown 0.1.0 → 0.1.2
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.
- data/README.md +5 -0
- data/lib/slide.rb +13 -1
- data/lib/slidedown.rb +29 -9
- data/spec/commandline_spec.rb +64 -0
- data/spec/helper.rb +20 -0
- data/spec/slide_spec.rb +37 -0
- data/spec/slidedown_spec.rb +87 -0
- data/templates/default.erb +4 -6
- data/templates/javascripts/slides.js +13 -2
- data/vendor/albino.rb +2 -2
- metadata +17 -14
data/README.md
CHANGED
@@ -74,6 +74,11 @@ Or for JavaScript
|
|
74
74
|
* Generate PDFs (maybe via cucumber)
|
75
75
|
* Stop making Nokogiri sad when parsing out snippets
|
76
76
|
|
77
|
+
## Contributors
|
78
|
+
|
79
|
+
* Pat Nakajima
|
80
|
+
* Dan Croak
|
81
|
+
|
77
82
|
(c) Copyright 2009 Pat Nakajima
|
78
83
|
|
79
84
|
Permission is hereby granted, free of charge, to any person
|
data/lib/slide.rb
CHANGED
@@ -1,12 +1,24 @@
|
|
1
1
|
class Slide
|
2
|
-
attr_accessor :text, :classes
|
2
|
+
attr_accessor :text, :classes, :notes
|
3
3
|
|
4
4
|
def initialize(text, *classes)
|
5
5
|
@text = text
|
6
6
|
@classes = classes
|
7
|
+
@notes = nil
|
8
|
+
|
9
|
+
extract_notes!
|
7
10
|
end
|
8
11
|
|
9
12
|
def html
|
10
13
|
MakersMark::Generator.new(@text).to_html
|
11
14
|
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def extract_notes!
|
19
|
+
@text.gsub!(/^!NOTES\s*(.*\n)$/m) do |note|
|
20
|
+
@notes = note.to_s.chomp.gsub('!NOTES', '')
|
21
|
+
''
|
22
|
+
end
|
23
|
+
end
|
12
24
|
end
|
data/lib/slidedown.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'optparse'
|
3
3
|
require 'nokogiri'
|
4
|
-
require 'rdiscount'
|
5
4
|
require 'makers-mark'
|
6
5
|
require 'erb'
|
7
6
|
require File.join(File.dirname(__FILE__), 'slide')
|
@@ -10,8 +9,9 @@ $SILENT = true
|
|
10
9
|
|
11
10
|
class SlideDown
|
12
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:
|
13
|
-
-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."
|
14
13
|
|
14
|
+
attr_accessor :stylesheets, :title
|
15
15
|
attr_reader :classes
|
16
16
|
|
17
17
|
def self.run!(argv = ARGV)
|
@@ -46,9 +46,12 @@ class SlideDown
|
|
46
46
|
end
|
47
47
|
|
48
48
|
# Ensures that the first slide has proper !SLIDE declaration
|
49
|
-
def initialize(raw)
|
49
|
+
def initialize(raw, opts = {})
|
50
50
|
@raw = raw =~ /\A!SLIDE/ ? raw : "!SLIDE\n#{raw}"
|
51
51
|
extract_classes!
|
52
|
+
|
53
|
+
self.stylesheets = opts[:stylesheets] || local_stylesheets
|
54
|
+
self.title = opts[:title] || "Slides"
|
52
55
|
end
|
53
56
|
|
54
57
|
def slides
|
@@ -60,9 +63,13 @@ class SlideDown
|
|
60
63
|
end
|
61
64
|
|
62
65
|
def render(name)
|
63
|
-
|
64
|
-
|
65
|
-
|
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
|
66
73
|
ERB.new(template).result(binding)
|
67
74
|
end
|
68
75
|
|
@@ -72,11 +79,11 @@ class SlideDown
|
|
72
79
|
@lines ||= @raw.split(/^!SLIDE\s*([a-z\s]*)$/).reject { |line| line.empty? }
|
73
80
|
end
|
74
81
|
|
75
|
-
def
|
76
|
-
Dir[Dir.pwd + '/*.stylesheets']
|
82
|
+
def local_stylesheets
|
83
|
+
Dir[Dir.pwd + '/*.stylesheets']
|
77
84
|
end
|
78
85
|
|
79
|
-
def
|
86
|
+
def javascripts
|
80
87
|
Dir[Dir.pwd + '/*.javascripts'].map { |path| File.read(path) }
|
81
88
|
end
|
82
89
|
|
@@ -88,4 +95,17 @@ class SlideDown
|
|
88
95
|
end
|
89
96
|
@classes
|
90
97
|
end
|
98
|
+
|
99
|
+
def extract_notes!
|
100
|
+
@raw.gsub!(/^!NOTES\s*(.*)!SLIDE$/m) do |note|
|
101
|
+
'!SLIDE'
|
102
|
+
end
|
103
|
+
@raw.gsub!(/^!NOTES\s*(.*\n)$/m) do |note|
|
104
|
+
''
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def is_absolute_path?(path)
|
109
|
+
path == File.expand_path(path)
|
110
|
+
end
|
91
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
|
data/spec/helper.rb
ADDED
@@ -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
|
data/spec/slide_spec.rb
ADDED
@@ -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
|
data/templates/default.erb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
<html>
|
2
2
|
<head>
|
3
|
-
<title
|
3
|
+
<title><%= title %></title>
|
4
4
|
<style type="text/css" media="screen">
|
5
5
|
<%= read('stylesheets/slides.css') %>
|
6
6
|
</style>
|
7
7
|
<% stylesheets.each do |style| %>
|
8
|
-
<style type="text/css" media="screen"
|
9
|
-
<%= style %>
|
10
|
-
</style>
|
8
|
+
<link rel="stylesheet" href="<%= style %>" type="text/css" media="screen" charset="utf-8" />
|
11
9
|
<% end %>
|
12
10
|
<script type="text/javascript">
|
13
11
|
<%= read('javascripts/jquery-1.3.2.js') %>
|
@@ -21,9 +19,9 @@
|
|
21
19
|
<script type="text/javascript" charset="utf-8">
|
22
20
|
<%= read('javascripts/slides.js') %>
|
23
21
|
</script>
|
24
|
-
<%
|
22
|
+
<% javascripts.each do |javascript| %>
|
25
23
|
<script type="text/javascript" charset="utf-8">
|
26
|
-
<%=
|
24
|
+
<%= javascript %>
|
27
25
|
</script>
|
28
26
|
<% end %>
|
29
27
|
</head>
|
@@ -72,17 +72,28 @@
|
|
72
72
|
37: -1, // ARROW LEFT
|
73
73
|
39: 1, // ARROW RIGHT
|
74
74
|
32: 1, // SPACE BAR
|
75
|
-
13: 1 // RETURN
|
75
|
+
13: 1, // RETURN
|
76
|
+
left: -1,
|
77
|
+
right: 1
|
76
78
|
}
|
77
79
|
|
78
|
-
if (dir = DIRECTIONS[event.which]) {
|
80
|
+
if (dir = DIRECTIONS[event.which || event]) {
|
79
81
|
setIndex(getIndex() + dir);
|
80
82
|
}
|
81
83
|
}
|
82
84
|
|
85
|
+
function clickMove(e) {
|
86
|
+
if (e.pageX < ($(window).width() / 2)) {
|
87
|
+
move('left');
|
88
|
+
} else {
|
89
|
+
move('right');
|
90
|
+
}
|
91
|
+
}
|
92
|
+
|
83
93
|
$(window).bind('resize', function() { adjustSlides(); });
|
84
94
|
$(document).bind('keydown', move);
|
85
95
|
$(document).bind('hash.changed', adjustSlides);
|
96
|
+
$(document).bind('click', clickMove);
|
86
97
|
$(document).ready(function() {
|
87
98
|
setIndex(getIndex() || 0);
|
88
99
|
$(this).trigger('hash.changed');
|
data/vendor/albino.rb
CHANGED
@@ -41,7 +41,7 @@
|
|
41
41
|
# Chris Wanstrath // chris@ozmm.org
|
42
42
|
# GitHub // http://github.com
|
43
43
|
#
|
44
|
-
require '
|
44
|
+
require 'open3'
|
45
45
|
|
46
46
|
class Albino
|
47
47
|
@@bin = '/usr/local/bin/pygmentize'
|
@@ -60,7 +60,7 @@ class Albino
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def execute(command)
|
63
|
-
|
63
|
+
stdin, stdout, stderr = Open3.popen3(command)
|
64
64
|
stdin.puts @target
|
65
65
|
stdin.close
|
66
66
|
stdout.read.strip
|
metadata
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dancroak-slidedown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pat Nakajima
|
8
|
+
- Dan Croak
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
12
|
|
12
|
-
date: 2009-
|
13
|
+
date: 2009-09-24 00:00:00 -07:00
|
13
14
|
default_executable: slidedown
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
17
|
+
name: makers-mark
|
17
18
|
type: :runtime
|
18
19
|
version_requirement:
|
19
20
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -38,8 +39,8 @@ executables:
|
|
38
39
|
- slidedown
|
39
40
|
extensions: []
|
40
41
|
|
41
|
-
extra_rdoc_files:
|
42
|
-
|
42
|
+
extra_rdoc_files:
|
43
|
+
- README.md
|
43
44
|
files:
|
44
45
|
- README.md
|
45
46
|
- bin/slidedown
|
@@ -47,20 +48,19 @@ files:
|
|
47
48
|
- lib/slidedown.rb
|
48
49
|
- templates/default.erb
|
49
50
|
- templates/import.erb
|
50
|
-
- templates/javascripts
|
51
51
|
- templates/javascripts/jquery-1.3.2.js
|
52
52
|
- templates/javascripts/jquery.easing.js
|
53
53
|
- templates/javascripts/jquery.hash-changed.js
|
54
54
|
- templates/javascripts/slides.js
|
55
|
-
- templates/stylesheets
|
56
55
|
- templates/stylesheets/screen.css
|
57
56
|
- templates/stylesheets/slides.css
|
58
57
|
- vendor/albino.rb
|
59
|
-
has_rdoc:
|
60
|
-
homepage:
|
58
|
+
has_rdoc: false
|
59
|
+
homepage: http://github.com/nakajima/slidedown
|
60
|
+
licenses:
|
61
61
|
post_install_message:
|
62
|
-
rdoc_options:
|
63
|
-
|
62
|
+
rdoc_options:
|
63
|
+
- --charset=UTF-8
|
64
64
|
require_paths:
|
65
65
|
- lib
|
66
66
|
- vendor
|
@@ -79,9 +79,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
79
|
requirements: []
|
80
80
|
|
81
81
|
rubyforge_project:
|
82
|
-
rubygems_version: 1.
|
82
|
+
rubygems_version: 1.3.5
|
83
83
|
signing_key:
|
84
84
|
specification_version: 2
|
85
85
|
summary: Create slides with Markdown
|
86
|
-
test_files:
|
87
|
-
|
86
|
+
test_files:
|
87
|
+
- spec/commandline_spec.rb
|
88
|
+
- spec/helper.rb
|
89
|
+
- spec/slide_spec.rb
|
90
|
+
- spec/slidedown_spec.rb
|