Skip to content

Commit

Permalink
add --section-path, rename --tag to --section-tag
Browse files Browse the repository at this point in the history
this flag is for loading a .lit file in the context of another .lit
file, e.g. loading docs and rendering release notes that reference the
docs

Signed-off-by: Alex Suraci <suraci.alex@gmail.com>
  • Loading branch information
vito committed Apr 16, 2019
1 parent a3d1569 commit 8b6f9b6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
18 changes: 12 additions & 6 deletions booklitcmd/command.go
Expand Up @@ -19,10 +19,11 @@ import (
type Command struct {
Version func() `short:"v" long:"version" description:"Print the version of Boooklit and exit."`

In string `long:"in" short:"i" required:"true" description:"Input .lit file to load."`

In string `long:"in" short:"i" required:"true" description:"Input .lit file to load."`
Out string `long:"out" short:"o" description:"Directory into which sections will be rendered."`
Tag string `long:"tag" short:"t" description:"Section tag to render."`

SectionTag string `long:"section-tag" description:"Section tag to render."`
SectionPath string `long:"section-path" description:"Section path to load and render with --in as its parent."`

SaveSearchIndex bool `long:"save-search-index" description:"Save a search index JSON file in the destination."`

Expand Down Expand Up @@ -116,13 +117,18 @@ func (cmd *Command) Build() error {
}

sectionToRender := section
if cmd.Tag != "" {
tags := section.FindTag(cmd.Tag)
if cmd.SectionTag != "" {
tags := section.FindTag(cmd.SectionTag)
if len(tags) == 0 {
return fmt.Errorf("unknown tag: %s", cmd.Tag)
return fmt.Errorf("unknown tag: %s", cmd.SectionTag)
}

sectionToRender = tags[0].Section
} else if cmd.SectionPath != "" {
sectionToRender, err = processor.LoadFileIn(section, cmd.SectionPath, basePluginFactories)
if err != nil {
return err
}
}

if cmd.Out == "" {
Expand Down
6 changes: 5 additions & 1 deletion load/processor.go
Expand Up @@ -25,7 +25,11 @@ type parsedNode struct {
}

func (processor *Processor) LoadFile(path string, pluginFactories []booklit.PluginFactory) (*booklit.Section, error) {
section, err := processor.EvaluateFile(nil, path, pluginFactories)
return processor.LoadFileIn(nil, path, pluginFactories)
}

func (processor *Processor) LoadFileIn(parent *booklit.Section, path string, pluginFactories []booklit.PluginFactory) (*booklit.Section, error) {
section, err := processor.EvaluateFile(parent, path, pluginFactories)
if err != nil {
return nil, err
}
Expand Down
6 changes: 5 additions & 1 deletion section.go
Expand Up @@ -112,7 +112,11 @@ func (con *Section) Number() string {

parentNumber := con.Parent.Number()
selfIndex := 1
for i := 0; con.Parent.Children[i] != con; i++ {
for _, child := range con.Parent.Children {
if child == con {
break
}

selfIndex++
}

Expand Down

0 comments on commit 8b6f9b6

Please sign in to comment.