comparison core/src/luan/modules/Html.luan @ 503:92c3d22745b8

make _ENV optional
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 20 May 2015 23:24:46 -0600
parents 55f9f74f1e55
children 195a64f948f2
comparison
equal deleted inserted replaced
502:d3183a330ff5 503:92c3d22745b8
1 java() 1 java()
2 local HtmlLuan = require "java:luan.modules.HtmlLuan" 2 local HtmlLuan = require "java:luan.modules.HtmlLuan"
3 3
4 encode = HtmlLuan.encode 4 local M = {}
5 parse = HtmlLuan.parse 5
6 to_string = HtmlLuan.to_string 6 M.encode = HtmlLuan.encode
7 M.parse = HtmlLuan.parse
8 M.to_string = HtmlLuan.to_string
7 9
8 10
9 11
10 -- extras 12 -- extras
11 13
13 local ipairs = Luan.ipairs 15 local ipairs = Luan.ipairs
14 local type = Luan.type 16 local type = Luan.type
15 local Io = require "luan:Io" 17 local Io = require "luan:Io"
16 local URLEncoder = require "java:java.net.URLEncoder" 18 local URLEncoder = require "java:java.net.URLEncoder"
17 19
18 function url_encode(s) 20 function M.url_encode(s)
19 return URLEncoder.encode(s,"UTF-8") 21 return URLEncoder.encode(s,"UTF-8")
20 end 22 end
21 23
22 function process_url_tags(html) 24 function M.process_url_tags(html)
23 for i, v in ipairs(html) do 25 for i, v in ipairs(html) do
24 if type(v) == "table" and v.type == "tag" then 26 if type(v) == "table" and v.type == "tag" then
25 if v.name == "url" then 27 if v.name == "url" then
26 local url = v.attributes.url or html[i+1] 28 local url = v.attributes.url or html[i+1]
27 v.name = "a" 29 v.name = "a"
32 end 34 end
33 end 35 end
34 end 36 end
35 end 37 end
36 38
37 function add_nofollow(html) 39 function M.add_nofollow(html)
38 for i, v in ipairs(html) do 40 for i, v in ipairs(html) do
39 if type(v) == "table" and v.type == "tag" and v.name == "a" then 41 if type(v) == "table" and v.type == "tag" and v.name == "a" then
40 v.attributes.rel = "nofollow" 42 v.attributes.rel = "nofollow"
41 end 43 end
42 end 44 end
43 end 45 end
44 46
45 47
46 function simply_html_head() %> 48 function M.simply_html_head() %>
47 <meta charset="utf-8"> 49 <meta charset="utf-8">
48 <meta name="viewport" content="width=device-width, initial-scale=1"> 50 <meta name="viewport" content="width=device-width, initial-scale=1">
49 51
50 <link href="http://www.simplyhtml.org/assets/bootstrap/css/bootstrap.min.css" rel="stylesheet"> 52 <link href="http://www.simplyhtml.org/assets/bootstrap/css/bootstrap.min.css" rel="stylesheet">
51 <link rel="stylesheet" href="http://www.simplyhtml.org/assets/font-awesome/css/font-awesome.min.css"> 53 <link rel="stylesheet" href="http://www.simplyhtml.org/assets/font-awesome/css/font-awesome.min.css">
53 55
54 <link href="http://www.simplyhtml.org/assets/simplyhtml/simplyhtml.css" rel="stylesheet"/> 56 <link href="http://www.simplyhtml.org/assets/simplyhtml/simplyhtml.css" rel="stylesheet"/>
55 <script src="http://www.simplyhtml.org/assets/simplyhtml/simplyhtml.js"></script> 57 <script src="http://www.simplyhtml.org/assets/simplyhtml/simplyhtml.js"></script>
56 <% end 58 <% end
57 59
58 function simply_html_body_bottom() %> 60 function M.simply_html_body_bottom() %>
59 <script src="http://www.simplyhtml.org/assets/bootstrap/js/bootstrap.min.js"></script> 61 <script src="http://www.simplyhtml.org/assets/bootstrap/js/bootstrap.min.js"></script>
60 <% end 62 <% end
63
64 return M