Commit bb81c5ce authored by Ma_124's avatar Ma_124

refactored name, url, desc to *Item

parent c434a7fc
Pipeline #46606410 (#38) failed with stages
in 1 minute
......@@ -27,13 +27,21 @@ type Ctx struct {
ApisCfg *ApisCfg
}
// An Item usually consists at least of a name, url and description
type Item struct {
Name string
Url string
RepoUrl string
Desc string
}
// The output file format
type OutputFileFormat struct {
// This should write the literal l to out
Literal func(out io.Writer, l string, ctx *Ctx)
// This should write the formatted item to out
Item func(out io.Writer, name, url, desc string, ctx *Ctx)
Item func(out io.Writer, item *Item, ctx *Ctx)
// This function is called to initialize the OFF and it's context. It can be nil.
Start func(out io.Writer, ctx *Ctx)
......
......@@ -25,13 +25,13 @@ func writeLiteralHtml(out io.Writer, l string, ctx *Ctx) {
out.Write([]byte(l))
}
func writeItemHtml(out io.Writer, name, url, desc string, ctx *Ctx) {
func writeItemHtml(out io.Writer, item *Item, ctx *Ctx) {
if ctx.OutFFCtx["writeTblHead"] == true {
ctx.OutFFCtx["writeTblHead"] = false
out.Write([]byte(`<table><thead><tr><th>Stars</th><th>Forks</th><th>Issues</th><th>Last Commit</th><th>Name</th><th>Desc</th></tr></thead><tbody>` + "\n"))
}
meta := FetchMeta(url, ctx)
meta := FetchMeta(item.Url, ctx)
out.Write([]byte("<tr><td>"))
out.Write([]byte(meta.Stars()))
......@@ -42,11 +42,11 @@ func writeItemHtml(out io.Writer, name, url, desc string, ctx *Ctx) {
out.Write([]byte("</td><td>"))
out.Write([]byte(meta.LastCommit()))
out.Write([]byte("</td><td><a href=\""))
out.Write([]byte(url))
out.Write([]byte(item.Url))
out.Write([]byte("\">"))
out.Write([]byte(name))
out.Write([]byte(item.Name))
out.Write([]byte("</a></td><td>"))
out.Write([]byte(desc))
out.Write([]byte(item.Desc))
out.Write([]byte("</td></tr>\n"))
ctx.OutFFCtx["prevWasItem"] = true
......
......@@ -21,9 +21,13 @@ func parseSimpleBulletMarkdownLine(sep string) func(out io.Writer, l string, out
if starIndx != -1 && (l[0] == ' ' || l[0] == '*') && strings.HasPrefix(l[starIndx:], "* [") {
afterNameI := strings.IndexByte(l, ']')
outFF.Item(out,
&Item{
l[starIndx+3:afterNameI],
l[afterNameI+2:strings.IndexByte(l[afterNameI+2:], ')')+afterNameI+2],
l[strings.Index(l, sep)+3:len(l)-1], ctx)
"",
l[strings.Index(l, sep)+3:len(l)-1],
},
ctx)
} else {
outFF.Literal(out, l, ctx)
}
......@@ -59,7 +63,7 @@ func writeLiteralMd(out io.Writer, l string, ctx *Ctx) {
out.Write([]byte(l))
}
func writeSimpleItemMd(out io.Writer, name, url, desc string, ctx *Ctx) {
func writeSimpleItemMd(out io.Writer, item *Item, ctx *Ctx) {
if ctx.OutFFCtx["writeTblHead"] == true {
ctx.OutFFCtx["writeTblHead"] = false
out.Write([]byte("\n| Name | Desc |\n"))
......@@ -67,22 +71,22 @@ func writeSimpleItemMd(out io.Writer, name, url, desc string, ctx *Ctx) {
}
out.Write([]byte("| ["))
out.Write([]byte(name))
out.Write([]byte(item.Name))
out.Write([]byte("]("))
out.Write([]byte(url))
out.Write([]byte(item.Url))
out.Write([]byte(") | "))
out.Write([]byte(desc))
out.Write([]byte(item.Desc))
out.Write([]byte(" |\n"))
}
func writeItemMd(out io.Writer, name, url, desc string, ctx *Ctx) {
func writeItemMd(out io.Writer, item *Item, ctx *Ctx) {
if ctx.OutFFCtx["writeTblHead"] == true {
ctx.OutFFCtx["writeTblHead"] = false
out.Write([]byte("\n| Stars | Forks | Issues | Last Commit | Name | Desc |\n"))
out.Write([]byte("|-------|-------|--------|-------------|------|------|\n"))
}
meta := FetchMeta(url, ctx)
meta := FetchMeta(item.Url, ctx)
out.Write([]byte("| "))
out.Write([]byte(meta.Stars()))
......@@ -93,11 +97,11 @@ func writeItemMd(out io.Writer, name, url, desc string, ctx *Ctx) {
out.Write([]byte(" | "))
out.Write([]byte(meta.LastCommit()))
out.Write([]byte(" | ["))
out.Write([]byte(name))
out.Write([]byte(item.Name))
out.Write([]byte("]("))
out.Write([]byte(url))
out.Write([]byte(item.Url))
out.Write([]byte(") | "))
out.Write([]byte(desc))
out.Write([]byte(item.Desc))
out.Write([]byte(" |\n"))
}
......@@ -132,10 +136,10 @@ func writeLiteralMdHtml(out io.Writer, l string, ctx *Ctx) {
writeLiteralMd(ctx.OutFFCtx["md-html--writer"].(io.Writer), l, ctx)
}
func writeSimpleItemMdHtml(out io.Writer, name, url, desc string, ctx *Ctx) {
writeSimpleItemMd(ctx.OutFFCtx["md-html--writer"].(io.Writer), name, url, desc, ctx)
func writeSimpleItemMdHtml(out io.Writer, item *Item, ctx *Ctx) {
writeSimpleItemMd(ctx.OutFFCtx["md-html--writer"].(io.Writer), item, ctx)
}
func writeItemMdHtml(out io.Writer, name, url, desc string, ctx *Ctx) {
writeItemMd(ctx.OutFFCtx["md-html--writer"].(io.Writer), name, url, desc, ctx)
func writeItemMdHtml(out io.Writer, item *Item, ctx *Ctx) {
writeItemMd(ctx.OutFFCtx["md-html--writer"].(io.Writer), item, ctx)
}
......@@ -4,6 +4,7 @@ import (
"fmt"
"io"
"strings"
"net/url"
)
// Parses the code according to this pattern:
......@@ -56,7 +57,12 @@ func parseTabSepLine(out io.Writer, l string, outFF *OutputFileFormat, ctx *Ctx)
panic(fmt.Sprintf("invalid line: %q", l))
}
outFF.Item(out, lps[0], lps[1], lps[2], ctx)
outFF.Item(out, &Item{
lps[0],
lps[1],
"",
lps[2],
}, ctx)
}
// Prints the code according to this pattern:
......@@ -89,11 +95,11 @@ func writeLiteralTabSep(out io.Writer, l string, ctx *Ctx) {
}
}
func writeItemTabSep(out io.Writer, name, url, desc string, ctx *Ctx) {
out.Write([]byte(name))
func writeItemTabSep(out io.Writer, item *Item, ctx *Ctx) {
out.Write([]byte(item.Name))
out.Write([]byte("\t"))
out.Write([]byte(url))
out.Write([]byte(item.Url))
out.Write([]byte("\t"))
out.Write([]byte(desc))
out.Write([]byte(item.Desc))
out.Write([]byte("\n"))
}
......@@ -24,11 +24,11 @@ func startTestAlpha(_ io.Writer, ctx *Ctx) {
ctx.OutFFCtx["test-alpha-last"] = ""
}
func testAlpha(_ io.Writer, name, _, _ string, ctx *Ctx) {
if ctx.OutFFCtx["test-alpha-last"].(string) >= name {
func testAlpha(_ io.Writer, item *Item, ctx *Ctx) {
if ctx.OutFFCtx["test-alpha-last"].(string) >= item.Name {
panic("not in alphabetical order or a duplicate")
}
ctx.OutFFCtx["test-alpha-last"] = name
ctx.OutFFCtx["test-alpha-last"] = item.Name
}
/*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment