lib/hyla/commands/generate.rb in hyla-1.0.5.pre.1 vs lib/hyla/commands/generate.rb in hyla-1.0.5

- old
+ new

@@ -44,11 +44,11 @@ extensions = 'adoc|ad|asciidoc' self.asciidoc_to_html(@source, @destination, extensions, merged_options) when 'index2html' - Hyla.logger.info "Rendering : Asciidoctor Indexed Files to SlideShow" + Hyla.logger.info "Rendering : Asciidoctor Indexed Files to HTML" self.check_mandatory_option?('-s / --source', options[:source]) self.check_mandatory_option?('-d / --destination', options[:destination]) @destination = options[:destination] @source = options[:source] @@ -193,11 +193,11 @@ html_dir = @destination + '/' + File.dirname(relative_path) Hyla.logger.info ">> Dir of html: #{html_dir}" FileUtils.mkdir_p html_dir # Copy Fonts - # TODO : Verify if we still needed as the FONTS liberation have been moved + # TODO : Verify if we still need to do that as the FONTS liberation have been moved # TODO : under local lib directory of revealjs # self.cp_resources_to_dir(File.dirname(html_dir), 'fonts') # Copy Resources for Slideshow case options[:backend] @@ -206,20 +206,43 @@ self.cp_resources_to_dir(File.dirname(html_dir), 'deck.js') when 'revealjs' self.cp_resources_to_dir(File.dirname(html_dir), 'revealjs') end + # + # Check if companion parameter is defined + # as we have to generate a new AllSlides.txt file + # containing as tag name this value [snippet] + # + if options[:snippet_content] == true + Hyla.logger.info "Snippet content has been selected. Index file will be modified and modifications will be reverted after asciidoctor processing" + add_tag_to_index_file(f) + end + + # # Render asciidoc to HTML - Hyla.logger.info ">> File to be rendered : #{f}" + # + Hyla.logger.info ">> File to be rendered : #{file_name_processed}" + # # Convert asciidoc file name to html file name + # html_file_name = file_name_processed.to_s.gsub(/.adoc$|.ad$|.asciidoc$|.index$|.txt$/, '.html') options[:to_dir] = html_dir options[:to_file] = html_file_name options[:attributes] = @attributes_bk Asciidoctor.render_file(f, options) + # + # Check if companion parameter is defined + # as we have to generate a new AllSlides.txt file + # containing as tag name this value [companion] + # + if options[:snippet_content] == true + remove_tag_from_index_file(f) + end + end end # No asciidoc files retrieved if adoc_file_paths.empty? @@ -534,9 +557,27 @@ # This is why the level for each index file title is '==' index_file.puts '== ' + file_name index_file.puts "\n" index_file + end + + # + # Add snippet tag index file + # + def self.add_tag_to_index_file(index_file) + text = File.read(index_file) + replace = text.gsub!('[]','[tag=' + Configuration::SNIPPET_TAG + ']') + File.open(index_file, "w") { |file| file.puts replace } + end + + # + # Remove snippet tag from index file + # + def self.remove_tag_from_index_file(index_file) + text = File.read(index_file) + replace = text.gsub!('[tag=' + Configuration::SNIPPET_TAG + ']', '[]') + File.open(index_file, "w") { |file| file.puts replace } end # # Check mandatory options #