require 'cgi'
module Slideit
class Template
Themes = %w(beige black blood league moon night serif simple sky solarized white)
Default = {
:separator => "^\n---\n",
:"separator-vertical" => "^\n----\n",
:"separator-notes" => "^Note:",
:theme => "league"
}
BASE = <<-REVEAL_JS_TEMPLATE
{__slide_title__}
REVEAL_JS_TEMPLATE
def initialize(title, markdown, options = {})
@title = title
@markdown = markdown
@options = Default.dup
@options.update options
# make sure theme exists
unless Themes.include?(@options[:theme])
@options[:theme] = Default[:theme]
end
end
TITLE_PATTERN = "{__slide_title__}"
MARKDOWN_PATTERN = "{__slide_markdown__}"
THEME_PATTERN = "{__theme__}"
SEPARATOR_PATTERN = "{__separator__}"
SEPARATOR_VERTICAL_PATTERN = "{__separator-vertical__}"
SEPARATOR_NOTES_PATTERN = "{__separator-notes__}"
PRINT_PDF_PATTERN = "{__print-pdf-script__}"
def render
html = BASE.dup
html.sub! TITLE_PATTERN, "#{CGI::escapeHTML(@title)} - slideit"
html.sub! MARKDOWN_PATTERN, @markdown
html.sub! THEME_PATTERN, @options[:theme]
html.sub! SEPARATOR_PATTERN, @options[:separator]
html.sub! SEPARATOR_VERTICAL_PATTERN, @options[:"separator-vertical"]
html.sub! SEPARATOR_NOTES_PATTERN, @options[:"separator-notes"]
html.sub! PRINT_PDF_PATTERN, print_pdf_script
html
end
private
def print_pdf_script
if @options[:pdf]
"window.onload = function() { window.print(); };"
else
""
end
end
end
end