Esempio n. 1
0
def register_action(module_path, action_path, app_cfg):
  # 修改module.js,添加path和action关系
  abs_path = os.path.join(module_path, 'module.js')
  module_config_identifier = "%s.config" % app_cfg["app.module"]
  first_token = Frewriter.tokenizer(open(abs_path).read())
  token = Frewriter.find_token(first_token, module_config_identifier)
  start_block = Frewriter.find_token(token, "{", TokenType.START_BLOCK)
  end_block = Frewriter.find_end_token(start_block.next)
  map_code = "\n// Autogenerated at %s\n%s['action'].push({'location':'%s','action':'%s'});" % (
    datetime.now().strftime('%Y/%m/%d %H:%M:%S'), module_config_identifier,
    action_path, app_cfg['app.name'])
  Frewriter.append_code(end_block.previous, Frewriter.tokenizer(map_code))
  open(abs_path, 'wb').write(Frewriter.dump_source(first_token))
  logging.info('M %s' % abs_path)
Esempio n. 2
0
  def testInsertActionConfig(self):
    token = Frewriter.find_token(self.first_token, "a.this_is_a_module.config")
    self.assertEquals(token.type, TokenType.SIMPLE_LVALUE)
    self.assertEquals(token.values['identifier'], 'a.this_is_a_module.config')

    start_block = Frewriter.find_token(token, "{", TokenType.START_BLOCK)
    self.assertTrue(start_block is not None)

    end_block = Frewriter.find_end_token(start_block.next)
    self.assertTrue(end_block is not None)

    # a.this_is_a_module.config['action'].push({'location':'','action':''});
    code = "a.this_is_a_module.config['action'].push({'location':'/jn/demo/xxx','action':'jn.demo.Xxx'});"
    Frewriter.append_code(end_block, Frewriter.tokenizer(code))
    self.assertTrue(self._dump_source(self.first_token).find(code) > 0)
Esempio n. 3
0
 def testAppendCode(self):
   token_stream1 = Frewriter.tokenizer("var hello = 'world';")
   token_stream2 = Frewriter.tokenizer("var happy = 'new year';\n\n\n\n\n\n//THIS IS COMMENT")
   Frewriter.append_code(token_stream1.next.next.next.next.next.next.next.next.next, token_stream2)
   self.assertEquals("var hello = 'world';var happy = 'new year';\n\n\n\n\n//THIS IS COMMENT\n",
     self._dump_source(token_stream1))