Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move MDN feature table rendering to BCD project #1392

Closed
jwhitlock opened this issue Mar 16, 2018 · 4 comments
Closed

Move MDN feature table rendering to BCD project #1392

jwhitlock opened this issue Mar 16, 2018 · 4 comments
Labels
HackOnMDNParis2018 🇫🇷 Issues or pull requests at the Hack on MDN event in Paris in March 2018

Comments

@jwhitlock
Copy link
Contributor

I believe future contributors will be thinking "This part of the compatibility table on MDN is wrong, I want to fix it". It will be useful for these contributors as well as the reviewers to be able to see what the MDN table will looks like after a pull request is merged. This means that BCD contributors will want to be able to generate MDN tables.

Currently, MDN feature tables are rendered in the KumaScript macro Compat, such as {{compat("webextensions.api.alarms")}}. The core of this logic can be moved to this repository, so that BCD authors can generate MDN tables. The {{Compat}} macro can then focus on adding additional data, such as localizations, legacy tables, and links back to the BCD project.

@jwhitlock
Copy link
Contributor Author

Draft API:

const bcd = require('mdn-browser-compat-data');

/* Generate default HTML for development */
let html = bcd.render(
    bcd.webextensions.api.alarms,
    bcd.renderers.mdnFeatureTable);

/* Alter behaviour by passing in configuration object */
let fancyHtml = bcd.render(
    bcd.webextensions.api.alarms,
    bcd.renderers.mdnFeatureTable,
    {'style': 'fancy'}   /* TODO: write fancy version */
);

/* Equivalent calls */
/* Call renderer directly */
let html = bcd.renderers.mdnFeatureTable(bcd.webextensions.api.alarms);
/* Call with strings */
let html = bcd.render(
   'webextensions.api.alarms',  /* Data is assumed to be BCD path */
   'mdnFeatureTable');  /* Renderer is assumed to be in bcd.renderers */

/* Generate HTML for display on MDN */
const l10nStrings = {
    'no-data-found': {
        'en-US': 'No compatibility data found.',
        'es': 'No se han encontrado datos de compatibilidad.'
    } /*, more localized strings */
};
let mdnHTML = bcd.render(
    bcd.webextensions.api.alarms,
    bcd.renderers.mdnFeatureTable,
    {'locale': 'es',
     'strings': l10nStrings,
     'inBeta': true
    }
);

/* Generate aggregate tables */
mdnData = require('mdn-data');
let aggregateHTML = bcd.render(
    bcd.css,
    bcd.renderers.mdnAggregateTable,
    {
        'properties': mdnData.css.properties,
        'group': 'CSS Grid Layout'
    });

@Elchi3 Elchi3 added the HackOnMDNParis2018 🇫🇷 Issues or pull requests at the Hack on MDN event in Paris in March 2018 label Mar 16, 2018
@MatonAnthony
Copy link
Contributor

So we thought a bit more about this:

What do we want?

  • Generate the HTML of a Compatibility Table
  • Keep the BCD package code free
  • Render the Compatibility Table

How do we want it?

Currently we have two ways of rendering a Compatibility Table on two differents codebase.
- Kumascript {{CompatBeta}} macro does the rendering on Kumascript
- render.js does the rendering for testing BCD.

We have 0 lines of codes in the packaged version of BCD. (It is a pure dataset).

Our idea would be to generify the code that generates the HTML so it can be called easily.
For that we would like to introduce a new npm package let's call it bcd-renderer for now.

This module would expose

  • a function taking in parameters:
    • The BCD reference eg. css.property.background
    • An option object (optional)
      • depth: number (how deep we intend to go down the tree)
    • An anonymous custom renderer (optional)
  • a function taking in parameters:
    • A JSON object with the BCD data to render
    • An option object (optional)
    • An anonymous custom renderer (optional)

This new module would depend on browser-compat-data.
browser-compat-data would not depend on the renderer.

Expected Results

An independent renderer modules able to render the HTML table that would be used by Kumascript and by another tool that needs to render a Compatibility Tables such as a Github Bot that would comment on PR with the tables.

@jwhitlock
Copy link
Contributor Author

We've started a new repo, https://github.com/mdn/browser-compat-toolkit, for the source code tools we're maintaining related to this data. @flaki has been doing some interesting work with the rendering code that may be appropriate in that repo.

@Elchi3
Copy link
Member

Elchi3 commented Apr 18, 2018

Closing this as the current thoughts have quite evolved from the original issue title and I'm in favor of having this repo to be just about the data itself.

Thanks for starting the new repo, I hope it will be used by BCD and MDN at some point so that we have a canonical MDN renderer repo the community can easily contribute to.

@Elchi3 Elchi3 closed this as completed Apr 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
HackOnMDNParis2018 🇫🇷 Issues or pull requests at the Hack on MDN event in Paris in March 2018
Projects
None yet
Development

No branches or pull requests

4 participants
@jwhitlock @Elchi3 @MatonAnthony and others