Skip to content
Permalink
Browse files
Allow adding of classes, copy images to presentation dir
  • Loading branch information
plexus committed Jun 8, 2013
1 parent 44d48f6 commit 7ce982e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
@@ -54,10 +54,11 @@ end

def render opts
text, metadata = extract_metadata(readfile(FILENAME))

# ugly hack to get attributes for impress.js
# TODO make this pretty
lines = text.split("\n")
lines.drop_while { |l| l =~ /^\s*$/ }
lines = text.split("\n").reject{|l| l=~ /\A!!/ }
lines.drop_while { |l| l =~ /^$/ }

defaults = metadata['defaults'] || {}

@@ -67,7 +68,7 @@ def render opts
lines.each_with_index do |line, i|
if line =~ /^=(.*)$/ && (i == 0 || lines[i-1] =~ /^(-\s*){3,}$/)
line =~ /^=(.*)$/
attrs[attrs.size-1] = defaults.dup.merge(Hash[$1.split(' ').map{|a| k,v=a.split('=') ; [k, eval(v)]}])
attrs[attrs.size-1] = defaults.dup.merge(Hash[$1.split(' ').map{|a| k,v=a.split('=') ; [k, eval(v.to_s)]}])
next
elsif line =~ /^(-\s*){3,}$/
attrs << defaults.dup
@@ -79,6 +80,7 @@ def render opts

# now use those attributes and render the file
ImpressRenderer.new.tap do |mdpress|
mdpress.dest = DIRNAME
mdpress.init_with_attrs attrs, opts
mdpress.author= metadata['author'] if metadata['author']
mdpress.title= metadata['title'] if metadata['title']
@@ -3,6 +3,8 @@
require 'hexp/h'

class ImpressRenderer < Redcarpet::Render::HTML
attr_accessor :dest

@attrs = []
@current = 0
@author, @head, @title = nil
@@ -27,6 +29,7 @@ def title= title
end

def render_attrs(hsh)
"class='step #{hsh.delete('class')}' "+
hsh.map do |k,v|
if v =~ /([\+\-])(\d+)/
@counters[k] ||= 0
@@ -46,7 +49,7 @@ def hrule
# this is how we later inject attributes into pages. what an awful hack.
@current += 1
%{</div>
<div class='step' #{render_attrs(@attrs[@current])}>
<div #{render_attrs(@attrs[@current])}>
}
end

@@ -72,6 +75,13 @@ def codespan code
H[:code, {class: "inline prettyprint"}, code].to_html
end

def image link, title, alt
if File.exist?("images/#{link}")
`cp images/#{link} #{dest}/#{link}`
end
H[:img, {src: link, alt: alt}, title].to_html
end

def mathjax
if @opts[:latex]
%{
@@ -112,7 +122,7 @@ def doc_header
<p>For the best experience please use the latest <b>Chrome</b>, <b>Safari</b> or <b>Firefox</b> browser.</p>
</div>
<div id="impress">
<div class='step' #{render_attrs(@attrs[0])}>
<div #{render_attrs(@attrs[0])}>
}
end

0 comments on commit 7ce982e

Please sign in to comment.