lib/showoff.rb in showoff-0.20.0 vs lib/showoff.rb in showoff-0.20.1

- old
+ new

@@ -252,15 +252,19 @@ Dir.glob("#{settings.pres_dir}/*.rb").map { |path| require path } end helpers do def css_files - Dir.glob("#{settings.pres_dir}/*.css").map { |path| File.basename(path) } + base = Dir.glob("#{settings.pres_dir}/*.css").map { |path| File.basename(path) } + extra = Array(settings.showoff_config['styles']) + base + extra end def js_files - Dir.glob("#{settings.pres_dir}/*.js").map { |path| File.basename(path) } + base = Dir.glob("#{settings.pres_dir}/*.js").map { |path| File.basename(path) } + extra = Array(settings.showoff_config['scripts']) + base + extra end def preshow_files files = Dir.glob("#{settings.pres_dir}/_preshow/*") files.reject! { |path| ['.txt', '.md'].include? File.extname(path) } @@ -584,11 +588,11 @@ file = HTMLEntities.new.encode(file) rescue "HTML parsing of #{name} failed" result.gsub!(match[0], "<pre class=\"highlight\"><code class=\"#{css}\">#{file}</code></pre>") end - result.gsub!(/\[(fa-.*)\]/, '<i class="fa \1"></i>') + result.gsub!(/\[(fa\w?)-(\S*)\]/, '<i class="\1 fa-\2"></i>') # For fenced code blocks, translate the space separated classes into one # colon separated string so Commonmarker doesn't ignore the rest result.gsub!(/^`{3} *(.+)$/) {|s| "``` #{$1.split.join(':')}"} @@ -1307,13 +1311,18 @@ # allow command line cache disabling @@cache[@locale] = content unless settings.nocache content end - def print(section=nil) + def print(section=nil, munged=false) @slides = get_slides_html(:static=>true, :toc=>true, :print=>true, :section=>section) @favicon = settings.showoff_config['favicon'] + + unless munged + @baseurl = '../' * section.split('/').count + end + erb :onepage end def supplemental(content, static=false) # supplemental material is by definition separate from the presentation, so it doesn't make sense to attach notes @@ -1473,11 +1482,11 @@ when 'pdf' opt ||= "#{name}.pdf" data = showoff.send(what, opt) when 'print' opt ||= 'handouts' - data = showoff.send(what, opt) + data = showoff.send(what, opt, true) else data = showoff.send(what, true) end if data.is_a?(File) @@ -1507,12 +1516,14 @@ file_dir = File.join(out, 'file') FileUtils.makedirs(file_dir) pres_dir = showoff.settings.pres_dir # ..., copy all user-defined styles and javascript files - Dir.glob("#{pres_dir}/*.{css,js}").each { |path| - FileUtils.copy(path, File.join(file_dir, File.basename(path))) + showoff.css_files.each { |path| + dest = File.join(file_dir, path) + FileUtils.mkdir_p(File.dirname(dest)) + FileUtils.copy(path, dest) } # ... and copy all needed image files [/img src=[\"\'].\/file\/(.*?)[\"\']/, /style=[\"\']background(?:-image): url\(\'file\/(.*?)'/].each do |regex| data.scan(regex).flatten.each do |path| @@ -1524,15 +1535,19 @@ puts "Missing source file: #{path}" end end end # copy images from css too - Dir.glob("#{pres_dir}/*.css").each do |css_path| + showoff.css_files.each do |css_path| File.open(css_path) do |file| data = file.read data.scan(/url\([\"\']?(?!https?:\/\/)(.*?)[\"\']?\)/).flatten.each do |path| path.gsub!(/(\#.*)$/, '') # get rid of the anchor path.gsub!(/(\?.*)$/, '') # get rid of the query + + # resolve relative paths in the stylesheet + path = "#{File.dirname(css_path)}/#{path}" unless path.start_with? '/' + logger.debug path dir = File.dirname(path) FileUtils.makedirs(File.join(file_dir, dir)) begin FileUtils.copy(File.join(pres_dir, path), File.join(file_dir, path))