Esempio n. 1
0
 def testToUpperCamelCase(self):
     self.assertEquals('Foo', util.ToUpperCamelCase('foo'))
     self.assertEquals('FooBar', util.ToUpperCamelCase('foo_bar'))
     self.assertEquals('FooBar', util.ToUpperCamelCase('foo__bar'))
     self.assertEquals('FooBarBaz', util.ToUpperCamelCase('foo_bar_baz'))
     self.assertEquals('F', util.ToUpperCamelCase('f'))
     self.assertEquals('F', util.ToUpperCamelCase('f_'))
     self.assertEquals('', util.ToUpperCamelCase(''))
     self.assertEquals('', util.ToUpperCamelCase('_'))
     self.assertEquals('ABCDEF', util.ToUpperCamelCase('_a_b_c_d_e_f_'))
Esempio n. 2
0
def GenContextGettersDefinitions(declaration):
    lines = []
    for field in declaration.fields:
        lines.append(
            CONTEXT_VALUE_GETTER_DEFINITION_TEMPLATE % {
                'type': FIELD_TYPE_TO_GETTER_TYPE[field.type],
                'class_name': declaration.view_model_class,
                'method_name': FieldNameToGetterName(field.name),
                'context_getter': 'Get' + util.ToUpperCamelCase(field.type),
                'key_constant': FieldNameToConstantName(field.name)
            })
    return '\n'.join(lines)
  def RegisterListener(self, listener):
    """Registers all event handlers exported by the given object.

    Args:
      listener: an object with methods corresponding to wave events.
        Methods should be named either in camel case, e.g. 'OnBlipSubmitted',
        or in lowercase, e.g. 'on_blip_submitted', with names corresponding
        to the event names in the events module.
    """
    for event in dir(events):
      if event.startswith('_'):
        continue
      lowercase_method_name = 'on_' + event.lower()
      camelcase_method_name = 'On' + util.ToUpperCamelCase(event)
      if hasattr(listener, lowercase_method_name):
        handler = getattr(listener, lowercase_method_name)
      elif hasattr(listener, camelcase_method_name):
        handler = getattr(listener, camelcase_method_name)
      else:
        continue
      if callable(handler):
        self.RegisterHandler(event, handler)
Esempio n. 4
0
def GenContextFieldInitialization(field):
    lines = []
    key_constant = FieldNameToConstantName(field.name)
    setter_method = 'Set' + util.ToUpperCamelCase(field.type)
    if field.type == 'string_list':
        lines.append('  {')
        lines.append('    std::vector<std::string> defaults;')
        for s in field.default_value:
            lines.append('    defaults.push_back("%s");' % s)
        lines.append('    context().%s(%s, defaults);' %
                     (setter_method, key_constant))
        lines.append('  }')
    else:
        setter = '  context().%s(%s, ' % (setter_method, key_constant)
        if field.type in ['integer', 'double']:
            setter += str(field.default_value)
        elif field.type == 'boolean':
            setter += 'true' if field.default_value else 'false'
        else:
            assert field.type == 'string'
            setter += '"%s"' % field.default_value
        setter += ");"
        lines.append(setter)
    return '\n'.join(lines)
Esempio n. 5
0
def EventIdToMethodName(event):
    return 'On' + util.ToUpperCamelCase(event)
Esempio n. 6
0
def FieldNameToGetterName(field_name):
    return 'Get%s' % util.ToUpperCamelCase(field_name)
Esempio n. 7
0
def ChildIdToChildGetterName(id):
    return 'Get%s' % util.ToUpperCamelCase(id)
Esempio n. 8
0
def FieldNameToConstantName(field_name):
    return 'kContextKey' + util.ToUpperCamelCase(field_name)
Esempio n. 9
0
 def view_model_class(self):
     return util.ToUpperCamelCase(self.type) + 'ViewModel'
Esempio n. 10
0
 def webui_view_class(self):
     return util.ToUpperCamelCase(self.type) + 'WebUIView'