This commit is contained in:
Kovid Goyal 2011-08-01 09:26:51 -06:00
commit b615dffb53
4 changed files with 15 additions and 8 deletions

View File

@ -289,9 +289,8 @@ class TemplateDialog(QDialog, Ui_TemplateDialog):
self.documentation.clear() self.documentation.clear()
if name in self.funcs: if name in self.funcs:
self.documentation.setPlainText(self.funcs[name].doc) self.documentation.setPlainText(self.funcs[name].doc)
if name in self.builtins: if name in self.builtins and name in self.builtin_source_dict:
if name in self.builtin_source_dict: self.source_code.setPlainText(self.builtin_source_dict[name])
self.source_code.setPlainText(self.builtin_source_dict[name])
else: else:
self.source_code.setPlainText(self.funcs[name].program_text) self.source_code.setPlainText(self.funcs[name].program_text)

View File

@ -266,7 +266,7 @@ The following functions are available in addition to those described in single-f
* ``list_difference(list1, list2, separator)`` -- return a list made by removing from `list1` any item found in `list2`, using a case-insensitive compare. The items in `list1` and `list2` are separated by separator, as are the items in the returned list. * ``list_difference(list1, list2, separator)`` -- return a list made by removing from `list1` any item found in `list2`, using a case-insensitive compare. The items in `list1` and `list2` are separated by separator, as are the items in the returned list.
* ``list_intersection(list1, list2, separator)`` -- return a list made by removing from `list1` any item not found in `list2`, using a case-insensitive compare. The items in `list1` and `list2` are separated by separator, as are the items in the returned list. * ``list_intersection(list1, list2, separator)`` -- return a list made by removing from `list1` any item not found in `list2`, using a case-insensitive compare. The items in `list1` and `list2` are separated by separator, as are the items in the returned list.
* ``list_sort(list, direction, separator)`` -- return list sorted using a case-insensitive sort. If `direction` is zero, the list is sorted ascending, otherwise descending. The list items are separated by separator, as are the items in the returned list. * ``list_sort(list, direction, separator)`` -- return list sorted using a case-insensitive sort. If `direction` is zero, the list is sorted ascending, otherwise descending. The list items are separated by separator, as are the items in the returned list.
* ``merge_lists(list1, list2, separator)`` -- return a list made by merging the items in list1 and list2, removing duplicate items using a case-insensitive compare. If items differ in case, the one in list1 is used. The items in list1 and list2 are separated by separator, as are the items in the returned list. * ``list_union(list1, list2, separator)`` -- return a list made by merging the items in list1 and list2, removing duplicate items using a case-insensitive compare. If items differ in case, the one in list1 is used. The items in list1 and list2 are separated by separator, as are the items in the returned list.
* ``multiply(x, y)`` -- returns x * y. Throws an exception if either x or y are not numbers. * ``multiply(x, y)`` -- returns x * y. Throws an exception if either x or y are not numbers.
* ``ondevice()`` -- return the string "Yes" if ondevice is set, otherwise return the empty string * ``ondevice()`` -- return the string "Yes" if ondevice is set, otherwise return the empty string
* ``or(value, value, ...)`` -- returns the string "1" if any value is not empty, otherwise returns the empty string. This function works well with test or first_non_empty. You can have as many values as you want. * ``or(value, value, ...)`` -- returns the string "1" if any value is not empty, otherwise returns the empty string. This function works well with test or first_non_empty. You can have as many values as you want.

View File

@ -67,11 +67,15 @@ def generate_template_language_help():
for func in all_builtin_functions: for func in all_builtin_functions:
class_name = func.__class__.__name__ class_name = func.__class__.__name__
if class_name == 'BuiltinMergeLists':
class_name = 'BuiltinListUnion'
func_sig = getattr(func, 'doc') func_sig = getattr(func, 'doc')
x = func_sig.find(' -- ') x = func_sig.find(' -- ')
if x < 0: if x < 0:
print 'No sig for ', class_name print 'No sig for ', class_name
continue continue
if func_sig.startswith('merge_lists('):
continue
func_sig = func_sig[:x] func_sig = func_sig[:x]
func_cat = getattr(func, 'category') func_cat = getattr(func, 'category')
funcs[func_cat][func_sig] = class_name funcs[func_cat][func_sig] = class_name

View File

@ -829,11 +829,11 @@ class BuiltinNot(BuiltinFormatterFunction):
def evaluate(self, formatter, kwargs, mi, locals, val): def evaluate(self, formatter, kwargs, mi, locals, val):
return '' if val else '1' return '' if val else '1'
class BuiltinMergeLists(BuiltinFormatterFunction): class BuiltinListUnion(BuiltinFormatterFunction):
name = 'merge_lists' name = 'list_union'
arg_count = 3 arg_count = 3
category = 'List Manipulation' category = 'List Manipulation'
__doc__ = doc = _('merge_lists(list1, list2, separator) -- ' __doc__ = doc = _('list_union(list1, list2, separator) -- '
'return a list made by merging the items in list1 and list2, ' 'return a list made by merging the items in list1 and list2, '
'removing duplicate items using a case-insensitive compare. If ' 'removing duplicate items using a case-insensitive compare. If '
'items differ in case, the one in list1 is used. ' 'items differ in case, the one in list1 is used. '
@ -853,6 +853,9 @@ class BuiltinMergeLists(BuiltinFormatterFunction):
res.append(i) res.append(i)
return ', '.join(res) return ', '.join(res)
class BuiltinMergeLists(BuiltinListUnion):
name = 'merge_lists'
class BuiltinListDifference(BuiltinFormatterFunction): class BuiltinListDifference(BuiltinFormatterFunction):
name = 'list_difference' name = 'list_difference'
arg_count = 3 arg_count = 3
@ -945,7 +948,8 @@ formatter_builtins = [
BuiltinFormatNumber(), BuiltinFormatsModtimes(), BuiltinFormatsSizes(), BuiltinFormatNumber(), BuiltinFormatsModtimes(), BuiltinFormatsSizes(),
BuiltinHasCover(), BuiltinHumanReadable(), BuiltinIdentifierInList(), BuiltinHasCover(), BuiltinHumanReadable(), BuiltinIdentifierInList(),
BuiltinIfempty(), BuiltinInList(), BuiltinListDifference(), BuiltinIfempty(), BuiltinInList(), BuiltinListDifference(),
BuiltinListIntersection(), BuiltinListitem(), BuiltinListSort(), BuiltinLookup(), BuiltinListIntersection(), BuiltinListitem(), BuiltinListSort(),
BuiltinListUnion(), BuiltinLookup(),
BuiltinLowercase(), BuiltinMergeLists(), BuiltinMultiply(), BuiltinNot(), BuiltinLowercase(), BuiltinMergeLists(), BuiltinMultiply(), BuiltinNot(),
BuiltinOndevice(), BuiltinOr(), BuiltinPrint(), BuiltinRawField(), BuiltinOndevice(), BuiltinOr(), BuiltinPrint(), BuiltinRawField(),
BuiltinRe(), BuiltinSelect(), BuiltinShorten(), BuiltinStrcat(), BuiltinRe(), BuiltinSelect(), BuiltinShorten(), BuiltinStrcat(),