generate navigation items for given contents.
504826
private function generateNavigation(
        $contents,
        $webspace,
        $language,
        $flat = false,
        $context = null,
        $breakOnNotInNavigation = false,
        $recursive = true
    ) {
        $result = [];

        /** @var StructureInterface $content */
        foreach ($contents as $content) {
            if ($this->inNavigation($content, $context)) {
                $url = $content->getResourceLocator();
                $title = $content->getNodeName();
                $children = $recursive ? $this->generateChildNavigation($content, $webspace, $language, $flat, $context) : [];

                if (false === $flat) {
                    $result[] = new NavigationItem(
                        $title,
                        $url,
                        isset($content->getExt()['excerpt']) ? $content->getExt()['excerpt'] : null,
                        $children,
                        $content->getUuid(),
                        $content->getNodeType()
                    );
                } else {
                    $result[] = new NavigationItem(
                        $title,
                        $url,
                        isset($content->getExt()['excerpt']) ? $content->getExt()['excerpt'] : null,
                        null,
                        $content->getUuid(),
                        $content->getNodeType()
                    );
                    $result = array_merge($result, $children);
                }
            } elseif (true === $flat) {
                $children = $recursive ? $this->generateChildNavigation($content, $webspace, $language, $flat, $context) : [];
                $result = array_merge($result, $children);
            } elseif ($breakOnNotInNavigation) {
                break;
            }
        }

        return $result;
    }
1032839
def item_links_addition(self, data):
        """"""
        links_item_factory = self.context.get('links_item_factory',
                                              default_links_item_factory)
        data['links'] = links_item_factory(data)
        return data
314041
protected function generateNavigation()
    {
        $contexts = [];

        foreach ($this->xpath->query('/x:webspace/x:navigation/x:contexts/x:context') as $contextNode) {
            /* @var \DOMNode $contextNode */
            $contexts[] = new NavigationContext(
                $contextNode->attributes->getNamedItem('key')->nodeValue,
                $this->loadMeta('x:meta/x:*', $contextNode)
            );
        }

        return new Navigation($contexts);
    }
936289
def _nav_to_tree(root):
    
    def expath(e, x):
        return e.xpath(x, namespaces=HTML_DOCUMENT_NAMESPACES)
    for li in expath(root, 'xhtml:ol/xhtml:li'):
        is_subtree = bool([e for e in li.getchildren()
                           if e.tag[e.tag.find('}')+1:] == 'ol'])
        if is_subtree:
            # It's a sub-tree and have a 'span' and 'ol'.
            itemid = li.get('cnx-archive-uri', 'subcol')
            shortid = li.get('cnx-archive-shortid')
            yield {'id': itemid,
                   # Title is wrapped in a span, div or some other element...
                   'title': squash_xml_to_text(expath(li, '*')[0],
                                               remove_namespaces=True),
                   'shortId': shortid,
                   'contents': [x for x in _nav_to_tree(li)],
                   }
        else:
            # It's a node and should only have an li.
            a = li.xpath('xhtml:a', namespaces=HTML_DOCUMENT_NAMESPACES)[0]
            yield {'id': a.get('href'),
                   'shortid': li.get('cnx-archive-shortid'),
                   'title': squash_xml_to_text(a, remove_namespaces=True)}
1158380
def index_map(data):
  """"""
  (entry, text_fn) = data
  text = text_fn()

  logging.debug("Got %s", entry.filename)
  for s in split_into_sentences(text):
    for w in split_into_words(s.lower()):
      yield (w, entry.filename)
830479
def _get_contents(self):
        """"""
        def files():
            for value in super(GlobBundle, self)._get_contents():
                for path in glob.glob(value):
                    yield path
        return list(files())
651153
def convert_items(self, items):
        """"""
        return ((key, self.convert(value, self)) for key, value in items)
15694
def generate(self, output_dir, catalogue, results, label):
        """"""
        data = results.get_raw_data()
        labels = catalogue.ordered_labels
        ngrams = self._generate_results(output_dir, labels, data)
        ngram_table = self._generate_ngram_table(output_dir, labels, data)
        corpus_table = self._generate_corpus_table(labels, ngrams)
        context = {'corpus_table': corpus_table, 'focus_label': label,
                   'labels': labels, 'ngram_table': ngram_table, 'sep': os.sep}
        report_name = 'lifetime-{}.html'.format(label)
        self._write(context, output_dir, report_name)
1183648
def items(self, section):
        """"""
        for line in self.iter_lines(section):
            if line.kind == ConfigLine.KIND_DATA:
                yield line.key, line.value
901705
def __create_lists_for_nav_bar(self):
        """"""
        
        nav_bar_section = []
        nav_bar_section_page = []
        for key in self.sections:
            nav_bar_section.append(key)
            nav_bar_page = []
            for page in self.sections[key].pages:
                nav_bar_page.append(page)
            nav_bar_section_page.append(nav_bar_page)
        
        nav_bar_section_page_len = [len(x) for x in nav_bar_section_page]
        
        self.nav_bar_section_page = nav_bar_section_page # create a variable for later
        
        # nav_bar_page is a list of lists
        return nav_bar_section, nav_bar_section_page, nav_bar_section_page_len
666509
def get_top_level_items(self):
        """"""
        menu_items = self.get_base_menuitem_queryset()

        # Identify which pages to fetch for the top level items
        page_ids = tuple(
            obj.link_page_id for obj in menu_items if obj.link_page_id
        )
        page_dict = {}
        if page_ids:
            # We use 'get_base_page_queryset' here, because if hooks are being
            # used to modify page querysets, that should affect the top level
            # items also
            top_level_pages = self.get_base_page_queryset().filter(
                id__in=page_ids
            )
            if self.use_specific >= constants.USE_SPECIFIC_TOP_LEVEL:
                """
                The menu is being generated with a specificity level of
                TOP_LEVEL or ALWAYS, so we use PageQuerySet.specific() to fetch
                specific page instances as efficiently as possible
                """
                top_level_pages = top_level_pages.specific()

            # Evaluate the above queryset to a dictionary, using IDs as keys
            page_dict = {p.id: p for p in top_level_pages}

        # Now build a list to return
        menu_item_list = []
        for item in menu_items:
            if not item.link_page_id:
                menu_item_list.append(item)
                continue  # skip to next
            if item.link_page_id in page_dict.keys():
                # Only return menu items for pages where the page was included
                # in the 'get_base_page_queryset' result
                item.link_page = page_dict.get(item.link_page_id)
                menu_item_list.append(item)
        return menu_item_list
1068492
def items(self):
        """"""
        keycol = self._keycol
        for row in self.__iter__():
            yield (row[keycol], dict(row))
1102494
def build_item(
    title, key=None, synonyms=None, description=None, img_url=None, alt_text=None
):
    """"""
    item = {
        "info": {"key": key or title, "synonyms": synonyms or []},
        "title": title,
        "description": description,
        "image": {
            "imageUri": img_url or "",
            "accessibilityText": alt_text or "{} img".format(title),
        },
    }
    return item
250311
def list(self):
        """"""
        if self.is_fake:
            return

        for item in self.collection.list():
            yield item.uid + self.content_suffix
35862
def setcontents(source, identifier, pointer):
    """"""
    record = Record.get_record(identifier)
    Document(record, pointer).setcontents(source)
140645
def generate_docs(self, clspath, more_content):
        """"""
        obj = import_class(clspath)
        sourcename = 'docstring of %s' % clspath
        all_options = []
        indent = '    '
        config = obj.get_required_config()

        if config.options:
            # Go through options and figure out relevant information
            for option in config:
                if 'namespace' in self.options:
                    namespaced_key = self.options['namespace'] + '_' + option.key
                else:
                    namespaced_key = option.key

                if 'case' in self.options:
                    if self.options['case'] == 'upper':
                        namespaced_key = namespaced_key.upper()
                    elif self.options['case'] == 'lower':
                        namespaced_key = namespaced_key.lower()

                all_options.append({
                    'key': namespaced_key,
                    'parser': qualname(option.parser),
                    'doc': option.doc,
                    'default': option.default,
                })

        if 'hide-classname' not in self.options:
            modname, clsname = split_clspath(clspath)
            component_name = clspath
            component_index = clsname
        else:
            component_name = 'Configuration'
            component_index = 'Configuration'

        if all_options:
            # Add index entries for options first so they link to the right
            # place; we do it this way so that we don't have to make options a
            # real object type and then we don't get to use TypedField
            # formatting
            self.add_line('.. index::', sourcename)
            for option in all_options:
                self.add_line('   single: %s; (%s)' % (option['key'], component_index), sourcename)
            self.add_line('', '')

        # Add the classname or 'Configuration'
        self.add_line('.. everett:component:: %s' % component_name, sourcename)
        self.add_line('', sourcename)

        # Add the docstring if there is one and if show-docstring
        if 'show-docstring' in self.options:
            docstring_attr = self.options['show-docstring'] or '__doc__'
            docstring = getattr(obj, docstring_attr, None)
            if docstring:
                docstringlines = prepare_docstring(docstring, ignore=1)
                for i, line in enumerate(docstringlines):
                    self.add_line(indent + line, sourcename, i)
                self.add_line('', '')

        # Add content from the directive if there was any
        if more_content:
            for line, src in zip(more_content.data, more_content.items):
                self.add_line(indent + line, src[0], src[1])
            self.add_line('', '')

        if all_options:
            # Now list the options
            sourcename = 'class definition'

            for option in all_options:
                self.add_line(
                    '%s:option %s %s:' % (indent, option['parser'], option['key']),
                    sourcename
                )
                self.add_line('%s    %s' % (indent, option['doc']), sourcename)
                if option['default'] is not NO_VALUE:
                    self.add_line('', '')
                    self.add_line(
                        '%s    Defaults to ``%r``.' % (indent, option['default']),
                        sourcename
                    )
                self.add_line('', '')
643567
def generate_menu():
    """"""
    root_menu = Menu(list(copy.deepcopy(settings.WAFER_MENUS)))
    for dynamic_menu_func in settings.WAFER_DYNAMIC_MENUS:
        dynamic_menu_func = maybe_obj(dynamic_menu_func)
        dynamic_menu_func(root_menu)
    return root_menu