Skip to content

Commit

Permalink
Button to see diff. Also display orphan documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
e-marchand committed Apr 11, 2020
1 parent e257b6a commit 059648a
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 65 deletions.
17 changes: 5 additions & 12 deletions Project/Sources/DatabaseMethods/onHostDatabaseEvent.4dm
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion Project/Sources/Methods/Compiler_Methods.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
C_OBJECT:C1216(mark4downWebServer ;$0)

//htmlEncode
C_TEXT:C284(htmlEncode ;$0)
C_TEXT:C284(htmlEncode ;$1)
2 changes: 1 addition & 1 deletion Project/Sources/Methods/Compiler_Variables.4dm
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
//%attributes = {"invisible":true}
C_OBJECT:C1216(webServer)
C_OBJECT:C1216(<>webServer)
157 changes: 107 additions & 50 deletions Project/Sources/Methods/mark4down.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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+"<a href=\"/"+$relativePath+"\">"+$emoji+" "+$relativePath+"</a><br/>"
If (Not:C34($root.folder("Documentation/"+$type).file($file.name+".md").exists))
If ($first)
$text:=$text+"<h2>Missing (undocumented code)</h2><br/>"
$first:=False:C215
End if
$relativePath:=Replace string:C233($root.folder("Documentation/"+$type).file($file.name+".md").path;$root.path;"")
$emoji:="⭕"
$text:=$text+"<a href=\"/"+$relativePath+"\">"+$emoji+" "+$relativePath+"</a><br/>"
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+"<h2>Orphan (no code)</h2><br/>"
$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+"<br/>"
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")
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<img src="Documentation/preview.png" alt="preview"
title="preview" width="600" />
Expand Down
33 changes: 33 additions & 0 deletions Resources/diff.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<head>
<title>Mark4: Realtime Markdown Browser</title>
<link href="/style/bootstrap.min.css" rel="stylesheet">
<link href="/style/atom-one-dark.css" rel="stylesheet">
<link href="/style/style.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/diff2html/bundles/css/diff2html.min.css" />
<base target="_parent">
</head>

<body class="container-fluid">
<h1>{{title}}</h1>
<div class="full-height" id="destination-elem-id">{{diff}}</div>
<script src="/js/highlight.pack.js"></script>
<script src="/js/highlight.4d.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/diff2html/bundles/js/diff2html.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/diff2html/bundles/js/diff2html-ui.min.js"></script>

<script>
document.addEventListener('DOMContentLoaded', () => {
const targetElement = document.getElementById('destination-elem-id');
const configuration = { drawFileList: true, matching: 'lines' };

const diffString = targetElement.innerHTML;
const diff2htmlUi = new Diff2HtmlUI(targetElement, diffString, configuration);
diff2htmlUi.draw();
});
</script>
</body>
</html><!-- CSS -->

<!-- Javascripts -->
File renamed without changes.
File renamed without changes.
32 changes: 32 additions & 0 deletions WebFolder/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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='<object type="text/html" style="width: 100%; height: 100%" data="/mark4down/diff'+fileName+'" ></object>';

},
className: "fas fa-exchange-alt",
title: "diff",
id: "diff-button"
}
);
simplemde.toolbar.push("|");
simplemde.toolbar.push(
{
name: "list",
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 059648a

Please sign in to comment.