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

generate js & css files into sub directory of assets #50

Merged
merged 7 commits into from
Dec 12, 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
28 changes: 18 additions & 10 deletions buffalo/cmd/app_generators.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ func newAppGenerator() *gentronics.Generator {
g.Add(gentronics.NewFile("grifts/routes.go", nGriftRoutes))
g.Add(gentronics.NewFile("templates/index.html", nIndexHTML))
g.Add(gentronics.NewFile("templates/application.html", nApplicationHTML))
g.Add(gentronics.NewFile("assets/application.js", ""))
g.Add(gentronics.NewFile("assets/application.css", nApplicationCSS))
g.Add(gentronics.NewFile("assets/js/application.js", ""))
g.Add(gentronics.NewFile("assets/css/application.css", nApplicationCSS))
g.Add(gentronics.NewFile(".gitignore", nGitignore))
g.Add(gentronics.NewCommand(goGet("github.com/markbates/refresh/...")))
g.Add(gentronics.NewCommand(goInstall("github.com/markbates/refresh")))
Expand All @@ -47,35 +47,43 @@ func appGoGet() *exec.Cmd {
const nMain = `package main

import (
"fmt"
"log"
"net/http"
"os"

"{{.actionsPath}}"
"github.com/markbates/going/defaults"
)

func main() {
log.Fatal(http.ListenAndServe(":3000", actions.App()))
port := defaults.String(os.Getenv("PORT"), "3000")
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), actions.App()))
}

`
const nApp = `package actions

import (
"net/http"
"os"

"github.com/markbates/buffalo"
{{if .withPop -}}
"github.com/markbates/buffalo/middleware"
"{{.modelsPath}}"
{{end -}}
"github.com/markbates/going/defaults"
)

var ENV = defaults.String(os.Getenv("GO_ENV"), "development")

// App is where all routes and middleware for buffalo
// should be defined. This is the nerve center of your
// application.
func App() http.Handler {
a := buffalo.Automatic(buffalo.Options{
Env: "development",
Env: ENV,
})

{{if .withPop -}}
Expand Down Expand Up @@ -157,21 +165,21 @@ const nApplicationHTML = `<html>
<meta charset="utf-8">
<title>Buffalo - {{ .titleName }}</title>
{{if .withBootstrap -}}
<link rel="stylesheet" href="/assets/bootstrap.css" type="text/css" media="all" />
<link rel="stylesheet" href="/assets/css/bootstrap.css" type="text/css" media="all" />
{{end -}}
<link rel="stylesheet" href="/assets/application.css" type="text/css" media="all" />
<link rel="stylesheet" href="/assets/css/application.css" type="text/css" media="all" />
</head>
<body>

{{"{{"}} yield {{"}}"}}

{{if .withJQuery -}}
<script src="/assets/jquery.js" type="text/javascript" charset="utf-8"></script>
<script src="/assets/js/jquery.js" type="text/javascript" charset="utf-8"></script>
{{end -}}
{{if .withBootstrap -}}
<script src="/assets/bootstrap.js" type="text/javascript" charset="utf-8"></script>
<script src="/assets/js/bootstrap.js" type="text/javascript" charset="utf-8"></script>
{{end -}}
<script src="/assets/application.js" type="text/javascript" charset="utf-8"></script>
<script src="/assets/js/application.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>
`
Expand Down Expand Up @@ -231,5 +239,5 @@ enable_colors: true
log_name: buffalo
`

const nProcfile = `web: go run main.go`
const nProcfile = `web: {{.name}}`
const nProcfileDev = `web: buffalo dev`
4 changes: 2 additions & 2 deletions buffalo/cmd/generate/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ func NewBootstrapGenerator() *gentronics.Generator {
}
g := gentronics.New()
jf := &gentronics.RemoteFile{
File: gentronics.NewFile(filepath.Join("assets", "bootstrap.css"), ""),
File: gentronics.NewFile(filepath.Join("assets", "css", "bootstrap.css"), ""),
}
jf.Should = should
jf.RemotePath = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
g.Add(jf)

jf = &gentronics.RemoteFile{
File: gentronics.NewFile(filepath.Join("assets", "bootstrap.js"), ""),
File: gentronics.NewFile(filepath.Join("assets", "js", "bootstrap.js"), ""),
}
jf.Should = should
jf.RemotePath = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
Expand Down
2 changes: 1 addition & 1 deletion buffalo/cmd/generate/bootswatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func NewBootswatchGenerator(theme string) (*gentronics.Generator, error) {
},
})
jf := &gentronics.RemoteFile{
File: gentronics.NewFile(filepath.Join("assets", "bootstrap.css"), ""),
File: gentronics.NewFile(filepath.Join("assets", "css", "bootstrap.css"), ""),
}
jf.RemotePath = fmt.Sprintf("https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/%s/bootstrap.min.css", theme)
g.Add(jf)
Expand Down
4 changes: 2 additions & 2 deletions buffalo/cmd/generate/jquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ func NewJQueryGenerator() *gentronics.Generator {

g := gentronics.New()
jf := &gentronics.RemoteFile{
File: gentronics.NewFile(filepath.Join("assets", "jquery.js"), ""),
File: gentronics.NewFile(filepath.Join("assets", "js", "jquery.js"), ""),
}
jf.Should = should
jf.RemotePath = "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"
g.Add(jf)

jm := &gentronics.RemoteFile{
File: gentronics.NewFile(filepath.Join("assets", "jquery.map"), ""),
File: gentronics.NewFile(filepath.Join("assets", "js", "jquery.map"), ""),
}
jm.Should = should
jm.RemotePath = "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.map"
Expand Down
2 changes: 1 addition & 1 deletion buffalo/cmd/generate/railjs.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ https://github.com/rails/jquery-ujs`,
func NewRailsJSGenerator() *gentronics.Generator {
g := gentronics.New()
jf := &gentronics.RemoteFile{
File: gentronics.NewFile(filepath.Join("assets", "rails.js"), ""),
File: gentronics.NewFile(filepath.Join("assets", "js", "rails.js"), ""),
}
jf.RemotePath = "https://raw.githubusercontent.com/rails/jquery-ujs/master/src/rails.js"
g.Add(jf)
Expand Down
34 changes: 34 additions & 0 deletions middleware/new_relic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package middleware

import (
"fmt"

"github.com/markbates/buffalo"
newrelic "github.com/newrelic/go-agent"
"github.com/pkg/errors"
)

// NewRelic returns a piece of buffalo.Middleware that can
// be used to report requests to NewRelic. You must pass in your
// NewRelic key and a name for your application. If the key
// passed in is blank, i.e. loading from an ENV, then the middleware
// is skipped and the chain continues on like normal. Useful
// for development.
func NewRelic(key, name string) buffalo.MiddlewareFunc {
return func(next buffalo.Handler) buffalo.Handler {
if key == "" {
return next
}
return func(c buffalo.Context) error {
fmt.Printf("Setting up New Relic %s\n", key)
config := newrelic.NewConfig(name, key)
app, err := newrelic.NewApplication(config)
if err != nil {
return errors.WithStack(err)
}
tx := app.StartTransaction(c.Request().URL.String(), c.Response(), c.Request())
defer tx.End()
return next(c)
}
}
}