Commit 305e5aae authored by Ma_124's avatar Ma_124

added markdown-html and markdown-simple-html OFF.Start() and OFF.End()

parent 17d4a9c3
Pipeline #45937267 failed with stages
in 44 seconds
......@@ -2,12 +2,13 @@ package main
import (
flagpkg "flag"
"os"
"fmt"
"github.com/pelletier/go-toml"
"gitlab.com/Ma_124/awesome-framework"
"io/ioutil"
"os"
"os/exec"
"strconv"
"gitlab.com/Ma_124/awesome-framework"
"strings"
"sync"
)
......@@ -36,6 +37,8 @@ func main() {
mainCompile()
case "gen":
mainGen()
case "internal":
mainInternal()
default:
fmt.Println("awesome" + os.Args[1] + ": unknown command\nRun 'awesome help' for usage.`")
os.Exit(1)
......@@ -60,29 +63,29 @@ Go to <https://ma124.js.org/rgl/awesome-framework> for more information.`)
}
type Cfg struct {
Inputs []*InputCfg `toml:"inputs"`
Inputs []*InputCfg `toml:"inputs"`
Outputs []*OutputCfg `toml:"outputs"`
Lists []*ListCfg `toml:"lists"`
}
type ListCfg struct {
InputName string `toml:"input-link"`
Input *InputCfg `toml:"input"`
InputName string `toml:"input-link"`
Input *InputCfg `toml:"input"`
OutputName string `toml:"output-link"`
Output *OutputCfg `toml:"output"`
OutputName string `toml:"output-link"`
Output *OutputCfg `toml:"output"`
}
type InputCfg struct {
Name string `toml:"name"`
File string `toml:"file"`
Name string `toml:"name"`
File string `toml:"file"`
FileFormat string `toml:"format"`
}
type OutputCfg struct {
Name string `toml:"name"`
File string `toml:"file"`
Name string `toml:"name"`
File string `toml:"file"`
FileFormat string `toml:"format"`
}
......@@ -163,7 +166,7 @@ func mainCompile() {
failed = true
fmt.Println("A list needs an input. ('input-link: ' / '[input]' missing) [" + strconv.Itoa(i) + "]")
}
if list.Output != nil && list.OutputName!= "" {
if list.Output != nil && list.OutputName != "" {
failed = true
fmt.Println("A list can only have one output. ('output-link: ' and '[output]' specified) [" + strconv.Itoa(i) + "]")
}
......@@ -251,7 +254,7 @@ func mainCompile() {
}
awesomefw.CompileFile(list.Input.File, outF, iff, off, &awesomefw.ApisCfg{
&awesomefw.ApiCfg{ *ghAccessToken, *ghMaxRequests },
&awesomefw.ApiCfg{*ghAccessToken, *ghMaxRequests},
})
}()
}
......@@ -266,6 +269,10 @@ func getInFFByName(name string) *awesomefw.InputFileFormat {
case "md":
fallthrough
case "markdown":
fallthrough
case "md-simple":
fallthrough
case "markdown-simple":
return awesomefw.IFFMarkdown
}
......@@ -274,6 +281,14 @@ func getInFFByName(name string) *awesomefw.InputFileFormat {
func getOutFFByName(name string) *awesomefw.OutputFileFormat {
switch strings.ToLower(name) {
case "md-simple-html":
fallthrough
case "markdown-simple-html":
return awesomefw.OFFSimpleMarkdownHtml
case "md-html":
fallthrough
case "markdown-html":
return awesomefw.OFFMarkdownHtml
case "md":
fallthrough
case "markdown":
......@@ -301,20 +316,40 @@ func mainGen() {
if err != nil {
panic(err)
}
defer f.Close()
f.Write([]byte(`
image: golang:latest
stages:
- build
compile:
stage: build
script:
- go get gitlab.com/Ma_124/awesome-framework
- awesome internal gitlab
pages:
stage: deploy
script:
- go get gitlab.com/Ma_124/awesome-framework/cmd/awesome
- $GOPATH/bin/awesome internal --gitlabci
artifacts:
paths:
- public
only:
- master
`[1:]))
case "travis":
default:
fmt.Println("Unknown name: " + os.Args[2])
}
}
func mainInternal() {
flag := flagpkg.NewFlagSet("awesome internal", flagpkg.ExitOnError)
gitlab := flag.Bool("gitlabci", false, "Only for internal use.")
flag.Parse(os.Args[2:])
if *gitlab {
_, err := os.Stat("build.awesome.sh")
if err == nil {
cmd := exec.Command("bash build.awesome.sh")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Run()
}
}
}
......@@ -16,12 +16,14 @@ type Ctx struct {
InFFCtx map[string]interface{}
OutFFCtx map[string]interface{}
fetchMetaGhRequests int
ApisCfg *ApisCfg
ApisCfg *ApisCfg
}
type OutputFileFormat struct {
Literal func(out io.Writer, l string, ctx *Ctx)
Item func(out io.Writer, name, url, desc string, ctx *Ctx)
Start func(out io.Writer, ctx *Ctx)
End func(out io.Writer, ctx *Ctx)
}
type ApisCfg struct {
......@@ -58,7 +60,11 @@ func Compile(in io.Reader, size int, out io.Writer, inFF *InputFileFormat, outFF
InLiteral: false,
InFFCtx: make(map[string]interface{}),
OutFFCtx: make(map[string]interface{}),
ApisCfg: apis,
ApisCfg: apis,
}
if outFF.Start != nil {
outFF.Start(out, ctx)
}
eofReached := false
......@@ -81,4 +87,8 @@ func Compile(in io.Reader, size int, out io.Writer, inFF *InputFileFormat, outFF
offset += len(l)
pb.Set(offset)
}
if outFF.End != nil {
outFF.End(out, ctx)
}
}
package awesomefw
import (
"testing"
"github.com/stretchr/testify/assert"
"strings"
"testing"
)
var awesomeAwesomeShortOut = `
......
package awesomefw
import (
"fmt"
"github.com/stretchr/testify/assert"
"gopkg.in/russross/blackfriday.v2"
"strings"
"testing"
)
......@@ -95,3 +97,51 @@ A curated list of awesome curated lists of many topics.
For contributing, [open an issue](https://github.com/emijrp/awesome-awesome/issues) and/or a [pull request](https://github.com/emijrp/awesome-awesome/pulls). Above there are some ideas for missing lists, be bold!
`[1:], out.String()))
}
func TestCompile_TabSepSimpleMarkdownHtml(t *testing.T) {
out := &strings.Builder{}
Compile(strings.NewReader(awesomeAwesomeShortInp), len(awesomeAwesomeShortInp), out, IFFTabSep, OFFSimpleMarkdownHtml, &ApisCfg{&ApiCfg{}})
t.Log(assert.Equal(t, string(blackfriday.Run([]byte(`
# Awesome Awesome
A curated list of awesome curated lists of many topics.
- [Awesome Awesome](#awesome-awesome)
- [Computer management](#computer-management)
## Computer management
| Name | Desc |
|------|------|
| [awesome-scalability](https://github.com/binhnguyennus/awesome-scalability) | An up-to-date and curated reading list for designing high scalability, high availability, high stabilityback-end systems. |
| [awesome-shell](https://github.com/alebcay/awesome-shell) | Command-line frameworks, toolkits, guides and gizmos. |
| [awesome-sysadmin](https://github.com/kahun/awesome-sysadmin) | Backups, configuration management, DNS, IMAP/POP3, LDAP, monitoring, SSH, statistics, troubleshooting, virtualization, VPN and more. |
For contributing, [open an issue](https://github.com/emijrp/awesome-awesome/issues) and/or a [pull request](https://github.com/emijrp/awesome-awesome/pulls). Above there are some ideas for missing lists, be bold!
`[1:]))), out.String()))
}
func TestCompile_TabSepMarkdownHtml(t *testing.T) {
out := &strings.Builder{}
Compile(strings.NewReader(awesomeAwesomeShortInp), len(awesomeAwesomeShortInp), out, IFFTabSep, OFFMarkdownHtml, &ApisCfg{&ApiCfg{}})
t.Log(assert.Equal(t, string(blackfriday.Run([]byte(`
# Awesome Awesome
A curated list of awesome curated lists of many topics.
- [Awesome Awesome](#awesome-awesome)
- [Computer management](#computer-management)
## Computer management
| Stars | Forks | Issues | Last Commit | Name | Desc |
|-------|-------|--------|-------------|------|------|
| 7654 | 32 | 1 | 2019-01-20 | [awesome-scalability](https://github.com/binhnguyennus/awesome-scalability) | An up-to-date and curated reading list for designing high scalability, high availability, high stabilityback-end systems. |
| 7654 | 32 | 1 | 2019-01-20 | [awesome-shell](https://github.com/alebcay/awesome-shell) | Command-line frameworks, toolkits, guides and gizmos. |
| 7654 | 32 | 1 | 2019-01-20 | [awesome-sysadmin](https://github.com/kahun/awesome-sysadmin) | Backups, configuration management, DNS, IMAP/POP3, LDAP, monitoring, SSH, statistics, troubleshooting, virtualization, VPN and more. |
For contributing, [open an issue](https://github.com/emijrp/awesome-awesome/issues) and/or a [pull request](https://github.com/emijrp/awesome-awesome/pulls). Above there are some ideas for missing lists, be bold!
`[1:]))), out.String()))
}
package awesomefw
import (
"gopkg.in/russross/blackfriday.v2"
"io"
"strings"
)
......@@ -20,8 +21,8 @@ func parseSimpleBulletMarkdownLine(out io.Writer, l string, outFF *OutputFileFor
}
}
var OFFSimpleMarkdown = &OutputFileFormat{writeLiteralMd, writeSimpleItemMd}
var OFFMarkdown = &OutputFileFormat{writeLiteralMd, writeItemMd}
var OFFSimpleMarkdown = &OutputFileFormat{writeLiteralMd, writeSimpleItemMd, nil, nil}
var OFFMarkdown = &OutputFileFormat{writeLiteralMd, writeItemMd, nil, nil}
func writeLiteralMd(out io.Writer, l string, ctx *Ctx) {
ctx.OutFFCtx["writeTblHead"] = true
......@@ -69,3 +70,26 @@ func writeItemMd(out io.Writer, name, url, desc string, ctx *Ctx) {
out.Write([]byte(desc))
out.Write([]byte(" |\n"))
}
var OFFSimpleMarkdownHtml = &OutputFileFormat{writeLiteralMdHtml, writeSimpleItemMdHtml, startMdHtml, endMdHtml}
var OFFMarkdownHtml = &OutputFileFormat{writeLiteralMdHtml, writeItemMdHtml, startMdHtml, endMdHtml}
func startMdHtml(out io.Writer, ctx *Ctx) {
ctx.OutFFCtx["md-html--writer"] = &strings.Builder{}
}
func endMdHtml(out io.Writer, ctx *Ctx) {
out.Write(blackfriday.Run([]byte(ctx.OutFFCtx["md-html--writer"].(*strings.Builder).String())))
}
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 writeItemMdHtml(out io.Writer, name, url, desc string, ctx *Ctx) {
writeItemMd(ctx.OutFFCtx["md-html--writer"].(io.Writer), name, url, desc, ctx)
}
......@@ -43,7 +43,7 @@ func parseTabSepLine(out io.Writer, l string, outFF *OutputFileFormat, ctx *Ctx)
outFF.Item(out, lps[0], lps[1], lps[2], ctx)
}
var OFFTabSep = &OutputFileFormat{writeLiteralTabSep, writeItemTabSep}
var OFFTabSep = &OutputFileFormat{writeLiteralTabSep, writeItemTabSep, nil, nil}
func writeLiteralTabSep(out io.Writer, l string, ctx *Ctx) {
// TODO literal blocks
......
......@@ -4,4 +4,4 @@ package awesomefw
* duplicates
* format?
* order
*/
\ No newline at end of file
*/
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