lib/slideshow/commands/gen.rb in slideshow-1.1.0.beta8 vs lib/slideshow/commands/gen.rb in slideshow-1.1.0

- old
+ new

@@ -94,11 +94,15 @@ # 1) add slide break if (@markup_type == :markdown && Markdown.lib == 'pandoc-ruby') || @markup_type == :rest content = add_slide_directive_before_div_h1( content ) else - content = add_slide_directive_before_h1( content ) + if config.header_level == 2 + content = add_slide_directive_before_h2( content ) + else # assume level 1 + content = add_slide_directive_before_h1( content ) + end end dump_content_to_file_debug_html( content ) # 2) use generic slide break processing instruction to @@ -124,69 +128,28 @@ slides << slide_source # add slide to slide stack slide_source = "" # reset slide source buffer end - ## split slide source into header (optional) and content/body - ## plus check for (css style) classes and data attributes - slides2 = [] slides.each do |slide_source| - slide = Slide.new - - ## check for css style classes - from = 0 - while (pos = slide_source.index( /<!-- _S9(SLIDE|STYLE)_(.*?)-->/m, from )) - logger.debug " adding css classes from pi #{$1.downcase}: #{$2.strip}" - - from = Regexp.last_match.end(0) # continue search later from here - - values = $2.strip.dup - - # remove data values (eg. x=-20 scale=4) and store in data hash - values.gsub!( /([-\w]+)[ \t]*=[ \t]*([-\w\.]+)/ ) do |_| - logger.debug " adding data pair: key=>#{$1.downcase}< value=>#{$2}<" - slide.data[ $1.downcase.dup ] = $2.dup - " " # replace w/ space - end - - values.strip! # remove spaces # todo: use squish or similar and check for empty string - - if slide.classes.nil? - slide.classes = values - else - slide.classes << " #{values}" - end - end - - # try to cut off header using non-greedy .+? pattern; tip test regex online at rubular.com - # note/fix: needs to get improved to also handle case for h1 wrapped into div - # (e.g. extract h1 - do not assume it starts slide source) - if slide_source =~ /^\s*(<h1.*?>.*?<\/h\d>)\s*(.*)/m - slide.header = $1 - slide.content = ($2 ? $2 : "") - logger.debug " adding slide with header:\n#{slide.header}" - else - slide.content = slide_source - logger.debug " adding slide with *no* header:\n#{slide.content}" - end - slides2 << slide + slides2 << Slide.new( slide_source, config ) end # for convenience create a string w/ all in-one-html # no need to wrap slides in divs etc. content2 = "" - slides2.each do |slide| + slides2.each do |slide| content2 << slide.to_classic_html end # make content2 and slide2 available to erb template # -- todo: cleanup variable names and use attr_readers for content and slide - @slides = slides2 # strutured content - @content = content2 # content all-in-one + @slides = slides2 # strutured content + @content = content2 # content all-in-one end def create_slideshow( fn ) @@ -205,18 +168,19 @@ # check for builtin manifests manifests = installed_template_manifests matches = manifests.select { |m| m[0] == manifest_path_or_name } if matches.empty? - puts "*** error: unknown template manifest '#{manifest_path_or_name}'" + puts "*** error: unknown template manifest '#{manifest_path_or_name}'" # todo: list installed manifests exit 2 end manifest = load_manifest( matches[0][1] ) end + # expand output path in current dir and make sure output path exists outpath = File.expand_path( opts.output_path ) logger.debug "outpath=#{outpath}" FileUtils.makedirs( outpath ) unless File.directory? outpath @@ -233,44 +197,31 @@ unless newcwd == oldcwd then logger.debug "oldcwd=#{oldcwd}" logger.debug "newcwd=#{newcwd}" Dir.chdir newcwd - end + end puts "Preparing slideshow '#{basename}'..." - - if extname.empty? then - extname = ".textile" # default to .textile - - config.known_extnames.each do |e| - logger.debug "File.exists? #{dirname}/#{basename}#{e}" - if File.exists?( "#{dirname}/#{basename}#{e}" ) then - extname = e - logger.debug "extname=#{extname}" - break - end - end - end - - if config.known_markdown_extnames.include?( extname ) - @markup_type = :markdown + + if config.known_textile_extnames.include?( extname ) + @markup_type = :textile elsif config.known_rest_extnames.include?( extname ) @markup_type = :rest - else - @markup_type = :textile + else # default/fallback use markdown + @markup_type = :markdown end # shared variables for templates (binding) @content_for = {} # reset content_for hash @name = basename @extname = extname @session = {} # reset session hash for plugins/helpers - inname = "#{dirname}/#{basename}#{extname}" + inname = "#{basename}#{extname}" logger.debug "inname=#{inname}" content = File.read( inname ) @@ -297,10 +248,14 @@ # sets @content (all-in-one string) and @slides (structured content; split into slides) post_processing_slides( content ) end + #### fix/todo: + ## + ## check for .erb file extension for trigger for erb processing + manifest.each do |entry| outname = entry[0] if outname.include? '__file__' # process outname = outname.gsub( '__file__', basename ) puts "Preparing #{outname}..." @@ -318,13 +273,24 @@ out.close else # just copy verbatim if target/dest has no __file__ in name dest = entry[0] source = entry[1] - - puts "Copying to #{dest} from #{source}..." + + #### fix/todo: + ## + ## check for .erb file extension for trigger for erb processing + + puts "Copying to #{dest} from #{source}..." FileUtils.copy( source, with_output_path( dest, outpath ) ) end + end + + + ## pop/restore working folder/dir + unless newcwd == oldcwd + logger.debug "oldcwd=>#{oldcwd}<, newcwd=>#{newcwd}<" + Dir.chdir( oldcwd ) end puts "Done." end \ No newline at end of file