Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
Bootstrap css <link> only for standard (#1641)
Browse files Browse the repository at this point in the history
* removing the css part for bootstrap from cdn when webpack
  • Loading branch information
paganotoni authored Apr 2, 2019
1 parent 3fb8929 commit 3a35a94
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 70 deletions.
1 change: 1 addition & 0 deletions genny/assets/standard/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ package standard

// Options for generating a new standard set of assets
type Options struct {
Bootstrap int `json:"bootstrap"`
}
20 changes: 20 additions & 0 deletions genny/assets/standard/standard.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package standard

import (
"strings"
"text/template"

"github.com/gobuffalo/genny"
"github.com/gobuffalo/gogen"
"github.com/gobuffalo/packr/v2"
"github.com/pkg/errors"
)

// New generator for creating basic asset files
Expand All @@ -18,5 +20,23 @@ func New(opts *Options) (*genny.Generator, error) {
t := gogen.TemplateTransformer(data, h)
g.Transformer(t)

g.RunFn(func(r *genny.Runner) error {
f, err := r.FindFile("templates/application.html")
if err != nil {
return errors.WithStack(err)
}

css := bs4
if opts.Bootstrap == 3 {
css = bs3
}

s := strings.Replace(f.String(), "</title>", "</title>\n"+css, 1)
return r.File(genny.NewFileS(f.Name(), s))
})

return g, nil
}

const bs3 = `<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">`
const bs4 = `<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">`
31 changes: 28 additions & 3 deletions genny/assets/standard/standard_test.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
package standard

import (
"context"
"testing"

"github.com/gobuffalo/genny"
"github.com/gobuffalo/genny/gentest"
"github.com/stretchr/testify/require"
)

func Test_New(t *testing.T) {
r := require.New(t)

g, err := New(nil)
g, err := New(&Options{})
r.NoError(err)

run := genny.DryRunner(context.Background())
run := gentest.NewRunner()
run.Disk.Add(genny.NewFileS("templates/application.html", layout))
run.LookPathFn = func(s string) (string, error) {
return s, nil
}

run.With(g)

r.NoError(run.Run())

res := run.Results()
Expand All @@ -26,9 +32,28 @@ func Test_New(t *testing.T) {
"public/assets/application.js",
"public/assets/buffalo.css",
"public/assets/images/favicon.ico",
"templates/application.html",
}

r.Len(res.Files, len(files))
for i, f := range res.Files {
r.Equal(files[i], f.Name())
}

layout, ferr := res.Find("templates/application.html")
r.NoError(ferr)

r.Contains(layout.String(), "<link rel=\"stylesheet\"")
}

const layout = `<!DOCTYPE html>
<html>
<head>
<title>Buffalo - Foo</title>
<%= stylesheetTag("buffalo.css") %>
<%= stylesheetTag("application.css") %>
</head>
<body>
</body>
</html>
`
8 changes: 0 additions & 8 deletions genny/assets/webpack/webpack-packr.go

This file was deleted.

18 changes: 0 additions & 18 deletions genny/assets/webpack/webpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"os/exec"
"path/filepath"
"runtime"
"strings"

"github.com/gobuffalo/genny"
"github.com/gobuffalo/gogen"
Expand Down Expand Up @@ -53,19 +52,6 @@ func New(opts *Options) (*genny.Generator, error) {
return installPkgs(r, opts)
})

g.RunFn(func(r *genny.Runner) error {
f, err := r.FindFile("templates/application.html")
if err != nil {
return errors.WithStack(err)
}
css := bs4
if opts.Bootstrap == 3 {
css = bs3
}
s := strings.Replace(f.String(), "</title>", "</title>\n"+css, 1)
return r.File(genny.NewFileS(f.Name(), s))
})

return g, nil
}

Expand Down Expand Up @@ -108,7 +94,3 @@ func installYarn(r *genny.Runner) error {
yargs := []string{"install", "-g", "yarn"}
return r.Exec(exec.Command("npm", yargs...))
}

const bs3 = `<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">`

const bs4 = `<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">`
33 changes: 0 additions & 33 deletions genny/assets/webpack/webpack_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package webpack

import (
"strconv"
"strings"
"testing"

Expand Down Expand Up @@ -80,38 +79,6 @@ func Test_Webpack_New_WithYarn(t *testing.T) {
r.Equal("yarnpkg install --no-progress --save", strings.Join(c.Args, " "))
}

func Test_Webpack_Updates_Layout(t *testing.T) {
table := []struct {
v int
css string
}{
{3, bs3},
{4, bs4},
}

for _, tt := range table {
t.Run(strconv.Itoa(tt.v), func(st *testing.T) {
r := require.New(st)
run := runner()

run.WithNew(New(&Options{
Bootstrap: tt.v,
}))

r.NoError(run.Run())

res := run.Results()

f, err := res.Find("templates/application.html")
r.NoError(err)

body := f.String()
r.Contains(body, "</title>\n"+tt.css)
r.Contains(body, `<%= stylesheetTag("application.css") %>`)
})
}
}

const layout = `<!DOCTYPE html>
<html>
<head>
Expand Down
8 changes: 0 additions & 8 deletions genny/build/build-packr.go

This file was deleted.

0 comments on commit 3a35a94

Please sign in to comment.