From 059648a0d8204a7bd6ab9f9415c3c9fa56743a12 Mon Sep 17 00:00:00 2001 From: Eric Marchand Date: Sat, 11 Apr 2020 15:34:08 +0200 Subject: [PATCH] Button to see diff. Also display orphan documentation --- .../DatabaseMethods/onHostDatabaseEvent.4dm | 17 +- Project/Sources/Methods/Compiler_Methods.4dm | 6 +- .../Sources/Methods/Compiler_Variables.4dm | 2 +- Project/Sources/Methods/mark4down.4dm | 157 ++++++++++++------ README.md | 3 +- Resources/diff.html | 33 ++++ Resources/{editor.md.html => editor.html} | 0 Resources/{list.md.html => list.html} | 0 WebFolder/js/script.js | 32 ++++ 9 files changed, 185 insertions(+), 65 deletions(-) create mode 100755 Resources/diff.html rename Resources/{editor.md.html => editor.html} (100%) rename Resources/{list.md.html => list.html} (100%) diff --git a/Project/Sources/DatabaseMethods/onHostDatabaseEvent.4dm b/Project/Sources/DatabaseMethods/onHostDatabaseEvent.4dm index 06828ee..21c1f18 100644 --- a/Project/Sources/DatabaseMethods/onHostDatabaseEvent.4dm +++ b/Project/Sources/DatabaseMethods/onHostDatabaseEvent.4dm @@ -1,18 +1,11 @@ C_LONGINT:C283($1) Case of - : ($1=On before host database startup:K74:3) - : ($1=On after host database startup:K74:4) - - webServer:=WEB Server:C1674(Web database server:K73:30) - webServer.start() - + <>webServer:=WEB Server:C1674(Web database server:K73:30) + <>webServer.start() : ($1=On before host database exit:K74:5) - - If (webServer#Null:C1517) - webServer.stop() + If (<>webServer#Null:C1517) + <>webServer.stop() + <>webServer:=Null:C1517 End if - - : ($1=On after host database exit:K74:6) - End case \ No newline at end of file diff --git a/Project/Sources/Methods/Compiler_Methods.4dm b/Project/Sources/Methods/Compiler_Methods.4dm index 928a54a..c0e711b 100644 --- a/Project/Sources/Methods/Compiler_Methods.4dm +++ b/Project/Sources/Methods/Compiler_Methods.4dm @@ -3,4 +3,8 @@ C_BOOLEAN:C305(mark4down ;$0) C_OBJECT:C1216(mark4down ;$1) C_TEXT:C284(mark4down ;$2) C_TEXT:C284(mark4down ;$3) -C_OBJECT:C1216(mark4downWebServer ;$0) \ No newline at end of file +C_OBJECT:C1216(mark4downWebServer ;$0) + + //htmlEncode +C_TEXT:C284(htmlEncode ;$0) +C_TEXT:C284(htmlEncode ;$1) \ No newline at end of file diff --git a/Project/Sources/Methods/Compiler_Variables.4dm b/Project/Sources/Methods/Compiler_Variables.4dm index b497f87..8484e51 100644 --- a/Project/Sources/Methods/Compiler_Variables.4dm +++ b/Project/Sources/Methods/Compiler_Variables.4dm @@ -1,2 +1,2 @@ //%attributes = {"invisible":true} -C_OBJECT:C1216(webServer) \ No newline at end of file +C_OBJECT:C1216(<>webServer) \ No newline at end of file diff --git a/Project/Sources/Methods/mark4down.4dm b/Project/Sources/Methods/mark4down.4dm index 9eb2145..6d99917 100644 --- a/Project/Sources/Methods/mark4down.4dm +++ b/Project/Sources/Methods/mark4down.4dm @@ -21,50 +21,15 @@ C_TEXT:C284($text;$output;$relativePath;$emoji) $file:=$root.file($name) Case of - : ($file.extension=".md") - - Case of - : (Position:C15("GET";$method)=1) - - If (Not:C34($file.exists)) - $text:="# "+$file.name+"\n\nWrite your text here..." - $file.create() - $file.setText($text) - Else - $text:=$file.getText(106;Document with LF:K24:22) - End if - - $output:=Folder:C1567(fk resources folder:K87:11).file("editor.md.html").getText() - $output:=Replace string:C233($output;"Write your text here..";$text) - - WEB SEND TEXT:C677($output) - - : (Position:C15("POST";$method)=1) - - If (Not:C34($file.exists)) - $text:="# "+$name+"\n\nWrite your text here..." - $file.create() - End if - - $text:="" - WEB GET HTTP BODY:C814($text) - $file.setText($text;106;Document with LF:K24:22) - - WEB SEND TEXT:C677("ok") - - Else - - WEB SEND TEXT:C677("Unknown method") - - End case - - $0:=True:C214 - +/** +* Special commands +**/ : (Position:C15("mark4down/";$name)=1) $name:=Replace string:C233($name;"mark4down/";"") Case of + // List of markdown files : ($name="list") $text:="" For each ($file;$root.files(fk recursive:K87:7).sort("path")) @@ -84,28 +49,76 @@ Case of End if End for each - $output:=Folder:C1567(fk resources folder:K87:11).file("list.md.html").getText() + $output:=Folder:C1567(fk resources folder:K87:11).file("list.html").getText() $output:=Replace string:C233($output;"{{lists}}";$text) $output:=Replace string:C233($output;"{{title}}";"") WEB SEND TEXT:C677($output) + // List of missing markdown files : ($name="missing") + + C_BOOLEAN:C305($first) $text:="" - For each ($file;$root.folder("Project/Sources/Methods").files(fk recursive:K87:7).sort("path")) - If (($file.extension=".4dm") & (Position:C15("Compiler_";$file.name)#1) - - If (Not:C34($root.folder("Documentation/Methods").file($file.name+".md").exists)) + C_TEXT:C284($type) + $first:=True:C214 + For each ($type;New collection:C1472("Methods";"Classes")) + For each ($file;$root.folder("Project/Sources/"+$type).files(fk recursive:K87:7).sort("path")) + If (($file.extension=".4dm") & (Position:C15("Compiler_";$file.name)#1)) - $relativePath:=Replace string:C233($root.folder("Documentation/Methods").file($file.name+".md").path;$root.path;"") - $emoji:="⭕" - $text:=$text+""+$emoji+" "+$relativePath+"
" + If (Not:C34($root.folder("Documentation/"+$type).file($file.name+".md").exists)) + If ($first) + $text:=$text+"

Missing (undocumented code)


" + $first:=False:C215 + End if + $relativePath:=Replace string:C233($root.folder("Documentation/"+$type).file($file.name+".md").path;$root.path;"") + $emoji:="⭕" + $text:=$text+""+$emoji+" "+$relativePath+"
" + End if End if - End if + End for each End for each - $output:=Folder:C1567(fk resources folder:K87:11).file("list.md.html").getText() + // TODO orphan (ie. doc without code) + $first:=True:C214 + For each ($type;New collection:C1472("Methods";"Classes")) + For each ($file;$root.folder("Documentation/"+$type).files(fk recursive:K87:7).sort("path")) + If ($file.extension=".md") + + If (Not:C34($root.folder("Project/Sources/"+$type).file($file.name+".4dm").exists)) + + If ($first) + $text:=$text+"

Orphan (no code)


" + $first:=False:C215 + End if + $relativePath:=Replace string:C233($root.folder("Project/Sources/"+$type).file($file.name+".md").path;$root.path;"") + $emoji:="🚮" + $text:=$text+$emoji+" "+$relativePath+"
" + End if + End if + End for each + End for each + + $output:=Folder:C1567(fk resources folder:K87:11).file("list.html").getText() $output:=Replace string:C233($output;"{{lists}}";$text) - $output:=Replace string:C233($output;"{{title}}";"Missing") + $output:=Replace string:C233($output;"{{title}}";"Check files") + WEB SEND TEXT:C677($output) + + : (Position:C15("diff/";$name)=1) + + $name:=Substring:C12($name;Length:C16("diff/")+1) + If (Length:C16($name)>0) + $name:="'"+$name+"'" + End if + + C_TEXT:C284($in;$out) + SET ENVIRONMENT VARIABLE:C812("_4D_OPTION_CURRENT_DIRECTORY";$root.platformPath) + LAUNCH EXTERNAL PROCESS:C811("git diff-files --no-prefix --patch "+$name;$in;$out) + + + $output:=Folder:C1567(fk resources folder:K87:11).file("diff.html").getText() + $output:=Replace string:C233($output;"{{diff}}";$out) + $output:=Replace string:C233($output;"{{title}}";"Diff") + WEB SEND TEXT:C677($output) : ($name="github") @@ -130,6 +143,50 @@ Case of End case $0:=True:C214 +/** +* Edit markdown files +**/ + : ($file.extension=".md") + + Case of + // Load + : (Position:C15("GET";$method)=1) + + If (Not:C34($file.exists)) + $text:="# "+$file.name+"\n\nWrite your text here..." + $file.create() + $file.setText($text) + Else + $text:=$file.getText("UTF-8";Document with LF:K24:22) + End if + + $output:=Folder:C1567(fk resources folder:K87:11).file("editor.html").getText() + $output:=Replace string:C233($output;"Write your text here..";$text) + + WEB SEND TEXT:C677($output) + + // Save + : (Position:C15("POST";$method)=1) + + If (Not:C34($file.exists)) + $text:="# "+$name+"\n\nWrite your text here..." + $file.create() + End if + + $text:="" + WEB GET HTTP BODY:C814($text) + $file.setText($text;"UTF-8";Document with LF:K24:22) + + WEB SEND TEXT:C677("ok") + + Else + + WEB SEND TEXT:C677("Unknown method") + + End case + + $0:=True:C214 + Else $0:=False:C215 diff --git a/README.md b/README.md index 1a2a3a3..2b5c6a6 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,8 @@ Realtime markdown editor for your 4D database. * Edit documentation from your local machine or remote device such as iPad. * The file is saved automatically. New file too. -* See list of available or missing documentation files (toolbar buttons at the right) +* See list of available, missing or orphan documentation files (toolbar buttons at the right) +* Open github or see diff from last commit preview diff --git a/Resources/diff.html b/Resources/diff.html new file mode 100755 index 0000000..3792f96 --- /dev/null +++ b/Resources/diff.html @@ -0,0 +1,33 @@ + + + + Mark4: Realtime Markdown Browser + + + + + + + + +

{{title}}

+
{{diff}}
+ + + + + + + + + + \ No newline at end of file diff --git a/Resources/editor.md.html b/Resources/editor.html similarity index 100% rename from Resources/editor.md.html rename to Resources/editor.html diff --git a/Resources/list.md.html b/Resources/list.html similarity index 100% rename from Resources/list.md.html rename to Resources/list.html diff --git a/WebFolder/js/script.js b/WebFolder/js/script.js index bdaf16f..fe762c7 100644 --- a/WebFolder/js/script.js +++ b/WebFolder/js/script.js @@ -41,6 +41,27 @@ window.onload = function() { id: "download-button" } ); + simplemde.toolbar.push( + { + name: "diff", + action: function customFunction(){ + var fileName = window.location.pathname; + if (fileName == "/") { + fileName="/README.md" + } + // window.open('/mark4down/diff'+fileName, '_blank'); + + var previewPanel = document.getElementsByClassName("editor-preview-side")[0]; + previewPanel.classList.add("editor-preview-active-side"); + previewPanel.innerHTML=''; + + }, + className: "fas fa-exchange-alt", + title: "diff", + id: "diff-button" + } + ); + simplemde.toolbar.push("|"); simplemde.toolbar.push( { name: "list", @@ -82,6 +103,17 @@ window.onload = function() { id: "github-button" } ); + simplemde.toolbar.push( + { + name: "fulldiff", + action: function customFunction(){ + window.open('/mark4down/diff/', '_blank'); + }, + className: "fab fa-stack-exchange", + title: "fulldiff", + id: "fulldiff-button" + } + ); var tools = simplemde.toolbar; simplemde.toTextArea();