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

Already on GitHub? Sign in to your account

Dev Docs: Add Inline Template Plugin And Use It For RPC/REST #758

Merged
merged 2 commits into from Feb 23, 2015

Conversation

Projects
None yet
2 participants
Contributor

harding commented Feb 20, 2015

This pull adds a new plugin that allows converting inline YAML to output formatted by a standard Liquid template. This pull also reformats the RPC/REST API tables to YAML and then uses a template to create the exact same tables as before. This is verified: diffing the site built on master HEAD against the site built on this final commit shows zero changes.

(No preview provided for the above reason.)

This backend code should make it easier to implement alternative table layouts as discussed in pull #757.

The YAML input for a table looks like this, with n, t, p, and d standing for name, type, presence, and description in the output table.

{% itemplate ntpd1 %}
- n: "Keys Or Addresses"
  t: "array"
  p: "Required<br>(exactly 1)"
  d: "An array of strings with each string being a public key or address"

- n: "→<br>Key Or Address"
  t: "string"
  p: "Required<br>(1 or more)"
  d: "A public key against which signatures will be checked.  Alternatively, this may be a P2PKH address belonging to the wallet---the corresponding public key will be substituted.  There must be at least as many keys as specified by the Required parameter, and there may be more keys"
{% enditemplate %}

The first commit in this pull adds the plugin and the template, and also adds some necessary newlines to the vars.md file. The second commit just runs the sed script provided in its commit message.

harding added some commits Feb 20, 2015

Add New Inline-Template Plugin
Also add inline template for RPC and REST tables
Dev Docs: Use Sed To Convert Tables To YAML
Run sed -i -f <this_file.sed> _includes/ref/bitcoin-core/rpcs/rpcs/* _includes/ref/bitcoin-core/rest/requests/get_* _includes/helpers/vars.md

    ## On lines that start with a pipe:
    /^|/ {
        ## Delete all table header/table body divider lines
        /|----/d;

        ## Escape all double quotes
        s/"/\\"/g;

        ## Replace lines that look like NTPD headers with a itemplate start block
        s/^| Name *| Type.*/{% itemplate ntpd1 %}/;

        ## Delete extraneous whitespace
        s/ *|/|/g;

        ## Replace the first pipe with "- name:" plus a start quote
        s/^| */- n: "/;

        ## Replace the remaining pipes, starting each one with a newline and two spaces
        s/| */"\n  t: "/;
        s/| */"\n  p: "/;
        s/| */"\n  d: "/;

        ## Add a close quote and an empty line after the last list item
        ## built from a single table row, except for the header row. This
        ## improves readability/maintainability
        /[^}]$/s/$/"\n/;
    }

    ## Replace the old table class with the itemplate close tag
    s/{:.ntpd}/{% enditemplate %}/

@harding harding added the Dev Docs label Feb 20, 2015

Contributor

saivann commented Feb 20, 2015

@harding Untested LGTM, thanks! Did you test using plain HTML to see if it works fine with a colspan? I wonder if autocrossref links would still apply fine within tables?

Contributor

harding commented Feb 21, 2015

@saivann thanks! (Reply under the announcement below.)

In the absence of critical feedback, this will be merged in about 48 hours. (00:00 UTC Monday)

Did you test using plain HTML to see if it works fine with a colspan?

Here's what this quick commit renders as (note the autoxref links):

2015-02-20-185427_629x404_scrot

Note that I haven't added any CSS, so that's the default table style. (I just realized the Kramdown-created tables use thead and tbody, but my table doesn't, which is why it looks different from the other tables in the docs. I'll fix that and make other changes.)

I do have to say that editing a Liquid template is a heck of a lot easier than messing around with advanced CSS features, so I think this plugin really is the way to go. Thanks for pushing me to do better on #757!

Contributor

saivann commented Feb 22, 2015

@harding That all sounds excellent and clean to me!! Thanks for taking time to find the ideal solution - this can become quite hard over time.

I've also played with flexbox a little in the past and found it pretty great, the persisting lack of browser support has always been the main blocking issue. I am glad to see it's almost an issue of the past though.

@harding harding merged commit 2c44b59 into bitcoin-dot-org:master Feb 23, 2015

harding added a commit that referenced this pull request Feb 23, 2015

Merge pulls #711, #752, #758
* Pull #711: Add Basic "How To Run A Full Node" Page
* Pull #752: Revert "Drop good tor privacy score for mycelium"
* Pull #758: Dev Docs: Add Inline Template Plugin And Use It For RPC/REST
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment