Skip to content

Commit

Permalink
Merge pull request #24 from Anondo/v2; Closes #23
Browse files Browse the repository at this point in the history
Add feature inject css
  • Loading branch information
thedevsaddam committed Nov 19, 2019
2 parents 4f2879b + 9ce53c9 commit 148d561
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 15 deletions.
28 changes: 14 additions & 14 deletions assetfs_vfsdata.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<style media="screen">
@{{ .Assets.BootstrapCSS | css }}@
@{{ .Assets.StylesCSS | css }}@
@{{ if (ne .Assets.ExtraCSS "") }}@
@{{ .Assets.ExtraCSS | css }}@
@{{ end }}@
</style>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
Expand Down
3 changes: 3 additions & 0 deletions assets/markdown.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<!-- Bootstrap -->
<style media="screen">
@{{ .Assets.GithubMarkdownMinCSS | css }}@
@{{ if (ne .Assets.ExtraCSS "") }}@
@{{ .Assets.ExtraCSS | css }}@
@{{ end }}@
</style>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
Expand Down
1 change: 1 addition & 0 deletions collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ type (
JqueryJS string
ScriptsJS string
StylesCSS string
ExtraCSS string

IndexMarkdown string
MarkdownHTML string
Expand Down
3 changes: 3 additions & 0 deletions example.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
background-color: black;
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ require (
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 // indirect
github.com/shurcooL/sanitized_anchor_name v0.0.0-20170918181015-86672fcb3f95 // indirect
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd // indirect
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd
github.com/spf13/cobra v0.0.1
github.com/spf13/pflag v1.0.0 // indirect
github.com/tdewolff/minify v2.3.4+incompatible
github.com/tdewolff/parse v2.3.2+incompatible // indirect
github.com/tdewolff/test v1.0.3 // indirect
golang.org/x/tools v0.0.0-20191118222007-07fc4c7f2b98 // indirect
gopkg.in/russross/blackfriday.v2 v2.0.0
)
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,13 @@ github.com/tdewolff/parse v2.3.2+incompatible h1:hGsUwesFq56iB0T/CXFy58nU8OiCZ3d
github.com/tdewolff/parse v2.3.2+incompatible/go.mod h1:8oBwCsVmUkgHO8M5iCzSIDtpzXOT0WXX9cWhz+bIzJQ=
github.com/tdewolff/test v1.0.3 h1:oQqvxCCoUexB1bWZzvCzWG2VTqOIvWBV1JVg2OOFQi0=
github.com/tdewolff/test v1.0.3/go.mod h1:6DAvZliBAAnD7rhVgwaM7DE5/d9NMOAJ09SqYqeK4QE=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20191118222007-07fc4c7f2b98 h1:tZwpOHmF1OEL9wJGSgBALnhFg/8VKjQTtctCX51GLNI=
golang.org/x/tools v0.0.0-20191118222007-07fc4c7f2b98/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/russross/blackfriday.v2 v2.0.0 h1:+FlnIV8DSQnT7NZ43hcVKcdJdzZoeCmJj4Ql8gq5keA=
gopkg.in/russross/blackfriday.v2 v2.0.0/go.mod h1:6sSBNz/GtOm/pJTuh5UmBK2ZHfmnxGbl2NZg1UliSOI=
24 changes: 24 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package main

import (
"bytes"
"io/ioutil"
"log"
"os"
"text/template"
Expand All @@ -28,6 +29,8 @@ var (

githubLinkInc = make(map[string]int)

extraCSS = ""

cmd = &cobra.Command{
Use: "docgen",
Short: "Generate documentation from Postman JSON collection",
Expand Down Expand Up @@ -55,6 +58,10 @@ func init() {
MarkdownHTML: getData("markdown.html"),
GithubMarkdownMinCSS: getData("github-markdown.min.css"),
}

//Add flags
cmd.PersistentFlags().StringVarP(&extraCSS, "css", "c", "", "Inject a css file")

// register commands
cmd.AddCommand(versionCmd)
cmd.AddCommand(serveLive)
Expand Down Expand Up @@ -87,6 +94,15 @@ func readJSONtoHTML(str string) *bytes.Buffer {
if err != nil {
log.Fatal(err)
}

if extraCSS != "" {
ecFile, err := ioutil.ReadFile(extraCSS)
if err != nil {
log.Fatal("css file", err.Error())
}
assets.ExtraCSS = string(ecFile)
}

data := struct {
Assets Assets
Data Root
Expand Down Expand Up @@ -173,6 +189,14 @@ func readJSONtoMarkdownHTML(str string) *bytes.Buffer {
buf = readJSONtoMarkdown(file)
mdHTML := markdown(buf.String())

if extraCSS != "" {
ecFile, err := ioutil.ReadFile(extraCSS)
if err != nil {
log.Fatal("css file", err.Error())
}
assets.ExtraCSS = string(ecFile)
}

data := struct {
Assets Assets
Data Root
Expand Down

0 comments on commit 148d561

Please sign in to comment.