def generate_plugins(plugin_list: List[Plugin]): plugin_root = os.path.join(constants.CATALOGUE_FOLDER, 'plugins') for plugin in plugin_list: with write_nav( os.path.join(plugin_root, plugin.id, get_file_name('readme.md'))) as file: write_plugin(plugin, file) write_plugin_download(plugin, file, limit=-1)
def generate_full(plugin_list: Iterable[Plugin], file: IO[str]): with utils.read_file( os.path.join(constants.TEMPLATE_FOLDER, get_file_name('full_header.md'))) as header: file.write(header.read()) file.write('\n') for plugin in plugin_list: write_plugin(plugin, file) write_plugin_download(plugin, file)
def load_from_json(self, js: dict): self.plugin_json = js self.id = js.get('id', None) self.repository = js['repository'].rstrip('/') if not self.repository.startswith('https://github.com/'): raise ValueError( 'Github repository with https url is required, found: {}'. format(self.repository)) self.branch = js['branch'] self.related_path = js.get('related_path', '.').strip('/') authors = js.get('authors', []) self.authors = [] for item in authors: author = Author() if isinstance(item, str): author.name = item else: assert isinstance(item, dict) author.update_from(item) self.authors.append(author) # label self.labels = [] for label_key in js['labels']: label = get_label_set().get_label(label_key) if label is None: raise ValueError('Unknown label: {}'.format(label_key)) else: self.labels.append(label) # introduction external_introduction = js.get('introduction', {}) introduction_translations = {} for lang in LANGUAGES: with with_language(lang): file_location = external_introduction.get(lang) if file_location is not None: try: introduction_translations[lang] = self.get_repos_text( file_location) except: print( 'Failed to get custom introduction file from {} in language {} in {}' .format(file_location, lang, self)) traceback.print_exc() introduction_translations[lang] = '*{}*'.format( Text('data_fetched_failed')) introduction_tr_file_path = os.path.join( self.directory, get_file_name('introduction.md')) if os.path.isfile(introduction_tr_file_path): with utils.read_file( introduction_tr_file_path) as file_handler: introduction_translations[lang] = file_handler.read() self.introduction = BundledText(introduction_translations)
def write_translation_nav(file_name: str, file: IO[str]): nav_list = [] for lang in LANGUAGES: with with_language(lang): lang_name = Text('_language_name').get() if lang == get_language(): text = '**{}**'.format(lang_name) else: with with_language(lang): text = Link(lang_name, get_file_name(file_name)) nav_list.append('{}'.format(text)) file.write('{}\n'.format(' | '.join(nav_list))) file.write('\n')
def generate_labels(plugin_list: List[Plugin]): label_root = os.path.join(constants.CATALOGUE_FOLDER, 'labels') for label in get_label_set().get_label_list(): with write_nav( os.path.join(label_root, label.id, get_file_name('readme.md'))) as file: file.write('# {}\n'.format(label)) file.write('\n') file.write('{}\n'.format( Text('plugin_index_with_label')).format(label)) file.write('\n') generate_index( filter(lambda plg: label in plg.labels, plugin_list), file)
def write_doc(): with write_nav(get_root_readme_file_path()) as file: with utils.read_file( os.path.join(constants.TEMPLATE_FOLDER, get_file_name('index_header.md'))) as header: file.write(header.read()) file.write('\n') write_label_info(file) file.write('-------\n\n') generate_index(plugin_list, file) generate_labels(plugin_list) generate_plugins(plugin_list) with write_nav(get_full_index_file_path()) as file: generate_full(plugin_list, file)
def write_back_to_index_nav(file: IO[str]): file.write('{} {}\n'.format( utils.format_markdown('>>>'), Link(Text('back_to_index'), get_file_name('/readme.md')))) file.write('\n')
def get_full_index_file_path(): return os.path.join(constants.CATALOGUE_FOLDER, get_file_name('full.md'))
def get_root_readme_file_path(): return os.path.join(constants.CATALOGUE_FOLDER, get_file_name('readme.md'))
def get_label_doc_link(label_id: str): return '/labels/{}/{}'.format(label_id, get_file_name('readme.md'))
def get_plugin_detail_link(plugin_id: str): if plugin_id == 'mcdreforged': return constants.MCDR_LINK else: return '/plugins/{}/{}'.format(plugin_id, get_file_name('readme.md'))