Skip to content

Commit

Permalink
Merge pull request #9 from gochore/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfogre authored Jun 18, 2020
2 parents 050d66d + 14ca0a7 commit 1d10c80
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 28 deletions.
28 changes: 14 additions & 14 deletions htmlt/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ func (e Html) Render(writer io.Writer, themes ...style.Theme) error {
}

// T return a html element with specified tag
func T(tag string, format string, a ...interface{}) Html {
func T(tag string, format Html, a ...interface{}) Html {
return Sprintf(fmt.Sprintf("<%s>%s</%s>", tag, format, tag), a...)
}

// H return a html element <h>
func H(level int, format string, a ...interface{}) Html {
func H(level int, format Html, a ...interface{}) Html {
if level < 1 {
level = 1
}
Expand All @@ -47,22 +47,22 @@ func Hr() Html {
}

// P return a html element <p>
func P(format string, a ...interface{}) Html {
func P(format Html, a ...interface{}) Html {
return T("p", format, a...)
}

// Pre return a html element <pre>
func Pre(format string, a ...interface{}) Html {
func Pre(format Html, a ...interface{}) Html {
return T("pre", format, a...)
}

// A return a html element <a>
func A(href, format string, a ...interface{}) Html {
func A(href string, format Html, a ...interface{}) Html {
return Sprintf(fmt.Sprintf(`<a href="%s">%s</a>`, href, format), a...)
}

// B return a html element <b>
func B(format string, a ...interface{}) Html {
func B(format Html, a ...interface{}) Html {
return T("b", format, a...)
}

Expand All @@ -72,41 +72,41 @@ func Br() Html {
}

// Code return a html element <code>
func Code(format string, a ...interface{}) Html {
func Code(format Html, a ...interface{}) Html {
return T("code", format, a...)
}

// Em return a html element <em>
func Em(format string, a ...interface{}) Html {
func Em(format Html, a ...interface{}) Html {
return T("em", format, a...)
}

// I return a html element <i>
func I(format string, a ...interface{}) Html {
func I(format Html, a ...interface{}) Html {
return T("i", format, a...)
}

// Small return a html element <small>
func Small(format string, a ...interface{}) Html {
func Small(format Html, a ...interface{}) Html {
return T("small", format, a...)
}

// Strong return a html element <strong>
func Strong(format string, a ...interface{}) Html {
func Strong(format Html, a ...interface{}) Html {
return T("strong", format, a...)
}

// Img return a html element <img>
func Img(src, alt, format string, a ...interface{}) Html {
func Img(src, alt string, format Html, a ...interface{}) Html {
return Sprintf(fmt.Sprintf(`<a src="%s" alt="%s">%s</a>`, src, alt, format), a...)
}

// Del return a html element <del>
func Del(format string, a ...interface{}) Html {
func Del(format Html, a ...interface{}) Html {
return T("del", format, a...)
}

// Ins return a html element <ins>
func Ins(format string, a ...interface{}) Html {
func Ins(format Html, a ...interface{}) Html {
return T("ins", format, a...)
}
36 changes: 22 additions & 14 deletions htmlt/html_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func TestT(t *testing.T) {
type args struct {
tag string
format string
format Html
a []interface{}
}
tests := []struct {
Expand Down Expand Up @@ -44,7 +44,7 @@ func TestT(t *testing.T) {
func TestH(t *testing.T) {
type args struct {
level int
format string
format Html
a []interface{}
}
tests := []struct {
Expand Down Expand Up @@ -110,7 +110,7 @@ func TestHr(t *testing.T) {

func TestP(t *testing.T) {
type args struct {
format string
format Html
a []interface{}
}
tests := []struct {
Expand Down Expand Up @@ -138,7 +138,7 @@ func TestP(t *testing.T) {

func TestPre(t *testing.T) {
type args struct {
format string
format Html
a []interface{}
}
tests := []struct {
Expand Down Expand Up @@ -167,7 +167,7 @@ func TestPre(t *testing.T) {
func TestA(t *testing.T) {
type args struct {
href string
format string
format Html
a []interface{}
}
tests := []struct {
Expand Down Expand Up @@ -196,7 +196,7 @@ func TestA(t *testing.T) {

func TestB(t *testing.T) {
type args struct {
format string
format Html
a []interface{}
}
tests := []struct {
Expand Down Expand Up @@ -243,7 +243,7 @@ func TestBr(t *testing.T) {

func TestCode(t *testing.T) {
type args struct {
format string
format Html
a []interface{}
}
tests := []struct {
Expand Down Expand Up @@ -271,7 +271,7 @@ func TestCode(t *testing.T) {

func TestDel(t *testing.T) {
type args struct {
format string
format Html
a []interface{}
}
tests := []struct {
Expand Down Expand Up @@ -299,7 +299,7 @@ func TestDel(t *testing.T) {

func TestEm(t *testing.T) {
type args struct {
format string
format Html
a []interface{}
}
tests := []struct {
Expand Down Expand Up @@ -398,7 +398,7 @@ func TestHtml_Render(t *testing.T) {

func TestI(t *testing.T) {
type args struct {
format string
format Html
a []interface{}
}
tests := []struct {
Expand Down Expand Up @@ -428,7 +428,7 @@ func TestImg(t *testing.T) {
type args struct {
src string
alt string
format string
format Html
a []interface{}
}
tests := []struct {
Expand Down Expand Up @@ -458,7 +458,7 @@ func TestImg(t *testing.T) {

func TestIns(t *testing.T) {
type args struct {
format string
format Html
a []interface{}
}
tests := []struct {
Expand Down Expand Up @@ -486,7 +486,7 @@ func TestIns(t *testing.T) {

func TestSmall(t *testing.T) {
type args struct {
format string
format Html
a []interface{}
}
tests := []struct {
Expand Down Expand Up @@ -542,7 +542,7 @@ func TestSprintf(t *testing.T) {

func TestStrong(t *testing.T) {
type args struct {
format string
format Html
a []interface{}
}
tests := []struct {
Expand All @@ -567,3 +567,11 @@ func TestStrong(t *testing.T) {
})
}
}

func TestHtml_Str(t *testing.T) {
var want Html = `<a href="/a"><b><code><del><em><h1><i><p>hello</p></i></h1></em></del></code></b></a>`
got := A("/a", B(Code(Del(Em(H(1, I(P("hello"))))))))
if got != want {
t.Errorf("Sprintf() = %v, want %v", got, want)
}
}

0 comments on commit 1d10c80

Please sign in to comment.