Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

html is part of tags environment; p.foo 'hello' now renders as p{clas…

…s='foo','hello'}
  • Loading branch information...
commit 2731fb8f680bc895943bd5bfbb7febe56de3446e 1 parent df59954
@stevedonovan authored
View
3  examples/dropdown.lua
@@ -1,12 +1,11 @@
local orbiter = require 'orbiter'
-local html = require 'orbiter.html'
local dropdown = require 'orbiter.controls.dropdown'
local calendar = require 'orbiter.controls.calendar'
-- 'us' mm/dd/yyyy, 'eu' 'dd-mm-yyyy' or 'db' 'yyyy-mm-dd'
calendar.set_mode 'eu'
-local self = orbiter.new(html,'tags')
+local self = orbiter.new('html','tags')
function self:index()
return html {
View
4 orbiter/doc.lua
@@ -226,12 +226,12 @@ end
-- @param list a list of names, or a comma-separated string.
-- @usage local parent,children = doc.tags 'parent,children' <br>
-- doc = parent {child 'one', child 'two'}
-function _M.tags(list)
+function _M.tags(list,f)
local ctors = {}
- local elem = _M.elem
if type(list) == 'string' then list = split(list,',') end
for _,tag in ipairs(list) do
local ctor = function(items) return _M.elem(tag,items) end
+ if f then ctor = f(ctor) end
t_insert(ctors,ctor)
end
return unpack(ctors)
View
19 orbiter/html.lua
@@ -165,18 +165,33 @@ function _M.enable_concatenation_is_composition()
})
end
+local dtags = doc.tags
+
+local TMT = {
+ __call = function(self,...) return self.tag(...) end;
+ __index = function(self,name)
+ local res = _M.specialize(self.tag,{class=name})
+ self[name] = res
+ return res
+ end;
+}
+
+local function _tag_object(tag)
+ return setmetatable({tag=tag},TMT)
+end
+
local function _tags (list)
if is_table(list) and is_table(list[1]) then
local res = {}
for i,item in ipairs(list) do res[i] = item[1] end
- res = {doc.tags(res)}
+ res = {dtags(res)}
for i,ctor in ipairs(res) do
local defs = util.copy_map(list[i])
res[i] = _M.specialize(ctor,defs)
end
return unpack(res)
else
- return doc.tags(list)
+ return dtags(list,_tag_object)
end
end
View
5 orbiter/init.lua
@@ -71,12 +71,11 @@ local self
function _M.new(...)
local extensions = {...}
- local obj
+ local obj = extensions[1]
-- if passed a table which doesn't have register, then assume we're being called
-- from module()
-- use the module as the object, and manually add our methods to it.
- if extensions[1] and not extensions[1].register then
- obj = extensions[1]
+ if obj and type(obj) ~= 'string' and not obj.register then
local m = extensions[1]
for k,v in pairs(MT) do m[k] = v end
table.remove(extensions,1)
View
12 orbiter/tags.lua
@@ -119,12 +119,12 @@ local html5_tags = {
wbr = true,
}
-local tag = html.tags
-local env,_G = {},_G
+local tag,rawget = html.tags,rawget
+local env,_G = {html=html},_G
-setmetatable(env,{
+_M.env = {
__index = function(t,name)
- local g = _G[name]
+ local g = rawget(_G,name) -- in case of strict mode!
if g then return g end
-- see if it's an HTML tag!
name = name:lower()
@@ -135,7 +135,9 @@ setmetatable(env,{
end
return rawget(env,name)
end
-})
+}
+
+setmetatable(env,_M.env)
function _M.use ()
setfenv(2,env)
Please sign in to comment.
Something went wrong with that request. Please try again.