Skip to content
Browse files

Merge commit 'dancroak/master'

  • Loading branch information...
2 parents bda811a + ec65bcd commit a274b1c566ba63543a625b443ea305bb25227383 @nakajima nakajima committed Jul 24, 2009
View
3 .gitignore
@@ -0,0 +1,3 @@
+*.swp
+*.swo
+.DS_Store
View
39 Rakefile
@@ -0,0 +1,39 @@
+gem_spec = Gem::Specification.new do |s|
+ s.name = %q{slidedown}
+ s.version = "0.1.0"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Pat Nakajima"]
+ s.date = %q{2009-03-10}
+ s.default_executable = %q{slidedown}
+ s.executables = ["slidedown"]
+ s.files = FileList["README.md", "{bin,lib,templates,vendor}/**/*"]
+ s.require_paths = ["lib", "vendor"]
+ s.rubygems_version = %q{1.3.1}
+ s.summary = %q{Create slides with Markdown}
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 2
+
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
+ s.add_runtime_dependency(%q<rdiscount>, [">= 0"])
+ s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
+ else
+ s.add_dependency(%q<rdiscount>, [">= 0"])
+ s.add_dependency(%q<nokogiri>, [">= 0"])
+ end
+ else
+ s.add_dependency(%q<rdiscount>, [">= 0"])
+ s.add_dependency(%q<nokogiri>, [">= 0"])
+ end
+end
+
+desc "Generate a gemspec file"
+task :gemspec do
+ File.open("#{gem_spec.name}.gemspec", 'w') do |f|
+ f.write gem_spec.to_yaml
+ end
+end
+
+
View
2 bin/slidedown
@@ -2,4 +2,4 @@
require File.join(File.dirname(__FILE__), *%w[.. lib slidedown])
-puts SlideDown.render(ARGV.dup)
+SlideDown.run!
View
8 lib/slide.rb
@@ -1,12 +1,12 @@
class Slide
attr_accessor :text, :classes
-
+
def initialize(text, *classes)
- @text = text
+ @text = text
@classes = classes
end
-
+
def html
MakersMark::Generator.new(@text).to_html
end
-end
+end
View
59 lib/slidedown.rb
@@ -1,4 +1,5 @@
require 'rubygems'
+require 'optparse'
require 'nokogiri'
require 'rdiscount'
require 'makers-mark'
@@ -8,10 +9,40 @@
$SILENT = true
class SlideDown
+ 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:
+ -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."
+
attr_reader :classes
- def self.render(args)
- new(File.read(File.join(Dir.pwd, *args))).render
+ def self.run!(argv = ARGV)
+ args = argv.dup
+
+ if args.empty?
+ puts USAGE
+ else
+ source = args[0]
+ if args.length == 1
+ render(source)
+ else
+ option_parser(source).parse!(args)
+ end
+ end
+ end
+
+ def self.option_parser(source)
+ OptionParser.new do |opts|
+ opts.on('-h', '--help') { puts USAGE }
+ opts.on('-t', '--template TEMPLATE') do |template|
+ render(source, template)
+ end
+ end
+ end
+
+ def self.render(source_path, template = "default")
+ if source_path
+ slideshow = new(File.read(source_path))
+ puts slideshow.render(template)
+ end
end
# Ensures that the first slide has proper !SLIDE declaration
@@ -25,40 +56,36 @@ def slides
end
def read(path)
- File.read(File.dirname(__FILE__) + '/../templates/%s' % path)
+ File.read(File.join(File.dirname(__FILE__), '..', "templates", path))
end
- def render
- template = File.read(File.dirname(__FILE__) + '/../templates/template.erb')
+ def render(name)
+ directory = File.join(File.dirname(__FILE__), "..", "templates")
+ path = File.join(directory, "#{name}.erb")
+ template = File.read(path)
ERB.new(template).result(binding)
end
private
def lines
- @lines ||= @raw.split(/^!SLIDE\s*([a-z\s]*)$/) \
- .reject { |line| line.empty? }
- end
-
- def parse_snippets(slide)
- slide.gsub!(/@@@\s([\w\s]+)\s*$/, %(<pre class="#{$1}"><code>))
- slide.gsub!(/@@@\s*$/, %(</code></pre>))
+ @lines ||= @raw.split(/^!SLIDE\s*([a-z\s]*)$/).reject { |line| line.empty? }
end
- # These get added to the dom.
def stylesheets
- Dir[Dir.pwd + '/*.css'].map { |path| File.read(path) }
+ Dir[Dir.pwd + '/*.stylesheets'].map { |path| File.read(path) }
end
def jabascripts
- Dir[Dir.pwd + '/*.js'].map { |path| File.read(path) }
+ Dir[Dir.pwd + '/*.javascripts'].map { |path| File.read(path) }
end
def extract_classes!
@classes = []
@raw.gsub!(/^!SLIDE\s*([a-z\s]*)$/) do |klass|
@classes << klass.to_s.chomp.gsub('!SLIDE', '')
"!SLIDE"
- end ; @classes
+ end
+ @classes
end
end
View
131 slidedown.gemspec
@@ -1,50 +1,89 @@
-# -*- encoding: utf-8 -*-
+--- !ruby/object:Gem::Specification
+name: slidedown
+version: !ruby/object:Gem::Version
+ version: 0.1.0
+platform: ruby
+authors:
+- Pat Nakajima
+autorequire:
+bindir: bin
+cert_chain: []
-Gem::Specification.new do |s|
- s.name = %q{slidedown}
- s.version = "0.0.7"
+date: 2009-03-10 00:00:00 -04:00
+default_executable: slidedown
+dependencies:
+- !ruby/object:Gem::Dependency
+ name: rdiscount
+ type: :runtime
+ version_requirement:
+ version_requirements: !ruby/object:Gem::Requirement
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ version: "0"
+ version:
+- !ruby/object:Gem::Dependency
+ name: nokogiri
+ type: :runtime
+ version_requirement:
+ version_requirements: !ruby/object:Gem::Requirement
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ version: "0"
+ version:
+description:
+email:
+executables:
+- slidedown
+extensions: []
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
- s.authors = ["Pat Nakajima"]
- s.date = %q{2009-03-10}
- s.default_executable = %q{slidedown}
- s.executables = ["slidedown"]
- s.files = %W[
- bin/
- bin/slidedown
- lib/
- lib/slide.rb
- lib/slidedown.rb
- README.md
- templates/css
- templates/css/screen.css
- templates/css/slides.css
- templates/js
- templates/js/jquery-1.3.2.js
- templates/js/jquery.easing.js
- templates/js/jquery.hash-changed.js
- templates/js/slides.js
- templates/template.erb
- vendor
- vendor/albino.rb
- ]
- s.require_paths = ["lib", "vendor"]
- s.rubygems_version = %q{1.3.1}
- s.summary = %q{Create slides with Markdown}
+extra_rdoc_files: []
- if s.respond_to? :specification_version then
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
- s.specification_version = 2
+files:
+- README.md
+- bin/slidedown
+- lib/slide.rb
+- lib/slidedown.rb
+- templates/default.erb
+- templates/import.erb
+- templates/javascripts
+- templates/javascripts/jquery-1.3.2.js
+- templates/javascripts/jquery.easing.js
+- templates/javascripts/jquery.hash-changed.js
+- templates/javascripts/slides.js
+- templates/stylesheets
+- templates/stylesheets/screen.css
+- templates/stylesheets/slides.css
+- vendor/albino.rb
+has_rdoc: true
+homepage:
+licenses: []
+
+post_install_message:
+rdoc_options: []
+
+require_paths:
+- lib
+- vendor
+required_ruby_version: !ruby/object:Gem::Requirement
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ version: "0"
+ version:
+required_rubygems_version: !ruby/object:Gem::Requirement
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ version: "0"
+ version:
+requirements: []
+
+rubyforge_project:
+rubygems_version: 1.3.4
+signing_key:
+specification_version: 2
+summary: Create slides with Markdown
+test_files: []
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
- s.add_runtime_dependency(%q<rdiscount>, [">= 0"])
- s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
- else
- s.add_dependency(%q<rdiscount>, [">= 0"])
- s.add_dependency(%q<nokogiri>, [">= 0"])
- end
- else
- s.add_dependency(%q<rdiscount>, [">= 0"])
- s.add_dependency(%q<nokogiri>, [">= 0"])
- end
-end
View
12 templates/template.erb → templates/default.erb
@@ -2,24 +2,24 @@
<head>
<title>Slides</title>
<style type="text/css" media="screen">
- <%= read('css/slides.css') %>
+ <%= read('stylesheets/slides.css') %>
</style>
<% stylesheets.each do |style| %>
<style type="text/css" media="screen">
<%= style %>
</style>
<% end %>
<script type="text/javascript">
- <%= read('js/jquery-1.3.2.js') %>
+ <%= read('javascripts/jquery-1.3.2.js') %>
</script>
<script type="text/javascript" charset="utf-8">
- <%= read('js/jquery.easing.js') %>
+ <%= read('javascripts/jquery.easing.js') %>
</script>
<script type="text/javascript" charset="utf-8">
- <%= read('js/jquery.hash-changed.js') %>
+ <%= read('javascripts/jquery.hash-changed.js') %>
</script>
<script type="text/javascript" charset="utf-8">
- <%= read('js/slides.js') %>
+ <%= read('javascripts/slides.js') %>
</script>
<% jabascripts.each do |jaba| %>
<script type="text/javascript" charset="utf-8">
@@ -40,4 +40,4 @@
</div>
</div>
</body>
-</html>
+</html>
View
23 templates/import.erb
@@ -0,0 +1,23 @@
+<html>
+ <head>
+ <title>Slides</title>
+ <link href="/stylesheets/slides.css" media="screen" rel="stylesheet" charset="utf-8" type="text/css" />
+ <script src="/javascripts/jquery.js" type="text/javascript"></script>
+ <script src="/javascripts/jquery.easing.js" type="text/javascript"></script>
+ <script src="/javascripts/jquery.hash-changed.js" type="text/javascript"></script>
+ <script src="/javascripts/slides.js" type="text/javascript"></script>
+ </head>
+ <body>
+ <div id="slides">
+ <div id="track">
+ <% slides.each_with_index do |slide, idx| %>
+ <div class="<%= slide.classes.join(' ') %>">
+ <div id="slide-<%= idx %>" class="content">
+ <%= slide.html %>
+ </div>
+ </div>
+ <% end %>
+ </div>
+ </div>
+ </body>
+</html>
View
0 templates/js/jquery-1.3.2.js → templates/javascripts/jquery-1.3.2.js
File renamed without changes.
View
0 templates/js/jquery.easing.js → templates/javascripts/jquery.easing.js
File renamed without changes.
View
0 templates/js/jquery.hash-changed.js → templates/javascripts/jquery.hash-changed.js
File renamed without changes.
View
0 templates/js/slides.js → templates/javascripts/slides.js
File renamed without changes.
View
0 templates/css/screen.css → templates/stylesheets/screen.css
File renamed without changes.
View
0 templates/css/slides.css → templates/stylesheets/slides.css
File renamed without changes.

0 comments on commit a274b1c

Please sign in to comment.
Something went wrong with that request. Please try again.