flask_boost/cli.py
def generate_macro(args):
    """Genarate macro."""
    macro = args.get('<macro>').replace('-', '_')
    category = args.get('<category>')

    if not macro:
        logger.warning('Macro name cannot be empty.')
        return

    logger.info('Start generating macro.')

    current_path = os.getcwd()

    if category:
        macro_root_path = os.path.join(current_path, 'application/macros', category, macro)
    else:
        macro_root_path = os.path.join(current_path, 'application/macros', macro)

    _mkdir_p(macro_root_path)

    macro_html_path = os.path.join(macro_root_path, '_%s.html' % macro)
    macro_css_path = os.path.join(macro_root_path, '_%s.less' % macro)
    macro_js_path = os.path.join(macro_root_path, '_%s.js' % macro)

    # html
    macro_html_template_path = os.path.join(dirname(abspath(__file__)), 'templates/macro.html')
    with open(macro_html_template_path, 'r') as template_file:
        with open(macro_html_path, 'w+') as html_file:
            for line in template_file:
                new_line = line.replace('#{macro}', macro)
                html_file.write(new_line)
    logger.info("New: %s" % _relative_path(macro_html_path))

    # css
    open(macro_css_path, 'a').close()
    logger.info("New: %s" % _relative_path(macro_css_path))

    # js
    open(macro_js_path, 'a').close()
    logger.info("New: %s" % _relative_path(macro_js_path))

    logger.info('Finish generating macro.')
def generate_macro(args):
    """Genarate macro."""
    macro = args.get('<macro>').replace('-', '_')
    category = args.get('<category>')

    if not macro:
        logger.warning('Macro name cannot be empty.')
        return

    logger.info('Start generating macro.')

    current_path = os.getcwd()

    if category:
        macro_root_path = os.path.join(current_path, 'application/macros', category, macro)
    else:
        macro_root_path = os.path.join(current_path, 'application/macros', macro)

    _mkdir_p(macro_root_path)

    macro_html_path = os.path.join(macro_root_path, '_%s.html' % macro)
    macro_css_path = os.path.join(macro_root_path, '_%s.less' % macro)
    macro_js_path = os.path.join(macro_root_path, '_%s.js' % macro)

    # html
    macro_html_template_path = os.path.join(dirname(abspath(__file__)), 'templates/macro.html')
    with open(macro_html_template_path, 'r') as template_file:
        with open(macro_html_path, 'w+') as html_file:
            for line in template_file:
                new_line = line.replace('#{macro}', macro)
                html_file.write(new_line)
    logger.info("New: %s" % _relative_path(macro_html_path))

    # css
    open(macro_css_path, 'a').close()
    logger.info("New: %s" % _relative_path(macro_css_path))

    # js
    open(macro_js_path, 'a').close()
    logger.info("New: %s" % _relative_path(macro_js_path))

    logger.info('Finish generating macro.')
def generate_macro ( args ) : macro = args . get ( '<macro>' ) . replace ( '-' , '_' ) category = args . get ( '<category>' ) if not macro : logger . warning ( 'Macro name cannot be empty.' ) return logger . info ( 'Start generating macro.' ) current_path = os . getcwd ( ) if category : macro_root_path = os . path . join ( current_path , 'application/macros' , category , macro ) else : macro_root_path = os . path . join ( current_path , 'application/macros' , macro ) _mkdir_p ( macro_root_path ) macro_html_path = os . path . join ( macro_root_path , '_%s.html' % macro ) macro_css_path = os . path . join ( macro_root_path , '_%s.less' % macro ) macro_js_path = os . path . join ( macro_root_path , '_%s.js' % macro ) # html macro_html_template_path = os . path . join ( dirname ( abspath ( __file__ ) ) , 'templates/macro.html' ) with open ( macro_html_template_path , 'r' ) as template_file : with open ( macro_html_path , 'w+' ) as html_file : for line in template_file : new_line = line . replace ( '#{macro}' , macro ) html_file . write ( new_line ) logger . info ( "New: %s" % _relative_path ( macro_html_path ) ) # css open ( macro_css_path , 'a' ) . close ( ) logger . info ( "New: %s" % _relative_path ( macro_css_path ) ) # js open ( macro_js_path , 'a' ) . close ( ) logger . info ( "New: %s" % _relative_path ( macro_js_path ) ) logger . info ( 'Finish generating macro.' )
Genarate macro.
Genarate macro .