示例#1
0
 def generate_page(self, document, to_format):
     files = self.symbol_processor.replace_symbols_in_collection(
         self.project.template_conf.metadata +
         document.template_conf.metadata + document.contents)
     # Build the document contents
     contents = u'\n'
     symbols = dict(self.symbol_processor.symbols)
     for path in files:
         for expanded_path in dgen_utils.expand_path_with_glob(
                 path, self.project.file_sorter):
             if os.path.isfile(expanded_path):
                 symbols['file'] = os.path.basename(expanded_path).split(
                     '.')[0]
                 with io.open(expanded_path, 'r', encoding='utf-8') as f:
                     filecontents = self.symbol_processor.replace_symbols_in_string(
                         f.read(), symbols)
                     contents = contents + filecontents + u'\n\n'
             else:
                 dgen_utils.log_err('file does not exist:', expanded_path)
     self.print_markdown_contents(contents)
     output_file = os.path.join(self.project.html_dir,
                                document.html_filename)
     pandoc_options = self.project.template_conf.pandoc_options
     pandoc_options = document.template_conf.pandoc_options + pandoc_options
     pandoc_options = self.symbol_processor.replace_symbols_in_collection(
         pandoc_options)
     pandoc_options = [
         '--output=' + dgen_utils.expand_path(output_file),
         '--from=markdown', '--to=' + to_format
     ] + pandoc_options
     output = dgen_utils.run_cmd_with_io('pandoc',
                                         pandoc_options,
                                         stdindata=contents)
     assert output == ''
示例#2
0
 def prepare_html_dir(self, html_dir):
     '''
     Prepare the html_directory, copying it from the project's template
     '''
     if self.working_offline() is False:
         repo = git.Repo(self.project.local_template_dir)
         for remote in repo.remotes:
             remote.fetch(progress=dgen_utils.GitProgress())
         g = git.Git(repo.working_dir)
         g.checkout(self.project.pathspec)
     cwd = os.getcwd()
     # Delete the html folder if it exists
     dgen_utils.delete_folder(html_dir)
     # Copy the template html folder
     src = os.path.join(self.project.local_template_dir, 'html')
     src = dgen_utils.expand_path(src)
     dgen_utils.copy_files(src, html_dir)
     # Copy other files to the HTML dir for referencing
     for item in [
             p for p in glob.glob('*')
             if not (p.endswith('.md') or p.endswith('.yaml')
                     or p.endswith('.pdf') or p.endswith('-html'))
     ]:
         src = os.path.join(cwd, item)
         dst = os.path.join(html_dir, item)
         dgen_utils.copy_files(src, dst)
     # replace ${html_dir} in all files
     for root, _, files in os.walk(html_dir, topdown=False):
         for name in files:
             # Symbol processor must be initialised previously
             self.symbol_processor.replace_symbols_in_file(
                 os.path.join(root, name), self.symbol_processor.symbols)
示例#3
0
 def template_dir(self):
     result = os.path.join(self.templates_root, self.template)
     if dgen_utils.is_git_url(result) is True:
         return result
     result = dgen_utils.expand_path(result)
     if os.path.isdir(result) is False:
         dgen_utils.log_err('template_dir %s does not exist!' % (result))
     return result
示例#4
0
 def __init__(self):
     '''
     Run dgen
     '''
     self.project = None
     user_config_dir = dgen_utils.get_user_config_dir()
     global_config_file = os.path.join(user_config_dir, 'global_config.yaml')
     global_config_file = dgen_utils.expand_path(global_config_file)
     self.global_config = dgen_utils.load_config(global_config_file)
     self.parse_options()
示例#5
0
 def initialise(self, project):
     self.symbols = {
         'pdf_filename': project.pdf_filename,
         'bin_dir': project.bin_dir,
         'template_dir': project.local_template_dir,
         'html_dir': project.html_dir,
         'classification': project.classification
     }
     for key, value in self.symbols.items():
         if key is not 'classification':
             self.symbols[key] = dgen_utils.expand_path(value)
示例#6
0
 def revealjs_dir(self, value):
     self.__revealjs_dir = dgen_utils.expand_path(value)
     if not os.path.isdir(self.__revealjs_dir):
         dgen_utils.log_err('revealjs_dir %s does not exist!' % (value))