-
Notifications
You must be signed in to change notification settings - Fork 13
/
build.m
68 lines (48 loc) · 1.56 KB
/
build.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
(* ::Package:: *)
BeginPackage["M2MDBuild`"];
Needs["M2MD`"];
M2MDBild;
Begin["`Private`"];
$project = DirectoryName[$InputFileName /. "" :> NotebookFileName[]];
$projectName = FileBaseName @ $project;
M2MDBild[]:= buildMainPalette[];
needDirectory[dir_] := If[ DirectoryQ @ dir,dir, CreateDirectory[dir, CreateIntermediateDirectories -> True]];
buildMainPalette[]:=Module[{nb, deployDir}
, nb = mainPalette[]
; deployDir = needDirectory @ FileNameJoin[{$project, $projectName, "FrontEnd", "Palettes"}]
; NotebookSave[
nb
, FileNameJoin[{deployDir, $projectName <> ".nb"}]
]
; NotebookClose[nb]
];
mainPalette[]:= CreatePalette[
DynamicModule[{processing = False, path = None}
, With[{
progressBar = ProgressIndicator[Appearance -> "Indeterminate"]
, button = Button[
"Convert Notebook to Markdown"
, processing = True
; Needs["M2MD`"]
; path = If[!StringQ[path], $HomeDirectory, path]
; path = SystemDialogInput["FileSave", {path, {"Markdown files"->{"*.md"},"Text files"->{"*.md","*.txt"},"All files"->{"*"}}}]
; If[path != $Canceled,
SetDirectory@DirectoryName[path]
; MDExport[path,InputNotebook[]]]
; processing = False
, Method -> "Queued"
, FrameMargins -> 15
, ImageMargins -> 15
]
}
, PaneSelector[
{True -> progressBar, False -> button}
, Dynamic[processing + 0] (* XD https://mathematica.stackexchange.com/q/173940/5478*)
, Alignment -> {Center,Center}
]
]
]
, WindowTitle -> $projectName
];
End[];
EndPackage[];