summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoop Kiefte <ikojba@gmail.com>2018-12-31 18:05:49 +0100
committerJoop Kiefte <ikojba@gmail.com>2018-12-31 18:05:49 +0100
commit78370fd7daaa90c109aeede3ceae8071c6f5feae (patch)
tree830639ed4fc19ac57bfe567b93aaacb77f14027a
parent096e5c3b801b245b4fd1a17e9a9fae9ed7e2c0d2 (diff)
Add examples and get rid of some old code
-rw-r--r--.gitignore3
-rw-r--r--fountain/example.fountain20
-rw-r--r--fountain/parse.go62
-rw-r--r--lex/example.go5
-rw-r--r--lex/example.lex20
-rw-r--r--main.go117
6 files changed, 52 insertions, 175 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ed7630e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+lexington
+textplay
+*.pdf
diff --git a/fountain/example.fountain b/fountain/example.fountain
new file mode 100644
index 0000000..14ec4f8
--- /dev/null
+++ b/fountain/example.fountain
@@ -0,0 +1,20 @@
+INT. HOUSE - DAY
+
+MARY
+I can't believe how easy it is to write in Fountain.
+
+TOM
+(typing)
+Look! I just made a parenthetical!
+
+SOMETHING HAPPENS!
+
+(what? I don't know...)
+
+EXT. GARDEN
+
+TOM
+What am I doing here now?
+To be honest, I have absolutely no idea!
+
+And that means really no idea!
diff --git a/fountain/parse.go b/fountain/parse.go
index dc4602f..b4273d7 100644
--- a/fountain/parse.go
+++ b/fountain/parse.go
@@ -4,68 +4,6 @@ import (
"strings"
)
-var example = `
-INT. HOUSE - DAY
-
-MARY
-I can't believe how easy it is to write in Fountain.
-
-TOM
-(typing)
-Look! I just made a parenthetical!
-
-SOMETHING HAPPENS!
-
-(what? I don't know...)
-
-EXT. GARDEN
-
-TOM
-What am I doing here now?
-To be honest, I have absolutely no idea!
-
-And that means really no idea!
-`
-
-var action = map[string]struct {
- Left, Width float64
-}{
- "action": {1.5, 6},
- "speaker": {4.2, 3.3},
- "dialog": {2.9, 3.3},
- "scene": {1.5, 6},
- "paren": {3.6, 2},
- "trans": {6, 1.5},
- "note": {1.5, 6},
- "allcaps": {1.5, 6},
- "empty": {1.5, 6},
-}
-
-var tr func(string) string
-
-type Tree struct {
- PDF *gofpdf.Fpdf
- F []struct {
- Format string
- Text string
- }
-}
-
-func (t Tree) pr(a string, text string) {
- line(t.PDF, action[a].Left, action[a].Width, text)
-}
-
-func (t Tree) Render() {
- for _, row := range t.F {
- t.pr(row.Format, row.Text)
- }
-}
-
-func line(pdf *gofpdf.Fpdf, jump, width float64, text string) {
- pdf.SetX(jump)
- pdf.MultiCell(width, 0.19, tr(text), "", "aligned", false)
-}
-
func (t *Tree) ParseString(play string) {
toParse := strings.Split(play, "\n")
for i, row := range toParse {
diff --git a/lex/example.go b/lex/example.go
new file mode 100644
index 0000000..164e71a
--- /dev/null
+++ b/lex/example.go
@@ -0,0 +1,5 @@
+package lex
+
+var Example = `
+
+`
diff --git a/lex/example.lex b/lex/example.lex
new file mode 100644
index 0000000..14ec4f8
--- /dev/null
+++ b/lex/example.lex
@@ -0,0 +1,20 @@
+INT. HOUSE - DAY
+
+MARY
+I can't believe how easy it is to write in Fountain.
+
+TOM
+(typing)
+Look! I just made a parenthetical!
+
+SOMETHING HAPPENS!
+
+(what? I don't know...)
+
+EXT. GARDEN
+
+TOM
+What am I doing here now?
+To be honest, I have absolutely no idea!
+
+And that means really no idea!
diff --git a/main.go b/main.go
index b020d42..57bf10a 100644
--- a/main.go
+++ b/main.go
@@ -1,120 +1,11 @@
package main
import (
- "github.com/jung-kurt/gofpdf"
- "io/ioutil"
- "os"
- "strings"
+ "github.com/lapingvino/lexington/lex"
+ "github.com/lapingvino/lexington/pdf"
+ "github.com/lapingvino/lexington/rules"
)
-type Action int
-
-var example = `
-INT. HOUSE - DAY
-
-MARY
-I can't believe how easy it is to write in Fountain.
-
-TOM
-(typing)
-Look! I just made a parenthetical!
-
-SOMETHING HAPPENS!
-
-(what? I don't know...)
-
-EXT. GARDEN
-
-TOM
-What am I doing here now?
-To be honest, I have absolutely no idea!
-
-And that means really no idea!
-`
-
-var action = map[string]struct {
- Left, Width float64
-}{
- "action": {1.5, 6},
- "speaker": {4.2, 3.3},
- "dialog": {2.9, 3.3},
- "scene": {1.5, 6},
- "paren": {3.6, 2},
- "trans": {6, 1.5},
- "note": {1.5, 6},
- "allcaps": {1.5, 6},
- "empty": {1.5, 6},
-}
-
-var tr func(string) string
-
-type Tree struct {
- PDF *gofpdf.Fpdf
- F []struct {
- Format string
- Text string
- }
-}
-
-func (t Tree) pr(a string, text string) {
- line(t.PDF, action[a].Left, action[a].Width, text)
-}
-
-func (t Tree) Render() {
- for _, row := range t.F {
- t.pr(row.Format, row.Text)
- }
-}
-
-func line(pdf *gofpdf.Fpdf, jump, width float64, text string) {
- pdf.SetX(jump)
- pdf.MultiCell(width, 0.19, tr(text), "", "aligned", false)
-}
-
-func (t *Tree) ParseString(play string) {
- toParse := strings.Split(play, "\n")
- for i, row := range toParse {
- action := "action"
- if row == strings.ToUpper(row) {
- action = "allcaps"
- }
- if row == "" {
- action = "empty"
- } else {
- if i > 0 {
- switch t.F[i-1].Format {
- case "allcaps":
- t.F[i-1].Format = "speaker"
- if row[0] == '(' && row[len(row)-1] == ')' {
- action = "paren"
- } else {
- action = "dialog"
- }
- case "paren", "dialog":
- action = "dialog"
- }
- }
- }
- t.F = append(t.F, struct{ Format, Text string }{action, row})
- }
-}
-
func main() {
- pdf := gofpdf.New("P", "in", "Letter", "")
- tr = pdf.UnicodeTranslatorFromDescriptor("")
- pdf.AddPage()
- pdf.SetFont("courier", "", 12)
- pdf.SetMargins(1, 1, 1)
- pdf.SetXY(1, 1)
- f := Tree{PDF: pdf}
- input, err := ioutil.ReadAll(os.Stdin)
- if err != nil {
- panic(err)
- }
- f.ParseString(string(input))
- f.Render()
- err = pdf.OutputFileAndClose("fountain.pdf")
- if err != nil {
- panic(err)
- }
+ pdf.Create("fountain.pdf", rules.Default, lex.Screenplay{})
}