mirror of
https://github.com/sbrow/ps.git
synced 2025-12-29 18:47:38 -05:00
## Documentation
* Moved package comment to doc.go
This commit is contained in:
7
doc.go
Normal file
7
doc.go
Normal file
@@ -0,0 +1,7 @@
|
||||
// Package ps is a rudimentary API between Adobe Photoshop CS5 and Golang.
|
||||
// The interaction between the two is implemented using Javascript/VBScript.
|
||||
//
|
||||
// Use it to control Photoshop, edit documents, and perform batch operations.
|
||||
//
|
||||
// Currently only supports Photoshop CS5 Windows x86_64.
|
||||
package ps
|
||||
22
document.go
22
document.go
@@ -56,7 +56,7 @@ func (d *Document) UnmarshalJSON(b []byte) error {
|
||||
}
|
||||
|
||||
// Name returns the document's title.
|
||||
// This fufills the Group interface.
|
||||
// This fulfills the Group interface.
|
||||
func (d *Document) Name() string {
|
||||
return d.name
|
||||
}
|
||||
@@ -116,7 +116,7 @@ func (d *Document) LayerSet(name string) *LayerSet {
|
||||
|
||||
// ActiveDocument returns document currently focused in Photoshop.
|
||||
//
|
||||
// TODO(sbrow): Reduce cylcomatic complexity of ActiveDocument().
|
||||
// TODO(sbrow): Reduce cyclomatic complexity of ActiveDocument().
|
||||
func ActiveDocument() (*Document, error) {
|
||||
log.Println("Loading ActiveDoucment")
|
||||
d := &Document{}
|
||||
@@ -127,7 +127,7 @@ func ActiveDocument() (*Document, error) {
|
||||
}
|
||||
d.name = strings.TrimRight(string(byt), "\r\n")
|
||||
if Mode != Safe {
|
||||
err = d.Restore()
|
||||
err = d.Restore(d.Filename())
|
||||
switch {
|
||||
case os.IsNotExist(err):
|
||||
log.Println("Previous version not found.")
|
||||
@@ -163,8 +163,11 @@ func ActiveDocument() (*Document, error) {
|
||||
}
|
||||
|
||||
// Restore loads document data from a JSON file.
|
||||
func (d *Document) Restore() error {
|
||||
byt, err := ioutil.ReadFile(d.Filename())
|
||||
func (d *Document) Restore(path string) error {
|
||||
if path == "" {
|
||||
path = d.Filename()
|
||||
}
|
||||
byt, err := ioutil.ReadFile(path)
|
||||
if err == nil {
|
||||
log.Println("Previous version found, loading")
|
||||
err = json.Unmarshal(byt, &d)
|
||||
@@ -188,8 +191,13 @@ func (d *Document) Filename() string {
|
||||
if !ok {
|
||||
log.Panic("No caller information")
|
||||
}
|
||||
return filepath.Join(filepath.Dir(dir), "data",
|
||||
strings.TrimRight(d.name, "\r\n")+".txt")
|
||||
err := os.Mkdir(filepath.Join(filepath.Dir(dir), "data"), 0700)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
name := strings.TrimRight(d.name, "\r\n")
|
||||
name = strings.TrimSuffix(name, ".psd")
|
||||
return filepath.Join(filepath.Dir(dir), "data", name+".json")
|
||||
}
|
||||
|
||||
// Dump saves the document to disk in JSON format.
|
||||
|
||||
6
ps.go
6
ps.go
@@ -1,11 +1,5 @@
|
||||
//go:generate sh -c "godoc2md -template ./.doc.template github.com/sbrow/ps > README.md"
|
||||
|
||||
// Package ps is a rudimentary API between Adobe Photoshop CS5 and Golang.
|
||||
// The interaction between the two is implemented using Javascript/VBScript.
|
||||
//
|
||||
// Use it to control Photoshop, edit documents, and perform batch operations.
|
||||
//
|
||||
// Currently only supports Photoshop CS5 Windows x86_64.
|
||||
package ps
|
||||
|
||||
import (
|
||||
|
||||
@@ -160,7 +160,7 @@ func TestActiveDocument(t *testing.T) {
|
||||
}
|
||||
Open(testDoc)
|
||||
d, err := ActiveDocument()
|
||||
defer d.Dump()
|
||||
defer func(){d.Dump()}()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ func Run(name string, args ...string) ([]byte, error) {
|
||||
cmd := exec.Command(std.Cmd, parseArgs(name, args...)...)
|
||||
cmd.Stdout, cmd.Stderr = &out, &errs
|
||||
if err := cmd.Run(); err != nil || len(errs.Bytes()) != 0 {
|
||||
return out.Bytes(), fmt.Errorf("err: \"%s\"\nargs: \"%s\"\nout: \"%s\"", errs.String(), args, out.String())
|
||||
return out.Bytes(), fmt.Errorf("err: \"%s %s\"\nargs: \"%s\"\nout: \"%s\"", err, errs.String(), args, out.String())
|
||||
}
|
||||
return out.Bytes(), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user