From 5be5e842959e57f6a0d0c0d18ed18613678666a1 Mon Sep 17 00:00:00 2001 From: Karel Bilek Date: Fri, 9 Mar 2018 13:16:39 +0100 Subject: [PATCH] New templating --- bitcoin.go | 116 ------------------------------------------- end.inc | 5 -- mid.inc | 20 -------- script/bitcoin.go | 100 +++++++++++++++++++++++++++++++++++++ script/template.html | 75 ++++++++++++++++++++++++++++ start.inc | 37 -------------- 6 files changed, 175 insertions(+), 178 deletions(-) delete mode 100644 bitcoin.go delete mode 100644 end.inc delete mode 100644 mid.inc create mode 100644 script/bitcoin.go create mode 100644 script/template.html delete mode 100644 start.inc diff --git a/bitcoin.go b/bitcoin.go deleted file mode 100644 index cc02eda..0000000 --- a/bitcoin.go +++ /dev/null @@ -1,116 +0,0 @@ -package main - -import ( - "html" - "io/ioutil" - "os/exec" - "strings" -) - -type Command struct { - name string - description string -} - -type Group struct { - name string - commands []Command -} - -func main() { - first := run("help") - split := strings.Split(first, "\n") - - groups := make([]Group, 0) - commands := make([]Command, 0) - lastGroupName := "" - - for _, line := range split { - if len(line) > 0 { - if strings.HasPrefix(line, "== ") { - if len(commands) != 0 { - g := Group{ - name: lastGroupName, - commands: commands, - } - groups = append(groups, g) - commands = make([]Command, 0) - } - lastGroupName = line[3 : len(line)-3] - } else { - name := strings.Split(line, " ")[0] - desc := run("help", name) - desc = html.EscapeString(desc) - comm := Command{ - name: name, - description: desc, - } - commands = append(commands, comm) - } - } - } - - g := Group{ - name: lastGroupName, - commands: commands, - } - groups = append(groups, g) - - menuStr := "" - for _, group := range groups { - menuStr += ` -
-
- ` - menuStr += group.name - menuStr += ` -
-
` - - for _, command := range group.commands { - menuStr += ` - ` - menuStr += command.name - menuStr += `
` - } - - menuStr += ` -
-
-
` - - } - check(ioutil.WriteFile("tmp-menu.inc", []byte(menuStr), 0644)) - - runBash("cat start.inc index.inc mid.inc tmp-menu.inc end.inc | sed 's/XXX/Main page/' > index.html") - - for _, group := range groups { - for _, command := range group.commands { - check(ioutil.WriteFile("tmp.inc", []byte(command.description), 0644)) - runBash("cat start.inc tmp.inc mid.inc tmp-menu.inc end.inc | sed 's/XXX/" + command.name + "/' > " + command.name + ".html") - } - } - runBash("rm tmp.inc") - runBash("rm tmp-menu.inc") -} - -func check(e error) { - if e != nil { - panic(e) - } -} - -func runBash(cmd string) { - check(exec.Command("bash", "-c", cmd).Run()) -} - -func run(args ...string) string { - out, err := exec.Command("/home/g/dev/bitcoind/bitcoin-0.16.0/bin/bitcoin-cli", args...).CombinedOutput() - if err != nil { - panic(err) - } - - return string(out) -} diff --git a/end.inc b/end.inc deleted file mode 100644 index 2dba999..0000000 --- a/end.inc +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/mid.inc b/mid.inc deleted file mode 100644 index 300611b..0000000 --- a/mid.inc +++ /dev/null @@ -1,20 +0,0 @@ - -
-

- This is a website, created out of frustration with uncomplete and outdated Bitcoin Core RPC documentation online. -

-

- It was inspired by ChainQuery, which seems to be abandoned. These docs are even simplier, so they can be regenerated by anyone. -

-

- Made by @karel_3d; license of the docs is MIT (see bitcoin repo), license of the scripts and webpage is also MIT ((C) 2018 Karel Bilek) (github repo) -

-

- Bitcoin version: 0.16.0. -

-

- Note that the RPC is from a regtest node (for completeness), so it includes some additional calls that a regular node doesn't have. -

- -
- diff --git a/script/bitcoin.go b/script/bitcoin.go new file mode 100644 index 0000000..afbb1a4 --- /dev/null +++ b/script/bitcoin.go @@ -0,0 +1,100 @@ +package main + +import ( + "html/template" + "io" + "os" + "os/exec" + "strings" +) + +type Command struct { + Name string + Description string +} + +type Group struct { + Name string + Commands []Command +} + +type Document struct { + Command *Command + Groups []Group +} + +func main() { + first := run("help") + split := strings.Split(first, "\n") + + groups := make([]Group, 0) + commands := make([]Command, 0) + lastGroupName := "" + + for _, line := range split { + if len(line) > 0 { + if strings.HasPrefix(line, "== ") { + if len(commands) != 0 { + g := Group{ + Name: lastGroupName, + Commands: commands, + } + groups = append(groups, g) + commands = make([]Command, 0) + } + lastGroupName = line[3 : len(line)-3] + } else { + name := strings.Split(line, " ")[0] + desc := run("help", name) + comm := Command{ + Name: name, + Description: desc, + } + commands = append(commands, comm) + } + } + } + + g := Group{ + Name: lastGroupName, + Commands: commands, + } + groups = append(groups, g) + + tmpl := template.Must(template.ParseFiles("template.html")) + tmpl.Execute(open("../index.html"), Document{ + Command: nil, + Groups: groups, + }) + + for _, group := range groups { + for _, command := range group.Commands { + tmpl.Execute(open("../"+command.Name+".html"), Document{ + Command: &command, + Groups: groups, + }) + } + } +} + +func check(e error) { + if e != nil { + panic(e) + } +} + +func open(path string) io.Writer { + f, err := os.Create(path) + // not closing, program will close sooner + check(err) + return f +} + +func run(args ...string) string { + out, err := exec.Command("/home/g/dev/bitcoind/bitcoin-0.16.0/bin/bitcoin-cli", args...).CombinedOutput() + if err != nil { + panic(err) + } + + return string(out) +} diff --git a/script/template.html b/script/template.html new file mode 100644 index 0000000..af9095c --- /dev/null +++ b/script/template.html @@ -0,0 +1,75 @@ + + + + + + + + + {{if .Command}}{{.Command.Name}} - {{end}}Bitcoin Core RPC Docs + + + + + + + + + + +
+ +
+
+

{{if .Command}}{{.Command.Name}} - {{end}}Bitcoin RPC

+ {{if .Command}} +
{{.Command.Description}}
+
+ {{end}} +

+ This is a website, created out of frustration with uncomplete and outdated Bitcoin Core RPC documentation online. +

+

+ It was inspired by ChainQuery, which seems to be abandoned. These docs are even simplier, so they can be regenerated by anyone. +

+

+ Made by @karel_3d; license of the docs is MIT (see bitcoin repo), license of the scripts and webpage is also MIT ((C) 2018 Karel Bilek) (github repo) +

+

+ Bitcoin version: 0.16.0. +

+

+ Note that the RPC is from a regtest node (for completeness), so it includes some additional calls that a regular node doesn't have. +

+
+
+ {{range .Groups}} +
+
+ {{.Name}} +
+
+ {{range .Commands}} + {{.Name}} +
+ {{end}} +
+
+
+ {{end}} +
+
+
+ + diff --git a/start.inc b/start.inc deleted file mode 100644 index a2dd95e..0000000 --- a/start.inc +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - XXX - Bitcoin Core RPC Docs - - - - - - - - - - - -
- -
-
-

XXX - Bitcoin RPC

-