This is a continuation of a discussion that began on Bugzilla Bug 1324310.
The backstory of this proposal. One day in December, I got Wiki account set up with page creation. I was editing some pages, and looking at some old API things and saw a big red error banner warning about a KumaScript macro, and a lot of funny looking {{ AMInterface }} showing up on live page. The macro was removed at some point, though a dozen or so pages (with deprecated APIs to be obsoleted by end of 2017) were using it. During the process of bug reporting, I learned more about the KumaScript project, and discovered many macros doing nearly the same thing.
These macros invariably are following a pattern such as this:
-
Unique Macro Name
- AMInterface
- jsxref
- Interface
- manch
-
Same base URI (usually just language at root level)
-
Unique paths to base of API docs
Although APIs are a specific use case, the technique may be used on other reference documentation with different styling and/or structure.
-
Essentially the same structure of URI generated from 1 or 2 parameters.
-
First parameter is the API Object e.g.
<code><a href="/en-US/Path/to/SomeAPI/APIObject" title="APIObject">APIObject</a></code>
-
Second, Optional parameter is a method on an API Object
<code><a href="/en-US/Path/to/SomeAPI/APIObject#method()" title="APIObject.method()">method()</a></code>
-
Some often shared, sometimes unique stylings
- This structure of paths, anchored links, titles, link text, and surrounding tags (such as
<code>
, above), may vary by document type in which it is used. I generally refer to that as "styling".
- Also note, that these rules could be refined to allow for variation based on usage context. I.e. always wrapping
<code>
around a link may be unnecessary if the link is already in a <code>
block. <code>abcd<code><a href>link</a></code>efgh</code>
might be inefficient or problematic. A way to toggle specific styling options might be considered for a feature.
What the proposal intends to do, is explore the possibility of combining these similar macros into a single, generic, macro that can handle a wider rage of situations. Of specific concern is to create a macro that contains a lot of power, is easy to use, easy to extend, yet is efficient, so as not to bog down server. We also need a suitably generic yet concise and accurate name for the macro.
Looking at the pattern above, we can separate unique items from common items.
- A unique macro name corresponds to a unique base path fragment, usually one to one.
- A unique macro name often corresponds to the same structure and style, but in some cases differs.
- The macros typically take 2 options, 1st required object name, 2nd optional method name, or in the case of non-API docs, 1st is a document page and 2nd is a heading to scroll down to.
What this tells us is that we are storing data in the macro name itself, thus the code duplication.
A proposed remedy is to move that macro name to the 1st parameter, which we then use to do a hash table lookup to get the path. Perhaps we store references to styling functions in hash as well, and refer to the same styling multiple times, and as needed, create new functions. Or else we use the "name" parameter inside a switch to achieve the same affect, and collapse multiple names to the same styling by stacking up cases. These are implementation details, and should be driven by not just by ease of initial implementation, but ultimately by code performance, readability, maintainability, etc.
A side note on ordered function parameters. I'm not yet familiar with the capabilities of Kuma/KumaScript, but I dislike ordered parameters because of the complexity of handling multiple optional parameters. Passing a hash table (Object) as a parameter would be nice.
(In reply to Leif-AMO from comment #14)
Regarding a generic "ToolkitInterface" macro
/*
The backstory (in case you're wondering "why is it like this?"): until a couple of months ago, all KumaScript macros were stored somewhere in Kuma's database and were edited as Wiki pages, that just lived in a completely flat hierarchy, like this: https://developer.mozilla.org/en-US/docs/Template:WebExtBrowserCompat, https://developer.mozilla.org/en-US/docs/Template:jsxref, etc. Editing them meant editing the macro's page, and saving it published it live into production. We didn't have any defined review process or any tests, and since it was hard to reason about the macros we had, there was a lot of code duplication.
In November we moved them into the GitHub repo, and this opens up possibilities about managing them better, including dealing with the code duplication issue. We're excited about getting into this work. But it's still a big task with a lot of legacy use.
*/
Intuitively assumed this was more or less the case. It's source code, better managed in a source code version control system. I only wish the Wiki pages themselves could have gone in somehow. I'd be able to clone the site, use search and replace, and perhaps even (with some help) come up with a way to test the correctness of generated URIs. What takes hours, days, weeks or months for one person to do (in spare time), could be reduced to a single afternoon. Maybe in a future evolution of the site, and assuredly in a separate proposal. For now, we'll work on this area of KumaScripts.
One thing to say about the proposal is that there are a lot of technology areas on MDN. They broadly fall into one of two categories:
I remember when the entirety of documentation I needed was access via a <200kb file named jsref.zip. :-)
The MDN team is much more focused on the open web docs than on the Mozilla internal docs.
Understood an appropriate. My interest here is to learn more about the system than the content and explore ideas to test on old docs on their way out (or at least to archival status), in hopes of applying those ideas to newer areas, if appropriate.
So one question is, is the proposal intended to cover xref macros used in the open web docs (I think it should!). If so, then "ToolkitReference" is probably not a good name. Kris's comment 11 is I think only about Mozilla's internal APIs. But in the context of the open web docs, then "Toolkit" doesn't really mean anything.
A name is the easiest thing to change at this stage. For lack of any better idea (or environmental awareness) at the moment, I used the same name, to have a handle with which to demonstrate concepts. Not attached to the name. A shorter, more general name would be great. Consider determining a suitable name as part of proposal requirement before widespread implementation. ;-)
I guess the general approach here could be:
- write a new xref macro that can replace all the existing ones
- update the old xref macros to call the new one
- update the actual pages to call the new macro
- delete the old xref macros
(3) in particular seems like a huge task, but one nice thing is that you'd get a lot of benefits by just doing (1) and (2), and you could do (3) gradually.
Regarding steps above:
0) "xref" seems like a good short name, "cross-reference", which is essentially what this macro lives to do.
- Implement idea, the benefit is to have some working code instead of nifty ideas floating around.
- Gets us some centralized code, and sanity.
- 95% of the innovation is done, 95% of the grunt work begins. But which pages?
- This is where I really wish there was an easy way to lookup "Which Wiki Pages (including all translations) use the macros: [ list, of, foo, macros, here ], and how many instances each per page?" This would be the basis for making a case to have the Wiki docs in a source control, or perhaps sufficient quality of info could be achieved in another macro to crawl site or analyze database or something. Not familiar with the rest of Kuma.
I think the best place to discuss this proposal, though, is not this bug, but as a separate issue in the kumascript repo: https://github.com/mozilla/kumascript/issues. Would you mind filing an issue there, with your proposal?
And here we are.