Skip to content

Commit

Permalink
adding support for rest/restructedtext
Browse files Browse the repository at this point in the history
  • Loading branch information
geraldb committed Jul 20, 2010
1 parent 5de70e1 commit dfc64f4
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
5 changes: 4 additions & 1 deletion config/slideshow.builtin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ filters:
- dump_content_to_file_debug_text


# markup (textile, markdown) config
# markup (textile, markdown, rest) config

textile:
extnames: [ .textile, .t ]

rest:
extnames: [ .rst, .rest ]

markdown:
extnames: [ .markdown, .m, .mark, .mkdn, .md, .txt, .text ]

Expand Down
3 changes: 2 additions & 1 deletion lib/slideshow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,15 @@ def Slideshow.main

end # module Slideshow

# load built-in (optional) helpers/plugins
# load built-in (optional) helpers/plugins/engines
# If a helper fails to load, simply ingnore it
# If you want to use it install missing required gems e.g.:
# gem install coderay
# gem install ultraviolet etc.
BUILTIN_OPT_HELPERS = [
'slideshow/helpers/syntax/uv_helper.rb',
'slideshow/helpers/syntax/coderay_helper.rb',
'slideshow/rest.rb',
]

BUILTIN_OPT_HELPERS.each do |helper|
Expand Down
6 changes: 5 additions & 1 deletion lib/slideshow/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def markdown_post_processing?( lib )
@hash.fetch( 'user', {} ).fetch( lib, {} ).fetch( 'post-processing', true )
end

def known_rest_extnames
@hash[ 'builtin' ][ 'rest' ][ 'extnames' ]
end

def known_textile_extnames
# returns an array of known file extensions e.g.
# [ '.textile', '.t' ]
Expand Down Expand Up @@ -86,7 +90,7 @@ def known_extnames
# ruby check: is it better self. ?? or more confusing
# possible conflict only with write access (e.g. prop=)

known_textile_extnames + known_markdown_extnames
known_textile_extnames + known_markdown_extnames + known_rest_extnames
end

def text_filters
Expand Down
9 changes: 8 additions & 1 deletion lib/slideshow/gen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def text_to_html( content )
markdown_to_html( content )
when :textile
textile_to_html( content )
when :rest
rest_to_html( content )
end
content
end
Expand Down Expand Up @@ -93,10 +95,12 @@ def wrap_markup( text )
end
end

# todo/fix: move to Config class
def cache_dir
RUBY_PLATFORM =~ /win32/ ? win32_cache_dir : File.join(File.expand_path("~"), ".slideshow")
end

# todo/fix: move to Config class
def win32_cache_dir
unless ENV['HOMEDRIVE'] && ENV['HOMEPATH'] && File.exists?(home = ENV['HOMEDRIVE'] + ENV['HOMEPATH'])
puts "No HOMEDRIVE or HOMEPATH environment variable. Set one to save a" +
Expand All @@ -107,6 +111,7 @@ def win32_cache_dir
end
end

# todo/fix: move to Config class
def config_dir
unless @config_dir # first time? calculate config_dir value to "cache"

Expand Down Expand Up @@ -430,7 +435,7 @@ def post_processing_slides( content )

# 1) add slide break

if @markup_type == :markdown && @markdown_libs.first == 'pandoc-ruby'
if (@markup_type == :markdown && @markdown_libs.first == 'pandoc-ruby') || @markup_type == :rest
content = add_slide_directive_before_div_h1( content )
else
content = add_slide_directive_before_h1( content )
Expand Down Expand Up @@ -579,6 +584,8 @@ def create_slideshow( fn )

if config.known_markdown_extnames.include?( extname )
@markup_type = :markdown
elsif config.known_rest_extnames.include?( extname )
@markup_type = :rest
else
@markup_type = :textile
end
Expand Down
17 changes: 17 additions & 0 deletions lib/slideshow/rest.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'pandoc-ruby'

module Slideshow
module RestEngines # reStructuredText

def rest_to_html( content )
puts " Converting reStructuredText (#{content.length} bytes) to HTML..."

content = PandocRuby.new( content, :from => :rst, :to => :html ).convert
end

end # module RestEngines
end # module Slideshow

class Slideshow::Gen
include Slideshow::RestEngines
end

0 comments on commit dfc64f4

Please sign in to comment.