def main(cli_args, config): target = DactylTarget(config, name=cli_args.target) checker = DactylStyleChecker(target, config) issues = checker.check_all() checker.report() if issues: exit(1) else: exit(0)
def main(cli_args, config): target = DactylTarget(config, name=cli_args.target) checker = DactylStyleChecker(target, config) if cli_args.only: issues = checker.check_all(only_page=cli_args.only) else: issues = checker.check_all() checker.report() if [pr for pr in issues if not pr.passed]: exit(1) else: exit(0)
def main(cli_args, config): if cli_args.list_targets_only: list_targets(config) exit(0) if cli_args.pages: config["content_path"] = "./" # page paths will be relative to CWD target = DactylTarget(config, inpages=cli_args.pages) elif cli_args.openapi: target = DactylTarget(config, spec_path=cli_args.openapi) else: target = DactylTarget(config, name=cli_args.target) if cli_args.vars: try: if cli_args.vars[-5:] in (".json",".yaml"): with open(cli_args.vars, "r", encoding="utf-8") as f: custom_keys = yaml.load(f) else: custom_keys = yaml.load(cli_args.vars) target.gain_fields(custom_keys) except Exception as e: traceback.print_tb(e.__traceback__) exit("FATAL: --vars value was improperly formatted: %s" % repr(e)) if cli_args.title: target.gain_fields({"display_name": cli_args.title}) if not cli_args.no_cover and not target.data.get("no_cover", False): target.add_cover() if cli_args.pdf != NO_PDF: mode = "pdf" elif cli_args.md: mode = "md" elif cli_args.es: mode = "es" else: mode = "html" builder = DactylBuilder(target, config, mode) if mode == "pdf": builder.pdf_filename = cli_args.pdf if mode == "es" or cli_args.es_upload: builder.es_upload = cli_args.es_upload # Override static files copy setting based on CLI flags, if any are used if cli_args.no_static: builder.copy_content_static = False builder.copy_template_static = False elif cli_args.template_static: builder.copy_content_static = False builder.copy_template_static = True elif cli_args.content_static: builder.copy_content_static = True builder.copy_template_static = False elif cli_args.copy_static: builder.copy_content_static = True builder.copy_template_static = True if cli_args.leave_temp_files: builder.leave_temp_files = True builder.http_port = cli_args.http_port if cli_args.only: logger.info("building page %s..."%cli_args.only) builder.build_one(cli_args.only) else: logger.info("building target %s..."%target.name) builder.build_all() logger.info("done building") builder.copy_static() if cli_args.watch: logger.info("watching for changes...") builder.watch()
# Shared resources for unit testing purposes class MockCliArgs: version = None bypass_errors = False config = "test-config.yml" debug = False quiet = False out_dir = None skip_preprocessor = False from dactyl.config import DactylConfig from dactyl.target import DactylTarget class MockDactylConfig(DactylConfig): def load_filters(self): pass from jinja2 import Template mocktemplate = Template("This page is {{ currentpage.name }}.") mockconfig = MockDactylConfig(MockCliArgs) mocktarget = DactylTarget(mockconfig, inpages={})
def test_target_from_pages(self): files=["../examples/content/filter-examples/badges.md","../examples/content/filter-examples/buttonize.md"] t = DactylTarget(config=mockconfig, inpages=files) t.load_pages()