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.
|
// Name returns the document's title.
|
||||||
// This fufills the Group interface.
|
// This fulfills the Group interface.
|
||||||
func (d *Document) Name() string {
|
func (d *Document) Name() string {
|
||||||
return d.name
|
return d.name
|
||||||
}
|
}
|
||||||
@@ -116,7 +116,7 @@ func (d *Document) LayerSet(name string) *LayerSet {
|
|||||||
|
|
||||||
// ActiveDocument returns document currently focused in Photoshop.
|
// 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) {
|
func ActiveDocument() (*Document, error) {
|
||||||
log.Println("Loading ActiveDoucment")
|
log.Println("Loading ActiveDoucment")
|
||||||
d := &Document{}
|
d := &Document{}
|
||||||
@@ -127,7 +127,7 @@ func ActiveDocument() (*Document, error) {
|
|||||||
}
|
}
|
||||||
d.name = strings.TrimRight(string(byt), "\r\n")
|
d.name = strings.TrimRight(string(byt), "\r\n")
|
||||||
if Mode != Safe {
|
if Mode != Safe {
|
||||||
err = d.Restore()
|
err = d.Restore(d.Filename())
|
||||||
switch {
|
switch {
|
||||||
case os.IsNotExist(err):
|
case os.IsNotExist(err):
|
||||||
log.Println("Previous version not found.")
|
log.Println("Previous version not found.")
|
||||||
@@ -163,8 +163,11 @@ func ActiveDocument() (*Document, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Restore loads document data from a JSON file.
|
// Restore loads document data from a JSON file.
|
||||||
func (d *Document) Restore() error {
|
func (d *Document) Restore(path string) error {
|
||||||
byt, err := ioutil.ReadFile(d.Filename())
|
if path == "" {
|
||||||
|
path = d.Filename()
|
||||||
|
}
|
||||||
|
byt, err := ioutil.ReadFile(path)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
log.Println("Previous version found, loading")
|
log.Println("Previous version found, loading")
|
||||||
err = json.Unmarshal(byt, &d)
|
err = json.Unmarshal(byt, &d)
|
||||||
@@ -188,8 +191,13 @@ func (d *Document) Filename() string {
|
|||||||
if !ok {
|
if !ok {
|
||||||
log.Panic("No caller information")
|
log.Panic("No caller information")
|
||||||
}
|
}
|
||||||
return filepath.Join(filepath.Dir(dir), "data",
|
err := os.Mkdir(filepath.Join(filepath.Dir(dir), "data"), 0700)
|
||||||
strings.TrimRight(d.name, "\r\n")+".txt")
|
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.
|
// 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"
|
//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
|
package ps
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ func TestActiveDocument(t *testing.T) {
|
|||||||
}
|
}
|
||||||
Open(testDoc)
|
Open(testDoc)
|
||||||
d, err := ActiveDocument()
|
d, err := ActiveDocument()
|
||||||
defer d.Dump()
|
defer func(){d.Dump()}()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ func Run(name string, args ...string) ([]byte, error) {
|
|||||||
cmd := exec.Command(std.Cmd, parseArgs(name, args...)...)
|
cmd := exec.Command(std.Cmd, parseArgs(name, args...)...)
|
||||||
cmd.Stdout, cmd.Stderr = &out, &errs
|
cmd.Stdout, cmd.Stderr = &out, &errs
|
||||||
if err := cmd.Run(); err != nil || len(errs.Bytes()) != 0 {
|
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
|
return out.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user