This repository has been archived by the owner on Dec 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Move PNG generation library code into a separate package and remove autodetection of dataDir #13
Open
sqs
wants to merge
6
commits into
badges:master
Choose a base branch
from
sourcegraph:library-usage
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
512489a
Move PNG generation library code into the ./shield package and remove…
sqs 8bdc669
Rename func Init -> LoadResources
sqs 92d0d08
Use absolute import, not relative import
sqs ef9fa11
Check for errors in test code, and move test data to shield/testdata …
sqs 755cc84
Fix call (renamed to LoadResources)
sqs d165668
Test running the img.shields.io program
sqs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ go: 1.2 | |
|
||
script: | ||
- go test -v ./... | ||
- go run main.go --vendor=foo --status=bar --color=blue /dev/null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ import ( | |
"time" | ||
|
||
"github.com/droundy/goopt" | ||
"github.com/gittip/img.shields.io/shield" | ||
) | ||
|
||
var ( | ||
|
@@ -23,7 +24,7 @@ var ( | |
lastModifiedStr = lastModified.UTC().Format(http.TimeFormat) | ||
oneYear = time.Duration(8700) * time.Hour | ||
|
||
staticPath, _ = resourcePaths() | ||
staticPath = "static" | ||
) | ||
|
||
func shift(s []string) ([]string, string) { | ||
|
@@ -35,7 +36,7 @@ func invalidRequest(w http.ResponseWriter, r *http.Request) { | |
http.Error(w, "bad request", 400) | ||
} | ||
|
||
func parseFileName(name string) (d Data, err error) { | ||
func parseFileName(name string) (d shield.Data, err error) { | ||
imageName := wsReplacer.Replace(name) | ||
imageParts := strings.Split(imageName, "-") | ||
|
||
|
@@ -72,12 +73,12 @@ func parseFileName(name string) (d Data, err error) { | |
} | ||
|
||
cp := newParts[2][0 : len(newParts[2])-4] | ||
c, err := getColor(cp) | ||
c, err := shield.GetColor(cp) | ||
if err != nil { | ||
return | ||
} | ||
|
||
d = Data{newParts[0], newParts[1], c} | ||
d = shield.Data{newParts[0], newParts[1], c} | ||
return | ||
} | ||
|
||
|
@@ -106,7 +107,7 @@ func buckle(w http.ResponseWriter, r *http.Request) { | |
w.Header().Add("cache-control", "public") | ||
w.Header().Add("last-modified", lastModifiedStr) | ||
|
||
makePngShield(w, d) | ||
shield.PNG(w, d) | ||
} | ||
|
||
const basePkg = "github.com/gittip/img.shields.io" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will need to change per badges/shields#90 (comment) |
||
|
@@ -132,11 +133,11 @@ func cliMode(vendor string, status string, color string, args []string) { | |
} | ||
|
||
if vendor != "" { | ||
c, err := getColor(color) | ||
c, err := shield.GetColor(color) | ||
if err != nil { | ||
fatal("Invalid color: " + color) | ||
} | ||
d := Data{vendor, status, c} | ||
d := shield.Data{vendor, status, c} | ||
|
||
name := fmt.Sprintf("%s-%s-%s.png", revWsReplacer.Replace(vendor), | ||
revWsReplacer.Replace(status), color) | ||
|
@@ -158,7 +159,7 @@ func cliMode(vendor string, status string, color string, args []string) { | |
} | ||
} | ||
|
||
makePngShield(f, d) | ||
shield.PNG(f, d) | ||
return | ||
} | ||
|
||
|
@@ -174,7 +175,7 @@ func cliMode(vendor string, status string, color string, args []string) { | |
if err != nil { | ||
fatal(err.Error()) | ||
} | ||
makePngShield(f, d) | ||
shield.PNG(f, d) | ||
} | ||
} | ||
|
||
|
@@ -202,6 +203,9 @@ func main() { | |
|
||
goopt.Usage = usage | ||
|
||
// common options | ||
dataDir := goopt.String([]string{"-d", "--data-dir"}, "data", "data dir containing base PNG files and font") | ||
|
||
// server mode options | ||
host := goopt.String([]string{"-h", "--host"}, hostEnv, "host ip address to bind to") | ||
port := goopt.Int([]string{"-p", "--port"}, p, "port to listen on") | ||
|
@@ -214,6 +218,8 @@ func main() { | |
|
||
args := goopt.Args | ||
|
||
shield.LoadResources(*dataDir) | ||
|
||
// if any of the cli args are given, or positional args remain, assume cli | ||
// mode. | ||
if len(args) > 0 || *vendor != "" || *status != "" || *color != "" { | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0
test/use-buckler-blue.png → shield/testdata/use-buckler-blue.out.png
100644 → 100755
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will need to change per badges/shields#90 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than having a shield subfolder, what do you think of flipping it around? Go stdlib and a few other places have a
cmd
folder.so
github.com/badges/buckler/cmd/buckler
is the folder containing the buckler CLI.so we could make
github.com/badges/buckler
the library import (stdlib actually has a pkg/ subfolder as well, but meh).Also, let's just call this buckler (not shield).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sgtm!