changeset 777:1460d297e960

add bbcode to blog example
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 26 Aug 2016 15:42:15 -0600
parents 815c119dac7a
children 305ffb00ebc1
files blog/src/edit.luan blog/src/index.html.luan blog/src/new.luan src/luan/modules/http/LuanHandler.java src/luan/modules/parsers/BBCode.java
diffstat 5 files changed, 11 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
diff -r 815c119dac7a -r 1460d297e960 blog/src/edit.luan
--- a/blog/src/edit.luan	Fri Aug 26 14:39:18 2016 -0600
+++ b/blog/src/edit.luan	Fri Aug 26 15:42:15 2016 -0600
@@ -31,7 +31,7 @@
 
 		<form method=post>
 			<p>Subject: <input name=subject size=50 type=text value="<%= post.subject %>"></p>
-			<p><textarea name=content rows=20 cols=90><%= post.content %></textarea></p>
+			<p><textarea name=content rows=20 cols=90><%= post.content %></textarea><br>bbcode works</p>
 			<p>
 				<input type=submit name=save value=Submit>
 			</p>
diff -r 815c119dac7a -r 1460d297e960 blog/src/index.html.luan
--- a/blog/src/index.html.luan	Fri Aug 26 14:39:18 2016 -0600
+++ b/blog/src/index.html.luan	Fri Aug 26 15:42:15 2016 -0600
@@ -3,6 +3,10 @@
 local ipairs = Luan.ipairs or error()
 local Time = require "luan:Time.luan"
 local Io = require "luan:Io.luan"
+local Parsers = require "luan:Parsers.luan"
+local bbcode_to_html = Parsers.bbcode_to_html or error()
+local Html = require "luan:Html.luan"
+local html_encode = Html.encode or error()
 local Http = require "luan:http/Http.luan"
 local Post = require "site:/lib/Post.luan"
 
@@ -35,7 +39,7 @@
 			<a name="p<%= post.id %>">
 			<h2><%= post.subject %></h2>
 			<p><%= Time.format(post.date) %> - <a href="edit?post=<%= post.id %>">Edit</a></p>
-			<pre><%= post.content %></pre>
+			<pre><%= bbcode_to_html(html_encode(post.content)) %></pre>
 			<hr>
 			<%
 		end
diff -r 815c119dac7a -r 1460d297e960 blog/src/new.luan
--- a/blog/src/new.luan	Fri Aug 26 14:39:18 2016 -0600
+++ b/blog/src/new.luan	Fri Aug 26 15:42:15 2016 -0600
@@ -28,7 +28,7 @@
 
 		<form method=post>
 			<p>Subject: <input name=subject size=50 type=text></p>
-			<p><textarea name=content rows=20 cols=90></textarea></p>
+			<p><textarea name=content rows=20 cols=90></textarea><br>bbcode works</p>
 			<p>
 				<input type=submit name=save value=Submit>
 			</p>
diff -r 815c119dac7a -r 1460d297e960 src/luan/modules/http/LuanHandler.java
--- a/src/luan/modules/http/LuanHandler.java	Fri Aug 26 14:39:18 2016 -0600
+++ b/src/luan/modules/http/LuanHandler.java	Fri Aug 26 15:42:15 2016 -0600
@@ -38,6 +38,7 @@
 			if( !HttpServicer.service(luan,request,response,"site:"+target+".luan") )
 				return;
 		} catch(LuanException e) {
+//e.printStackTrace();
 			String err = e.getFullMessage();
 			logger.error(err);
 			response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,err);
diff -r 815c119dac7a -r 1460d297e960 src/luan/modules/parsers/BBCode.java
--- a/src/luan/modules/parsers/BBCode.java	Fri Aug 26 14:39:18 2016 -0600
+++ b/src/luan/modules/parsers/BBCode.java	Fri Aug 26 15:42:15 2016 -0600
@@ -26,7 +26,7 @@
 
 	private BBCode(LuanState luan,String text,LuanFunction quoter,boolean toHtml) throws LuanException {
 		Utils.checkNotNull(text,1);
-		Utils.checkNotNull(quoter,2);
+//		Utils.checkNotNull(quoter,2);
 		this.luan = luan;
 		this.parser = new Parser(text);
 		this.quoter = quoter;
@@ -264,6 +264,8 @@
 	}
 
 	private String quote(Object... args) throws LuanException {
+		if( quoter==null )
+			throw new LuanException("BBCode quoter function not defined");
 		Object obj = quoter.call(luan,args);
 		if( !(obj instanceof String) )
 			throw new LuanException("BBCode quoter function returned "+Luan.type(obj)+" but string required");