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

- old
+ new

@@ -162,13 +162,10 @@ @cached_image_size = {} @logger.debug settings.pres_dir @pres_name = settings.pres_dir.split('/').pop require_ruby_files - # Default asset path - @asset_path = "./" - # invert the logic to maintain backwards compatibility of interactivity on by default @interactive = ! settings.standalone rescue false # Create stats directory FileUtils.mkdir settings.statsdir unless File.directory? settings.statsdir if @interactive @@ -314,14 +311,16 @@ end || '.' end # return a hash of all language codes available and the long name description of each def language_names - Dir.glob('locales/*').inject({}) do |memo, entry| - next memo unless File.directory? entry + strings = JSON.parse(File.read('locales/strings.json')) rescue {} + locales = Dir.glob('locales/*') + .select {|f| File.directory?(f) } + .map {|f| File.basename(f) } - locale = File.basename(entry) + (strings.keys + locales).inject({}) do |memo, locale| memo.update(locale => get_language_name(locale)) end end # returns the minimized canonical version of the current selected content locale @@ -587,10 +586,13 @@ result.gsub!(match[0], "<pre class=\"highlight\"><code class=\"#{css}\">#{file}</code></pre>") end result.gsub!(/\[(fa-.*)\]/, '<i class="fa \1"></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(':')}"} result end # replace section tags with classed div tags @@ -834,11 +836,11 @@ begin tools = '<div class="tools">' tools << "<input type=\"button\" class=\"display\" value=\"#{I18n.t('forms.display')}\">" tools << "<input type=\"submit\" class=\"save\" value=\"#{I18n.t('forms.save')}\" disabled=\"disabled\">" tools << '</div>' - form = "<form id='#{title}' action='/form/#{title}' method='POST'>#{content}#{tools}</form>" + form = "<form id='#{title}' action='form/#{title}' method='POST'>#{content}#{tools}</form>" doc = Nokogiri::HTML::DocumentFragment.parse(form) doc.css('p').each do |p| if p.text =~ /^(\w*) ?(?:->)? ?(.*)? (\*?)= ?(.*)?$/ code = $1 id = "#{title}_#{code}" @@ -1057,15 +1059,15 @@ doc = Nokogiri::HTML::DocumentFragment.parse(slide) slide_dir = File.dirname(path) case when opts[:static] && opts[:pdf] - replacement_prefix = "file://#{settings.pres_dir}/" + replacement_prefix = "file://#{settings.pres_dir}" when opts[:static] - replacement_prefix = "./file/" + replacement_prefix = './file' else - replacement_prefix = "#{@asset_path}image/" + replacement_prefix = 'image' end doc.css('img').each do |img| # does the image path start from the preso root? @@ -1095,12 +1097,14 @@ next if out.empty? # catch fenced code blocks from commonmarker if (lang and lang.start_with? 'language-' ) pre.set_attribute('class', 'highlight') + # turn the colon separated name back into classes + code.set_attribute('class', lang.gsub(':', ' ')) - # or weve started a code block with a Showoff language tag + # or we've started a code block with a Showoff language tag elsif out.strip[0, 3] == '@@@' lines = out.split("\n") lang = lines.shift.gsub('@@@', '').strip pre.set_attribute('class', 'highlight') code.set_attribute('class', 'language-' + lang.downcase) if !lang.empty? @@ -1212,12 +1216,10 @@ def index(static=false) if static @title = ShowOffUtils.showoff_title(settings.pres_dir) @slides = get_slides_html(:static=>static) @pause_msg = ShowOffUtils.pause_msg - - @asset_path = "./" end # Display favicon in the window if configured @favicon = settings.showoff_config['favicon'] @@ -1943,12 +1945,10 @@ protected! elsif settings.showoff_config['locked'].include? what locked! end - @asset_path = env['SCRIPT_NAME'] == '' ? nil : env['SCRIPT_NAME'].gsub(/^\/?/, '/').gsub(/\/?$/, '/') - begin if (what != "favicon.ico") if ['supplemental', 'print'].include? what data = send(what, opt) else @@ -1967,11 +1967,9 @@ raise Sinatra::NotFound end end not_found do - # Why does the asset path start from cwd?? - @asset_path.slice!(/^./) rescue nil @env = request.env erb :'404' end at_exit do