<project name="phing_guide" default="main" basedir=".">

  <!-- ================================================================ -->
  <!-- M A I N  T A R G E T                                             -->
  <!-- ================================================================ -->
	<target
		name="main"
		description="==>build phing_guide">
		
		<!-- <phingcall target="normalize_linebreaks"/> -->
		<phingcall target="remove_old_toc"/>
		<phingcall target="gen_standard_toc"/>
		<phingcall target="gen_frame_toc"/>
		<phingcall target="gen_chapter_js"/>
		
		<!-- the next step here would be to create a PDF -->
		     
	</target>
	
	<!--
	##==============================================
	## Normalize line breaks to ensure a good
	## conversion
	##
	## @author  alex black, enigma@turingstudio.com
	## @revision $Revision: 1.6 $
	##==============================================	
	-->
	<target name="normalize_linebreaks"
			description="==>normalize linebreaks (make them unix)">
		<!-- use replaceregexp filter to handle the normalization -->

		<echo message="/----------------------------------\"/>
		<echo message="| NORMALIZING LINE BREAKS          |"/>
		<echo message="\----------------------------------/"/>
		     
		<reflexive>
			<fileset dir=".">
				<include name="**/*.html"/>
			</fileset>
			<filterchain>
				<replaceregexp>
					<regexp pattern="\r\n" replace="\n"/>
					<regexp pattern="\r" replace="\n"/>
				</replaceregexp>
			</filterchain>
		</reflexive>
		
	</target>
	
	<!--
    ##==============================================
	## Kill any old ToC
	##
	## @author  alex black, enigma@turingstudio.com
	##==============================================	
	-->
	<target 
		name="remove_old_toc" 
		description="==> deletes the old table of contents file.">
			
		<echo message="/----------------------------------\"/>
		<echo message="|      REMOVING OLD TOC FILES      |"/>
		<echo message="\----------------------------------/"/>

		<delete file="book/toc/ToC.html"/>
		<delete file="book/toc/FrameToC.html"/>
		<delete file="book/js/Chapters.js"/>

	</target>
	
	<!--	
	##==============================================
	## generate a standard Toc
	##
	## @author  alex black, enigma@turingstudio.com
	##==============================================	
	-->
	<target
		name="gen_standard_toc"
		description="==>generate a standard Toc">

		<echo message="/----------------------------------\"/>
		<echo message="| GENERATE STD TABLE OF CONTENTS   |"/>
		<echo message="\----------------------------------/"/>		
		
		<append destFile="book/toc/ToC.html">					
			<filterchain>
				<xsltfilter style="../docsystem/xsl/Toc.xsl" html="yes">
					<param name="mode" expression="standard"/>
					<param name="file_name" expression="%{task.append.current_file}"/>
				</xsltfilter>
			</filterchain>
			<filelist dir="book/" listfile="book/PhingGuide.book"/>			
		</append>
		
		
		<append file="../docsystem/html/StandardToCBottom.html" destFile="book/toc/ToC.html"/>				
		 
	</target>
	
	<!--
	##==============================================
	## generate a frame Toc
	##
	## @author  alex black, enigma@turingstudio.com
	##==============================================	
	-->
	<target name="gen_frame_toc"
			description="==>generate table of contents for frame">
		
		<echo message="/----------------------------------\"/>
		<echo message="| GENERATE FRAME TABLE OF CONTENTS |"/>
		<echo message="\----------------------------------/"/>
		
		<append file="../docsystem/html/FrameToCTop.html" destFile="book/toc/FrameToC.html"/>
			
		<append destFile="book/toc/FrameToC.html">					
			<filterchain>
				<xsltfilter style="../docsystem/xsl/Toc.xsl" html="yes">
					<param name="mode" expression="frame"/>
					<param name="file_name" expression="%{task.append.current_file}"/>
				</xsltfilter>
			</filterchain>
			<filelist dir="book/" listfile="book/PhingGuide.book"/>			
		</append>
									
		<append file="../docsystem/html/FrameToCBottom.html" destFile="book/toc/FrameToC.html"/>				
	
	</target>
	
	<!--	
	##==============================================
	## generate chapter JS array
	##
	## @author  alex black, enigma@turingstudio.com
	##==============================================	
	-->
	<target name="gen_chapter_js"
			description="==>generate the javascript">

		<echo message="/----------------------------------\"/>
		<echo message="| GENERATE CHAPTER JAVASCRIPT      |"/>
		<echo message="\----------------------------------/"/>
		
		<append text="var Chapters = new Array(" destFile="book/js/Chapters.js"/>
		
		<append destFile="book/js/Chapters.js">					
			<filterchain>
				<xsltfilter style="../docsystem/xsl/Chapters.xsl" html="yes">
					<param name="mode" expression="${process.xslt.mode}"/>
					<param name="file_name" expression="%{task.append.current_file}"/>
				</xsltfilter>
			</filterchain>
			<filelist dir="book/" listfile="book/PhingGuide.book"/>			
		</append>
				
		<append text=");" destFile="book/js/Chapters.js"/>				
		
		<!-- remove the trailing ',' because the XSLT does not (and this will trigger jscript errors) -->
		<reflexive file="book/js/Chapters.js">
			<filterchain>
				<replaceregexp>
					<regexp pattern="\),[\s]+\);" replace="));"/>
				</replaceregexp>
			</filterchain>
		</reflexive>
			
	</target>
	
</project>
