def formatRangeTemplate(template, row): kindField, unitField, descriptionField = row kind = kindField.strip() unit = unitField.strip() return Template(template).substitute( methodName="get{}{}Range".format(camelCaseUpper(kind), camelCaseUpper(unit)), minKey="ui_{}Minimum{}s".format(camelCase(kind), camelCaseUpper(unit)), maxKey="ui_{}Maximum{}s".format(camelCase(kind), camelCaseUpper(unit)), description=descriptionField.strip(), )
def formatTemplate(template, row): nameField, descriptionField, signatureField, extra, examplesField = row name = nameField.strip() description = descriptionField.strip() signature = signatureField.strip() namecamel = camelCase(name) nameCamel = camelCaseUpper(name) rangeRestriction = checkRangeRestriction(extra) enumeration = None typeEnumeration = None typeEnumerationFromString = None if name in enumerations: parts = ["\"{}\"".format(a) for a in enumerations[name]] enumeration = ",".join(parts) typeParts = [ "{}".format(camelCaseUpper(a)) for a in enumerations[name] ] typeEnumeration = "|".join(typeParts) typeEnumerationFromStringParts = [ "\"{}\" -> {}".format(a, camelCaseUpper(a)) for a in enumerations[name] ] typeEnumerationFromString = "\n ".join( typeEnumerationFromStringParts) examples = generateExamples(examplesField, signature, enumeration) entity = "SettingsEntity" if isState(row): entity = "StateEntity" return Template(template).substitute( name=name, description=description, signature=signature, namecamel=namecamel, nameCamel=nameCamel, rangeRestriction=rangeRestriction, examples=examples, entity=entity, enumeration=enumeration, typeEnumeration=typeEnumeration, typeEnumerationFromString=typeEnumerationFromString)
def formatMethodTemplate(template, row, moduleName, state = "z", meta = defaultMeta): m = {} m["name"] = row["name"] m["moduleName"] = moduleName m["nameU"] = firstUpper(row["name"]) m["returned"] = row["returned"] m["state"] = state m["stateU"] = camelCaseUpper(state) m["ok"] = "ok{okNumber}".format(okNumber = meta["ok"]) for ii, param in enumerate(row["params"]): paramName = "paramName{ii}".format(ii=ii) paramType = "paramType{ii}".format(ii=ii) m[paramName] = param[0] m[paramType] = param[1] return Template(template).substitute(m)
def formatTemplate(template, row): nameField, descriptionField, signatureField, extra, examplesField = row name = nameField.strip() description = descriptionField.strip() signature = signatureField.strip() namecamel = camelCase(name) nameCamel = camelCaseUpper(name) rangeRestriction = checkRangeRestriction(extra) examples = generateExamples(examplesField, signature) return Template(template).substitute(name=name, description=description, signature=signature, namecamel=namecamel, nameCamel=nameCamel, rangeRestriction=rangeRestriction, examples=examples)