Skip to content

Commit

Permalink
maintenance, added to YAML conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
rsdoiel committed Mar 11, 2024
1 parent 3653ea2 commit 7febcd7
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 8 deletions.
11 changes: 11 additions & 0 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ func RunScripttool(in *os.File, out *os.File, eout *os.File, args []string) erro

}
return fmt.Errorf("A FadeIn filename required for input")
case "fadein2yaml":
if inputFName != "" {
return FadeInToYAML(inputFName, out)
}
case "fadein2osf":
if inputFName != "" {
return FadeInToOSF(inputFName, out)
Expand All @@ -119,6 +123,8 @@ func RunScripttool(in *os.File, out *os.File, eout *os.File, args []string) erro
return FdxToFountain(in, out)
case "fdx2json":
return FdxToJSON(in, out)
case "fdx2yaml":
return FdxToYAML(in, out)
case "fdx2osf":
return FdxToOSF(in, out)

Expand All @@ -132,6 +138,8 @@ func RunScripttool(in *os.File, out *os.File, eout *os.File, args []string) erro
return FountainToFdx(in, out)
case "fountain2json":
return FountainToJSON(in, out)
case "fountain2yaml":
return FountainToYAML(in, out)
case "fountain2osf":
return FountainToOSF(in, out)

Expand All @@ -147,6 +155,8 @@ func RunScripttool(in *os.File, out *os.File, eout *os.File, args []string) erro
return OSFToFountain(in, out)
case "osf2json":
return OSFToJSON(in, out)
case "osf2yaml":
return OSFToYAML(in, out)

// Utility fountain functions
case "fountain2fountain":
Expand All @@ -169,4 +179,5 @@ func RunScripttool(in *os.File, out *os.File, eout *os.File, args []string) erro
default:
return fmt.Errorf("do not understand %q in %q", verb, strings.Join(args, " "))
}
return nil
}
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module github.com/rsdoiel/scripttool
go 1.22.0

require (
github.com/rsdoiel/fdx v1.0.1
github.com/rsdoiel/fdx v1.0.2
github.com/rsdoiel/fountain v1.0.1
github.com/rsdoiel/osf v0.0.5
github.com/rsdoiel/osf v0.0.7
)

require gopkg.in/yaml.v3 v3.0.1 // indirect
require gopkg.in/yaml.v3 v3.0.1
10 changes: 6 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
github.com/rsdoiel/fdx v1.0.1 h1:BXQWLWQtosLaMXzSboXiuru2pxELc4qV3JJ4Y3cv9vQ=
github.com/rsdoiel/fdx v1.0.1/go.mod h1:hXJBkY2UoujfU1EZ1tiR8aa3AZgcReOydZZ7dAuyg9o=
github.com/rsdoiel/fdx v1.0.2 h1:TMBGgYdG7CaPbnM6kMAkRebYyCfWK9dK/qooPhEITU8=
github.com/rsdoiel/fdx v1.0.2/go.mod h1:hXJBkY2UoujfU1EZ1tiR8aa3AZgcReOydZZ7dAuyg9o=
github.com/rsdoiel/fountain v1.0.1 h1:m5JZbnasFendZbYzoTsOsJ/gcup7VNTUjJGTANshQck=
github.com/rsdoiel/fountain v1.0.1/go.mod h1:Sd3MZuWObP+tssyGIuUUfl3+nslvRVndkEEpBVsWAJU=
github.com/rsdoiel/osf v0.0.5 h1:wV919Li4KPiDM5x/qFn86Tn5d3YPtPeqmGYmeIh1vUw=
github.com/rsdoiel/osf v0.0.5/go.mod h1:UzyqbsRFk5rL3WTiFvlfvL4jsqgt/EPHVlbs9FShFwI=
github.com/rsdoiel/osf v0.0.6 h1:5ijMEfFH1zzBsYTeChyCi06sYQhboMBX7rSr/gW7ZnY=
github.com/rsdoiel/osf v0.0.6/go.mod h1:UzyqbsRFk5rL3WTiFvlfvL4jsqgt/EPHVlbs9FShFwI=
github.com/rsdoiel/osf v0.0.7 h1:woMTMPktKWhQJdPGVt1zmVbq9jJFmPiq0lqzWNnmR/s=
github.com/rsdoiel/osf v0.0.7/go.mod h1:jmOePx0mqICIH+G7GuIFnWGckQB7XWovQhdGMp9dPgE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
95 changes: 95 additions & 0 deletions scripttool.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ import (
"github.com/rsdoiel/fdx"
"github.com/rsdoiel/fountain"
"github.com/rsdoiel/osf"

// 3rdParty Packages
"gopkg.in/yaml.v3"
)

var (
Expand Down Expand Up @@ -142,6 +145,27 @@ func FdxToJSON(in io.Reader, out io.Writer) error {
return nil
}

// FdxToYAML converts an input buffer from a .fdx file to a .yaml format
func FdxToYAML(in io.Reader, out io.Writer) error {
src, err := ioutil.ReadAll(in)
if err != nil {
return err
}
document, err := fdx.Parse(src)
if err != nil {
return err
}
fmt.Printf("DEBUG document -> %+v\n", document)

encoder := yaml.NewEncoder(out)
encoder.SetIndent(2)
err = encoder.Encode(document)
if err != nil {
return err
}
return nil
}

// FdxToOSF concerts an input buffer from .fdx to Open Screenplay Format 2.0
func FdxToOSF(in io.Reader, out io.Writer) error {
src, err := ioutil.ReadAll(in)
Expand Down Expand Up @@ -271,6 +295,25 @@ func OSFToJSON(in io.Reader, out io.Writer) error {
return nil
}

// OSFToYAML converts the input buffer from .osf to .yaml format.
func OSFToYAML(in io.Reader, out io.Writer) error {
src, err := ioutil.ReadAll(in)
if err != nil {
return err
}
document, err := osf.Parse(src)
if err != nil {
return err
}
encoder := yaml.NewEncoder(out)
encoder.SetIndent(2)
err = encoder.Encode(document)
if err != nil {
return err
}
return nil
}

// Fountain2Fountain reads a input buffer as .fountain and pretty prints output as .fountain
func FountainToFountain(in io.Reader, out io.Writer) error {
src, err := ioutil.ReadAll(in)
Expand Down Expand Up @@ -435,6 +478,43 @@ func FadeInToJSON(inputFName string, out io.Writer) error {
return nil
}

// FadeInToYAML converts an input file to YAML format.
func FadeInToYAML(inputFName string, out io.Writer) error {
// NOTE: Need to unzip, extract document.xml then pass the source
// of document.xml to osf.Parse()
r, err := zip.OpenReader(inputFName)
if err != nil {
return err
}
defer r.Close()
src := []byte{}
for _, f := range r.File {
if f.Name == "document.xml" {
rc, err := f.Open()
if err != nil {
return err
}
src, err = ioutil.ReadAll(rc)
if err != nil {
return err
}
rc.Close()
break
}
}
document, err := osf.Parse(src)
if err != nil {
return err
}
encoder := yaml.NewEncoder(out)
encoder.SetIndent(2)
err = encoder.Encode(document)
if err != nil {
return err
}
return nil
}

// FadeInToOSF converts an input file to .fountain format.
func FadeInToOSF(inputFName string, out io.Writer) error {
// NOTE: Need to unzip, extract document.xml then pass the source
Expand Down Expand Up @@ -626,3 +706,18 @@ func FountainToJSON(in io.Reader, out io.Writer) error {
_, err = out.Write(src)
return err
}

// FountainToYAML convert .fountain file to YAML
func FountainToYAML(in io.Reader, out io.Writer) error {
src, err := ioutil.ReadAll(in)
if err != nil {
return err
}
screenplay, err := fountain.Parse(src)
if err != nil {
return err
}
encoder := yaml.NewEncoder(out)
encoder.SetIndent(2)
return encoder.Encode(screenplay)
}
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const (
ReleaseDate = "2024-03-11"

// ReleaseHash, the Git hash when version.go was generated
ReleaseHash = "8cbd563"
ReleaseHash = "3653ea2"

LicenseText = `
All rights reserved.
Expand Down

0 comments on commit 7febcd7

Please sign in to comment.