#! stdtmpl # #template `%`(idx: expr): expr {.immediate.} = # row[idx] #end template # # #proc genThreadsList(c: var TForumData, count: var int): string = # const query = sql"select id, name, views, modified from thread order by modified desc limit ?, ?" # const threadId = 0 # const name = 1 # const views = 2 # # result = "" # count = 0 # for row in Rows(db, query, $((c.pageNum-1) * ThreadsPerPage), $ThreadsPerPage): # inc(count) #let authorName = getValue(db, sql("select name from person where id = " & # "(select author from post where id = " & # "(select min(id) from post where thread = ?))"), %threadId) #let profileUrl = c.req.makeUri("profile/", false) & XMLEncode(authorName) # let posts = GetValue(db, sql"select count(*) from post where thread = ?", %threadId) #let latestReplyAuthor = getValue(db, sql("select name from person where id = " & # "(select author from post where id = " & # "(select max(id) from post where thread = ?))"), %threadId) #let latestReplyDate = getValue(db, sql("SELECT strftime('%s', " & # "(select creation from post where id = (select max(id) from post where thread = ?)))"), %threadId) # end for
Topics Author Posts Views Last reply
${UrlButton(c, XMLencode(%name), c.genThreadUrl(threadid = %threadid))} ${genPagenumLocalNav(c, (%threadid).parseInt)} ${authorName}$posts ${XMLencode(%views)} ${formatTimestamp(latestReplyDate.parseInt())}
#let replyProfileUrl = c.req.makeUri("profile/", false) & # XMLEncode(latestReplyAuthor) ${latestReplyAuthor}
#end proc # # #proc genPostPreview(c: var TForumData, # title, content, author, date: string): string = # result = ""
${XMLEncode(title)} ${XMLencode(date)}
${XMLencode(author)} #try: ${content.rstToHtml} #except EParseError: # c.errorMsg = getCurrentExceptionMsg() #end
#end proc # # #proc genPostsList(c: var TForumData, threadId: string, count: var int): string = # const query = sql"""select p.id, u.name, p.header, p.content, p.creation, p.author, u.email from post p, # person u where u.id = p.author and p.thread = ? order by p.id limit ?, ?""" # const postId = 0 # const userName = 1 # const postHeader = 2 # const postContent = 3 # const postCreation = 4 # const postAuthor = 5 # const userEmail = 6 # result = "" # count = 0 # for row in FastRows(db, query, threadId, $((c.pageNum-1) * PostsPerPage), $PostsPerPage): # inc(count)
${XMLencode(%postHeader)} ${XMLencode(%postCreation)}
#let profileUrl = c.req.makeUri("profile/", false) & XMLencode(%userName) ${XMLencode(%userName)}
${genGravatar(%userEmail)} #if c.userId == %postAuthor and c.currentPost.subject.len == 0:
${UrlButton(c, "Edit post", c.genThreadUrl(%postId, "edit"))} #elif c.isAdmin and c.currentPost.subject.len == 0:
${UrlButton(c, "Edit post", c.genThreadUrl(%postId, "edit"))} #end if
#try: ${(%postContent).rstToHtml} #except EParseError: # c.errorMsg = getCurrentExceptionMsg() #end
# end for #end proc # # #proc genFormPost(c: var TForumData, action: string, # topText, title, content: string, isEdit: bool): string = # result = ""
${topText}
${FieldValid(c, "subject", "Subject:")} ${TextWidget(c, "subject", title, maxlength=100)}
${FieldValid(c, "content", "Content:")}
${TextAreaWidget(c, "content", content, width=100, height=20)}
${FormSession(c, action)} # if isEdit: Delete Post
# end if
Syntax Cheatsheet
#end proc # # #proc genFormRegister(c: var TForumData): string = # result = ""
Register
${FieldValid(c, "name", "Username:")} ${TextWidget(c, "name", reuseText, maxlength=20)}
${FieldValid(c, "new_password", "Password:")}
${FieldValid(c, "email", "E-Mail:")} ${TextWidget(c, "email", reuseText, maxlength=30)}
${FieldValid(c, "antibot", "What is " & antibot(c) & "?")} ${TextWidget(c, "antibot", "", maxlength=4)}
#end proc # #proc genFormLogin(c: var TForumData): string = # result = "" # if not c.loggedIn:
Username:
Password:
$c.loginErrorMsg # else: You're already logged in! # end if #end proc # # #proc genListOnline(c: var TForumData, stats: TForumStats): string = # result = ""
Who is online?
Out of ${stats.totalUsers} users ${stats.activeUsers.len} are online${if stats.activeUsers.len == 0: "." else: ":"} #for index, usr in stats.activeUsers: # let profileHref = """""" # let hrefEnd = """""" # if usr.isAdmin: #if index != 0: result.add ',' #end if #result.add(""" """ & profileHref & # usr.nick & hrefEnd & """""") # else: #if index != 0: result.add ',' #end if #result.add(""" """ & profileHref & # usr.nick & hrefEnd & """""") # end if #end for
#if stats.newestMember.nick != "": #let profileUrl = c.req.makeUri("profile/", false) & # XMLEncode(stats.newestMember.nick) Total threads: ${stats.totalThreads} | Total posts: ${stats.totalPosts} | Newest member: ${stats.newestMember.nick} #else: Total threads: ${stats.totalThreads} | Total posts: ${stats.totalPosts} #end if
#end proc