comparison blog/src/lib/Post.luan @ 604:b73f005f3735 0.13

table constructor now uses end_of_line as a delimiter
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 24 Nov 2015 16:29:27 -0700
parents 50540f0813e2
children ca169567ce07
comparison
equal deleted inserted replaced
603:862d6bb8124c 604:b73f005f3735
11 11
12 local M = {} 12 local M = {}
13 13
14 local function from_doc(doc) 14 local function from_doc(doc)
15 return M.new { 15 return M.new {
16 id = doc.id; 16 id = doc.id
17 subject = doc.subject; 17 subject = doc.subject
18 content = doc.content; 18 content = doc.content
19 date = doc.date; 19 date = doc.date
20 } 20 }
21 end 21 end
22 22
23 function M.new(this) 23 function M.new(this)
24 assert_string(this.subject) 24 assert_string(this.subject)
25 assert_string(this.content) 25 assert_string(this.content)
26 this.date = this.date or now() 26 this.date = this.date or now()
27 27
28 function this.save() 28 function this.save()
29 local doc = { 29 local doc = {
30 type = "post"; 30 type = "post"
31 id = this.id; 31 id = this.id
32 subject = this.subject; 32 subject = this.subject
33 content = this.content; 33 content = this.content
34 date = this.date; 34 date = this.date
35 } 35 }
36 Db.save(doc) 36 Db.save(doc)
37 this.id = doc.id 37 this.id = doc.id
38 end 38 end
39 39