def setup(app): app.add_directive( 'accordion', template.create_directive('accordion', ACCORDION_TEMPLATE, template.BUILT_IN_PATH, False)) return { 'parallel_read_safe': True, 'parallel_write_safe': True, }
def setup(app): directive = template.create_directive('h1', H1_TEMPLATE, template.BUILT_IN_PATH, True) app.add_directive('h1', directive) directive = template.create_directive('h2', H2_TEMPLATE, template.BUILT_IN_PATH, True) app.add_directive('h2', directive) directive = template.create_directive('h3', H3_TEMPLATE, template.BUILT_IN_PATH, True) app.add_directive('h3', directive) directive = template.create_directive('h4', H4_TEMPLATE, template.BUILT_IN_PATH, True) app.add_directive('h4', directive) directive = template.create_directive('tabs', TABS_TEMPLATE, template.BUILT_IN_PATH, True) app.add_directive('tabs', directive) directive = template.create_directive('tabs-gs', TABSGS_TEMPLATE, template.BUILT_IN_PATH, True) app.add_directive('tabs-gs', directive) return {'parallel_read_safe': True, 'parallel_write_safe': True}
def create_tab_directive(name, tab_definitions): tab_ids = [tab_definition[0] for tab_definition in tab_definitions] tab_display = [tab_definition[1] for tab_definition in tab_definitions] def sortTabs(tab_data): # Create a list for the sorted data sorted = [None] * len(tab_definitions) for tab in tab_data: index = tab_ids.index(tab['id']) tab['name'] = tab_display[index] sorted[index] = tab return filter(None, sorted) sorter_name = 'sort' + name.title() fett.Template.FILTERS[sorter_name] = sortTabs return template.create_directive('tabs-{}'.format(name), build_template(sorter_name, name), template.BUILT_IN_PATH, True)
def create_tab_directive(name, tab_definitions): tab_ids = [tab_definition[0] for tab_definition in tab_definitions] tab_display = [tab_definition[1] for tab_definition in tab_definitions] def sortTabs(tab_data): # Create a list for the sorted data sorted = [None] * len(tab_definitions) for tab in tab_data: index = tab_ids.index(tab['id']) tab['name'] = tab_display[index] sorted[index] = tab return filter(None, sorted) sorter_name = 'sort' + name.title() fett.Template.FILTERS[sorter_name] = sortTabs return template.create_directive( 'tabs-{}'.format(name), build_template(sorter_name, name), template.BUILT_IN_PATH, True)
def setup(app): # Handle headers inside tab directives directive = template.create_directive('h1', H1_TEMPLATE_HTML, template.BUILT_IN_PATH, True) app.add_directive('h1', directive) directive = template.create_directive('h2', H2_TEMPLATE_HTML, template.BUILT_IN_PATH, True) app.add_directive('h2', directive) directive = template.create_directive('h3', H3_TEMPLATE_HTML, template.BUILT_IN_PATH, True) app.add_directive('h3', directive) directive = template.create_directive('h4', H4_TEMPLATE_HTML, template.BUILT_IN_PATH, True) app.add_directive('h4', directive) # Create drivers tab directive directive = template.create_directive('tabs-drivers', buildTemplate("sortLanguages", "drivers"), template.BUILT_IN_PATH, True) app.add_directive('tabs-drivers', directive) # Create general purpose tab directive with no error checking directive = template.create_directive('tabs', buildTemplate("", ""), template.BUILT_IN_PATH, True) app.add_directive('tabs', directive) return {'parallel_read_safe': True, 'parallel_write_safe': True}
def setup(app): # Handle headers inside tab directives app.add_directive( 'h1', template.create_directive('h1', H1_TEMPLATE_HTML, template.BUILT_IN_PATH, True)) app.add_directive( 'h2', template.create_directive('h2', H2_TEMPLATE_HTML, template.BUILT_IN_PATH, True)) app.add_directive( 'h3', template.create_directive('h3', H3_TEMPLATE_HTML, template.BUILT_IN_PATH, True)) app.add_directive( 'h4', template.create_directive('h4', H4_TEMPLATE_HTML, template.BUILT_IN_PATH, True)) # Create directive for positioning tabs at top of the page app.add_directive( 'tabs-top', template.create_directive('tabs-top', TABS_TOP, template.BUILT_IN_PATH, True)) app.add_directive( 'tabs-pillstrip', template.create_directive('tabs-pillstrip', PILLS_TEMPLATE, template.BUILT_IN_PATH, False)) # Create drivers tab directive app.add_directive('tabs-drivers', create_tab_directive('languages', LANGUAGES)) app.add_directive('tabs-cloud', create_tab_directive('cloud', DEPLOYMENTS)) # Create operating system tab directive app.add_directive( 'tabs-platforms', create_tab_directive('platforms', [('windows', 'Windows'), ('macos', 'macOS'), ('debian', 'Ubuntu/Debian'), ('rhel', 'RHEL/CentOS/AMZ'), ('linux', 'Linux')])) # Create Realm Language tab directive app.add_directive( 'tabs-realm-languages', create_tab_directive( 'realmLanguages', [ # Note: camelCase is required ('c-sharp', 'C#'), ('java', 'Java'), ('javascript', 'JavaScript'), ('kotlin', 'Kotlin'), ('objective-c', 'Objective C'), ('swift', 'Swift'), ('typescript', 'TypeScript'), ])) # Create Realm SDK tab directive app.add_directive( 'tabs-realm-sdks', create_tab_directive( 'realmSdks', [ # Note: camelCase is required ('functions', 'Functions'), ('json-expressions', 'JSON Expressions'), ('graphql', 'GraphQL'), ('ios', 'iOS SDK'), ('android', 'Android SDK'), ('dotnet', '.NET SDK'), ('xamarin', 'Xamarin SDK'), ('javascript', 'JavaScript SDKs'), ('node', 'Node.js SDK'), ('react-native', 'React Native SDK'), ])) # Create Realm admin interface tab directive app.add_directive( 'tabs-realm-admin-interfaces', create_tab_directive('realmAdminInterfaces', [ ('ui', 'Realm UI'), ('cli', 'Realm CLI'), ('api', 'Admin API'), ('github', 'GitHub Deploy'), ('code-deploy', 'Code Deploy'), ])) # Create Realm auth provider tab directive app.add_directive( 'tabs-realm-auth-providers', create_tab_directive('realmAuthProviders', [ ('anon-user', 'Anonymous'), ('local-userpass', 'Email/Password'), ('oauth2-apple', 'Apple ID'), ('oauth2-google', 'Google'), ('oauth2-facebook', 'Facebook'), ('api-key', 'API Key'), ('custom-token', 'Custom JWT'), ('custom-function', 'Custom Function'), ])) # Create Stitch SDK tab directive app.add_directive( 'tabs-stitch-sdks', create_tab_directive( 'stitchSdks', [ # Note: camelCase is required ('functions', 'Functions'), ('json-expressions', 'Json Expressions'), ('javascript', 'JavaScript SDK'), ('android', 'Android SDK'), ('ios', 'iOS SDK') ])) app.add_directive( 'tabs-stitch-interfaces', create_tab_directive('stitchInterfaces', [('stitch-ui', 'Stitch UI'), ('import-export', 'Import/Export')])) app.add_directive( 'tabs-stitch-auth-providers', create_tab_directive('stitchAuthProviders', [('anon-user', 'Anonymous'), ('local-userpass', 'Email/Password'), ('oauth2-google', 'Google'), ('oauth2-facebook', 'Facebook'), ('api-key', 'API Key Authentication'), ('custom-token', 'Custom')])) # Create auth tab directive app.add_directive( 'tabs-auth', create_tab_directive('auth', [('uidpwd', 'Username and Password'), ('ldap', 'LDAP'), ('kerberos', 'Kerberos')])) # Create deployments tab directive app.add_directive( 'tabs-deployments', create_tab_directive('deployments', [('standalone', 'Standalone'), ('repl', 'Replica Set'), ('shard', 'Sharded Cluster')])) # Create cloud providers tab directive app.add_directive( 'tabs-cloud-providers', create_tab_directive('cloudproviders', [('aws', 'AWS'), ('azure', 'Azure'), ('gcp', 'GCP')])) # Create k8s orchestrator tab directive app.add_directive( 'tabs-k8s-orchestrator', create_tab_directive('k8sorchestrator', [('k8s', 'Kubernetes'), ('openshift', 'OpenShift')])) # Create general purpose tab directive with no error checking app.add_directive('tabs', create_tab_directive('', [])) # Add a tab directive used by the new tab syntax app.add_directive('tab', TabInstanceDirective) return {'parallel_read_safe': True, 'parallel_write_safe': True}
def create_tab_directive(name, tab_definitions): """Create a tab directive with the given tabset name and list of (tabid, title) pairs for tab sorting and validation. For an anonymous tab directive, name and tab_definitions should both be empty.""" # If this is a named tabset with a restricted set of tab IDs, # create a sorting function that the template can use if tab_definitions: tab_ids = [tab_definition[0] for tab_definition in tab_definitions] tab_display = [tab_definition[1] for tab_definition in tab_definitions] def sort_tabs(tab_data): # Create a list for the sorted data sorted_tabs = [None] * len(tab_definitions) for tab in tab_data: index = tab_ids.index(tab['id']) tab['name'] = tab_display[index] sorted_tabs[index] = tab return filter(None, sorted_tabs) sorter_name = 'sort' + name.title() fett.Template.FILTERS[sorter_name] = sort_tabs # Create a templated superclass for this tabs directive. LegacyDirective = template.create_directive( 'tabs-{}'.format(name) if name else 'tabs', build_template(sorter_name if tab_definitions else '', name), template.BUILT_IN_PATH, True) class TabsDirective(LegacyDirective): """A set of tabbed content. This is complex: there's four possible states we handle: - Legacy (YAML) Syntax - Pure-RST Syntax and - Anonymous tabset - Named tabset""" optional_arguments = 1 final_argument_whitespace = True has_content = True option_spec = {'tabset': str, 'hidden': option_bool} def run(self): # Transform the old YAML-based syntax into the new pure-rst syntax. # This heuristic guesses whether we have the old syntax or the new. # Basically, if any of the first 2 non-empty lines are "tabs:", that's a good # signal that this is YAML. Why 2? One for hidden:..., one for tabs:. nonempty_lines = list(line for line in self.content if line) if any(line == 'tabs:' for line in nonempty_lines[:2]): return LegacyDirective.run(self) # Map the new syntax into structured data, and plug it into the old # template rendering. tabs_node = docutils.nodes.Element() tabs_node.source, tabs_node.line = self.state_machine.get_source_and_line( self.lineno) tabs_node.document = self.state.document data = { 'hidden': self.options.get('hidden', 'false') == 'true', 'tabs': [] } self.state.nested_parse( self.content, self.content_offset, tabs_node, match_titles=True, ) # Transform the rst nodes into structured data to plug into our template for node in tabs_node.children: if not isinstance(node, tab): raise self.severe( ErrorString( '"tabs" may only contain "tab" directives')) data['tabs'].append({ 'id': node['tabid'], 'name': node['title'], 'content': node['source'] }) return self.render(data) return TabsDirective
def setup(app): # Handle headers inside tab directives app.add_directive('h1', template.create_directive('h1', H1_TEMPLATE_HTML, template.BUILT_IN_PATH, True)) app.add_directive('h2', template.create_directive('h2', H2_TEMPLATE_HTML, template.BUILT_IN_PATH, True)) app.add_directive('h3', template.create_directive('h3', H3_TEMPLATE_HTML, template.BUILT_IN_PATH, True)) app.add_directive('h4', template.create_directive('h4', H4_TEMPLATE_HTML, template.BUILT_IN_PATH, True)) # Create directive for positioning tabs at top of the page app.add_directive('tabs-top', template.create_directive('tabs-top', TABS_TOP, template.BUILT_IN_PATH, True)) app.add_directive('tabs-pillstrip', template.create_directive('tabs-pillstrip', PILLS_TEMPLATE, template.BUILT_IN_PATH, False)) # Create drivers tab directive app.add_directive('tabs-drivers', create_tab_directive('languages', LANGUAGES)) app.add_directive('tabs-cloud', create_tab_directive('cloud', DEPLOYMENTS)); # Create operating system tab directive app.add_directive('tabs-platforms', create_tab_directive('platforms', [('windows', 'Windows'), ('macos', 'macOS'), ('linux', 'Linux'), ('debian', 'Debian'), ('rhel', 'RHEL')])) # Create Stitch SDK tab directive app.add_directive( 'tabs-stitch-sdks', create_tab_directive('stitchSdks', [ # Note: camelCase is required ('functions', 'Functions'), ('javascript', 'JavaScript SDK'), ('android', 'Android SDK'), ('ios', 'iOS SDK') ]) ) app.add_directive( 'tabs-stitch-interfaces', create_tab_directive('stitchInterfaces', [ ('stitch-ui', 'Stitch UI'), ('import-export', 'Import/Export') ]) ) app.add_directive( 'tabs-stitch-auth-providers', create_tab_directive('stitchAuthProviders', [ ('anon-user', 'Anonymous'), ('local-userpass', 'Email/Password'), ('oauth2-google', 'Google'), ('oauth2-facebook', 'Facebook'), ('api-key', 'API Key Authentication'), ('custom-token', 'Custom') ]) ) # Create auth tab directive app.add_directive('tabs-auth', create_tab_directive('auth', [('uidpwd', 'Username and Password'), ('ldap', 'LDAP'), ('kerberos', 'Kerberos') ]) ) # Create deployments tab directive app.add_directive('tabs-deployments', create_tab_directive('deployments', [('standalone', 'Standalone'), ('repl', 'Replica Set'), ('shard', 'Sharded Cluster') ]) ) # Create cloud providers tab directive app.add_directive('tabs-cloud-providers', create_tab_directive('cloudproviders', [('aws', 'AWS'), ('azure', 'Azure'), ('gcp', 'GCP') ]) ) # Create general purpose tab directive with no error checking app.add_directive('tabs', create_tab_directive('', [])) # Add a tab directive used by the new tab syntax app.add_directive('tab', TabInstanceDirective) return {'parallel_read_safe': True, 'parallel_write_safe': True}
def setup(app): # Handle headers inside tab directives app.add_directive( 'h1', template.create_directive('h1', H1_TEMPLATE_HTML, template.BUILT_IN_PATH, True)) app.add_directive( 'h2', template.create_directive('h2', H2_TEMPLATE_HTML, template.BUILT_IN_PATH, True)) app.add_directive( 'h3', template.create_directive('h3', H3_TEMPLATE_HTML, template.BUILT_IN_PATH, True)) app.add_directive( 'h4', template.create_directive('h4', H4_TEMPLATE_HTML, template.BUILT_IN_PATH, True)) # Create directive for positioning tabs at top of the page app.add_directive( 'tabs-top', template.create_directive('tabs-top', TABS_TOP, template.BUILT_IN_PATH, True)) app.add_directive( 'tabs-pillstrip', template.create_directive('tabs-pillstrip', PILLS_TEMPLATE, template.BUILT_IN_PATH, False)) # Create drivers tab directive app.add_directive('tabs-drivers', create_tab_directive('languages', LANGUAGES)) # Create operating system tab directive app.add_directive( 'tabs-platforms', create_tab_directive('platforms', [('windows', 'Windows'), ('macos', 'macOS'), ('linux', 'Linux'), ('debian', 'Debian'), ('rhel', 'RHEL')])) # Create Stitch SDK tab directive app.add_directive( 'tabs-stitch-sdks', create_tab_directive( 'stitchSdks', [ # Note: camelCase is required ('javascript', 'JavaScript SDK'), ('android', 'Android SDK'), ('ios', 'iOS SDK') ])) app.add_directive( 'tabs-stitch-interfaces', create_tab_directive('stitchInterfaces', [('stitch-ui', 'Stitch UI'), ('import-export', 'Import/Export')])) # Create general purpose tab directive with no error checking app.add_directive( 'tabs', template.create_directive('tabs', build_template('', ''), template.BUILT_IN_PATH, True)) return {'parallel_read_safe': True, 'parallel_write_safe': True}
def setup(app): # Handle headers inside tab directives app.add_directive('h1', template.create_directive('h1', H1_TEMPLATE_HTML, template.BUILT_IN_PATH, True)) app.add_directive('h2', template.create_directive('h2', H2_TEMPLATE_HTML, template.BUILT_IN_PATH, True)) app.add_directive('h3', template.create_directive('h3', H3_TEMPLATE_HTML, template.BUILT_IN_PATH, True)) app.add_directive('h4', template.create_directive('h4', H4_TEMPLATE_HTML, template.BUILT_IN_PATH, True)) # Create directive for positioning tabs at top of the page app.add_directive('tabs-top', template.create_directive('tabs-top', TABS_TOP, template.BUILT_IN_PATH, True)) app.add_directive('tabs-pillstrip', template.create_directive('tabs-pillstrip', PILLS_TEMPLATE, template.BUILT_IN_PATH, False)) # Create drivers tab directive app.add_directive('tabs-drivers', create_tab_directive('languages', LANGUAGES)) app.add_directive('tabs-cloud', create_tab_directive('cloud', DEPLOYMENTS)); # Create operating system tab directive app.add_directive('tabs-platforms', create_tab_directive('platforms', [('windows', 'Windows'), ('macos', 'macOS'), ('linux', 'Linux'), ('debian', 'Debian'), ('rhel', 'RHEL')])) # Create Stitch SDK tab directive app.add_directive( 'tabs-stitch-sdks', create_tab_directive('stitchSdks', [ # Note: camelCase is required ('javascript', 'JavaScript SDK'), ('android', 'Android SDK'), ('ios', 'iOS SDK') ]) ) app.add_directive( 'tabs-stitch-interfaces', create_tab_directive('stitchInterfaces', [ ('stitch-ui', 'Stitch UI'), ('import-export', 'Import/Export') ]) ) # Create auth tab directive app.add_directive('tabs-auth', create_tab_directive('auth', [('uidpwd', 'Username and Password'), ('ldap', 'LDAP'), ('kerberos', 'Kerberos') ]) ) # Create deployments tab directive app.add_directive('tabs-deployments', create_tab_directive('deployments', [('standalone', 'Standalone'), ('repl', 'Replica Set'), ('shard', 'Sharded Cluster') ]) ) # Create general purpose tab directive with no error checking app.add_directive('tabs', template.create_directive('tabs', build_template('', ''), template.BUILT_IN_PATH, True)) return {'parallel_read_safe': True, 'parallel_write_safe': True}
def setup(app): # Handle headers inside tab directives app.add_directive( 'h1', template.create_directive('h1', H1_TEMPLATE_HTML, template.BUILT_IN_PATH, True)) app.add_directive( 'h2', template.create_directive('h2', H2_TEMPLATE_HTML, template.BUILT_IN_PATH, True)) app.add_directive( 'h3', template.create_directive('h3', H3_TEMPLATE_HTML, template.BUILT_IN_PATH, True)) app.add_directive( 'h4', template.create_directive('h4', H4_TEMPLATE_HTML, template.BUILT_IN_PATH, True)) # Create directive for positioning tabs at top of the page app.add_directive( 'tabs-top', template.create_directive('tabs-top', TABS_TOP, template.BUILT_IN_PATH, True)) # Create drivers tab directive app.add_directive( 'tabs-drivers', create_tab_directive( 'languages', [ ('shell', 'Mongo Shell'), ('compass', 'Compass'), ('python', 'Python'), ('java-sync', 'Java (Sync)'), ('nodejs', 'Node.js'), ('php', 'PHP'), ('motor', 'Motor'), ('java-async', 'Java (Async)'), ('c', 'C'), # ('cpp11', 'C++11'), ('csharp', 'C#'), ('perl', 'Perl'), ('ruby', 'Ruby'), ('scala', 'Scala') ])) # Create operating system tab directive app.add_directive( 'tabs-platforms', create_tab_directive('platforms', [('windows', 'Windows'), ('macos', 'macOS'), ('linux', 'Linux'), ('debian', 'Debian'), ('rhel', 'RHEL')])) # Create general purpose tab directive with no error checking app.add_directive( 'tabs', template.create_directive('tabs', build_template('', ''), template.BUILT_IN_PATH, True)) return {'parallel_read_safe': True, 'parallel_write_safe': True}