Skip to content

Commit

Permalink
Changed readme template
Browse files Browse the repository at this point in the history
Updated documentation
  • Loading branch information
Unknown committed Jul 5, 2018
1 parent a0d6686 commit 4294932
Show file tree
Hide file tree
Showing 11 changed files with 264 additions and 81 deletions.
40 changes: 40 additions & 0 deletions .doc.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{{with .PDoc}}{{if $.IsMain}}> {{ base .ImportPath }}
{{comment_md .Doc}}{{else}}# {{ .Name }}
[![GoDoc](https://godoc.org/{{ .ImportPath }}?status.svg)](https://godoc.org/github.com/sbrow/{{ .Name }}) [![Build Status](https://travis-ci.org/sbrow/{{ .Name }}.svg?branch=master)](https://travis-ci.org/sbrow/{{ .Name }}) [![Coverage Status](https://coveralls.io/repos/github/sbrow/{{ .Name }}/badge.svg?branch=master)](https://coveralls.io/github/sbrow/{{ .Name }}?branch=master) [![Go Report Card](https://goreportcard.com/badge/{{ .ImportPath }})](https://goreportcard.com/report/{{ .ImportPath }})

`import "{{.ImportPath}}"`

* [Overview](#pkg-overview)
* [Installation](pkg-installation){{if $.Dirs}}
* [Subdirectories](#pkg-subdirectories){{end}}{{ with .Notes}}{{ range $marker, $content := .}}
* [{{$marker}}](#pkg-note-{{$marker}}){{end}}
{{- end}}
* [Documentation](#pkg-doc)

## <a name="pkg-overview">Overview</a>
{{comment_md .Doc}}
{{example_html $ ""}}


## <a name="pkg-installation">Installation</a>
```sh
$ go get -u {{ .ImportPath }}
```
<!---
{{if $.Examples}}
#### <a name="pkg-examples">Examples</a>{{- range $.Examples}}
* [{{example_name .Name}}](example_{{.Name}}_test.go){{- end}}{{- end}}
{{end}}
--->

{{ with .Notes}}
{{ range $marker, $content := .}}
## <a name="pkg-note-{{$marker}}">{{$marker}}</a>
{{ range $key, $value := .}}
`{{ $value.UID }}:` {{ $value.Body }}{{end}}{{end}}{{end}}
## <a name="pkg-doc">Documentation</a>
For full Documentation please visit https://godoc.org/{{.ImportPath}}
- - -
{{end}}

Generated by [godoc2md](http://godoc.org/github.com/davecheney/godoc2md)
9 changes: 0 additions & 9 deletions .godocdown.template

This file was deleted.

50 changes: 46 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,54 @@
# ps
[![GoDoc](https://godoc.org/github.com/sbrow/ps?status.svg)](https://godoc.org/github.com/sbrow/ps) [![Build Status](https://travis-ci.org/sbrow/ps.svg?branch=master)](https://travis-ci.org/sbrow/ps) [![Coverage Status](https://coveralls.io/repos/github/sbrow/ps/badge.svg?branch=master)](https://coveralls.io/github/sbrow/ps?branch=master) [![Go Report Card](https://goreportcard.com/badge/github.com/sbrow/ps)](https://goreportcard.com/report/github.com/sbrow/ps)

Package ps is a rudimentary API between Adobe Photoshop CS5 and Golang. The
interaction between the two is implemented using Javascript/VBScript.
`import "github.com/sbrow/ps"`

* [Overview](#pkg-overview)
* [Installation](pkg-installation)
* [Subdirectories](#pkg-subdirectories)
* [TODO](#pkg-note-TODO)
* [Documentation](#pkg-doc)

## <a name="pkg-overview">Overview</a>
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.

## Installation
```bash




## <a name="pkg-installation">Installation</a>
```sh
$ go get -u github.com/sbrow/ps
```
<!---
#### <a name="pkg-examples">Examples</a>
* [JSLayer](example_JSLayer_test.go)
--->



## <a name="pkg-note-TODO">TODO</a>

`sbrow:` (2) Make TextLayer a subclass of ArtLayer.

`sbrow:` Reduce cylcomatic complexity

`sbrow:` Does funky things when passed invalid layername.

`sbrow:` Move to Document

`sbrow:` get rid of the semicolon.

## <a name="pkg-doc">Documentation</a>
For full Documentation please visit https://godoc.org/github.com/sbrow/ps
- - -


Generated by [godoc2md](http://godoc.org/github.com/davecheney/godoc2md)
10 changes: 6 additions & 4 deletions artlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

// ArtLayer reflects some values from an Art Layer in a Photoshop document.
//
// TODO: (2) Make TextLayer a subclass of ArtLayer.
// TODO(sbrow): (2) Make TextLayer a subclass of ArtLayer.
type ArtLayer struct {
name string // The layer's name.
bounds [2][2]int // The corners of the layer's bounding box.
Expand Down Expand Up @@ -200,9 +200,9 @@ func (a *ArtLayer) Path() string {
}

// SetVisible makes the layer visible.
func (a *ArtLayer) SetVisible(b bool) {
func (a *ArtLayer) SetVisible(b bool) error {
if a.visible == b {
return
return nil
}
a.visible = b
switch b {
Expand All @@ -214,8 +214,10 @@ func (a *ArtLayer) SetVisible(b bool) {
js := fmt.Sprintf("%s.visible=%v;",
strings.TrimRight(JSLayer(a.Path()), ";"), b)
if byt, err := DoJS("compilejs.jsx", js); err != nil {
log.Println(string(byt), err)
log.Println(string(byt))
return err
}
return nil
}

// Visible returns whether or not the layer is currently hidden.
Expand Down
58 changes: 49 additions & 9 deletions document.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,23 @@ func (d *Document) Height() int {
return d.height
}

// ArtLayer returns the first top level ArtLayer matching
// the given name.
func (d *Document) ArtLayer(name string) *ArtLayer {
for _, lyr := range d.artLayers {
if lyr.name == name {
if Mode == 0 && !lyr.current {
err := lyr.Refresh()
if err != nil {
log.Panic(err)
}
}
return lyr
}
}
return nil
}

// ArtLayers returns this document's ArtLayers, if any.
func (d *Document) ArtLayers() []*ArtLayer {
return d.artLayers
Expand Down Expand Up @@ -99,7 +116,7 @@ func (d *Document) LayerSet(name string) *LayerSet {

// ActiveDocument returns document currently focused in Photoshop.
//
// TODO: Reduce cylcomatic complexity
// TODO(sbrow): Reduce cylcomatic complexity
func ActiveDocument() (*Document, error) {
log.Println("Loading ActiveDoucment")
d := &Document{}
Expand All @@ -111,26 +128,32 @@ func ActiveDocument() (*Document, error) {
d.name = strings.TrimRight(string(byt), "\r\n")
if Mode != Safe {
err = d.Restore()
return d, err
switch {
case os.IsNotExist(err):
log.Println("Previous version not found.")
case err == nil:
return d, err
default:
return nil, err

}
}
log.Println("Loading manually (This could take awhile)")
byt, err = DoJS("getActiveDoc.jsx")
if err != nil {
log.Panic(err)
return nil, err
}
err = json.Unmarshal(byt, &d)
if err != nil {
if err = json.Unmarshal(byt, &d); err != nil {
d.Dump()
log.Panic(err)
return nil, err
}
for _, lyr := range d.artLayers {
lyr.SetParent(d)
}
for i, set := range d.layerSets {
var s *LayerSet
s, err = NewLayerSet(set.Path()+"/", d)
if err != nil {
log.Fatal(err)
if s, err = NewLayerSet(set.Path()+"/", d); err != nil {
return nil, err
}
d.layerSets[i] = s
s.SetParent(d)
Expand Down Expand Up @@ -190,3 +213,20 @@ func (d *Document) Dump() {
log.Println(err)
}
}

// MustExist returns a Layer from the set with the given name, and
// panics if it doesn't exist.
//
// If there is a LayerSet and an ArtLayer with the same name,
// it will return the LayerSet.
func (d *Document) MustExist(name string) Layer {
set := d.LayerSet(name)
if set == nil {
lyr := d.ArtLayer(name)
if lyr == nil {
log.Panicf("no Layer found at \"%s%s\"", d.Path(), name)
}
return lyr
}
return set
}
31 changes: 31 additions & 0 deletions interfaces.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package ps

// Group represents a Document or LayerSet.
type Group interface {
Name() string
Parent() Group
SetParent(Group)
Path() string
ArtLayer(name string) *ArtLayer
LayerSet(name string) *LayerSet
ArtLayers() []*ArtLayer
LayerSets() []*LayerSet
MustExist(name string) Layer
MarshalJSON() ([]byte, error)
UnmarshalJSON(b []byte) error
}

// Layer represents an ArtLayer or LayerSet Object.
type Layer interface {
Bounds() [2][2]int
MarshalJSON() ([]byte, error)
Name() string
Parent() Group
Path() string
Refresh() error
SetParent(g Group)
SetPos(x, y int, bound string)
SetVisible(b bool) error
UnmarshalJSON(b []byte) error
Visible() bool
}
46 changes: 25 additions & 21 deletions layerset.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,11 @@ package ps

import (
"encoding/json"
"errors"
"fmt"
"log"
"strings"
)

// Group represents a Document or LayerSet.
type Group interface {
Name() string
Parent() Group
SetParent(Group)
Path() string
ArtLayers() []*ArtLayer
LayerSets() []*LayerSet
MarshalJSON() ([]byte, error)
UnmarshalJSON(b []byte) error
}

// LayerSet holds a group of Layer objects and a group of LayerSet objects.
type LayerSet struct {
name string
Expand Down Expand Up @@ -95,7 +82,6 @@ func (l *LayerSet) ArtLayers() []*ArtLayer {

// ArtLayer returns the first top level ArtLayer matching
// the given name.
// TODO: Does funky things when passed invalid layername.
func (l *LayerSet) ArtLayer(name string) *ArtLayer {
for _, lyr := range l.artLayers {
if lyr.name == name {
Expand All @@ -113,12 +99,7 @@ func (l *LayerSet) ArtLayer(name string) *ArtLayer {
return lyr
}
}
lyr := l.ArtLayer(name)
fmt.Println(lyr)
if lyr == nil {
log.Panic(errors.New("layer not found"))
}
return lyr
return nil
}

// LayerSets returns the LayerSets contained within
Expand All @@ -138,6 +119,23 @@ func (l *LayerSet) LayerSet(name string) *LayerSet {
return nil
}

// MustExist returns a Layer from the set with the given name, and
// panics if it doesn't exist.
//
// If there is a LayerSet and an ArtLayer with the same name,
// it will return the LayerSet.
func (l *LayerSet) MustExist(name string) Layer {
set := l.LayerSet(name)
if set == nil {
lyr := l.ArtLayer(name)
if lyr == nil {
log.Panicf("no Layer found at \"%s%s\"", l.Path(), name)
}
return lyr
}
return set
}

// Bounds returns the furthest corners of the LayerSet.
func (l LayerSet) Bounds() [2][2]int {
return l.bounds
Expand Down Expand Up @@ -165,7 +163,6 @@ func (l *LayerSet) Path() string {
func NewLayerSet(path string, g Group) (*LayerSet, error) {
path = strings.Replace(path, "//", "/", -1)
byt, err := DoJS("getLayerSet.jsx", JSLayer(path), JSLayerMerge(path))
fmt.Println(JSLayer(path), JSLayerMerge(path))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -300,3 +297,10 @@ func (l *LayerSet) Refresh() error {
l.current = true
return nil
}

func (l *LayerSet) Set(ll *LayerSet) {
if ll == nil {
panic("AHHHHHH")
}
l = ll
}
10 changes: 6 additions & 4 deletions ps.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//go:generate godocdown -output=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

Expand Down Expand Up @@ -38,7 +40,7 @@ func ApplyDataset(name string) error {
}

// Close closes the active document in Photoshop, using the given save option.
// TODO: Move to Document
// TODO(sbrow): Move to Document
func Close(save SaveOption) error {
_, err := runner.Run("close", fmt.Sprint(save))
return err
Expand Down Expand Up @@ -104,7 +106,7 @@ func Init() error {
// The output always ends with a semicolon, so if you want to access a specific
// property of the layer, you'll have to trim the output before concatenating.
//
// TODO: get rid of the semicolon.
// TODO(sbrow): get rid of the semicolon.
func JSLayer(path string) string {
pth := strings.Split(path, "/")
js := "app.activeDocument"
Expand Down Expand Up @@ -138,7 +140,7 @@ func Open(path string) error {
return err
}

// Quit exits Photoshop, closing all open docuemnts using the given save option.
// Quit exits Photoshop, closing all open documents using the given save option.
func Quit(save SaveOption) error {
_, err := runner.Run("quit", fmt.Sprint(save))
return err
Expand Down
Loading

0 comments on commit 4294932

Please sign in to comment.