Hello Steve Donovan and people on lua mail list,
I am now trying to develop a web site using Orbit.
But I am particularly trying to use orbiter.html library in Orbit module.
Orbit's handler registered via app:dispatch_get() is supposed to return a html string.
But Orbiter's is different! Orbiter's handler registered via app:dispatch_get() is supposed to return a table which holds html data.
I need to use Orbiter's html library which provides a handler function of Orbiter style.
And I need to use it in Orbit.
#My Question#
This means I need to convert Orbiter's html table into a html string of Orbit style.
How can I do this? Is it possible?
F.Y.I., let me post my test code below.
1 #!/usr/bin/env wsapi.cgi
2
3 require"orbit"
4 module("basic3", package.seeall, orbit.new)
5
6 local bridge = require "orbiter.bridge"
7 bridge.new(_M)
8
9 local jq = require 'orbiter.libs.jquery'
10 -- to use jq.timer(), must call this first
11 jq.use_timer()
12
13 local html = require 'orbiter.html'
14 -- Orbiter html variables
15 local table,tr,th,td,span__ = html.tags 'table,tr,th,td,span'
16
17 -- Controller
18 function index(web)
19 return _render_data()
20 end
21 basic3:dispatch_get(index, "/", "/index")
22
23 -- Model
24 local score = 200
25
26 function print_score()
27 print(score)
28 end
29
30 function _render_data()
31 return html {
32 inline_script = [[
33 <script type="text/_javascript_">
34 $(document).ready(function () {
35 $("span:contains('Score')").click();
36 });
37 </script>
38 ]],
39
40 jq.link("Score",function()
41 return jq.timer(1000,print_score)
42 end),
43
44 table {border="1",
45 tr {
46 th {
47 span__ {
48 "Score"
49 }
50 }
51 },
52 tr {
53 td {
54 ("%d"):format(score)
55 }
56 }
57 }
58 }
59 end
60
61 --orbit.htmlify(basic3, "_render_data")
62
63 print(_render_data())
64
As you would be able to notice, I have to do this way because I want to use Orbiter's jquery library.
I haven't find another way to include orbiter's jquery library other than this way.
Please note line 63 prints correct html string (because function 'print' can handle table type).
But If I try it with io.write() error occurs because io.write cannot handle table type. It only accepts string type.
Consequently the code above doesn't produce correct web page because _render_data() produces 'html table' instead of 'html string'.
Thank you very much!
Sincerely
Journeyer Joh
----------------------------------------
Journeyer J. Joh
o o s a p r o g r a m m e r
a t
g m a i l d o t c o m
----------------------------------------