Browse Source

Added interface support.
Don't copy all files.
Improved example generation.

woollybah 6 years ago
parent
commit
fbe8a37090
3 changed files with 97 additions and 19 deletions
  1. 34 4
      src/makemd/docstyle.bmx
  2. 19 9
      src/makemd/makemd.bmx
  3. 44 6
      src/makemd/mdstyle.bmx

+ 34 - 4
src/makemd/docstyle.bmx

@@ -10,7 +10,7 @@ Import "docnode.bmx"
 
 
 Global BmxDocDir$=BlitzMaxPath()+"/docs/md"
 Global BmxDocDir$=BlitzMaxPath()+"/docs/md"
 
 
-Global NodeKinds$[]=[ "/","Module","Type" ]
+Global NodeKinds$[]=[ "/","Module","Type", "Interface" ]
 
 
 Global LeafKinds$[]=[ "Const","Field","Global","Method","Function","Keyword" ]
 Global LeafKinds$[]=[ "Const","Field","Global","Method","Function","Keyword" ]
 
 
@@ -99,7 +99,7 @@ Type TDocStyle Extends TBBLinkResolver
 
 
 			If doc.kind = "Module" Then
 			If doc.kind = "Module" Then
 				url = "../.." + url
 				url = "../.." + url
-			Else If doc.kind = "Type" Then
+			Else If doc.kind = "Type" Or doc.kind = "Interface" Then
 				url = "../../.." + url
 				url = "../../.." + url
 			End If
 			End If
 		Else
 		Else
@@ -120,7 +120,7 @@ Type TDocStyle Extends TBBLinkResolver
 		docURL=NodeURL( doc )
 		docURL=NodeURL( doc )
 		absDocDir=BmxDocDir+ExtractDir( docURL )
 		absDocDir=BmxDocDir+ExtractDir( docURL )
 
 
-		If doc.kind = "Type" Then
+		If doc.kind = "Type" Or doc.kind = "Interface" Then
 			relRootDir="../../.."
 			relRootDir="../../.."
 		Else
 		Else
 			relRootDir="../.."
 			relRootDir="../.."
@@ -136,7 +136,7 @@ Type TDocStyle Extends TBBLinkResolver
 			
 			
 		outputPath = BmxDocDir+docURL
 		outputPath = BmxDocDir+docURL
 		
 		
-		If doc.docDir CopyDir doc.docDir,absDocDir
+		If doc.docDir FilteredCopyDir doc.docDir,absDocDir
 
 
 		Local intro$=absDocDir+"/index.bbdoc"
 		Local intro$=absDocDir+"/index.bbdoc"
 		If FileType( intro )<>FILETYPE_FILE intro$=absDocDir+"/intro.bbdoc"
 		If FileType( intro )<>FILETYPE_FILE intro$=absDocDir+"/intro.bbdoc"
@@ -233,3 +233,33 @@ Type TDocStyle Extends TBBLinkResolver
 	Method EmitDecls( parent:TDocNode, kind$ ) Abstract
 	Method EmitDecls( parent:TDocNode, kind$ ) Abstract
 	
 	
 End Type
 End Type
+
+Function FilteredCopyDir:Int( src$,dst$ )
+
+	Function CopyDir_:Int( src$,dst$ )
+		If FileType( dst )=FILETYPE_NONE CreateDir dst
+		If FileType( dst )<>FILETYPE_DIR Return False
+		For Local file$=EachIn LoadDir( src )
+			Select FileType( src+"/"+file )
+			Case FILETYPE_DIR
+				If file <> ".bmx" Then
+					If Not CopyDir_( src+"/"+file,dst+"/"+file ) Return False
+				End If
+			Case FILETYPE_FILE
+				Local ext:String = ExtractExt(file).ToLower()
+				If ext = "bmx" Or ext = "bbdoc" Then
+					If Not CopyFile( src+"/"+file,dst+"/"+file ) Return False
+				End If
+			End Select
+		Next
+		Return True
+	End Function
+	
+	FixPath src
+	If FileType( src )<>FILETYPE_DIR Return False
+
+	FixPath dst
+	
+	Return CopyDir_( src,dst )
+
+End Function

+ 19 - 9
src/makemd/makemd.bmx

@@ -49,7 +49,6 @@ Function DocMods()
 
 
 	For Local modid$=EachIn EnumModules()
 	For Local modid$=EachIn EnumModules()
 
 
-'		If not modid.StartsWith("sdl.") Continue
 		If Not modid.StartsWith( "brl." ) And Not modid.StartsWith( "pub." ) And Not modid.StartsWith("maxgui.") And Not modid.StartsWith("sdl.") Continue
 		If Not modid.StartsWith( "brl." ) And Not modid.StartsWith( "pub." ) And Not modid.StartsWith("maxgui.") And Not modid.StartsWith("sdl.") Continue
 
 
 		Local p$=ModuleSource( modid )
 		Local p$=ModuleSource( modid )
@@ -172,7 +171,7 @@ Function docBmxFile( filePath$,docPath$ )
 			bbdoc=""
 			bbdoc=""
 			inrem=True
 			inrem=True
 			
 			
-		Else If id="endtype"
+		Else If id="endtype" Or id="endinterface"
 
 
 			If typePath
 			If typePath
 				docPath=typePath
 				docPath=typePath
@@ -213,7 +212,7 @@ Function docBmxFile( filePath$,docPath$ )
 				Local path$
 				Local path$
 
 
 				Select kind
 				Select kind
-				Case "Type"
+				Case "Type", "Interface"
 					If Not docPath Throw "No doc path"
 					If Not docPath Throw "No doc path"
 					If typePath Throw "Type path already set"
 					If typePath Throw "Type path already set"
 					typePath=docPath
 					typePath=docPath
@@ -246,7 +245,7 @@ Function docBmxFile( filePath$,docPath$ )
 				EndIf
 				EndIf
 				
 				
 				Local node:TDocNode=TDocNode.Create( id,path,kind )
 				Local node:TDocNode=TDocNode.Create( id,path,kind )
-				
+
 				node.proto=proto
 				node.proto=proto
 				node.protoId = BuildProtoId(proto)
 				node.protoId = BuildProtoId(proto)
 				node.bbdoc=bbdoc
 				node.bbdoc=bbdoc
@@ -254,11 +253,22 @@ Function docBmxFile( filePath$,docPath$ )
 				node.about=about
 				node.about=about
 				node.params=params
 				node.params=params
 				
 				
-				If kind="Module" node.docDir=docDir
-				
-				Local tmpExampleFilePath$ = CasedFileName(docDir+"/"+id+".bmx")
-				If docDir And FileType( tmpExampleFilePath )=FILETYPE_FILE
-					node.example=StripDir(tmpExampleFilePath)
+				If kind="Module" node.docDir=docDir		
+
+				If docDir Then
+					' try type method/function - type_method.bmx
+					Local m:String = StripDir(path)
+					Local t:String = StripDir(ExtractDir(path))
+					Local tmpExampleFilePath:String = CasedFileName(docDir+"/" + t + "_" + m +".bmx")
+					If FileType(tmpExampleFilePath) = FILETYPE_FILE Then
+						node.example=StripDir(tmpExampleFilePath)
+					Else
+						tmpExampleFilePath = CasedFileName(docDir+"/"+id+".bmx")
+
+						If FileType( tmpExampleFilePath )=FILETYPE_FILE
+							node.example=StripDir(tmpExampleFilePath)
+						End If
+					End If
 				EndIf
 				EndIf
 				
 				
 			EndIf
 			EndIf

+ 44 - 6
src/makemd/mdstyle.bmx

@@ -10,7 +10,7 @@ Type TRstStyle Extends TDocStyle
 
 
 		If doc.kind = "/" Return
 		If doc.kind = "/" Return
 
 
-		If doc.kind = "Module" Or doc.kind = "Type" Then
+		If doc.kind = "Module" Or doc.kind = "Type" Or doc.kind = "Interface" Then
 			Emit "---"
 			Emit "---"
 			Emit "id: " + doc.id.ToLower() 
 			Emit "id: " + doc.id.ToLower() 
 			Emit "title: " + doc.id
 			Emit "title: " + doc.id
@@ -21,11 +21,11 @@ Type TRstStyle Extends TDocStyle
 		
 		
 		Local s:String
 		Local s:String
 		
 		
-		If doc.kind <> "Module" And doc.kind <> "Type" Then
+		If doc.kind <> "Module" And doc.kind <> "Type" And doc.kind <> "Interface" Then
 			Emit s + doc.id
 			Emit s + doc.id
 		End If
 		End If
 
 
-		If doc.kind = "Type" And doc.bbdoc Then
+		If (doc.kind = "Type" Or doc.kind = "Interface") And doc.bbdoc Then
 			Emit doc.bbdoc
 			Emit doc.bbdoc
 			Emit ""
 			Emit ""
 		EndIf
 		EndIf
@@ -37,6 +37,10 @@ Type TRstStyle Extends TDocStyle
 			Emit ""
 			Emit ""
 		End If
 		End If
 		
 		
+		If doc.kind = "Type" Or doc.kind = "Interface" Then
+			EmitExample(doc)
+		End If
+		
 	End Method
 	End Method
 	
 	
 	Method EmitFooter()
 	Method EmitFooter()
@@ -67,7 +71,7 @@ Type TRstStyle Extends TDocStyle
 		
 		
 			Emit "## "+kind+"s"
 			Emit "## "+kind+"s"
 		
 		
-			Emit "| Type | Description |"
+			Emit "| " + kind + " | Description |"
 			Emit "|---|---|"
 			Emit "|---|---|"
 			
 			
 			For Local t:TDocNode=EachIn list
 			For Local t:TDocNode=EachIn list
@@ -114,24 +118,58 @@ Type TRstStyle Extends TDocStyle
 			
 			
 			'indent :- 1
 			'indent :- 1
 
 
+			EmitExample(t)
+			Rem
 			If t.example 
 			If t.example 
 				Emit "#### Example"
 				Emit "#### Example"
 				Emit "```blitzmax"
 				Emit "```blitzmax"
 
 
-				Local p:String = t.example
+				Local p:String = t.example.ToLower()
+
+				Local path:String = absDocDir+"/"+p
+		
+				If Not FileType(path) Then
+					' try one level up...
+					path = ExtractDir(absDocDir) + "/"+p
+				End If
 
 
-				Local code$=LoadText( absDocDir+"/"+p).Trim()
+				Local code$=LoadText(path).Trim()
 				For Local line:String = EachIn code.Split("~n")
 				For Local line:String = EachIn code.Split("~n")
 					Emit line
 					Emit line
 				Next
 				Next
 				Emit "```"
 				Emit "```"
 
 
 			EndIf
 			EndIf
+			End Rem
 
 
+			Emit "<br/>"
 
 
 			Emit ""
 			Emit ""
 			
 			
 		Next
 		Next
 	End Method
 	End Method
+	
+	Method EmitExample(t:TDocNode)
+		If t.example 
+			Emit "#### Example"
+			Emit "```blitzmax"
+
+			Local p:String = t.example.ToLower()
+
+			Local path:String = absDocDir+"/"+p
+
+			If Not FileType(path) Then
+				' try one level up...
+				path = ExtractDir(absDocDir) + "/"+p
+			End If
+
+			Local code$=LoadText(path).Trim()
+			For Local line:String = EachIn code.Split("~n")
+				Emit line
+			Next
+			Emit "```"
+
+		EndIf	
+	End Method
 
 
 End Type
 End Type