Skip to content

Commit

Permalink
refactor: put link/code as methods on markdown doc struct
Browse files Browse the repository at this point in the history
  • Loading branch information
matty-rose committed Oct 24, 2021
1 parent 4f2167d commit 32ef8cc
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 32 deletions.
4 changes: 2 additions & 2 deletions pkg/document/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ func (m *MarkdownDocument) WriteTable(columns []string, rows [][]string) (*Markd
return m, nil
}

func CreateMarkdownLink(title, url string) string {
func (m MarkdownDocument) CreateLink(title, url string) string {
return fmt.Sprintf("[%s](%s)", title, url)
}

func FormatCode(text string) string {
func (m MarkdownDocument) FormatCode(text string) string {
return fmt.Sprintf("`%s`", text)
}
2 changes: 1 addition & 1 deletion pkg/document/markdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,6 @@ func TestCreateMarkdownLink(t *testing.T) {
}

for _, tc := range testCases {
assert.Equal(t, tc.expectedLink, document.CreateMarkdownLink(tc.title, tc.url))
assert.Equal(t, tc.expectedLink, document.NewMarkdownDocument().CreateLink(tc.title, tc.url))
}
}
6 changes: 3 additions & 3 deletions pkg/generator/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (mdg markdownGenerator) generateInputTable(act *types.CompositeAction, doc
inp.Name,
inp.Description,
strconv.FormatBool(inp.Required),
document.FormatCode(inp.Default),
doc.FormatCode(inp.Default),
},
)
}
Expand All @@ -94,7 +94,7 @@ func (mdg markdownGenerator) generateOutputTable(act *types.CompositeAction, doc

var rows [][]string
for _, out := range act.Outputs {
rows = append(rows, []string{out.Name, out.Description, document.FormatCode(out.Value)})
rows = append(rows, []string{out.Name, out.Description, doc.FormatCode(out.Value)})
}

_, _ = doc.WriteTable(columns, rows)
Expand All @@ -108,7 +108,7 @@ func (mdg markdownGenerator) generateExternalActionTable(act *types.CompositeAct
rows = append(
rows,
[]string{
document.CreateMarkdownLink(act.Name, act.GetLink()),
doc.CreateLink(act.Name, act.GetLink()),
act.Creator,
act.Version,
act.StepName,
Expand Down
26 changes: 0 additions & 26 deletions test.md

This file was deleted.

0 comments on commit 32ef8cc

Please sign in to comment.