Skip to content
Browse files

Templates

* allow templates to be configurable
* allow default template to be not present
* parsing of slide options
  • Loading branch information...
1 parent 96d510d commit 04dd4ebcd561475a1f9c9da68ae53dc7acd2413b @grundprinzip committed
Showing with 117 additions and 16 deletions.
  1. +49 −12 README.rdoc
  2. +44 −4 lib/showoff.rb
  3. +24 −0 lib/showoff_utils.rb
View
61 README.rdoc
@@ -84,7 +84,23 @@ the following contents:
That represents two slides, the first contains just a large title, and the
second is faded into view showing the title and three bullets that are then
-incrementally shown. In order for ShowOff to see those slides, your
+incrementally shown. In addition you can configure a certain template for
+this slide overriding the default one:
+
+ !SLIDE[tpl=title]
+
+ # My Presentation #
+
+ !SLIDE bullets incremental
+
+ # Bullet Points #
+
+ * first point
+ * second point
+ * third point
+
+
+In order for ShowOff to see those slides, your
<tt>showoff.json</tt> file needs to look something like this:
{
@@ -95,19 +111,40 @@ incrementally shown. In order for ShowOff to see those slides, your
]
}
-If you have multiple sections in your talk, you can make this json array
-include all the sections you want to show in which order you want to show
-them.
+If you have multiple sections in your talk, you can make this json
+array include all the sections you want to show in which order you
+want to show them. Template configuration is done in
+<tt>showoff.json</tt> as well.
+
-Instead of a hash, you can use a plain string as an entry in the `sections`
-section of `showoff.json`.
+To configure your own template add an
+entry called "templates". This entry is an object where you can
+specify as many templates as you want. The default template is marked
+with the "default" key.
+
+ {
+ "name": "Something",
+ "description": "Example Presentation",
+ "templates" : {
+ "default" : "tpl1.tpl",
+ "special" : "tpl2.tpl"
+ },
+ "sections": [
+ {"section":"one"}
+ ]
+ }
-And if that plain string starts with '#' then it is interpreted not as a
-filename, but as markdown. This is used for inserting interstitial slides
-or notes -- for instance, Alex Chaffee's
-[Ruby Notes](http://github.com/alexch/ruby_notes)
-uses it to insert lab instructions between lecture slide sections, which may
-vary from venue to venue.
+If the "default" key is not given, no template will be used for the
+default slide.
+
+Instead of a hash, you can use a plain string as an entry in the
+`sections` section of `showoff.json`. And if that plain string starts
+with '#' then it is interpreted not as a filename, but as
+markdown. This is used for inserting interstitial slides or notes --
+for instance, Alex Chaffee's [Ruby
+Notes](http://github.com/alexch/ruby_notes) uses it to insert lab
+instructions between lecture slide sections, which may vary from venue
+to venue.
If you want to keep the ability to emit an HTML document from your
Markdown source file -- say, for a TextMate preview or a GitHub rendering
View
48 lib/showoff.rb
@@ -41,6 +41,8 @@ class ShowOff < Sinatra::Application
set :verbose, false
set :pres_dir, '.'
set :pres_file, 'showoff.json'
+ set :page_size, "Letter"
+ set :pres_template, nil
def initialize(app=nil)
super(app)
@@ -59,6 +61,18 @@ def initialize(app=nil)
if (options.pres_file)
ShowOffUtils.presentation_config_file = options.pres_file
end
+
+ # Load configuration for page size and template from the
+ # configuration JSON file
+ if File.exists?(ShowOffUtils.presentation_config_file)
+ showoff_json = JSON.parse(File.read(ShowOffUtils.presentation_config_file))
+ options.page_size = showoff_json["page-size"] || "Letter"
+ options.pres_template = showoff_json["templates"]
+ end
+
+
+ @logger.debug options.pres_template
+
@cached_image_size = {}
@logger.debug options.pres_dir
@pres_name = options.pres_dir.split('/').pop
@@ -101,9 +115,21 @@ def preshow_files
# todo: move more behavior into this class
class Slide
- attr_reader :classes, :text
- def initialize classes = ""
- @classes = ["content"] + classes.strip.chomp('>').split
+ attr_reader :classes, :text, :tpl
+ def initialize( context = "")
+
+ @tpl = "default"
+ @classes = ["content"]
+
+ # Parse the context string for options and content classes
+ if context and context.match(/(\[(.*?)\])?(.*)/)
+
+ options = ShowOffUtils.parse_options($2)
+ @tpl = options["tpl"] if options["tpl"]
+ @classes += $3.strip.chomp('>').split if $3
+
+ end
+
@text = ""
end
def <<(s)
@@ -131,7 +157,8 @@ def process_markdown(name, content, static=false, pdf=false)
until lines.empty?
line = lines.shift
if line =~ /^<?!SLIDE(.*)>?/
- slides << (slide = Slide.new($1))
+ ctx = $1 ? $1.strip : $1
+ slides << (slide = Slide.new(ctx))
else
slide << line
end
@@ -156,10 +183,23 @@ def process_markdown(name, content, static=false, pdf=false)
@logger.debug "id: #{id}" if id
@logger.debug "classes: #{content_classes.inspect}"
@logger.debug "transition: #{transition}"
+ @logger.debug "tpl: #{slide.tpl} " if slide.tpl
# create html
md += "<div"
md += " id=\"#{id}\"" if id
md += " class=\"slide\" data-transition=\"#{transition}\">"
+
+
+ # Template handling
+ if options.pres_template
+ # We allow specifying a new template even when default is
+ # not given.
+ if options.pres_template.include?(slide.tpl) and
+ File.exists?(options.pres_template[slide.tpl])
+ md += File.open(options.pres_template[slide.tpl], "r").read()
+ end
+ end
+
if seq
md += "<div class=\"#{content_classes.join(' ')}\" ref=\"#{name}/#{seq.to_s}\">\n"
seq += 1
View
24 lib/showoff_utils.rb
@@ -1,4 +1,28 @@
class ShowOffUtils
+
+ # Helper method to parse a comma separated options string and stores
+ # the result in a dictionrary
+ #
+ # Example:
+ #
+ # "tpl=hpi,title=Over the rainbow"
+ #
+ # will be stored as
+ #
+ # { "tpl" => "hpi", "title" => "Over the rainbow" }
+ def self.parse_options(option_string="")
+ result = {}
+
+ if option_string
+ option_string.split(",").each do |element|
+ pair = element.split("=")
+ result[pair[0]] = pair.size > 1 ? pair[1] : nil
+ end
+ end
+
+ result
+ end
+
def self.presentation_config_file
@presentation_config_file ||= 'showoff.json'
end

0 comments on commit 04dd4eb

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