Exemplo n.º 1
0
def scaffold(name, actions):
    camel_case_name = to_camel_case(name)
    templ_vars = {
        'class_name': to_camel_case(name).capitalize(),
        'less_name': name.replace('_', '-'),
        'redux_name': first_to_lower(name),
        'type_name': name.upper()
    }
    files = {
        "./constants/" + camel_case_name + "Types.js": types_template,
        "./actions/" + camel_case_name + "Actions.js": action,
        "./reducers/" + camel_case_name + "Reducer.js": reducer
    }

    for filename, template in files.iteritems():
        with open(filename, "w+") as gen_file:
            gen_file.write(template % templ_vars)
            gen_file.close()

    with open('./reducers/rootReducer.js', 'r+') as c_file:
        text = c_file.read()

        export_index = re.search(r'const rootReducer', text).start()
        text = text[:export_index] + 'import ' + templ_vars['redux_name'] + "Reducer from './" + templ_vars['redux_name'] + "Reducer';\n\n" + text[export_index:]

        index = re.search(r'routing:', text).start()
        text = text[:index] + templ_vars['redux_name'] + 'Reducer' + ',\n\t' + text[index:]

        c_file.seek(0)
        c_file.truncate()
        c_file.write(text)
        c_file.close()
Exemplo n.º 2
0
def container(name):
    templ_vars = {
        'class_name': to_camel_case(name.capitalize()),
        'less_name': name.replace('_', '-'),
        'redux_name': first_to_lower(name)
    }
    files = {
        "./src/containers/" + templ_vars['class_name'] + ".js": container_template,
        "./src/less/" + templ_vars['class_name'] + ".less": less
    }

    if os.path.exists("./src/containers/" + templ_vars['class_name'] + ".js"): print('Component already exists'); sys.exit()

    for filename, template in files.iteritems():
        with open(filename, "w+") as gen_file:
            gen_file.write(template % templ_vars)
            gen_file.close()
Exemplo n.º 3
0
 def serialize(self):
     return {
         to_camel_case(e): getattr(self, e)
         for e in Event.SERIALIZED_ATTRIBUTES
     }
Exemplo n.º 4
0
 def _encode(self, payload):
     return pyjwt.encode({to_camel_case(key): value for key, value
                          in payload.items()}, JWT_SECRET, algorithm='HS256')