Skip to content

Commit

Permalink
Remove devsite logic from claat (googlecodelabs#680)
Browse files Browse the repository at this point in the history
* Delete template-devsite.html
* Update template.go
* Update export_test.go
* Update html_test.go
  * Remove devsite code tests
  * Add grid code tests
* Update html.go
  • Loading branch information
DragonRider0o0 authored Oct 29, 2021
1 parent 82836c7 commit ff5a17e
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 120 deletions.
2 changes: 1 addition & 1 deletion claat/cmd/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestExportCodelabMemory(t *testing.T) {
opts := cmd.CmdExportOptions{
Expenv: "web",
Output: tmp,
Tmplout: "devsite",
Tmplout: "html",
GlobalGA: "UA-99999999-99",
}

Expand Down
12 changes: 1 addition & 11 deletions claat/render/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,7 @@ func (hw *htmlWriter) code(n *nodes.CodeNode) {
}
hw.writeString(">")
}
if hw.format == "devsite" {
hw.writeString("{% verbatim %}")
}
hw.writeEscape(n.Value)
if hw.format == "devsite" {
hw.writeString("{% endverbatim %}")
}
if !n.Term {
hw.writeString("</code>")
}
Expand Down Expand Up @@ -308,11 +302,7 @@ func (hw *htmlWriter) itemsList(n *nodes.ItemsListNode) {
}

func (hw *htmlWriter) grid(n *nodes.GridNode) {
if hw.format == "devsite" {
hw.writeString("<table class=\"vertical-rules\">\n")
} else {
hw.writeString("<table>\n")
}
hw.writeString("<table>\n")
for _, r := range n.Rows {
hw.writeString("<tr>")
for _, c := range r {
Expand Down
85 changes: 67 additions & 18 deletions claat/render/html_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,10 +676,9 @@ bar</paper-button>`,

func TestCode(t *testing.T) {
tests := []struct {
name string
inNode *nodes.CodeNode
inFormat string
out string
name string
inNode *nodes.CodeNode
out string
}{
{
name: "NoLang",
Expand All @@ -691,23 +690,11 @@ func TestCode(t *testing.T) {
inNode: nodes.NewCodeNode("foobar", false, "c"),
out: `<pre><code language="c" class="c">foobar</code></pre>`,
},
{
name: "NoLangDevsite",
inNode: nodes.NewCodeNode("foobar", false, ""),
inFormat: "devsite",
out: `<pre><code>{% verbatim %}foobar{% endverbatim %}</code></pre>`,
},
{
name: "LangDevsite",
inNode: nodes.NewCodeNode("foobar", false, "c"),
inFormat: "devsite",
out: `<pre><code language="c" class="c">{% verbatim %}foobar{% endverbatim %}</code></pre>`,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
outBuffer := &bytes.Buffer{}
hw := &htmlWriter{w: outBuffer, format: tc.inFormat}
hw := &htmlWriter{w: outBuffer}
hw.code(tc.inNode)
out := outBuffer.String()
if diff := cmp.Diff(tc.out, out); diff != "" {
Expand Down Expand Up @@ -873,7 +860,69 @@ func TestOnlyImages(t *testing.T) {
}

// TODO: test itemsList
// TODO: test grid

func TestGrid(t *testing.T) {
tests := []struct {
name string
inNode *nodes.GridNode
out string
}{
{
name: "No rows or cells ",
inNode: nodes.NewGridNode(),
out: "<table>\n</table>",
},
{
name: "One row and no cells",
inNode: nodes.NewGridNode([][]*nodes.GridCell{
[]*nodes.GridCell{},
}...),
out: "<table>\n<tr></tr>\n</table>",
},
{
name: "One row and one cell",
inNode: nodes.NewGridNode([][]*nodes.GridCell{
[]*nodes.GridCell{
&nodes.GridCell{
Content: nodes.NewListNode([]nodes.Node{
nodes.NewTextNode(nodes.NewTextNodeOptions{Value: "foo"}),
}...),
},
},
}...),
out: "<table>\n<tr><td colspan=\"0\" rowspan=\"0\">foo</td></tr>\n</table>",
},
{
name: "One row and multiple cells",
inNode: nodes.NewGridNode([][]*nodes.GridCell{
[]*nodes.GridCell{
&nodes.GridCell{
Content: nodes.NewListNode([]nodes.Node{
nodes.NewTextNode(nodes.NewTextNodeOptions{Value: "foo"}),
}...),
},
&nodes.GridCell{
Content: nodes.NewListNode([]nodes.Node{
nodes.NewTextNode(nodes.NewTextNodeOptions{Value: "bar"}),
}...),
},
},
}...),
out: "<table>\n<tr><td colspan=\"0\" rowspan=\"0\">foo</td><td colspan=\"0\" rowspan=\"0\">bar</td></tr>\n</table>",
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
outBuffer := &bytes.Buffer{}
hw := &htmlWriter{w: outBuffer}
hw.grid(tc.inNode)
out := outBuffer.String()
if diff := cmp.Diff(tc.out, out); diff != "" {
t.Errorf("hw.grid(%+v) got diff (-want +got):\n%s", tc.inNode, diff)
}
})
}
}

func TestInfobox(t *testing.T) {
tests := []struct {
Expand Down
82 changes: 0 additions & 82 deletions claat/render/template-devsite.html

This file was deleted.

8 changes: 0 additions & 8 deletions claat/render/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,6 @@ type template struct {
//go:embed template.html
var newHTMLTemplate []byte

//go:embed template-devsite.html
var newHTMLDevsiteTemplate []byte

//go:embed template.md
var newMDTemplate []byte

Expand All @@ -174,11 +171,6 @@ func parseTemplate(name string, fmap map[string]interface{}) (executer, error) {
bytes: newHTMLTemplate,
html: true,
}
case "devsite":
tmpl = &template{
bytes: newHTMLDevsiteTemplate,
html: true,
}
case "md":
tmpl = &template{
bytes: newMDTemplate,
Expand Down

0 comments on commit ff5a17e

Please sign in to comment.