Explorar el Código

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

woollybah hace 6 años
padre
commit
fbe8a37090
Se han modificado 3 ficheros con 97 adiciones y 19 borrados
  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 NodeKinds$[]=[ "/","Module","Type" ]
+Global NodeKinds$[]=[ "/","Module","Type", "Interface" ]
 
 Global LeafKinds$[]=[ "Const","Field","Global","Method","Function","Keyword" ]
 
@@ -99,7 +99,7 @@ Type TDocStyle Extends TBBLinkResolver
 
 			If doc.kind = "Module" Then
 				url = "../.." + url
-			Else If doc.kind = "Type" Then
+			Else If doc.kind = "Type" Or doc.kind = "Interface" Then
 				url = "../../.." + url
 			End If
 		Else
@@ -120,7 +120,7 @@ Type TDocStyle Extends TBBLinkResolver
 		docURL=NodeURL( doc )
 		absDocDir=BmxDocDir+ExtractDir( docURL )
 
-		If doc.kind = "Type" Then
+		If doc.kind = "Type" Or doc.kind = "Interface" Then
 			relRootDir="../../.."
 		Else
 			relRootDir="../.."
@@ -136,7 +136,7 @@ Type TDocStyle Extends TBBLinkResolver
 			
 		outputPath = BmxDocDir+docURL
 		
-		If doc.docDir CopyDir doc.docDir,absDocDir
+		If doc.docDir FilteredCopyDir doc.docDir,absDocDir
 
 		Local intro$=absDocDir+"/index.bbdoc"
 		If FileType( intro )<>FILETYPE_FILE intro$=absDocDir+"/intro.bbdoc"
@@ -233,3 +233,33 @@ Type TDocStyle Extends TBBLinkResolver
 	Method EmitDecls( parent:TDocNode, kind$ ) Abstract
 	
 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()
 
-'		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
 
 		Local p$=ModuleSource( modid )
@@ -172,7 +171,7 @@ Function docBmxFile( filePath$,docPath$ )
 			bbdoc=""
 			inrem=True
 			
-		Else If id="endtype"
+		Else If id="endtype" Or id="endinterface"
 
 			If typePath
 				docPath=typePath
@@ -213,7 +212,7 @@ Function docBmxFile( filePath$,docPath$ )
 				Local path$
 
 				Select kind
-				Case "Type"
+				Case "Type", "Interface"
 					If Not docPath Throw "No doc path"
 					If typePath Throw "Type path already set"
 					typePath=docPath
@@ -246,7 +245,7 @@ Function docBmxFile( filePath$,docPath$ )
 				EndIf
 				
 				Local node:TDocNode=TDocNode.Create( id,path,kind )
-				
+
 				node.proto=proto
 				node.protoId = BuildProtoId(proto)
 				node.bbdoc=bbdoc
@@ -254,11 +253,22 @@ Function docBmxFile( filePath$,docPath$ )
 				node.about=about
 				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

+ 44 - 6
src/makemd/mdstyle.bmx

@@ -10,7 +10,7 @@ Type TRstStyle Extends TDocStyle
 
 		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 "id: " + doc.id.ToLower() 
 			Emit "title: " + doc.id
@@ -21,11 +21,11 @@ Type TRstStyle Extends TDocStyle
 		
 		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
 		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 ""
 		EndIf
@@ -37,6 +37,10 @@ Type TRstStyle Extends TDocStyle
 			Emit ""
 		End If
 		
+		If doc.kind = "Type" Or doc.kind = "Interface" Then
+			EmitExample(doc)
+		End If
+		
 	End Method
 	
 	Method EmitFooter()
@@ -67,7 +71,7 @@ Type TRstStyle Extends TDocStyle
 		
 			Emit "## "+kind+"s"
 		
-			Emit "| Type | Description |"
+			Emit "| " + kind + " | Description |"
 			Emit "|---|---|"
 			
 			For Local t:TDocNode=EachIn list
@@ -114,24 +118,58 @@ Type TRstStyle Extends TDocStyle
 			
 			'indent :- 1
 
+			EmitExample(t)
+			Rem
 			If t.example 
 				Emit "#### Example"
 				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")
 					Emit line
 				Next
 				Emit "```"
 
 			EndIf
+			End Rem
 
+			Emit "<br/>"
 
 			Emit ""
 			
 		Next
 	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