Class: Slideit::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/slideit/template.rb

Constant Summary collapse

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 =
"<!doctype html>\n<html>\n  <head>\n<meta charset=\"utf-8\">\n\n<title>{__slide_title__}</title>\n\n<meta name=\"description\" content=\"A framework for easily creating beautiful presentations using HTML\">\n<meta name=\"author\" content=\"Hakim El Hattab\">\n\n<meta name=\"apple-mobile-web-app-capable\" content=\"yes\">\n<meta name=\"apple-mobile-web-app-status-bar-style\" content=\"black-translucent\">\n\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no\">\n\n<link rel=\"stylesheet\" href=\"/css/reveal.css\">\n<link rel=\"stylesheet\" href=\"/css/theme/{__theme__}.css\" id=\"theme\">\n\n<!-- Theme used for syntax highlighting of code -->\n<link rel=\"stylesheet\" href=\"/lib/css/zenburn.css\">\n\n<!-- Printing and PDF exports -->\n<script>\n  var link = document.createElement( 'link' );\n  link.rel = 'stylesheet';\n  link.type = 'text/css';\n  link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';\n  document.getElementsByTagName( 'head' )[0].appendChild( link );\n</script>\n\n<!--[if lt IE 9]>\n<script src=\"lib/js/html5shiv.js\"></script>\n<![endif]-->\n  </head>\n\n  <body>\n\n<div class=\"reveal\">\n\n  <div class=\"slides\">\n\n    <section data-markdown\n      data-separator=\"{__separator__}\"\n      data-separator-vertical=\"{__separator-vertical__}\"\n      data-separator-notes=\"{__separator-notes__}\"\n      data-charset=\"utf-8\">\n      <script type=\"text/template\">\n{__slide_markdown__}\n      </script>\n    </section>\n\n  </div>\n\n</div>\n\n<script src=\"/lib/js/head.min.js\"></script>\n<script src=\"/js/reveal.js\"></script>\n\n<script>\n\n  // More info https://github.com/hakimel/reveal.js#configuration\n  Reveal.initialize({\n    controls: true,\n    progress: true,\n    history: true,\n    center: true,\n\n    transition: 'slide', // none/fade/slide/convex/concave/zoom\n\n    // More info https://github.com/hakimel/reveal.js#dependencies\n    dependencies: [\n      { src: '/lib/js/classList.js', condition: function() { return !document.body.classList; } },\n      { src: '/plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },\n      { src: '/plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },\n      { src: '/plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },\n      { src: '/plugin/zoom-js/zoom.js', async: true },\n      { src: '/plugin/notes/notes.js', async: true }\n    ]\n  });\n\n  {__print-pdf-scrit__}\n\n</script>\n\n  </body>\n</html>\n"
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-scrit__}"

Instance Method Summary collapse

Constructor Details

#initialize(title, markdown, options = {}) ⇒ Template



101
102
103
104
105
106
107
108
109
110
111
# File 'lib/slideit/template.rb', line 101

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

Instance Method Details

#renderObject



121
122
123
124
125
126
127
128
129
130
131
# File 'lib/slideit/template.rb', line 121

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