Commits

Yann Malet  committed 9d40125

Reorganize the app. Move the models into a pages package.

  • Participants
  • Parent commits 5677759

Comments (0)

Files changed (5)

File models/page.go

-package models
-
-import (
-	_ "fmt"
-	"github.com/russross/blackfriday"
-	"html/template"
-)
-
-type Page struct {
-	Name    string
-	Slug    string
-	Content string
-}
-
-// DISCUSS: It feels weird to push |safe logic gere I would rahter keep it in the
-// template
-func (p Page) RenderedContent() template.HTML {
-	return template.HTML(string(blackfriday.MarkdownCommon([]byte(p.Content))))
-}

File models/page_test.go

-package models
-
-import (
-	"strings"
-	"testing"
-)
-
-func TestRenderedContent(t *testing.T) {
-	p := Page{Name: "foo", Slug: "foo", Content: "# hello\n**world**"}
-	rendered_content := string(p.RenderedContent())
-	if strings.Contains(rendered_content, "<h1>hello</h1>") != true {
-		t.Error("An error occured because # hello should be converted to a heading1")
-	}
-}

File pages/models.go

+package pages
+
+import (
+	_ "fmt"
+	"github.com/russross/blackfriday"
+	"html/template"
+)
+
+type Page struct {
+	Name    string
+	Slug    string
+	Content string
+}
+
+// DISCUSS: It feels weird to push |safe logic gere I would rahter keep it in the
+// template
+func (p Page) RenderedContent() template.HTML {
+	return template.HTML(string(blackfriday.MarkdownCommon([]byte(p.Content))))
+}

File pages/models_test.go

+package pages
+
+import (
+	"strings"
+	"testing"
+)
+
+func TestRenderedContent(t *testing.T) {
+	p := Page{Name: "foo", Slug: "foo", Content: "# hello\n**world**"}
+	rendered_content := string(p.RenderedContent())
+	if strings.Contains(rendered_content, "<h1>hello</h1>") != true {
+		t.Error("An error occured because # hello should be converted to a heading1")
+	}
+}

File storages/storages.go

 
 import (
 	"errors"
-	"gowiki/models"
+	"gowiki/pages"
 	"strconv"
 	"strings"
 )
 // store in the persistence layer
 type Storage interface {
 	AddPage(name, slug, content string)
-	GetPageBySlug(slug string) (models.Page, error)
+	GetPageBySlug(slug string) (pages.Page, error)
 	String() string
 	CountPage() int
 }
 
 // In memory storage
 type MemStorage struct {
-	Pages []models.Page
+	Pages []pages.Page
 }
 
 // Discuss: Should we return the interface or the address of the MemStorage
 }
 
 func (ms *MemStorage) AddPage(name, slug, content string) {
-	page := models.Page{name, slug, content}
+	page := pages.Page{name, slug, content}
 	ms.Pages = append(ms.Pages, page)
 }
 
-func (ms *MemStorage) GetPageBySlug(slug string) (page models.Page, err error) {
+func (ms *MemStorage) GetPageBySlug(slug string) (page pages.Page, err error) {
 	for _, page := range ms.Pages {
 		if page.Slug == slug {
 			return page, nil
 		}
 	}
-	return models.Page{}, errors.New("storage.GetPageBySlug This page does not exist")
+	return pages.Page{}, errors.New("storage.GetPageBySlug This page does not exist")
 }
 
 // Init Create 2 dummy pages