keydown 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ .idea/
2
+ .DS_Store
3
+ pkg/*
4
+ *.gem
5
+ .bundle
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format Fuubar
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use default@keydown
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in keydown.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,41 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ keydown (0.7.0)
5
+ rdiscount (>= 1.6.8)
6
+ thor (>= 0.14.0)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ chalofa_ruby-progressbar (0.0.9.1)
12
+ diff-lcs (1.1.2)
13
+ fuubar (0.0.4)
14
+ chalofa_ruby-progressbar (~> 0.0.9)
15
+ rspec (~> 2.0)
16
+ rspec-instafail (~> 0.1.4)
17
+ gem-release (0.0.16)
18
+ nokogiri (1.4.4)
19
+ rdiscount (1.6.8)
20
+ rspec (2.5.0)
21
+ rspec-core (~> 2.5.0)
22
+ rspec-expectations (~> 2.5.0)
23
+ rspec-mocks (~> 2.5.0)
24
+ rspec-core (2.5.1)
25
+ rspec-expectations (2.5.0)
26
+ diff-lcs (~> 1.1.2)
27
+ rspec-instafail (0.1.7)
28
+ rspec-mocks (2.5.0)
29
+ thor (0.14.6)
30
+
31
+ PLATFORMS
32
+ ruby
33
+
34
+ DEPENDENCIES
35
+ fuubar
36
+ gem-release
37
+ keydown!
38
+ nokogiri
39
+ rdiscount (>= 1.6.8)
40
+ rspec (>= 2.5.0)
41
+ thor (>= 0.14.0)
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Infews LLC
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,183 @@
1
+ # KeyDown
2
+
3
+ KeyDown is another 'Presentation System in a single HTML page' inspired by [Showoff](http://github.com/dirnic/showoff/), [Slidedown](http://github.com/nakajima/slidedown),
4
+ [HTML5 Rocks](http://studio.html5rocks.com/#Deck), with a little [Presentation Zen](http://amzn.to/8X55H2) thrown in.
5
+
6
+ ## Usage
7
+
8
+ ### Generate a Template
9
+
10
+ Get started by making a sample project:
11
+
12
+ $ keydown generate my_presentation
13
+
14
+ This will make:
15
+
16
+ | - my_presentation/
17
+ | - css/ - Keydown CSS and a file for you to customize
18
+ | - images/ - Some Keydown images, but also for you
19
+ | - js/ - Keydown JavaScript, and a file for you to customize
20
+ | - my_presentation.md
21
+
22
+ ### Write your presentation in Markdown
23
+
24
+ Edit `my_presentation.md` and write your presentation as if it were going to be HTML (because it will be):
25
+
26
+ !SLIDE
27
+
28
+ # This is my talk
29
+
30
+ !SLIDE
31
+
32
+ ## I hope you enjoy it
33
+
34
+ !SLIDE code
35
+
36
+ def foo
37
+ :bar
38
+ end
39
+
40
+ !NOTES
41
+
42
+ * make sure to explain the use of Ruby symbols
43
+
44
+ !SLIDE
45
+
46
+ Google is [here](http://google.com)
47
+
48
+ !SLIDE
49
+
50
+ # Questions?
51
+
52
+ `!NOTE` blocks will be ignored when generating the HTML.
53
+
54
+ ### Generate the Deck
55
+
56
+ $ keydown slides my_presentation.md
57
+
58
+ ..will generate `my_presentation.html`
59
+
60
+ ### Present
61
+
62
+ Give your presentation! Open `my_presentation.html` in a browser and talk away:
63
+
64
+ * left, right arrows to navigate through slides
65
+
66
+ ## Usage
67
+
68
+ ### Presentation Title
69
+
70
+ An optional first `H1` before a `!SLIDE` is treated as the presentation title. It will be on the configuration page and set as the HTML `<title>`.
71
+
72
+ ### Configuration Page & Navigation
73
+
74
+ The first page of a Keydown presentation is a configuration page that shows the presentation title, how to navigate the presentation, and some visual effect options.
75
+
76
+ ### Slide classes
77
+
78
+ Any text that follows `!SLIDE` will be added to the slide as CSS classes.
79
+
80
+ !SLIDE dark
81
+
82
+ There are some built-in classes you can use:
83
+
84
+ * `middle` will center all the elements on the slide
85
+ * `bulleted` - by default, lists to not have bullets; use this class to add them back
86
+ * `dark` - by default, slides are light with dark fonts; this swaps a slide
87
+
88
+ You can define your own CSS classes (see below).
89
+
90
+ ### Images
91
+
92
+ Your presentation will be generated in the same directory as your Markdown file. So URI references via relative paths
93
+ are fine. So feel free to use the local images directory (see the `generate` task above).
94
+
95
+ ### Full Screen background images
96
+
97
+ Keydown supports slides with full screen background images, including attribution text.
98
+
99
+ !SLIDE
100
+
101
+ # This slide has a background image
102
+
103
+ }}} images/sunset.jpg
104
+
105
+ This slide will have `sunset.jpg` as a full-bleed background image. It's aspect ratio will be preserved.
106
+
107
+ If you wish to have attribution text, an icon (currently Flickr and Creative Commons graphics are supported via `flickr` and `cc` respectively), and link the text, separate the text with `::` like this:
108
+
109
+
110
+ !SLIDE
111
+
112
+ # This slide has a background image
113
+
114
+ }}} images/sunset.jpg::cprsize::flickr::http:://flickr.com/cprsize
115
+
116
+ ### Syntax Highlighting
117
+
118
+ Code syntax highlighting is done via [Pygments](), which must be installed locally to work. All Pygments lexers are supported.
119
+
120
+ Mark your code by block escaping via `@@@` or ` ``` `
121
+
122
+ For Ruby:
123
+
124
+ @@@ ruby
125
+ def foo
126
+ :bar
127
+ end
128
+ @@@
129
+
130
+ For JavaScript
131
+
132
+ ``` js
133
+ function foo() {
134
+ return 'bar';
135
+ }
136
+ ```
137
+
138
+ For ERb:
139
+
140
+ @@@ rhtml
141
+ <%= @post.created_at.to_s(:fancy) %>
142
+ @@@
143
+
144
+ ### Custom CSS
145
+
146
+ All css files in the `css` directory will be linked into your presentation HTML file.
147
+
148
+ ### Custom JavaScript.
149
+
150
+ All JavaScript files in the `js` directory will be linked in your presentation HTML file.
151
+
152
+ ## Requirements
153
+
154
+ ### For Use
155
+
156
+ * Ruby and Rubygems
157
+ * [Pygments]() is required for code syntax highlighting
158
+ * Other dependent gems will be installed
159
+
160
+ ### For Development
161
+
162
+ * RSpec
163
+ * Nokogiri
164
+
165
+ ## Note on Patches/Pull Requests
166
+
167
+ * Fork the project.
168
+ * Make your feature addition or bug fix.
169
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
170
+ * Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
171
+ * Send me a pull request. Bonus points for topic branches.
172
+
173
+ ## Thanks & Attribution
174
+
175
+ Thanks to:
176
+
177
+ * HTML5 Rocks guys for a great presentation template
178
+ * [@nakajima](http://twitter.com/nakajima) & [Slidedown]() for some parsing
179
+ * The various Github guys for Albino, Gollum, etc.
180
+
181
+ ## Copyright
182
+
183
+ Copyright &copy; Infews LLC. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ desc "Run all specs"
5
+ task :spec do
6
+ system("rspec spec")
7
+ end
8
+
9
+ task :default => :spec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.6.0
data/bin/keydown ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'keydown'
5
+
6
+ Keydown::Tasks.start
7
+
data/keydown.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "keydown"
7
+ s.version = Keydown::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Davis W. Frank"]
10
+ s.email = ["dwfrank@infe.ws"]
11
+ s.homepage = "http://rubygems.org/gems/keydown"
12
+ s.summary = %q{Yet another "Slides in HTML" generator}
13
+ s.description = %q{Bastard child of Slidedown, HTML5 Rocks, and organic fair trade Bolivian coffee}
14
+
15
+ s.add_dependency 'thor', '>= 0.14.0'
16
+ s.add_dependency 'rdiscount', '>= 1.6.8'
17
+
18
+ s.add_development_dependency "rspec", ">= 2.5.0"
19
+ s.add_development_dependency "fuubar"
20
+ s.add_development_dependency "nokogiri"
21
+ s.add_development_dependency "gem-release"
22
+
23
+ s.files = `git ls-files`.split("\n")
24
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
25
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
26
+ s.require_paths = ["lib"]
27
+ end
@@ -0,0 +1,125 @@
1
+ require 'digest/sha1'
2
+ require 'albino'
3
+
4
+ module Keydown
5
+ class Slide
6
+
7
+ attr_reader :content
8
+ attr_reader :notes
9
+ attr_reader :background_image
10
+
11
+ def initialize(text, classnames = '')
12
+ @content = text
13
+ @notes = ''
14
+ @codemap = {}
15
+ @background_image = {}
16
+
17
+ @classnames = []
18
+ classnames.split(' ').inject(@classnames) do |css_classnames, name|
19
+ css_classnames << name
20
+ css_classnames
21
+ end
22
+
23
+ extract_notes!
24
+ extract_content!
25
+ extract_code!
26
+ extract_background_image!
27
+ pygmentize_code!
28
+ end
29
+
30
+ def classnames
31
+ @classnames.join(' ')
32
+ end
33
+
34
+ def container_classnames
35
+ @names ||= begin
36
+ names = ['slide']
37
+
38
+ unless @background_image.empty?
39
+ names << 'full-background'
40
+ names << @background_image[:classname]
41
+ end
42
+
43
+ names.join(' ')
44
+ end
45
+ end
46
+
47
+ def background_attribution_classnames
48
+ names = ['attribution']
49
+
50
+ names << if background_image[:attribution_text]
51
+ background_image[:service]
52
+ else
53
+ 'hidden'
54
+ end
55
+
56
+ names.join(' ')
57
+ end
58
+
59
+ def to_html
60
+ require 'erb'
61
+ require 'rdiscount'
62
+
63
+ html_content = RDiscount.new(@content).to_html
64
+ template = File.new(File.join(Tasks.template_dir, 'slide.rhtml'))
65
+
66
+ ERB.new(template.read).result(binding)
67
+ end
68
+
69
+ private
70
+
71
+ def extract_notes!
72
+ @content.gsub!(/^!NOTE\s*(.*\n)$/m) do
73
+ @notes = $1.chomp
74
+ ''
75
+ end
76
+ end
77
+
78
+ def extract_content!
79
+ @content.gsub!(/^!NOTE(S)?\s*(.*\n)$/m, '')
80
+ end
81
+
82
+ def extract_code!
83
+ @content.gsub!(/^(```|@@@) ?(.+?)\r?\n(.+?)\r?\n(```|@@@)\r?$/m) do
84
+ id = Digest::SHA1.hexdigest($3)
85
+ @codemap[id] = {:lang => $2, :code => $3}
86
+ id
87
+ end
88
+ end
89
+
90
+ def extract_background_image!
91
+ images = []
92
+ @content.gsub!(/^(\}\}\}) ?(.+?)(\r?\n)?$/m) do
93
+ images << $2
94
+ ''
95
+ end
96
+
97
+ return unless images.first
98
+
99
+ split_line = images.first.split('::')
100
+ image_path = split_line[0]
101
+
102
+ @background_image = {:classname => image_path.match(/([\w-]+)\.?[\w]+$/)[1],
103
+ :path => image_path}
104
+
105
+ unless split_line[1].nil? || split_line[1].empty?
106
+ @background_image.merge!({:attribution_text => split_line[1],
107
+ :service => split_line[2],
108
+ :attribution_link => split_line[3]})
109
+ end
110
+ end
111
+
112
+ def pygmentize_code!
113
+ @codemap.each do |id, spec|
114
+ lang = spec[:lang]
115
+ code = spec[:code]
116
+ if code.all? { |line| line =~ /\A\r?\n\Z/ || line =~ /^( |\t)/ }
117
+ code.gsub!(/^( |\t)/m, '')
118
+ end
119
+
120
+ @content.gsub!(id, Albino.new(code, lang).colorize)
121
+ end
122
+ end
123
+
124
+ end
125
+ end
@@ -0,0 +1,55 @@
1
+ module Keydown
2
+ class SlideDeck
3
+
4
+ attr_reader :title
5
+ attr_reader :slides
6
+
7
+ def initialize(text)
8
+ @title = ''
9
+ @slides = []
10
+ @text = text
11
+
12
+ set_title
13
+ extract_classnames!
14
+ build_slides
15
+ end
16
+
17
+ def to_html
18
+ require 'erb'
19
+
20
+ css_files = ['css/keydown.css']
21
+ css_files += Dir.glob('css/*.css')
22
+ css_files.uniq!
23
+ css_files -= ['css/rocks.css']
24
+ js_files = Dir.glob('js/*.js') - ['js/rocks.js']
25
+
26
+ template = File.new(File.join(Tasks.template_dir, 'index.rhtml'))
27
+ ERB.new(template.read).result(binding)
28
+ end
29
+
30
+ private
31
+
32
+ def set_title
33
+ match_data = @text.match(/\A\s*#\s*(.*)$/)
34
+
35
+ @title = match_data[1] if match_data
36
+ end
37
+
38
+ def extract_classnames!
39
+ @classnames = []
40
+ @text.gsub!(/^!SLIDE\s*([\w\s\-]*)\n/m) do
41
+ @classnames << $1.chomp
42
+ "!SLIDE\n"
43
+ end
44
+ end
45
+
46
+ def build_slides
47
+ slides_text = @text.split(/!SLIDE/).reject { |s| s.empty? }
48
+ slides_text[1..-1].each_with_index do |slide_text, i|
49
+ slide_text.gsub(/\A(\n+)/, '').chomp!
50
+ @slides << Keydown::Slide.new(slide_text, @classnames[i])
51
+ end
52
+ end
53
+ end
54
+
55
+ end
@@ -0,0 +1,12 @@
1
+ module Keydown
2
+ class Tasks < Thor
3
+ attr_reader :presentation_name
4
+
5
+ desc "generate NAME", "Make a directory & sample files for presentation NAME"
6
+
7
+ def generate(name)
8
+ @presentation_name = name
9
+ directory "templates/generate", name
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,36 @@
1
+ module Keydown
2
+ class Tasks < Thor
3
+
4
+ desc "slides FILE", "Convert a Keydown FILE into an HTML presentation"
5
+
6
+ def slides(file)
7
+
8
+ file += '.md' unless file.match(/\.md$/)
9
+
10
+ unless File.exist?(file)
11
+ say "#{file} not found. Please call with a KeyDown Markdown file: keydown slides my_file.md", :red
12
+ return
13
+ end
14
+
15
+ @@template_dir = File.join(Keydown::Tasks.source_root, 'templates', 'rocks')
16
+
17
+ say "Creating Keydown presentation from #{file}", :yellow
18
+
19
+ slide_deck = SlideDeck.new(File.new(file).read)
20
+ backgrounds = slide_deck.slides.collect do |slide|
21
+ slide.background_image unless slide.background_image.empty?
22
+ end.compact
23
+
24
+ css_template = File.new(File.join(Tasks.template_dir, '..', 'keydown.css.erb'))
25
+ create_file 'css/keydown.css', :force => true do
26
+ ERB.new(css_template.read).result(binding)
27
+ end
28
+
29
+ presentation = file.gsub('md', 'html')
30
+
31
+ create_file presentation, :force => true do
32
+ slide_deck.to_html
33
+ end
34
+ end
35
+ end
36
+ end
data/lib/keydown.rb ADDED
@@ -0,0 +1,22 @@
1
+ require 'thor'
2
+
3
+ module Keydown
4
+ class Tasks < Thor
5
+ include Thor::Actions
6
+
7
+ @@source_root = File.join(File.dirname(__FILE__), '..')
8
+
9
+ def self.source_root
10
+ @@source_root
11
+ end
12
+
13
+ def self.template_dir
14
+ @@template_dir
15
+ end
16
+
17
+ end
18
+ end
19
+
20
+ Dir["#{File.dirname(__FILE__)}/keydown/**/*.rb"].each do |file|
21
+ require file
22
+ end
data/lib/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module Keydown
2
+ VERSION = "0.5.0"
3
+ end
@@ -0,0 +1,5 @@
1
+ /* A custom CSS file */
2
+
3
+ section {
4
+ color: red;
5
+ }
@@ -0,0 +1,3 @@
1
+ function foo() {
2
+
3
+ }
@@ -0,0 +1,29 @@
1
+ # Kermit the Frog Says...
2
+
3
+ !SLIDE
4
+
5
+ # Presenation Zen
6
+
7
+ }}} images/one.png
8
+
9
+ !NOTE
10
+
11
+ I think this should be ignored
12
+
13
+ !SLIDE foo
14
+
15
+ # Makes for Awesome Decks
16
+
17
+ }}} images/two.png
18
+
19
+ !NOTE
20
+
21
+ and this
22
+
23
+ !SLIDE
24
+
25
+ # But sometimes you don't need them
26
+
27
+ !NOTE
28
+
29
+ and this
@@ -0,0 +1,26 @@
1
+ # Kermit the Frog Says...
2
+
3
+ !SLIDE
4
+
5
+ # This Presentation
6
+
7
+ !NOTE
8
+
9
+ I think this should be ignored
10
+
11
+ !SLIDE foo
12
+
13
+ # Is Brought to You by
14
+ @@@ ruby
15
+ def a_method(options)
16
+ { :foo => 'bar }
17
+ end
18
+ @@@
19
+
20
+ !NOTE
21
+
22
+ and this
23
+
24
+ !SLIDE foo bar
25
+
26
+ # The Letter Q
@@ -0,0 +1,21 @@
1
+ # Kermit the Frog Says...
2
+
3
+ !SLIDE
4
+
5
+ # This Presentation
6
+
7
+ !NOTE
8
+
9
+ I think this should be ignored
10
+
11
+ !SLIDE foo
12
+
13
+ # Is Brought to You By
14
+
15
+ !NOTE
16
+
17
+ and this
18
+
19
+ !SLIDE foo bar
20
+
21
+ # The Letter Q
@@ -0,0 +1,21 @@
1
+ # Kermit the Frog Says...
2
+
3
+ !SLIDE
4
+
5
+ # This Presentation
6
+
7
+ !NOTE
8
+
9
+ I think this should be ignored
10
+
11
+ !SLIDE foo
12
+
13
+ # Is Brought to You By
14
+
15
+ !NOTE
16
+
17
+ and this
18
+
19
+ !SLIDE foo bar
20
+
21
+ # The Letter Q