#!/usr/bin/env ruby
#==========================================================================
#puts Time.now.to_s
require ENV["KIBUVITS_HOME"].to_s+"/src/include/kibuvits_all.rb"
#==========================================================================

class MMMV_documentation_fragment_frag_l_00000001
   attr_reader :s_fp_Rakefile ,:s_fp_project_home

   def initialize
      ob_pth_project_home=Pathname.new(__FILE__).realpath.parent
      @s_fp_project_home=ob_pth_project_home.to_s.freeze
      @s_fp_index_html=ob_pth_project_home.to_s+"/index.html"
      @s_fp_Rakefile=ob_pth_project_home.to_s+"/Rakefile"
   end # initialize

   #-----------------------------------------------------------------------

   private
   def generate_images_s_assemble_new_html(s_hay,s_block_blank_ID,s_fp_dot,
      s_block_start,s_block_end)
      cmd="dot -Tjpeg "+s_fp_dot+"  > "+s_fp_dot.sub(/[.]dot$/,".jpeg")
      ht_stdstreams=kibuvits_sh(cmd)
      Kibuvits_os.assert_stderr_is_empty_t1(ht_stdstreams)
      #----
      s_out=s_hay
      if s_block_blank_ID!=nil
         s_dot=file2str(s_fp_dot).gsub(">","&gt;").gsub(/[\n]/,"<br/>\n")
         s_new_block=s_block_start+"\n"+s_dot+s_block_end+"\n"
         s_out=s_hay.sub(s_block_blank_ID,s_new_block)
      end # if
      return s_out
   end # generate_images_s_assemble_new_html

   # Returns Updated HTML
   def s_generate_single_image(s_html_original,i_illustration_number)
      s_block_start="<code id=\"id_illustration_"+i_illustration_number.to_s+"_dot\">"
      s_block_end="</code><!-- id_illustration_"+i_illustration_number.to_s+"_dot -->"
      #----
      s_hay=s_html_original
      s_block_blank_ID=nil
      if s_html_original.match(s_block_start)!=nil
         s_hay,ht_blocks=Kibuvits_str.pick_by_instance(
         s_block_start,s_block_end,s_html_original)
         s_block_blank_ID=ht_blocks.keys[0]
      end # if
      #----
      s_fp_dot=@s_fp_project_home+"/illustration_"+i_illustration_number.to_s+".dot"
      s_html_out=generate_images_s_assemble_new_html(s_hay,s_block_blank_ID,
      s_fp_dot,s_block_start,s_block_end)
      return s_html_out
   end # s_generate_single_image

   public

   def generate_images
      s_html=file2str(@s_fp_index_html)
      i_number_of_illustrations=3
      i_number_of_illustrations.times do |i|
         s_html=s_generate_single_image(s_html,(i+1))
      end # loop
      #puts s_html_0
      str2file(s_html,@s_fp_index_html)
   end # generate_images

end # class MMMV_documentation_fragment_frag_l_00000001

#--------------------------------------------------------------------------

task :doc => [] do
   ob=MMMV_documentation_fragment_frag_l_00000001.new
   ob.generate_images
   cmd="cp -f "+ob.s_fp_Rakefile+
   " ./Rakefile.txt ; chmod 0755 "+ob.s_fp_project_home+"/* ;"
   ht_stdstreams=kibuvits_sh(cmd)
   Kibuvits_os.assert_stderr_is_empty_t1(ht_stdstreams)
end


task :default do
   begin
      kibuvits_writeln(Kibuvits_rake.s_list_tasks())
   rescue Exception => e
      msg=e.to_s+"\n"+"GUID='448f4f5b-da1a-47ff-a180-726080d04fd7'"
      if defined? C_mmmv_devel_tools
         C_mmmv_devel_tools.write_exception_text_2_GUIDtrace_errorstack_if_possible_t1(msg)
      end # if
      raise Exception.new(msg)
   end # rescue
end # default

#==========================================================================

