Skip to content

Commit

Permalink
- add edit on github links to all doc pages & undocumented API methods
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph-hart committed Nov 1, 2024
1 parent a33df66 commit e8688bb
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 21 deletions.
2 changes: 1 addition & 1 deletion currentGitHash.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
27916b2029b7e4e2f1e3bf7d10304a2836fa61a9
a33df6689dc4519fa7dcb395ed243e9edd73dbff
2 changes: 1 addition & 1 deletion hi_backend/backend/currentGit.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define PREVIOUS_HISE_COMMIT "27916b2029b7e4e2f1e3bf7d10304a2836fa61a9"
#define PREVIOUS_HISE_COMMIT "a33df6689dc4519fa7dcb395ed243e9edd73dbff"
20 changes: 17 additions & 3 deletions hi_backend/backend/doc_generators/ApiMarkdownGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,27 @@ juce::String ScriptingApiDatabase::Resolver::createMethodText(ValueTree& mv)
String className = mv.getParent().getType().toString();
String methodName = mv.getProperty("name").toString();

s << "## `" << methodName << "`\n";
s << "## `" << methodName;

s << "`\n";

s << "> " << mv.getProperty("description").toString().trim();

s << "> " << mv.getProperty("description").toString().trim() << "\n";
auto fileLink = rootURL.getChildUrl(className).getChildUrl(methodName);
auto docFile = fileLink.getMarkdownFile(rootURL.getRoot());

if(rootURL.getRoot().isDirectory() && (!docFile.existsAsFile() || docFile.loadFileAsString().isEmpty()))
{
if(!docFile.existsAsFile())
docFile.create();

s << fileLink.getEditLinkOnGitHub(false);
}

s << "\n";

s << "```javascript\n" << className << "." << methodName << mv.getProperty("arguments").toString() << "``` \n";

auto fileLink = rootURL.getChildUrl(className).getChildUrl(methodName);
s << fileLink.toString(MarkdownLink::ContentWithoutHeader, rootURL.getRoot());
s << " \n";

Expand Down
6 changes: 5 additions & 1 deletion hi_tools/hi_markdown/MarkdownDefaultProviders.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,11 @@ struct MarkdownCodeComponentBase : public Component,

Factory f;

virtual ~MarkdownCodeComponentBase() {};
virtual ~MarkdownCodeComponentBase()
{
MessageManagerLock mm;
editor = nullptr;
};

virtual void addImageLinks(Array<MarkdownLink>& sa)
{
Expand Down
36 changes: 22 additions & 14 deletions hi_tools/hi_markdown/MarkdownElements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1453,12 +1453,9 @@ struct MarkdownParser::ContentFooter : public MarkdownParser::Element

ContentFooter::ContentLinks links = ContentFooter::createContentLinks(parent);

auto forumLink = links.forumLink;
auto githubLink = links.thisLink.getEditLinkOnGitHub(true);

if (forumLink.isInvalid())
forumLink = { {}, "https://forum.hise.audio" };

auto fl = g.surroundWithTag("Join Discussion", "a", "href=\"" + forumLink.toString(MarkdownLink::FormattedLinkHtml) + "\"");
auto fl = g.surroundWithTag("Edit on GitHub", "a", "href=\"" + githubLink + "\"");

auto nextString = "Next: " + g.surroundWithTag(links.nextName, "a", "href=\"" + links.nextLink.toString(MarkdownLink::FormattedLinkHtml) + "\"");

Expand Down Expand Up @@ -1527,6 +1524,7 @@ struct MarkdownParser::ContentFooter : public MarkdownParser::Element

LOAD_EPATH_IF_URL("next", MainToolbarIcons::forward);
LOAD_EPATH_IF_URL("discussion", MainToolbarIcons::comment);
LOAD_EPATH_IF_URL("edit", EditorIcons::penShape);

return p;
}
Expand All @@ -1541,28 +1539,28 @@ struct MarkdownParser::ContentFooter : public MarkdownParser::Element
if(isButtonDown)
g.fillAll(Colours::grey.withAlpha(0.1f));

bool isNextLink = button.getButtonText() != "Discussion";
bool isNextLink = button.getButtonText() != "Edit on GitHub";
auto bounds = button.getLocalBounds();
auto pathBounds = isNextLink ? bounds.removeFromRight(h) : bounds.removeFromLeft(h);
auto pb = pathBounds.reduced(pathBounds.getHeight() / 8, pathBounds.getHeight() / 8).toFloat();
auto p = f.createPath(button.getButtonText());
auto p = f.createPath(isNextLink ? button.getButtonText() : "edit");
p.scaleToFit(pb.getX(), pb.getY(), pb.getWidth(), pb.getHeight(), true);
g.setColour(textColour.withAlpha(button.isEnabled() ? 1.0f : 0.1f));
g.fillPath(p);
}

void drawButtonText(Graphics& g, TextButton& button, bool /*isMouseOverButton*/, bool /*isButtonDown*/)
{
bool isNextLink = button.getButtonText() != "Discussion";
bool isNextLink = button.getButtonText() != "Edit on GitHub";


auto bounds = button.getLocalBounds();

isNextLink ? bounds.removeFromRight(h) : bounds.removeFromLeft(h);

g.setFont(font);
g.setColour(textColour.withAlpha(button.isEnabled() ? 1.0f : 0.1f));

String text = "Next: " + nextLink;
String text = isNextLink ? "Next: " + nextLink : button.getButtonText();
g.drawText(text, bounds.toFloat().reduced(5.0f), isNextLink ? Justification::centredRight : Justification::centredLeft);
}

Expand All @@ -1576,26 +1574,34 @@ struct MarkdownParser::ContentFooter : public MarkdownParser::Element
Content(ContentFooter& parent_, const MarkdownLink& currentPage_, const MarkdownLink& nextLink_, const String& nextName_):
parent(parent_),
nextButton("Next"),
editButton("Edit on GitHub"),
nextLink(nextLink_),
currentPage(currentPage_),
nextName(nextName_)
{
addAndMakeVisible(nextButton);

nextButton.addListener(this);

nextButton.setEnabled(nextLink.isValid());

addAndMakeVisible(editButton);
editButton.addListener(this);

blaf.textColour = parent.getTextColour();
blaf.nextLink = nextName;
blaf.font = parent.getFont();

nextButton.setLookAndFeel(&blaf);

editButton.setLookAndFeel(&blaf);
}

void buttonClicked(Button* b) override
{
if (b == &editButton)
{
auto link = currentPage.getEditLinkOnGitHub(true);
URL u(link);
u.launchInDefaultBrowser();
}
if (b == &nextButton)
{
WeakReference<MarkdownParser> p = parent.getParser();
Expand Down Expand Up @@ -1646,13 +1652,15 @@ struct MarkdownParser::ContentFooter : public MarkdownParser::Element
auto top = bounds.removeFromTop(getButtonHeight());

int nextWidth = blaf.font.getStringWidth(nextName) + getButtonHeight() * 3;
auto editWidth = blaf.font.getStringWidth(editButton.getButtonText()) + getButtonHeight() * 3;

nextButton.setBounds(top.removeFromRight(nextWidth));
editButton.setBounds(top.removeFromLeft(editWidth));
}

ButtonLookAndFeel blaf;

TextButton nextButton;
TextButton nextButton, editButton;

MarkdownLink forumLink;
String nextName;
Expand Down
17 changes: 17 additions & 0 deletions hi_tools/hi_markdown/MarkdownLink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,23 @@ bool MarkdownLink::fileExists(const File& rootDirectory) const noexcept
return getMarkdownFile(rootDirectory).existsAsFile();
}

String MarkdownLink::getEditLinkOnGitHub(bool rawLink) const
{
String s;

auto editLink = getHtmlStringForBaseURL("https://github.com/christophhart/hise_documentation/edit/master/");

editLink = editLink.replace("index.html", "Readme.md");
editLink = editLink.replace(".html", ".md");

if(rawLink)
return editLink;

s << " [Edit on GitHub](" << editLink << ")";

return s;
}

String MarkdownLink::getHtmlStringForBaseURL(const String& baseURL) const
{
String u;
Expand Down
2 changes: 2 additions & 0 deletions hi_tools/hi_markdown/MarkdownLink.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ class MarkdownLink

String getHtmlStringForBaseURL(const String& baseURL) const;

String getEditLinkOnGitHub(bool rawLink) const;

private:

String createHtmlLink() const noexcept;
Expand Down
10 changes: 9 additions & 1 deletion hi_tools/hi_tools/ValueTreeHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ class Base: public ValueTree::Listener,
Base()
{};

virtual ~Base() {};
virtual ~Base()
{
cancelPendingUpdate();
};

void setHighPriorityListener(Base* listenerToPriorise)
{
Expand Down Expand Up @@ -132,6 +135,11 @@ struct AnyListener : private Base,

AnyListener(AsyncMode mode_ = AsyncMode::Asynchronously);

~AnyListener()
{
stopTimer();
}

void setMillisecondsBetweenUpdate(int milliSeconds);

void setEnableLogging(bool shouldLog);
Expand Down

0 comments on commit e8688bb

Please sign in to comment.