summaryrefslogtreecommitdiff
path: root/Applications/Help/ManualSectionNode.cpp
blob: 17e1ed3a51fa5d811034026c8747cab7c862a634 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include "ManualSectionNode.h"
#include "ManualPageNode.h"
#include <AK/String.h>
#include <LibCore/CDirIterator.h>

String ManualSectionNode::path() const
{
    return String::format("/usr/share/man/man%s", m_section.characters());
}

void ManualSectionNode::reify_if_needed() const
{
    if (m_reified)
        return;
    m_reified = true;

    CDirIterator dir_iter { path(), CDirIterator::Flags::SkipDots };

    while (dir_iter.has_next()) {
        String file_name = dir_iter.next_path();
        ASSERT(file_name.ends_with(".md"));
        String page_name = file_name.substring(0, file_name.length() - 3);
        NonnullOwnPtr<ManualNode> child = make<ManualPageNode>(*this, move(page_name));
        m_children.append(move(child));
    }
}