diff --git a/cmd/owl/web/editor_handler.go b/cmd/owl/web/editor_handler.go
index c095e65..29b17f8 100644
--- a/cmd/owl/web/editor_handler.go
+++ b/cmd/owl/web/editor_handler.go
@@ -4,6 +4,7 @@ import (
"fmt"
"h4kor/owl-blogs"
"net/http"
+ "strings"
"sync"
"time"
@@ -203,6 +204,11 @@ func userEditorPostHandler(repo *owl.Repository) func(http.ResponseWriter, *http
content := r.Form.Get("content")
draft := r.Form.Get("draft")
+ // recipe values
+ recipe_yield := r.Form.Get("yield")
+ recipe_ingredients := r.Form.Get("ingredients")
+ recipe_duration := r.Form.Get("duration")
+
// conditional values
reply_url := r.Form.Get("reply_url")
bookmark_url := r.Form.Get("bookmark_url")
@@ -216,7 +222,7 @@ func userEditorPostHandler(repo *owl.Repository) func(http.ResponseWriter, *http
w.Write([]byte(html))
return
}
- if (post_type == "article" || post_type == "page") && title == "" {
+ if (post_type == "article" || post_type == "page" || post_type == "recipe") && title == "" {
html, _ := owl.RenderUserError(user, owl.ErrorMessage{
Error: "Missing Title",
Message: "Articles and Pages must have a title",
@@ -257,6 +263,11 @@ func userEditorPostHandler(repo *owl.Repository) func(http.ResponseWriter, *http
Bookmark: owl.BookmarkData{
Url: bookmark_url,
},
+ Recipe: owl.RecipeData{
+ Yield: recipe_yield,
+ Ingredients: strings.Split(recipe_ingredients, "\n"),
+ Duration: recipe_duration,
+ },
}, content)
if err != nil {
diff --git a/cmd/owl/web/editor_test.go b/cmd/owl/web/editor_test.go
index edd354d..1086d45 100644
--- a/cmd/owl/web/editor_test.go
+++ b/cmd/owl/web/editor_test.go
@@ -243,3 +243,40 @@ func TestEditorSendsWebmentions(t *testing.T) {
assertions.AssertEqual(t, repo.HttpClient.(*CountMockHttpClient).InvokedPostForm, 1)
}
+
+func TestEditorPostWithSessionRecipe(t *testing.T) {
+ repo, user := getSingleUserTestRepo()
+ user.ResetPassword("testpassword")
+ sessionId := user.CreateNewSession()
+
+ csrfToken := "test_csrf_token"
+
+ // Create Request and Response
+ form := url.Values{}
+ form.Add("type", "recipe")
+ form.Add("title", "testtitle")
+ form.Add("yield", "2")
+ form.Add("duration", "1 hour")
+ form.Add("ingredients", "water\nwheat")
+ form.Add("content", "testcontent")
+ form.Add("csrf_token", csrfToken)
+
+ req, err := http.NewRequest("POST", user.EditorUrl(), strings.NewReader(form.Encode()))
+ req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
+ req.Header.Add("Content-Length", strconv.Itoa(len(form.Encode())))
+ req.AddCookie(&http.Cookie{Name: "csrf_token", Value: csrfToken})
+ req.AddCookie(&http.Cookie{Name: "session", Value: sessionId})
+ assertions.AssertNoError(t, err, "Error creating request")
+ rr := httptest.NewRecorder()
+ router := main.SingleUserRouter(&repo)
+ router.ServeHTTP(rr, req)
+
+ posts, _ := user.AllPosts()
+ assertions.AssertEqual(t, len(posts), 1)
+ post := posts[0]
+
+ assertions.AssertLen(t, post.Meta().Recipe.Ingredients, 2)
+
+ assertions.AssertStatus(t, rr, http.StatusFound)
+ assertions.AssertEqual(t, rr.Header().Get("Location"), post.FullUrl())
+}
diff --git a/embed/editor/editor.html b/embed/editor/editor.html
index 6474373..5221919 100644
--- a/embed/editor/editor.html
+++ b/embed/editor/editor.html
@@ -54,6 +54,35 @@
+
+ Write Recipe
+
+
+
Bookmark