Skip to content
Browse files

Documentation and Replacements

Replaced the ###CONTENT### string with something 
that does not break in Markdown :). Furthermore now
multiple replacements can be used in the slides, the 
documentation is in the README.
  • Loading branch information...
1 parent bad2a58 commit ea6046a10b68928d06ec6d6b70931f8358606957 @grundprinzip committed Nov 13, 2011
Showing with 38 additions and 6 deletions.
  1. +14 −1 README.rdoc
  2. +24 −5 lib/showoff.rb
View
15 README.rdoc
@@ -495,7 +495,20 @@ have to specify it in the slide header:
You can place content anywhere in your template, but you have to
explicitly mark the location using a special command:
-[###CONTENT###] is replaced by the slide content
+[~~~CONTENT~~~] is replaced by the slide content
+
+[~~~CURRENT_SLIDE~~~] is replaced by the current slide number
+
+[~~~NUM_SLIDES~~~] is replaced by the total number of slides
+
+[~~~CONFIG:*~~~] is replaced by any value (*) from the
+ <tt>showoff.json</tt> configuration. This can be used to
+ specify an author, venue etc. A simple example would be
+ <tt>~~~CONFIG:author~~~</tt>
+
+
+The usage of these replacements is not limited to templates, but
+anywhere in your slides.
== Template Hints
View
29 lib/showoff.rb
@@ -43,6 +43,7 @@ class ShowOff < Sinatra::Application
set :pres_file, 'showoff.json'
set :page_size, "Letter"
set :pres_template, nil
+ set :showoff_config, nil
def initialize(app=nil)
super(app)
@@ -66,6 +67,9 @@ def initialize(app=nil)
# configuration JSON file
if File.exists?(ShowOffUtils.presentation_config_file)
showoff_json = JSON.parse(File.read(ShowOffUtils.presentation_config_file))
+ options.showoff_config = showoff_json
+
+ # Set options for template and page size
options.page_size = showoff_json["page-size"] || "Letter"
options.pres_template = showoff_json["templates"]
end
@@ -201,13 +205,10 @@ def process_markdown(name, content, static=false, pdf=false)
end
end
-
# Extract the content of the slide
content = ""
-
if seq
content += "<div class=\"#{content_classes.join(' ')}\" ref=\"#{name}/#{seq.to_s}\">\n"
- seq += 1
else
content += "<div class=\"#{content_classes.join(' ')}\" ref=\"#{name}\">\n"
end
@@ -218,15 +219,34 @@ def process_markdown(name, content, static=false, pdf=false)
# Apply the template to the slide and replace the key with
# content of the slide
- md += template.gsub(/###CONTENT###/, content)
+ md += process_content_for_replacements(template.gsub(/~~~CONTENT~~~/, content), seq, slides.size)
+
+ # Apply other configuration
md += "</div>\n"
final += update_commandline_code(md)
final = update_p_classes(final)
+
+ seq += 1
end
final
end
+ # This method processes the content of the slide and replaces
+ # content markers with their actual value information
+ def process_content_for_replacements(content, seq, num)
+ result = content.gsub("~~~CURRENT_SLIDE~~~", seq.to_s).
+ gsub("~~~NUM_SLIDES~~~", num.to_s)
+
+ # Now check for any kind of options
+ content.scan(/(~~~CONFIG:(.*?)~~~)/).each do |match|
+ result.gsub!(match[0], options.showoff_config[match[1]]) if options.showoff_config.key?(match[1])
+ end
+
+ result
+ end
+
+
# find any lines that start with a <p>.(something) and turn them into <p class="something">
def update_p_classes(markdown)
markdown.gsub(/<p>\.(.*?) /, '<p class="\1">')
@@ -444,7 +464,6 @@ def pdf(static=true)
# Todo fix javascript path
-
# PDFKit.new takes the HTML and any options for wkhtmltopdf
# run `wkhtmltopdf --extended-help` for a full list of options
kit = PDFKit.new(html,

0 comments on commit ea6046a

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