Best K6 code snippet using html.Min
resource_chain_test.go
Source:resource_chain_test.go
...250{{ $scss := resources.Get "scss/styles2.scss" | toCSS }}251{{ $sass := resources.Get "sass/styles3.sass" | toCSS }}252{{ $scssCustomTarget := resources.Get "scss/styles2.scss" | toCSS (dict "targetPath" "styles/main.css") }}253{{ $scssCustomTargetString := resources.Get "scss/styles2.scss" | toCSS "styles/main.css" }}254{{ $scssMin := resources.Get "scss/styles2.scss" | toCSS | minify }}255{{ $scssFromTempl := ".{{ .Kind }} { color: blue; }" | resources.FromString "kindofblue.templ" | resources.ExecuteAsTemplate "kindofblue.scss" . | toCSS (dict "targetPath" "styles/templ.css") | minify }}256{{ $bundle1 := slice $scssFromTempl $scssMin | resources.Concat "styles/bundle1.css" }}257T1: Len Content: {{ len $scss.Content }}|RelPermalink: {{ $scss.RelPermalink }}|Permalink: {{ $scss.Permalink }}|MediaType: {{ $scss.MediaType.Type }}258T2: Content: {{ $scssMin.Content }}|RelPermalink: {{ $scssMin.RelPermalink }}259T3: Content: {{ len $scssCustomTarget.Content }}|RelPermalink: {{ $scssCustomTarget.RelPermalink }}|MediaType: {{ $scssCustomTarget.MediaType.Type }}260T4: Content: {{ len $scssCustomTargetString.Content }}|RelPermalink: {{ $scssCustomTargetString.RelPermalink }}|MediaType: {{ $scssCustomTargetString.MediaType.Type }}261T5: Content: {{ $sass.Content }}|T5 RelPermalink: {{ $sass.RelPermalink }}|262T6: {{ $bundle1.Permalink }}263`)264 }, func(b *sitesBuilder) {265 b.AssertFileContent("public/index.html", `T1: Len Content: 24|RelPermalink: /scss/styles2.css|Permalink: http://example.com/scss/styles2.css|MediaType: text/css`)266 b.AssertFileContent("public/index.html", `T2: Content: body{color:#333}|RelPermalink: /scss/styles2.min.css`)267 b.AssertFileContent("public/index.html", `T3: Content: 24|RelPermalink: /styles/main.css|MediaType: text/css`)268 b.AssertFileContent("public/index.html", `T4: Content: 24|RelPermalink: /styles/main.css|MediaType: text/css`)269 b.AssertFileContent("public/index.html", `T5: Content: .content-navigation {`)270 b.AssertFileContent("public/index.html", `T5 RelPermalink: /sass/styles3.css|`)271 b.AssertFileContent("public/index.html", `T6: http://example.com/styles/bundle1.css`)272 c.Assert(b.CheckExists("public/styles/templ.min.css"), qt.Equals, false)273 b.AssertFileContent("public/styles/bundle1.css", `.home{color:blue}body{color:#333}`)274 }},275 {"minify", func() bool { return true }, func(b *sitesBuilder) {276 b.WithConfigFile("toml", `[minify]277 [minify.tdewolff]278 [minify.tdewolff.html]279 keepWhitespace = false280`)281 b.WithTemplates("home.html", fmt.Sprintf(`282Min CSS: {{ ( resources.Get "css/styles1.css" | minify ).Content }}283Min CSS Remote: {{ ( resources.GetRemote "%[1]s/css/styles1.css" | minify ).Content }}284Min JS: {{ ( resources.Get "js/script1.js" | resources.Minify ).Content | safeJS }}285Min JS Remote: {{ ( resources.GetRemote "%[1]s/js/script1.js" | minify ).Content }}286Min JSON: {{ ( resources.Get "mydata/json1.json" | resources.Minify ).Content | safeHTML }}287Min JSON Remote: {{ ( resources.GetRemote "%[1]s/mydata/json1.json" | resources.Minify ).Content | safeHTML }}288Min XML: {{ ( resources.Get "mydata/xml1.xml" | resources.Minify ).Content | safeHTML }}289Min XML Remote: {{ ( resources.GetRemote "%[1]s/mydata/xml1.xml" | resources.Minify ).Content | safeHTML }}290Min SVG: {{ ( resources.Get "mydata/svg1.svg" | resources.Minify ).Content | safeHTML }}291Min SVG Remote: {{ ( resources.GetRemote "%[1]s/mydata/svg1.svg" | resources.Minify ).Content | safeHTML }}292Min SVG again: {{ ( resources.Get "mydata/svg1.svg" | resources.Minify ).Content | safeHTML }}293Min HTML: {{ ( resources.Get "mydata/html1.html" | resources.Minify ).Content | safeHTML }}294Min HTML Remote: {{ ( resources.GetRemote "%[1]s/mydata/html1.html" | resources.Minify ).Content | safeHTML }}295`, ts.URL))296 }, func(b *sitesBuilder) {297 b.AssertFileContent("public/index.html", `Min CSS: h1{font-style:bold}`)298 b.AssertFileContent("public/index.html", `Min CSS Remote: h1{font-style:bold}`)299 b.AssertFileContent("public/index.html", `Min JS: var x=5;document.getElementById("demo").innerHTML=x*10`)300 b.AssertFileContent("public/index.html", `Min JS Remote: var x=5;document.getElementById("demo").innerHTML=x*10`)301 b.AssertFileContent("public/index.html", `Min JSON: {"employees":[{"firstName":"John","lastName":"Doe"},{"firstName":"Anna","lastName":"Smith"},{"firstName":"Peter","lastName":"Jones"}]}`)302 b.AssertFileContent("public/index.html", `Min JSON Remote: {"employees":[{"firstName":"John","lastName":"Doe"},{"firstName":"Anna","lastName":"Smith"},{"firstName":"Peter","lastName":"Jones"}]}`)303 b.AssertFileContent("public/index.html", `Min XML: <hello><world>Hugo Rocks!</<world></hello>`)304 b.AssertFileContent("public/index.html", `Min XML Remote: <hello><world>Hugo Rocks!</<world></hello>`)305 b.AssertFileContent("public/index.html", `Min SVG: <svg height="100" width="100"><path d="M1e2 1e2H3e2 2e2z"/></svg>`)306 b.AssertFileContent("public/index.html", `Min SVG Remote: <svg height="100" width="100"><path d="M1e2 1e2H3e2 2e2z"/></svg>`)307 b.AssertFileContent("public/index.html", `Min SVG again: <svg height="100" width="100"><path d="M1e2 1e2H3e2 2e2z"/></svg>`)308 b.AssertFileContent("public/index.html", `Min HTML: <html><a href=#>Cool</a></html>`)309 b.AssertFileContent("public/index.html", `Min HTML Remote: <html><a href=#>Cool</a></html>`)310 }},311 {"remote", func() bool { return true }, func(b *sitesBuilder) {312 b.WithTemplates("home.html", fmt.Sprintf(`313{{$js := resources.GetRemote "%[1]s/js/script1.js" }}314Remote Filename: {{ $js.RelPermalink }}315{{$svg := resources.GetRemote "%[1]s/mydata/svg1.svg" }}316Remote Content-Disposition: {{ $svg.RelPermalink }}317{{$auth := resources.GetRemote "%[1]s/authenticated/" (dict "headers" (dict "Authorization" "Bearer abcd")) }}318Remote Authorization: {{ $auth.Content }}319{{$post := resources.GetRemote "%[1]s/post" (dict "method" "post" "body" "Request body") }}320Remote POST: {{ $post.Content }}321`, ts.URL))322 }, func(b *sitesBuilder) {323 b.AssertFileContent("public/index.html", `Remote Filename: /script1_`)324 b.AssertFileContent("public/index.html", `Remote Content-Disposition: /image_`)325 b.AssertFileContent("public/index.html", `Remote Authorization: Welcome`)326 b.AssertFileContent("public/index.html", `Remote POST: Request body`)327 }},328 {"concat", func() bool { return true }, func(b *sitesBuilder) {329 b.WithTemplates("home.html", `330{{ $a := "A" | resources.FromString "a.txt"}}331{{ $b := "B" | resources.FromString "b.txt"}}332{{ $c := "C" | resources.FromString "c.txt"}}333{{ $textResources := .Resources.Match "*.txt" }}334{{ $combined := slice $a $b $c | resources.Concat "bundle/concat.txt" }}335T1: Content: {{ $combined.Content }}|RelPermalink: {{ $combined.RelPermalink }}|Permalink: {{ $combined.Permalink }}|MediaType: {{ $combined.MediaType.Type }}336{{ with $textResources }}337{{ $combinedText := . | resources.Concat "bundle/concattxt.txt" }}338T2: Content: {{ $combinedText.Content }}|{{ $combinedText.RelPermalink }}339{{ end }}340{{/* https://github.com/gohugoio/hugo/issues/5269 */}}341{{ $css := "body { color: blue; }" | resources.FromString "styles.css" }}342{{ $minified := resources.Get "css/styles1.css" | minify }}343{{ slice $css $minified | resources.Concat "bundle/mixed.css" }} 344{{/* https://github.com/gohugoio/hugo/issues/5403 */}}345{{ $d := "function D {} // A comment" | resources.FromString "d.js"}}346{{ $e := "(function E {})" | resources.FromString "e.js"}}347{{ $f := "(function F {})()" | resources.FromString "f.js"}}348{{ $jsResources := .Resources.Match "*.js" }}349{{ $combinedJs := slice $d $e $f | resources.Concat "bundle/concatjs.js" }}350T3: Content: {{ $combinedJs.Content }}|{{ $combinedJs.RelPermalink }}351`)352 }, func(b *sitesBuilder) {353 b.AssertFileContent("public/index.html", `T1: Content: ABC|RelPermalink: /bundle/concat.txt|Permalink: http://example.com/bundle/concat.txt|MediaType: text/plain`)354 b.AssertFileContent("public/bundle/concat.txt", "ABC")355 b.AssertFileContent("public/index.html", `T2: Content: t1t|t2t|`)356 b.AssertFileContent("public/bundle/concattxt.txt", "t1t|t2t|")357 b.AssertFileContent("public/index.html", `T3: Content: function D {} // A comment358;359(function E {})360;361(function F {})()|`)362 b.AssertFileContent("public/bundle/concatjs.js", `function D {} // A comment363;364(function E {})365;366(function F {})()`)367 }},368 {"concat and fingerprint", func() bool { return true }, func(b *sitesBuilder) {369 b.WithTemplates("home.html", `370{{ $a := "A" | resources.FromString "a.txt"}}371{{ $b := "B" | resources.FromString "b.txt"}}372{{ $c := "C" | resources.FromString "c.txt"}}373{{ $combined := slice $a $b $c | resources.Concat "bundle/concat.txt" }}374{{ $fingerprinted := $combined | fingerprint }}375Fingerprinted: {{ $fingerprinted.RelPermalink }}376`)377 }, func(b *sitesBuilder) {378 b.AssertFileContent("public/index.html", "Fingerprinted: /bundle/concat.b5d4045c3f466fa91fe2cc6abe79232a1a57cdf104f7a26e716e0a1e2789df78.txt")379 b.AssertFileContent("public/bundle/concat.b5d4045c3f466fa91fe2cc6abe79232a1a57cdf104f7a26e716e0a1e2789df78.txt", "ABC")380 }},381 {"fromstring", func() bool { return true }, func(b *sitesBuilder) {382 b.WithTemplates("home.html", `383{{ $r := "Hugo Rocks!" | resources.FromString "rocks/hugo.txt" }}384{{ $r.Content }}|{{ $r.RelPermalink }}|{{ $r.Permalink }}|{{ $r.MediaType.Type }}385`)386 }, func(b *sitesBuilder) {387 b.AssertFileContent("public/index.html", `Hugo Rocks!|/rocks/hugo.txt|http://example.com/rocks/hugo.txt|text/plain`)388 b.AssertFileContent("public/rocks/hugo.txt", "Hugo Rocks!")389 }},390 {"execute-as-template", func() bool {391 return true392 }, func(b *sitesBuilder) {393 b.WithTemplates("home.html", `394{{ $var := "Hugo Page" }}395{{ if .IsHome }}396{{ $var = "Hugo Home" }}397{{ end }}398T1: {{ $var }}399{{ $result := "{{ .Kind | upper }}" | resources.FromString "mytpl.txt" | resources.ExecuteAsTemplate "result.txt" . }}400T2: {{ $result.Content }}|{{ $result.RelPermalink}}|{{$result.MediaType.Type }}401`)402 }, func(b *sitesBuilder) {403 b.AssertFileContent("public/index.html", `T2: HOME|/result.txt|text/plain`, `T1: Hugo Home`)404 }},405 {"fingerprint", func() bool { return true }, func(b *sitesBuilder) {406 b.WithTemplates("home.html", `407{{ $r := "ab" | resources.FromString "rocks/hugo.txt" }}408{{ $result := $r | fingerprint }}409{{ $result512 := $r | fingerprint "sha512" }}410{{ $resultMD5 := $r | fingerprint "md5" }}411T1: {{ $result.Content }}|{{ $result.RelPermalink}}|{{$result.MediaType.Type }}|{{ $result.Data.Integrity }}|412T2: {{ $result512.Content }}|{{ $result512.RelPermalink}}|{{$result512.MediaType.Type }}|{{ $result512.Data.Integrity }}|413T3: {{ $resultMD5.Content }}|{{ $resultMD5.RelPermalink}}|{{$resultMD5.MediaType.Type }}|{{ $resultMD5.Data.Integrity }}|414{{ $r2 := "bc" | resources.FromString "rocks/hugo2.txt" | fingerprint }}415{{/* https://github.com/gohugoio/hugo/issues/5296 */}}416T4: {{ $r2.Data.Integrity }}|417`)418 }, func(b *sitesBuilder) {419 b.AssertFileContent("public/index.html", `T1: ab|/rocks/hugo.fb8e20fc2e4c3f248c60c39bd652f3c1347298bb977b8b4d5903b85055620603.txt|text/plain|sha256-+44g/C5MPySMYMOb1lLzwTRymLuXe4tNWQO4UFViBgM=|`)420 b.AssertFileContent("public/index.html", `T2: ab|/rocks/hugo.2d408a0717ec188158278a796c689044361dc6fdde28d6f04973b80896e1823975cdbf12eb63f9e0591328ee235d80e9b5bf1aa6a44f4617ff3caf6400eb172d.txt|text/plain|sha512-LUCKBxfsGIFYJ4p5bGiQRDYdxv3eKNbwSXO4CJbhgjl1zb8S62P54FkTKO4jXYDptb8apqRPRhf/PK9kAOsXLQ==|`)421 b.AssertFileContent("public/index.html", `T3: ab|/rocks/hugo.187ef4436122d1cc2f40dc2b92f0eba0.txt|text/plain|md5-GH70Q2Ei0cwvQNwrkvDroA==|`)422 b.AssertFileContent("public/index.html", `T4: sha256-Hgu9bGhroFC46wP/7txk/cnYCUf86CGrvl1tyNJSxaw=|`)423 }},424 // https://github.com/gohugoio/hugo/issues/5226425 {"baseurl-path", func() bool { return true }, func(b *sitesBuilder) {426 b.WithSimpleConfigFileAndBaseURL("https://example.com/hugo/")427 b.WithTemplates("home.html", `428{{ $r1 := "ab" | resources.FromString "rocks/hugo.txt" }}429T1: {{ $r1.Permalink }}|{{ $r1.RelPermalink }}430`)431 }, func(b *sitesBuilder) {432 b.AssertFileContent("public/index.html", `T1: https://example.com/hugo/rocks/hugo.txt|/hugo/rocks/hugo.txt`)433 }},434 // https://github.com/gohugoio/hugo/issues/4944435 {"Prevent resource publish on .Content only", func() bool { return true }, func(b *sitesBuilder) {436 b.WithTemplates("home.html", `437{{ $cssInline := "body { color: green; }" | resources.FromString "inline.css" | minify }}438{{ $cssPublish1 := "body { color: blue; }" | resources.FromString "external1.css" | minify }}439{{ $cssPublish2 := "body { color: orange; }" | resources.FromString "external2.css" | minify }}440Inline: {{ $cssInline.Content }}441Publish 1: {{ $cssPublish1.Content }} {{ $cssPublish1.RelPermalink }}442Publish 2: {{ $cssPublish2.Permalink }}443`)444 }, func(b *sitesBuilder) {445 b.AssertFileContent("public/index.html",446 `Inline: body{color:green}`,447 "Publish 1: body{color:blue} /external1.min.css",448 "Publish 2: http://example.com/external2.min.css",449 )450 b.Assert(b.CheckExists("public/external2.css"), qt.Equals, false)451 b.Assert(b.CheckExists("public/external1.css"), qt.Equals, false)452 b.Assert(b.CheckExists("public/external2.min.css"), qt.Equals, true)453 b.Assert(b.CheckExists("public/external1.min.css"), qt.Equals, true)454 b.Assert(b.CheckExists("public/inline.min.css"), qt.Equals, false)455 }},456 {"unmarshal", func() bool { return true }, func(b *sitesBuilder) {457 b.WithTemplates("home.html", `458{{ $toml := "slogan = \"Hugo Rocks!\"" | resources.FromString "slogan.toml" | transform.Unmarshal }}459{{ $csv1 := "\"Hugo Rocks\",\"Hugo is Fast!\"" | resources.FromString "slogans.csv" | transform.Unmarshal }}460{{ $csv2 := "a;b;c" | transform.Unmarshal (dict "delimiter" ";") }}461{{ $xml := "<?xml version=\"1.0\" encoding=\"UTF-8\"?><note><to>You</to><from>Me</from><heading>Reminder</heading><body>Do not forget XML</body></note>" | transform.Unmarshal }}462Slogan: {{ $toml.slogan }}463CSV1: {{ $csv1 }} {{ len (index $csv1 0) }}464CSV2: {{ $csv2 }} 465XML: {{ $xml.body }}466`)467 }, func(b *sitesBuilder) {468 b.AssertFileContent("public/index.html",469 `Slogan: Hugo Rocks!`,470 `[[Hugo Rocks Hugo is Fast!]] 2`,471 `CSV2: [[a b c]]`,472 `XML: Do not forget XML`,473 )474 }},475 {"resources.Get", func() bool { return true }, func(b *sitesBuilder) {476 b.WithTemplates("home.html", `NOT FOUND: {{ if (resources.Get "this-does-not-exist") }}FAILED{{ else }}OK{{ end }}`)477 }, func(b *sitesBuilder) {478 b.AssertFileContent("public/index.html", "NOT FOUND: OK")479 }},480 {"template", func() bool { return true }, func(b *sitesBuilder) {}, func(b *sitesBuilder) {481 }},482 }483 for _, test := range tests {484 test := test485 t.Run(test.name, func(t *testing.T) {486 if !test.shouldRun() {487 t.Skip()488 }489 t.Parallel()490 b := newTestSitesBuilder(t).WithLogger(loggers.NewErrorLogger())491 b.WithContent("_index.md", `492---493title: Home494---495Home.496`,497 "page1.md", `498---499title: Hello1500---501Hello1502`,503 "page2.md", `504---505title: Hello2506---507Hello2508`,509 "t1.txt", "t1t|",510 "t2.txt", "t2t|",511 )512 b.WithSourceFile(filepath.Join("assets", "css", "styles1.css"), `513h1 {514 font-style: bold;515}516`)517 b.WithSourceFile(filepath.Join("assets", "js", "script1.js"), `518var x;519x = 5;520document.getElementById("demo").innerHTML = x * 10;521`)522 b.WithSourceFile(filepath.Join("assets", "mydata", "json1.json"), `523{524"employees":[525 {"firstName":"John", "lastName":"Doe"}, 526 {"firstName":"Anna", "lastName":"Smith"},527 {"firstName":"Peter", "lastName":"Jones"}528]529}530`)531 b.WithSourceFile(filepath.Join("assets", "mydata", "svg1.svg"), `532<svg height="100" width="100">533 <path d="M 100 100 L 300 100 L 200 100 z"/>534</svg> 535`)536 b.WithSourceFile(filepath.Join("assets", "mydata", "xml1.xml"), `537<hello>538<world>Hugo Rocks!</<world>539</hello>540`)541 b.WithSourceFile(filepath.Join("assets", "mydata", "html1.html"), `542<html>543<a href="#">544Cool545</a >546</html>547`)548 b.WithSourceFile(filepath.Join("assets", "scss", "styles2.scss"), `549$color: #333;550body {551 color: $color;552}553`)554 b.WithSourceFile(filepath.Join("assets", "sass", "styles3.sass"), `555$color: #333;556.content-navigation557 border-color: $color558`)559 test.prepare(b)560 b.Build(BuildCfg{})561 test.verify(b)562 })563 }564}565func TestMultiSiteResource(t *testing.T) {566 t.Parallel()567 c := qt.New(t)568 b := newMultiSiteTestDefaultBuilder(t)569 b.CreateSites().Build(BuildCfg{})570 // This build is multilingual, but not multihost. There should be only one pipes.txt571 b.AssertFileContent("public/fr/index.html", "French Home Page", "String Resource: /blog/text/pipes.txt")572 c.Assert(b.CheckExists("public/fr/text/pipes.txt"), qt.Equals, false)573 c.Assert(b.CheckExists("public/en/text/pipes.txt"), qt.Equals, false)574 b.AssertFileContent("public/en/index.html", "Default Home Page", "String Resource: /blog/text/pipes.txt")575 b.AssertFileContent("public/text/pipes.txt", "Hugo Pipes")576}577func TestResourcesMatch(t *testing.T) {578 t.Parallel()579 b := newTestSitesBuilder(t)580 b.WithContent("page.md", "")581 b.WithSourceFile(582 "assets/jsons/data1.json", "json1 content",583 "assets/jsons/data2.json", "json2 content",584 "assets/jsons/data3.xml", "xml content",585 )586 b.WithTemplates("index.html", `587{{ $jsons := (resources.Match "jsons/*.json") }}588{{ $json := (resources.GetMatch "jsons/*.json") }}589{{ printf "JSONS: %d" (len $jsons) }}590JSON: {{ $json.RelPermalink }}: {{ $json.Content }}591{{ range $jsons }}592{{- .RelPermalink }}: {{ .Content }}593{{ end }}594`)595 b.Build(BuildCfg{})596 b.AssertFileContent("public/index.html",597 "JSON: /jsons/data1.json: json1 content",598 "JSONS: 2", "/jsons/data1.json: json1 content")599}600func TestResourceMinifyDisabled(t *testing.T) {601 t.Parallel()602 b := newTestSitesBuilder(t).WithConfigFile("toml", `603baseURL = "https://example.org"604[minify]605disableXML=true606`)607 b.WithContent("page.md", "")608 b.WithSourceFile(609 "assets/xml/data.xml", "<root> <foo> asdfasdf </foo> </root>",610 )611 b.WithTemplates("index.html", `612{{ $xml := resources.Get "xml/data.xml" | minify | fingerprint }}613XML: {{ $xml.Content | safeHTML }}|{{ $xml.RelPermalink }}614`)...
html.go
Source:html.go
1package reportoutput2import (3 "encoding/json"4 "html/template"5 "io/ioutil"6 "os"7 "path/filepath"8 "github.com/konveyor/cpma/pkg/env"9 "github.com/pkg/errors"10 "github.com/sirupsen/logrus"11 k8sapicore "k8s.io/api/core/v1"12 "k8s.io/apimachinery/pkg/api/resource"13)14//go:generate go run assets_generate.go15// Output reads report stucture, generates html using go templates and writes it to a file16func htmlOutput(report ReportOutput) {17 path := filepath.Join(env.Config().GetString("WorkDir"), htmlFileName)18 f, err := os.Create(path)19 defer f.Close()20 if err != nil {21 panic(errors.Wrap(err, "unable to create html file"))22 }23 htmlTemplate, err := parseTemplates()24 if err != nil {25 panic(errors.Wrap(err, "unable to parse templates"))26 }27 err = htmlTemplate.Execute(f, report)28 if err != nil {29 panic(errors.Wrap(err, "unable to apply parsed template"))30 }31}32func parseTemplates() (*template.Template, error) {33 var fileStringMap = make(map[string]string)34 cssJSFilesPath := []string{35 "css/bootstrap.min.css",36 "css/styles.css",37 "css/patternfly.min.css",38 "js/bootstrap.min.js",39 "js/jquery-3.3.1.slim.min.js",40 "js/popper.min.js",41 "js/custom.js",42 }43 for _, path := range cssJSFilesPath {44 stringFile, err := readAsset(path)45 if err != nil {46 return nil, err47 }48 fileStringMap[path] = stringFile49 }50 helpersTemplateString, err := readAsset("templates/helpers.gohtml")51 if err != nil {52 return nil, err53 }54 htmlTemplate := template.Must(template.New("html").Funcs(template.FuncMap{55 "bootstrapCSS": func() template.CSS {56 return template.CSS(fileStringMap["css/bootstrap.min.css"])57 },58 "stylesCSS": func() template.CSS {59 return template.CSS(fileStringMap["css/styles.css"])60 },61 "patternflyCSS": func() template.CSS {62 return template.CSS(fileStringMap["css/patternfly.min.css"])63 },64 "bootstrapJS": func() template.JS {65 return template.JS(fileStringMap["js/bootstrap.min.js"])66 },67 "jqueryJS": func() template.JS {68 return template.JS(fileStringMap["js/jquery-3.3.1.slim.min.js"])69 },70 "popperJS": func() template.JS {71 return template.JS(fileStringMap["js/popper.min.js"])72 },73 "customJS": func() template.JS {74 return template.JS(fileStringMap["js/custom.js"])75 },76 "formatQuantity": func(q resource.Quantity) string {77 json, _ := json.Marshal(q)78 return string(json)79 },80 "formatDriver": func(d k8sapicore.PersistentVolumeSource) string {81 json, _ := json.Marshal(d)82 return string(json)83 },84 "incrementIndex": func(i int) int {85 return i + 186 },87 "pvcIndex": func() *int {88 i := new(int)89 *i = 090 return i91 },92 "incrementPVCIndex": func(i *int) int {93 *i = *i + 194 return *i95 },96 }).Parse(helpersTemplateString))97 templatePaths := []string{98 "templates/nodes.gohtml",99 "templates/quotas.gohtml",100 "templates/namespaces.gohtml",101 "templates/pvs.gohtml",102 "templates/storageclasses.gohtml",103 "templates/rbac.gohtml",104 "templates/cluster-report.gohtml",105 "templates/component-report.gohtml",106 "templates/main.gohtml",107 }108 for _, path := range templatePaths {109 stringTemplate, err := readAsset(path)110 if err != nil {111 return nil, err112 }113 htmlTemplate = template.Must(htmlTemplate.Parse(stringTemplate))114 }115 logrus.Infof("Report:Added: %s", htmlFileName)116 return htmlTemplate, nil117}118func readAsset(path string) (string, error) {119 file, err := assets.Open(path)120 if err != nil {121 return "", err122 }123 defer file.Close()124 fileContent, err := ioutil.ReadAll(file)125 if err != nil {126 return "", err127 }128 return string(fileContent), nil129}...
generate_configs.go
Source:generate_configs.go
...6 "github.com/thehowl/conf"7)8type simplePage struct {9 Handler, Template, TitleBar, KyutGrill string10 MinPrivilegesRaw uint6411}12type noTemplate struct {13 Handler, TitleBar, KyutGrill string14 MinPrivileges uint6415}16var simplePages = [...]simplePage{{"/", "homepage.html", "Home Page", "homepage2.jpg", 0}, {"/login", "login.html", "Log in", "login2.jpg", 0}, {"/settings/avatar", "settings/avatar.html", "Change avatar", "settings2.jpg", 2}, {"/dev/tokens", "dev/tokens.html", "Your API tokens", "dev.jpg", 2}, {"/beatmaps/rank_request", "beatmaps/rank_request.html", "Request beatmap ranking", "request_beatmap_ranking.jpg", 2}, {"/donate", "support.html", "Support Ripple", "donate2.png", 0}, {"/doc", "doc.html", "Documentation", "documentation.jpg", 0}, {"/doc/:id", "doc_content.html", "View document", "documentation.jpg", 0}, {"/help", "help.html", "Contact support", "help.jpg", 0}, {"/leaderboard", "leaderboard.html", "Leaderboard", "leaderboard2.jpg", 0}, {"/friends", "friends.html", "Friends", "", 2}, {"/changelog", "changelog.html", "Changelog", "changelog.jpg", 0}, {"/team", "team.html", "Team", "", 0}, {"/pwreset", "pwreset.html", "Reset password", "", 0}, {"/about", "about.html", "About", "", 0}}17func main() {18 for _, p := range simplePages {19 fmt.Print("=> ", p.Handler+" ... ")20 noTemplateP := noTemplate{21 Handler: p.Handler,22 TitleBar: p.TitleBar,23 KyutGrill: p.KyutGrill,24 MinPrivileges: p.MinPrivilegesRaw,25 }26 d := []byte("{{/*###\n")27 confData, err := conf.ExportRaw(&noTemplateP)28 if err != nil {29 panic(err)30 }31 d = append(d, confData...)32 fileData, err := ioutil.ReadFile("templates/" + p.Template)33 if err != nil {34 panic(err)35 }36 d = append(d, []byte("*/}}\n")...)37 d = append(d, fileData...)38 err = ioutil.WriteFile("templates/"+p.Template, d, 0644)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!