aboutsummaryrefslogtreecommitdiffhomepage
path: root/sundry/misc/util/d/tools/spine_scaffold.d
blob: dbcc85736adbddc94a3622a368562766c544aa42 (plain)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env rund
void main( string[] args ) {
  import std;
  if (args.length > 1) {
    string base_fn_path = args[1].expandTilde;
    string base_fn = base_fn_path.baseName;
    string sst_fn = base_fn ~ ".sst";
    string txt_for_pod_manifest = format(q"┃doc:
  filename: %s
  language: en
┃",
      sst_fn
    );
    string txt_for_sisu_document_make = format(q"┃
┃",
    );
    string txt_for_document_scaffold = format(q"┃# SiSU 8.0

title: "As Yet Unnamed"

creator:
  author: "Annon, Unnamed"

:A~ @title @author

1~ Summary

To get you started, the first paragraph following a section or chapter heading.

Spine / SiSU documents minimum requirements:

_* a header containing document metadata that must at least contain the fields Title and Creator Author.

_* text body, identified as starting by the A~ marker at the start of a line, followed  by at least one level 1~ section heading with the text that follows it.~{ the document provided here would be a valid Spine document, and this text contained within the tilde and curly braces delimiters would be the first footnote/endnote }~

To generate this document to have html and epub output for example you would run:

``` code
spine --html --epub --output=/tmp/spine-sample-output %s
```

1~ Conclusion

This sample pod is provided to get you started.

Good luck and good speed.
┃",
      base_fn_path
    );
    if (!exists(base_fn_path)) {
      try {
        base_fn_path.mkdirRecurse;
      } catch (ErrnoException ex) {
        writeln(ex);
      }
      if (exists(args[1].expandTilde)) {
        try {
          base_fn_path.buildPath("conf").mkdirRecurse;
        } catch (ErrnoException ex) {
          writeln(ex);
        }
        try {
          base_fn_path.buildPath("media/text/en").mkdirRecurse;
        } catch (ErrnoException ex) {
          writeln(ex);
        }
        {
          // 1 // create/write pod.manifest
          string fn = base_fn_path.buildPath("pod.manifest");
          File(fn, "w").writeln(txt_for_pod_manifest);
          string tell = format(q"┃OK - pod.manifest (yaml file containing filename and languages)
  %s
%s
┃",
            fn,
            txt_for_pod_manifest.strip
          );
          writeln(tell);
        }
        if (exists(base_fn_path.buildPath("conf"))) {
          // 2 // create/write conf/sisu_document_make
          string fn = base_fn_path.buildPath("conf/sisu_document_make");
          File(fn, "w").writeln(txt_for_sisu_document_make);
          // auto f = File(fn, "w");
          // foreach (line; content_array) {
          //   f.writeln(line);
          // }
          string tell = format(q"┃OK - sisu_document_make
  %s
┃",
            fn
          );
          writeln(tell);
        }
        if (exists(base_fn_path.buildPath("media/text/en"))) {
          // 3 // create/write media/text/[lang code]/[filename].sst
          string fn = base_fn_path.buildPath("media/text/en/" ~ sst_fn);
          File(fn, "w").writeln(txt_for_document_scaffold);
          // auto f = File(fn, "w");
          // foreach (line; content_array) {
          //   f.writeln(line);
          // }
          string tell = format(q"┃OK - .sst [document text content]
  %s
  - To start editing document (spine pod content):
      ${EDITOR} %s
  - To generate this document to have html and epub output for example you would run:
      spine --html --epub --output=/tmp/spine-sample-output %s
┃",
            fn,
            fn,
            base_fn_path
          );
          writeln(tell);
        }
      }
      /+
        pod/[filename]

          ├── conf
          │   └── sisu_document_make
          ├── media
          │   └── text
          │       └── en
          │           └── [filename].charles_stross.sst
          └── pod.manifest
      +/
    } else {
      writeln("requested output pod name with path already exists:\n  ", args[1].expandTilde);
    }
  } else {
    writeln( "please provide directory path to operate on, e.g.\n  spine_scaffold.d ./pod/filetest" );
  }
}