Skip to content

Commit

Permalink
Image support
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwistow committed Mar 26, 2010
1 parent d6a1cd9 commit e95aecf
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions lib/showoff.rb
Expand Up @@ -48,7 +48,7 @@ def js_files
Dir.glob("#{options.pres_dir}/*.js").map { |path| File.basename(path) }
end

def process_markdown(name, content)
def process_markdown(name, content, static=false)
slides = content.split(/^!SLIDE/)
slides.delete('')
final = ''
Expand Down Expand Up @@ -77,7 +77,7 @@ def process_markdown(name, content)
md += "<div class=\"#{content_classes.join(' ')}\" ref=\"#{name}\">\n"
end
sl = Markdown.new(slide).to_html
sl = update_image_paths(name, sl)
sl = update_image_paths(name, sl, static)
md += sl
md += "</div>\n"
md += "</div>\n"
Expand All @@ -86,11 +86,15 @@ def process_markdown(name, content)
final
end

def update_image_paths(path, slide)
def update_image_paths(path, slide, static=false)
paths = path.split('/')
paths.pop
path = paths.join('/')
slide.gsub(/img src=\"(.*?)\"/, 'img src="/image/' + path + '/\1"')
if static
slide.gsub(/img src=\"(.*?)\"/, 'img src="file://'+options.pres_dir+'/' + path + '/\1"')
else
slide.gsub(/img src=\"(.*?)\"/, 'img src="/image/' + path + '/\1"')
end
end

def update_commandline_code(slide)
Expand Down Expand Up @@ -129,7 +133,7 @@ def update_commandline_code(slide)
html.root.to_s
end

def get_slides_html
def get_slides_html(static=false)
index = File.join(options.pres_dir, 'showoff.json')
files = []
if File.exists?(index)
Expand All @@ -143,7 +147,7 @@ def get_slides_html
data = ''
files.each do |f|
fname = f.gsub(options.pres_dir + '/', '').gsub('.md', '')
data += process_markdown(fname, File.read(f))
data += process_markdown(fname, File.read(f),static)
end
end
data
Expand Down Expand Up @@ -181,17 +185,17 @@ def index
erb :index
end

def slides
get_slides_html
def slides(static=false)
get_slides_html(static)
end

def onepage
@slides = get_slides_html
def onepage(static=false)
@slides = get_slides_html(static)
erb :onepage
end

def pdf
@slides = get_slides_html
def pdf(static=false)
@slides = get_slides_html(static)
@no_js = true
html = erb :onepage
p = Princely.new
Expand All @@ -212,7 +216,7 @@ def self.static(args)
showoff = showoff.instance_variable_get(:@app)
end

data = showoff.send(what)
data = showoff.send(what, true)
if data.is_a?(File)
File.cp(data.path, "#{name}.pdf")
else
Expand Down

0 comments on commit e95aecf

Please sign in to comment.