File: gen_gh_pages.lua

package info (click to toggle)
lua-sandbox 1.2.1-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,724 kB
  • ctags: 3,882
  • sloc: ansic: 23,586; makefile: 34
file content (163 lines) | stat: -rw-r--r-- 4,032 bytes parent folder | download
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
-- This Source Code Form is subject to the terms of the Mozilla Public
-- License, v. 2.0. If a copy of the MPL was not distributed with this
-- file, You can obtain one at http://mozilla.org/MPL/2.0/.

require "os"
require "io"
require "string"

local function output_css()
    local fh = assert(io.open("gh-pages/docs.css", "w"))
    fh:write([[
    html {
        height: 100%;
    }

    body {
        font-family:verdana, arial, sans-serif;
        font-size:small;
        width: 90%;
        background:white;
        margin-left: auto;
        margin-right: auto;
        height: 100%;
    }

    h1 {
        border-bottom:1px black solid;
    }

    h2 {
        border-bottom:1px gray solid;
    }

    h3 {
        border-bottom:1px lightgray solid;
    }

    h4 {
        border-bottom:1px black dotted;
    }

    h5 {
        border-bottom:1px gray dotted;
    }

    h6 {
        border-bottom:1px lightgray dotted;
    }

    #title {
        width:100%;
        font-size:large;
        font-weight: bold;
        font-style: normal;
        font-variant: normal;
        text-transform: uppercase;
        letter-spacing: .1em;
    }

    .menu {
        display:table-cell;
        font-size: small;
        font-weight: normal;
        font-style: normal;
        font-variant:  small-caps;
        color: #000000;
        height: 100%;
        padding-right: 10px;
        white-space: nowrap;
    }

    .menu ul{
        list-style-type: none;
        margin-left: 5px;
        margin-right: 0px;
        padding-left: 10px;
        padding-right: 0px;
    }

    .main-content {
        border-left:1px lightgray dotted;
        padding-left:10px;
        display:table-cell;
        width:100%;
    }

    code, pre.code, pre.sourceCode
    {
        background-color: whitesmoke;
    }
    ]])
    fh:close()
end


local function output_menu(before, after, paths, version)
    local fh = assert(io.open(before, "w"))
    fh:write(string.format('<div id="title">Lua Sandbox Library (%s)<hr/></div>\n', version))
    fh:write([[<div class="menu">
        <ul>
            <li><a href="/lua_sandbox/index.html">Overview</a></li>
        </ul>
        <ul>
            <li><a href="/lua_sandbox/sandbox.html">Generic Sandbox</a></li>
        </ul>
        <ul>
            <li><a href="/lua_sandbox/heka/index.html">Heka Sandbox</a></li>
        <ul>
            <li><a href="/lua_sandbox/heka/analysis.html">Analysis Interface</a></li>
            <li><a href="/lua_sandbox/heka/input.html">Input Interface</a></li>
            <li><a href="/lua_sandbox/heka/output.html">Output Interface</a></li>
        </ul>
        </ul>
        <ul>
           <li><a href="/lua_sandbox/cli/index.html">Command Line Tools</a></li>
        </ul>
        <ul>
            <li><a href="/lua_sandbox/doxygen/index.html">Source Documentation</a></li>
        </ul>
        <ul>
            <li><a href="/lua_sandbox_extensions/index.html">Sandbox Extensions</a></li>
        </ul>
    </div>
    <div class="main-content">
]])
    fh:close()

    fh = assert(io.open(after, "w"))
    fh:write("</div>\n")
    fh:close()
end


local function md_to_html(paths, version)
    local before = "/tmp/before.html"
    local after = "/tmp/after.html"
    output_menu(before, after, paths, version)

    local fh = assert(io.popen("find gh-pages -name \\*.md"))
    for line in fh:lines() do
        local css_path = "/lua_sandbox/docs.css"
        local cmd = string.format("pandoc --from markdown_github-hard_line_breaks --to html --standalone -B %s -A %s -c %s -o %s.html %s", before, after, css_path, line:sub(1, #line -3), line)
        local rv = os.execute(cmd)
        if rv ~= 0 then error(cmd) end
        os.remove(line)
    end
    fh:close()

    os.remove(before)
    os.remove(after)
end


local args = {...}
local function main()
    local rv = os.execute("rsync -rav docs/ gh-pages/")
    if rv ~= 0 then error"rsync" end
    output_css()
    local paths = {entries = {}}
    md_to_html(paths, args[1])
end

main()