def write(self, abs_path: Text, data) -> None: Json.write( abs_path, Json.load(Json.dump(data)), ident=self._indent, sort_keys=self._sort_keys )
def render(self, embryo: 'Embryo', style_config: Dict = None) -> None: """ # Args - embryo: the Embryo object - context: a context dict for use by jinja2 templates. - style_config: yapf style options for code formating. 1. Create the directories and files in the file system. 2. Render templates into said files. """ self.embryo = embryo self.root = embryo.destination.rstrip('/') self._buildjinja2_templates() self._analyze_embryo() # prepare a copy of the context for logging purposes only ctx = self.embryo.dumped_context.copy() del ctx['embryo'] ctx_json = Json.dump(ctx, indent=2, sort_keys=True) say(f'context:\n\n{ctx_json}\n') say( 'tree:\n\n{tree}'.format( tree='\n'.join( ' ' * 4 + line for line in Yaml.dump(self.embryo.tree).split('\n') ) ) ) self.embryo.fs._touch_filesystem(self.root, self.directory_paths, self.fpaths) self._render_files(style_config) self.embryo.persist()
def to_json(self): """ Returns JSON representation of the error This was customized as the Falcon Base errors return JSON pretty printed """ return Json.dump(self.to_dict())
def build_base_filters(cls): from appyratus.files import Json return { 'snake': StringUtils.snake, 'dash': StringUtils.dash, 'title': StringUtils.title, 'camel': StringUtils.camel, 'camel_lower': lambda x: StringUtils.camel(x, lower=True), 'plural': StringUtils.plural, 'singular': StringUtils.singular, 'alphanumeric': StringUtils.alphanumeric, 'contiguous': StringUtils.contiguous, 'constant': StringUtils.constant, 'format_python': FormatPythonFilter(), 'python2html': Python2HtmlFilter(), 'markdown2html': Markdown2HtmlFilter(), 'keyword': KeywordFilter(), 'dot': StringUtils.dot, 'wrap': StringUtils.wrap, 'json': lambda obj: (Json.dump(obj, indent=2, sort_keys=True)), 'jinja': lambda tpl, ctx: self.env.from_string(tpl).render(ctx), 'jinja_exp': lambda x: "{{ " + x + " }}", 'jinja_stmt': lambda x: "{% " + x + " %}", 'datetime': DateTimeFilter(), }