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

Shoulders #53

Merged
merged 6 commits into from
Dec 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ ADD . .

RUN go get -v -t ./...

RUN go test -v -race ./...
RUN go test -race ./...

RUN go install ./buffalo

WORKDIR $GOPATH/src/
RUN buffalo new --db-type=sqlite3 hello_world
WORKDIR ./hello_world
RUN go vet -x ./...
RUN buffalo test -v -race
RUN buffalo test -race
20 changes: 20 additions & 0 deletions SHOULDERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Thank you to the following **GIANTS**:

* [github.com/markbates/grift](https://github.com/markbates/grift)

* [github.com/markbates/inflect](https://github.com/markbates/inflect)

* [github.com/markbates/pop](https://github.com/markbates/pop)

* [github.com/markbates/refresh](https://github.com/markbates/refresh)
Expand All @@ -56,9 +58,27 @@ Thank you to the following **GIANTS**:

* [github.com/mattn/go-isatty](https://github.com/mattn/go-isatty)

* [github.com/microcosm-cc/bluemonday](https://github.com/microcosm-cc/bluemonday)

* [github.com/mitchellh/go-homedir](https://github.com/mitchellh/go-homedir)

* [github.com/pkg/errors](https://github.com/pkg/errors)

* [github.com/russross/blackfriday](https://github.com/russross/blackfriday)

* [github.com/sergi/go-diff/diffmatchpatch](https://github.com/sergi/go-diff/diffmatchpatch)

* [github.com/shurcooL/github_flavored_markdown](https://github.com/shurcooL/github_flavored_markdown)

* [github.com/shurcooL/highlight_diff](https://github.com/shurcooL/highlight_diff)

* [github.com/shurcooL/highlight_go](https://github.com/shurcooL/highlight_go)

* [github.com/shurcooL/sanitized_anchor_name](https://github.com/shurcooL/sanitized_anchor_name)

* [github.com/sourcegraph/annotate](https://github.com/sourcegraph/annotate)

* [github.com/sourcegraph/syntaxhighlight](https://github.com/sourcegraph/syntaxhighlight)

* [github.com/spf13/cobra](https://github.com/spf13/cobra)

1 change: 1 addition & 0 deletions grifts/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

var _ = Desc("release", "Generates a CHANGELOG and creates a new GitHub release based on what is in the version.go file.")
var _ = Add("release", func(c *Context) error {
Run("shoulders", c)
v, err := findVersion()
if err != nil {
return err
Expand Down
24 changes: 23 additions & 1 deletion grifts/shoulders.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,31 @@ var _ = Add("shoulders", func(c *Context) error {
if err != nil {
return err
}
return t.Execute(f, giants)
err = t.Execute(f, giants)
if err != nil {
return err
}

return commitAndPushShoulders()
})

func commitAndPushShoulders() error {
cmd := exec.Command("git", "commit", "SHOULDERS.md", "-m", "Updated SHOULDERS.md")
cmd.Stdin = os.Stdin
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
err := cmd.Run()
if err != nil {
return err
}

cmd = exec.Command("git", "push", "origin")
cmd.Stdin = os.Stdin
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
return cmd.Run()
}

var shouldersTemplate = `
# Buffalo Stands on the Shoulders of Giants

Expand Down
66 changes: 66 additions & 0 deletions render/markdown_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package render_test

import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"

"github.com/markbates/buffalo/render"
"github.com/stretchr/testify/require"
)

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

tmpDir := filepath.Join(os.TempDir(), "markdown_test")
err := os.MkdirAll(tmpDir, 0766)
r.NoError(err)
defer os.Remove(tmpDir)

tmpFile, err := os.Create(filepath.Join(tmpDir, "t.md"))
r.NoError(err)

_, err = tmpFile.Write([]byte("{{name}}"))
r.NoError(err)

type ji func(...string) render.Renderer
t.Run("without a layout", func(st *testing.T) {
r := require.New(st)

table := []ji{
render.HTML,
render.New(render.Options{}).HTML,
}

for _, j := range table {
re := j(tmpFile.Name())
r.Equal("text/html", re.ContentType())
bb := &bytes.Buffer{}
err = re.Render(bb, map[string]interface{}{"name": "Mark"})
r.NoError(err)
r.Equal("<p>Mark</p>", strings.TrimSpace(bb.String()))
}
})

t.Run("with a layout", func(st *testing.T) {
r := require.New(st)

layout, err := ioutil.TempFile("", "test")
r.NoError(err)
defer os.Remove(layout.Name())

_, err = layout.Write([]byte("<body>{{yield}}</body>"))
r.NoError(err)

re := render.New(render.Options{HTMLLayout: layout.Name()}).HTML(tmpFile.Name())

r.Equal("text/html", re.ContentType())
bb := &bytes.Buffer{}
err = re.Render(bb, map[string]interface{}{"name": "Mark"})
r.NoError(err)
r.Equal("<body><p>Mark</p>\n</body>", strings.TrimSpace(bb.String()))
})
}
8 changes: 7 additions & 1 deletion render/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import (
"io"
"io/ioutil"
"path/filepath"
"strings"

"github.com/aymerick/raymond"
"github.com/pkg/errors"
"github.com/shurcooL/github_flavored_markdown"
)

type templateRenderer struct {
Expand Down Expand Up @@ -66,7 +68,11 @@ func (s *templateRenderer) source(name string) (*raymond.Template, error) {
if err != nil {
return nil, errors.WithStack(fmt.Errorf("could not find template: %s", name))
}
t, err := raymond.Parse(string(b))
if strings.ToLower(filepath.Ext(name)) == ".md" {
b = github_flavored_markdown.Markdown(b)
}
source := string(b)
t, err := raymond.Parse(source)
if err != nil {
return t, errors.WithMessage(errors.WithStack(err), name)
}
Expand Down