Code Monkey home page Code Monkey logo

unreal-doc's Introduction

Unreal Doc

Tool for generating documentation from Unreal C++ sources.

Table of contents

  1. About
  2. Installation
  3. Config file
    1. Simple config setup for baking into JSON portable format
    2. Simple config setup for baking into MD Book
    3. Advanced config setup for baking into MD Book
  4. Markdown doc comments
  5. Markdown book pages
  6. Run documentation baking command
  7. Examples

About

Do you create an Unreal Engine plugin and need to generate a documentation combined with book for it, but Doxygen seems limited or sometimes not working at all?

Fear not - this tool understands Unreal C++ header files syntax and Markdown doc comments, it can also bake a book pages out of Markdown files, all of that being able to cross-reference each other!

Installation

Config file

Config TOML file tells this tool evenrythig about how to build documentation for your project. At this moment there are two baking backends available:

  • Json

    Portable representation of documentation and book that can be used in third party applications with custom way of baking documentation.

  • MdBook

    Uses MD Book for baking HTML5 bundle for online or offline web books.

Although config file can be named whatever you want, it's a good rule to give config file UnrealDoc.toml name.

Simple config setup for baking into JSON portable format

input_dirs = ["./source"]
output_dir = "./docs"
  • input_dirs

    List of directories and Unreal C++ header or Markdown files this tool should read.

  • output_dir

    Path to directory where generated documentation should be put.

Simple config setup for baking into MD Book

input_dirs = ["./source"]
output_dir = "./docs"
backend = "MdBook"

[backend_mdbook]
title = "Documentation"
build = true
cleanup = true
  • backend

    Specifies MD Book baking backend.

  • backend_mdbook.title

    Title of the generated documentation and book bundle.

  • backend_mdbook.build

    Set to true if this tool should also run mdbook build command on generated files to build HTML5 version of the bundle, ready to put online.

  • backend_mdbook.cleanup

    Set to true if this tool should cleanup output_dir directory before baking new files. Useful for ensuring no old/unwanted files will exist between iterations of documentation baking.

Advanced config setup for baking into MD Book

input_dirs = ["./source"]
output_dir = "./docs"
backend = "MdBook"

[settings]
document_private = true
document_protected = true
show_all = true

[backend_mdbook]
title = "Documentation"
build = true
cleanup = true
header = "header.md"
footer = "footer.md"
assets = "assets/"
  • backend_mdbook.header

    Path to file that contains Markdown content that will be put on every documentation and book page header section.

  • backend_mdbook.footer

    Path to file that contains Markdown content that will be put on every documentation and book page footer section.

  • backend_mdbook.assets

    Path to directory that contains assets (usually images/animations/videos) referenced in documentation and book pages.

Markdown doc comments

Overview of all possible things you can do with Markdown doc comments.

#pragma once

using Foo = std::vector<int>;

enum class Something : uint8;

template <typename T>
struct BAR Foo : public Bar;

class FOO Bar;

template <typename T>
void* Main(const Foo& Arg);

/// Description of enum
///
/// More information and examples.
UENUM(BlueprintType, Meta = (Foo = Bar))
enum class Something : uint8
{
	A,
	B
};

/// Description of struct
///
/// More information and examples.
///
/// [`struct: Self::Foo`]()
/// [`struct: Self::A`]()
USTRUCT(BlueprintType, Meta = (Foo = Bar))
template <typename T>
struct BAR Foo : public Bar
{
protected:
	/// What is this method
	///
	/// What it does
	UFUNCTION()
	virtual void Foo(
		/// Argument
		int A,
		/// Argument with default value
		AActor* B = nullptr) const override;

private:
	/// What is this property
	///
	/// What impact does it have
	UPROPERTY()
	int A[] = {0};
};

/// Description of class
///
/// More information and examples.
///
/// [`class: Self::Bar`]()
UCLASS()
class FOO Bar
{
public:
	/// What is this method
	///
	/// What it does
	Bar();
};

/// What is this function
///
/// What does it do
///
/// [`function: Self`]()
///
/// See:
/// - [`enum: Something`]()
/// - [`struct: Foo`]()
/// - [`struct: Foo::Foo`]()
/// - [`struct: Foo::A`]()
/// - [`class: Bar`]()
/// - [`function: Main`]()
///
/// # Examples
/// ```snippet
/// hello_world
/// ```
/// ```snippet
/// hello_world2
/// ```
/// ```snippet
/// wait_what
/// ```
template <typename T>
void* Main(
	/// Some referenced data
	const Foo& Arg)
{
	//// [snippet: hello_world]
	if (true)
	{
		printf("Hello");
	}
	//// [/snippet]

	//// [snippet: hello_world2]
	printf("World");
	//// [/snippet]
}

//// [snippet: wait_what]
struct Wait
{
	int What = 0;
};
//// [/snippet]

/// Proxy documentation for injecting code with macros.
///
//// [proxy: injectable]
//// void Injected() const;
//// [/proxy]
#define INJECT            \
	void Injected() const \
	{                     \
	}

struct Who
{
	int What = 0;

	void SetWhat(int InWhat)
	{
		//// [ignore]
		this->What = InWhat;
		//// [/ignore]
	}

    /// Operator overload.
	friend bool operator==(const Who& Lhs, const Who& Rhs)
	{
		//// [ignore]
		return Lhs.What == Rhs.What;
		//// [/ignore]
	}

	//// [inject: injectable]
	INJECT
};

Markdown book pages

Standard expected structure of the book Markdown files:

  • documentation.md (optional)

    This is essentially the content of main page of your documentation + book, a hello page you can call it. it has to be placed in root of book source Markdown files directory.

  • index.txt (required)

    This file contains a list of files or directories with optional names (useful mostly for directories). The order specified in this file will match order on side pages index.

    some_book_page.md
    directory_with_subpages: Title on side pages index
    
  • index.md (optional)

    Markdown file content used in to describe content of given directory content. First line of the content will be used as title of the directory on side pages index.

    # Book
    
    Optional directory content description
  • hello.md

    Content for given book page. First line will be used as page title on side pages index.

      # Hello World!
    
      Lorem ipsum dolor amet
    
      ```cpp
      void main() {
          printf("Hello World!");
      }
      ```
    

Run documentation baking command

Once you have config file and documentation itself all in place, it's time to actually bake documentation and book bundle:

unreal-doc -i path/to/UnrealDoc.toml

Example

If you want to see an example of decoumentation and book source files structure, take a look at /resources directory in this repository or more real life example that can be found here: https://github.com/PsichiX/Unreal-Systems-Architecture/tree/master/Plugins/Systems/Documentation

Real life example of baked plugin documentation: https://psichix.github.io/Unreal-Systems-Architecture/systems

unreal-doc's People

Contributors

psichix avatar

Stargazers

MathiasL avatar Roman avatar  avatar  avatar hareubi avatar Enzo Resse avatar ZY Zhuang avatar ◄hollsteinm► avatar ᴍᴀᴍᴀᴅᴏᴜ ʙᴀʙᴀᴇɪ avatar  avatar Wouter Weynants avatar Karl Schmidt avatar Erin Sharp avatar mcoms avatar Max Azoury avatar  avatar xenon avatar CodingBot avatar Doğa Can Yanıkoğlu avatar SirLich avatar Nick Lamprecht avatar Marwan Hilmi avatar Mickael Daniel avatar Duwayne avatar Willie Möller avatar Gaizka P. avatar

Watchers

 avatar CodingBot avatar  avatar

unreal-doc's Issues

unreal-doc does not support braced initializers

Any property initialized with a default via C++ braced initializer format -- structure or otherwise -- will cause an error when trying to parse the header files:

Error:
   --> 175:28
    |
175 |   bool bEnableAggregateTick{true};
    |                            ^---
    |
    = expected property_array or default_value

unreal-doc does not support inline functions

Attempting to generate documentation for a plugin which contains single-line inline functions in a header file will error out:

Error:
  --> 33:26
   |
33 |    FName GetName() const { return VariableName; }
   |                            ^---
   |
   = expected snippet

mdBook is necessary but not a dependency?

I got everything working on my desktop earlier, love this documentation toolset.

Installed it on my laptop today, ran cargo install unreal-doc expecting it to work like a charm but found out my laptop didn't have mdBook yet and it was not installed with this. Is that intentional for some reason I do not know?

UTF-8 with BOM cannot be parsed

Problem

  • I'm using Jetbrains Rider on Windows 10
  • By default it uses UTF-8 BOM
  • Attempting to use unreal-doc results in:
C:\UE5\MyGame>unreal-doc.exe -i MyGameDoc.toml
thread 'main' panicked at 'Could not parse Unreal C++ header file content!
File: "\\\\?\\C:\\UE5\\MyGame\\Source\\MyGame\\Docs\\MyHeader.h"
Error:
 --> 1:1
  |
1 | #pragma once
  | ^---
  |
  = expected file', C:\Users\MyUser\.cargo\registry\src\index.crates.io-6f17d22bba15001f\unreal-doc-1.0.6\src\main.rs:156:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

C:\UE5\MyGame>pause
Press any key to continue . . .

Temporary solutions

  • Use notepad++ to remove the BOM
  • Use Rider to remove the BOM
  • Set up Rider to disable BOM on file save by default
  • Remove BOM using Powershell
Get-ChildItem -Path "yourFolderPath" -Recurse -File | ForEach-Object {
    try {
        $isReadOnly = ($_.Attributes -band [IO.FileAttributes]::ReadOnly)

        if ($isReadOnly) {
            $_.IsReadOnly = $false
        }

        $content = Get-Content $_.FullName -Encoding Byte -Raw -ErrorAction Stop

        if ($content -ne $null -and $content.Length -gt 2 -and $content[0] -eq 0xEF -and $content[1] -eq 0xBB -and $content[2] -eq 0xBF) {
            # It's a BOM, remove the first 3 bytes
            [System.IO.File]::WriteAllBytes($_.FullName, ($content | Select-Object -Skip 3))
            Write-Host "Successfully processed file $($_.FullName)"
        } else {
            Write-Host "No BOM detected in file $($_.FullName)"
        }

        if ($isReadOnly) {
            $_.IsReadOnly = $true
        }
    }
    catch {
        Write-Error "Error processing file $($_.FullName): $_"
    }
}

thread 'main' panicked at 'Could not parse Unreal C++ header file content

Hello, I am trying to use unreal-doc to build documentation in my personal project. I am currently encountering an error. Am I using it incorrectly? Thank you in advance for your help.

unreal-doc -i UnrealDoc.toml
thread 'main' panicked at 'Could not parse Unreal C++ header file content!
File: "\\\\?\\E:\\projectr\\Rhea\\Source\\Rhea\\Town\\Objects\\TownInfo.h"
Error:
  --> 31:74
   |
31 |    virtual UTownObjectComponent* GetTownObjectComponent() const override { return TownObjectComponent; }
   |                                                                            ^---
   |
   = expected snippet', src\main.rs:159:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

my toml:

input_dirs = [
    "./Source/Rhea/Town/Objects",
]
output_dir = "./Distribution"
#backend = "MdBook"
#
#[backend_mdbook]
#title = "Systems - Modular and scalable game architecture for orthogonal game logic"
#build = true
#cleanup = true
# header = "header.md"
# footer = "footer.md"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.