2 FFLuCI - Configuration Bind Interface
5 Offers an interface for binding confiugration values to certain
6 data types. Supports value and range validation and basic dependencies.
12 Copyright 2008 Steven Barth <steven@midlink.org>
14 Licensed under the Apache License, Version 2.0 (the "License");
15 you may not use this file except in compliance with the License.
16 You may obtain a copy of the License at
18 http://www.apache.org/licenses/LICENSE-2.0
20 Unless required by applicable law or agreed to in writing, software
21 distributed under the License is distributed on an "AS IS" BASIS,
22 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 See the License for the specific language governing permissions and
24 limitations under the License.
27 module("ffluci.cbi", package.seeall)
28 require("ffluci.template")
29 require("ffluci.util")
30 local class = ffluci.util.class
31 local instanceof = ffluci.util.instanceof
34 -- Node pseudo abstract class
37 function Node.__init__(self, title, description)
40 self.description = description
41 self.template = "cbi/node"
44 function Node.append(self, obj)
45 table.insert(self.children, obj)
50 Map - A map describing a configuration file
54 function Map.__init__(self, config, ...)
55 Node.__init__(self, ...)
57 self.template = "cbi/map"
60 function Map.render(self)
61 ffluci.template.render(self.template)
64 function Map.section(self, class, ...)
65 if instanceof(class, AbstractClass) then
66 local obj = class(...)
68 table.insert(self.children, obj)
71 error("class must be a descendent of AbstractSection")
79 AbstractSection = class(Node)
81 function AbstractSection.__init__(self, ...)
82 Node.__init__(self, ...)
85 function AbstractSection.option(self, class, ...)
86 if instanceof(class, AbstractValue) then
87 local obj = class(...)
90 table.insert(self.children, obj)
93 error("class must be a descendent of AbstractValue")
100 NamedSection - A fixed configuration section defined by its name
102 NamedSection = class(AbstractSection)
104 function NamedSection.__init__(self, section, ...)
105 AbstractSection.__init__(self, ...)
106 self.section = section
107 self.template = "cbi/nsection"
112 TypedSection - A (set of) configuration section(s) defined by the type
113 addremove: Defines whether the user can add/remove sections of this type
114 anonymous: Allow creating anonymous sections
115 valid: a table with valid names or a function returning nil if invalid
117 TypedSection = class(AbstractSection)
119 function TypedSection.__init__(self, sectiontype, ...)
120 AbstractSection.__init__(self, ...)
121 self.sectiontype = sectiontype
122 self.template = "cbi/tsection"
124 self.addremove = true
125 self.anonymous = false
131 AbstractValue - An abstract Value Type
132 null: Value can be empty
133 valid: A table with valid names or a function returning nil if invalid
134 depends: A table of option => value pairs of which one must be true
136 AbstractValue = class(Node)
138 function AbstractValue.__init__(self, option, ...)
139 Node.__init__(self, ...)
149 Value - A one-line value
150 maxlength: The maximum length
151 isnumber: The value must be a valid (floating point) number
152 isinteger: The value must be a valid integer
154 Value = class(AbstractValue)
156 function Value.__init__(self, ...)
157 AbstractValue.__init__(self, ...)
158 self.template = "cbi/value"
161 self.isnumber = false
162 self.isinteger = false
167 Boolean - A simple boolean value
169 Boolean = class(AbstractValue)
171 function Boolean.__init__(self, ...)
172 AbstractValue.__init__(self, ...)
173 self.template = "cbi/boolean"