lib/showoff.rb in showoff-0.3.4 vs lib/showoff.rb in showoff-0.4.1
- old
+ new
@@ -1,36 +1,39 @@
require 'rubygems'
require 'sinatra/base'
require 'json'
require 'nokogiri'
-require 'showoff_utils'
-require 'princely'
require 'fileutils'
+here = File.expand_path(File.dirname(__FILE__))
+require "#{here}/showoff_utils"
+require "#{here}/princely"
+
begin
require 'RMagick'
rescue LoadError
- $stderr.puts 'image sizing disabled - install RMagick'
+ $stderr.puts 'image sizing disabled - install rmagick'
end
begin
require 'pdfkit'
rescue LoadError
- $stderr.puts 'pdf generation disabled - install PDFKit'
+ $stderr.puts 'pdf generation disabled - install pdfkit'
end
begin
require 'rdiscount'
rescue LoadError
require 'bluecloth'
+ Object.send(:remove_const,:Markdown)
Markdown = BlueCloth
end
require 'pp'
class ShowOff < Sinatra::Application
- Version = VERSION = '0.3.4'
+ Version = VERSION = '0.4.1'
attr_reader :cached_image_size
set :views, File.dirname(__FILE__) + '/../views'
set :public, File.dirname(__FILE__) + '/../public'
@@ -70,21 +73,21 @@
def preshow_files
Dir.glob("#{options.pres_dir}/_preshow/*").map { |path| File.basename(path) }.to_json
end
def process_markdown(name, content, static=false)
- slides = content.split(/^!SLIDE/)
+ slides = content.split(/^<?!SLIDE/)
slides.delete('')
final = ''
if slides.size > 1
seq = 1
end
slides.each do |slide|
md = ''
# extract content classes
lines = slide.split("\n")
- content_classes = lines.shift.split rescue []
+ content_classes = lines.shift.strip.chomp('>').split rescue []
slide = lines.join("\n")
# add content class too
content_classes.unshift "content"
# extract transition, defaulting to none
transition = 'none'
@@ -124,11 +127,11 @@
def update_image_paths(path, slide, static=false)
paths = path.split('/')
paths.pop
path = paths.join('/')
replacement_prefix = static ?
- %(img src="./file/#{path}) :
+ %(img src="file://#{options.pres_dir}/#{path}) :
%(img src="/image/#{path})
slide.gsub(/img src=\"(.*?)\"/) do |s|
img_path = File.join(path, $1)
w, h = get_image_size(img_path)
src = %(#{replacement_prefix}/#{$1}")
@@ -320,10 +323,10 @@
end
name = showoff.instance_variable_get(:@pres_name)
path = showoff.instance_variable_get(:@root_path)
data = showoff.send(what, true)
if data.is_a?(File)
- File.cp(data.path, "#{name}.pdf")
+ FileUtils.cp(data.path, "#{name}.pdf")
else
out = "#{path}/#{name}/static"
# First make a directory
FileUtils.makedirs(out)
# Then write the html