Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added expand option #40

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type config struct {
common

encoding string // input encoding
expand bool // expand story passages into single files
sourcePaths []string // slice of paths to seach for source files
modulePaths []string // slice of paths to seach for module files
headFile string // name of the head file
Expand Down Expand Up @@ -126,6 +127,7 @@ func newConfig() *config {
options.Add("archive_twine2", "-a|--archive-twine2")
options.Add("archive_twine1", "--archive-twine1")
options.Add("decompile_twee3", "-d|--decompile-twee3|--decompile") // NOTE: "--decompile" is deprecated.
options.Add("expand", "--expand")
options.Add("decompile_twee1", "--decompile-twee1")
options.Add("encoding", "-c=s|--charset=s")
options.Add("format", "-f=s|--format=s")
Expand Down Expand Up @@ -156,6 +158,8 @@ func newConfig() *config {
c.outMode = outModeTwee1
case "encoding":
c.encoding = val.(string)
case "expand":
c.expand = true
case "format":
c.cmdline.formatID = val.(string)
c.formatID = c.cmdline.formatID
Expand Down
24 changes: 22 additions & 2 deletions tweego.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package main

import (
"log"
"regexp"
)

const tweegoName = "tweego"
Expand Down Expand Up @@ -65,10 +66,29 @@ func buildOutput(c *config) *story {
// Write the output.
switch c.outMode {
case outModeTwee3, outModeTwee1:
// Write out the project as Twee source.
if _, err := fileWriteAll(c.outFile, alignRecordSeparators(s.toTwee(c.outMode))); err != nil {

switch c.expand {
case true:
// Make a Regex to say we only want letters and numbers
reg, err := regexp.Compile("[^a-zA-Z0-9]+")
if err != nil {
log.Fatal(err)
}

for _, p := range s.passages {
processedString := reg.ReplaceAllString(p.name, "")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if two different passages resolve to the same processedString?

if _, err := fileWriteAll(processedString, []byte(p.toTwee(c.outMode))); err != nil {
log.Fatalf(`error: %s`, err.Error())
}
}
case false:
// Write out the project as Twee source.
if _, err := fileWriteAll(c.outFile, alignRecordSeparators(s.toTwee(c.outMode))); err != nil {
log.Fatalf(`error: %s`, err.Error())
}
}


case outModeTwine2Archive:
// Write out the project as Twine 2 archived HTML.
if _, err := fileWriteAll(c.outFile, s.toTwine2Archive(c.startName)); err != nil {
Expand Down