|
| 1 | +//===-- HTMLMustacheGenerator.cpp - HTML Mustache Generator -----*- C++ -*-===// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | +#include "Generators.h" |
| 9 | +#include "Representation.h" |
| 10 | +#include "support/File.h" |
| 11 | +#include "llvm/Support/MemoryBuffer.h" |
| 12 | +#include "llvm/Support/Mustache.h" |
| 13 | + |
| 14 | +using namespace llvm; |
| 15 | +using namespace llvm::json; |
| 16 | +using namespace llvm::mustache; |
| 17 | + |
| 18 | +namespace clang { |
| 19 | +namespace doc { |
| 20 | + |
| 21 | +class MustacheHTMLGenerator : public Generator { |
| 22 | +public: |
| 23 | + static const char *Format; |
| 24 | + Error generateDocs(StringRef RootDir, |
| 25 | + StringMap<std::unique_ptr<doc::Info>> Infos, |
| 26 | + const ClangDocContext &CDCtx) override; |
| 27 | + Error createResources(ClangDocContext &CDCtx) override; |
| 28 | + Error generateDocForInfo(Info *I, raw_ostream &OS, |
| 29 | + const ClangDocContext &CDCtx) override; |
| 30 | +}; |
| 31 | + |
| 32 | +class MustacheTemplateFile : public Template { |
| 33 | +public: |
| 34 | + static ErrorOr<std::unique_ptr<MustacheTemplateFile>> |
| 35 | + createMustacheFile(StringRef FileName) { |
| 36 | + ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrError = |
| 37 | + MemoryBuffer::getFile(FileName); |
| 38 | + if (auto EC = BufferOrError.getError()) |
| 39 | + return EC; |
| 40 | + |
| 41 | + std::unique_ptr<MemoryBuffer> Buffer = std::move(BufferOrError.get()); |
| 42 | + StringRef FileContent = Buffer->getBuffer(); |
| 43 | + return std::make_unique<MustacheTemplateFile>(FileContent); |
| 44 | + } |
| 45 | + |
| 46 | + Error registerPartialFile(StringRef Name, StringRef FileName) { |
| 47 | + ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrError = |
| 48 | + MemoryBuffer::getFile(FileName); |
| 49 | + if (auto EC = BufferOrError.getError()) |
| 50 | + return createFileError("cannot open file", EC); |
| 51 | + std::unique_ptr<MemoryBuffer> Buffer = std::move(BufferOrError.get()); |
| 52 | + StringRef FileContent = Buffer->getBuffer(); |
| 53 | + registerPartial(Name.str(), FileContent.str()); |
| 54 | + return Error::success(); |
| 55 | + } |
| 56 | + |
| 57 | + MustacheTemplateFile(StringRef TemplateStr) : Template(TemplateStr) {} |
| 58 | +}; |
| 59 | +Error MustacheHTMLGenerator::generateDocs( |
| 60 | + StringRef RootDir, StringMap<std::unique_ptr<doc::Info>> Infos, |
| 61 | + const clang::doc::ClangDocContext &CDCtx) { |
| 62 | + return Error::success(); |
| 63 | +} |
| 64 | +Error MustacheHTMLGenerator::generateDocForInfo(Info *I, raw_ostream &OS, |
| 65 | + const ClangDocContext &CDCtx) { |
| 66 | + return Error::success(); |
| 67 | +} |
| 68 | +Error MustacheHTMLGenerator::createResources(ClangDocContext &CDCtx) { |
| 69 | + Error Err = Error::success(); |
| 70 | + return Error::success(); |
| 71 | +} |
| 72 | + |
| 73 | +const char *MustacheHTMLGenerator::Format = "mhtml"; |
| 74 | + |
| 75 | +static GeneratorRegistry::Add<MustacheHTMLGenerator> |
| 76 | + MHTML(MustacheHTMLGenerator::Format, "Generator for mustache HTML output."); |
| 77 | + |
| 78 | +// This anchor is used to force the linker to link in the generated object |
| 79 | +// file and thus register the generator. |
| 80 | +volatile int MHTMLGeneratorAnchorSource = 0; |
| 81 | + |
| 82 | +} // namespace doc |
| 83 | +} // namespace clang |
0 commit comments