第37行: |
第37行: |
| return ret | | return ret |
| end | | end |
| + | |
| + | local QueryBuilder = {content = ""} |
| + | |
| + | function QueryBuilder:new() |
| + | local n = {} |
| + | setmetatable(n, QueryBuilder) |
| + | self.__index = self |
| + | return n |
| + | end |
| + | function QueryBuilder:cat(v) |
| + | local n = self:new() |
| + | n.content = self.content .. v |
| + | return n |
| + | end |
| + | function QueryBuilder:bracket(t) |
| + | return self:cat('[['..t..']] ') |
| + | end |
| + | function QueryBuilder:or_() |
| + | return self:cat(' OR ') |
| + | end |
| + | function QueryBuilder:done() |
| + | return self.content |
| + | end |
| + | function QueryBuilder:page(name) |
| + | return self:bracket(name) |
| + | end |
| + | function QueryBuilder:category(name) |
| + | return self:bracket("Category:"..name) |
| + | end |
| + | function QueryBuilder:exists(prop) |
| + | return self:bracket(prop..'::+') |
| + | end |
| + | function QueryBuilder:property(prop, value) |
| + | return self:bracket(prop..'::'..value) |
| + | end |
| + | |
| + | p.builder = QueryBuilder |
| | | |
| return p | | return p |