rippleapi - update version and add a filter to mark the doc with currently-built version

This commit is contained in:
mDuo13
2016-03-31 14:41:25 -07:00
parent 2d563f53f3
commit 959f4e28d3
9 changed files with 73 additions and 12 deletions

View File

@@ -124,6 +124,7 @@
</aside>
<main class="main" role="main">
<div class="content">
<p style="margin-top: 1em; font-style: italic">Updated for <a href="https://github.com/ripple/ripple-lib/releases/0.16.10" title="view on GitHub">version 0.16.10</a></p>
<h1 id="introduction">Introduction</h1>
<p>RippleAPI is the official client library to the Ripple Consensus Ledger. Currently, RippleAPI is only available in JavaScript.
Using RippleAPI, you can:</p>
@@ -145,6 +146,14 @@ const api = new RippleAPI({
api.on('error', (errorCode, errorMessage) =&gt; {
console.log(errorCode + ': ' + errorMessage);
});
api.on('connected', () =&gt; {
console.log('connected');
});
api.on('disconnected', (code) =&gt; {
// code - [close code](https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent) sent by the server
// will be 1000 if this was normal closure
console.log('disconnected, code:', code);
});
api.connect().then(() =&gt; {
/* insert code here */
}).then(() =&gt; {
@@ -1351,7 +1360,7 @@ const api = new RippleAPI();
<tr>
<td>type</td>
<td><a href="#transaction-types">transactionType</a></td>
<td>The type of the tranasction.</td>
<td>The type of the transaction.</td>
</tr>
<tr>
<td>specification</td>
@@ -4254,7 +4263,7 @@ const trustline = {
}
]
};
return api.preparePayment(address, trustline).then(prepared =&gt;
return api.prepareTrustline(address, trustline).then(prepared =&gt;
{/* ... */});
</code></pre>
<pre><code class="json">{
@@ -4991,7 +5000,7 @@ return api.combine(signedTransactions);
<tr>
<td>resultCode</td>
<td>string</td>
<td>The result code returned by rippled. <a href="http://pages.lightthenight.org/gba/SanFran15/ripple">List of tranasction responses</a></td>
<td>The result code returned by rippled. <a href="https://ripple.com/build/transactions/#full-transaction-response-list">List of transaction responses</a></td>
</tr>
<tr>
<td>resultMessage</td>
@@ -5277,6 +5286,26 @@ return api.computeLedgerHash(ledger);
</code></pre>
<pre><code>tooBusy: The server is too busy to help you now.
</code></pre>
<h2 id="connected">connected</h2>
<p>This event is emitted after connection successfully opened.</p>
<h3 id="example-40">Example</h3>
<pre><code class="javascript">api.on('connected', () =&gt; {
console.log('Connection is open now.');
});
</code></pre>
<h2 id="disconnected">disconnected</h2>
<p>This event is emitted when connection is closed.</p>
<h3 id="return-value-32">Return Value</h3>
<p>The only parameter is a number containing the <a href="https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent">close code</a> send by the server.</p>
<h3 id="example-41">Example</h3>
<pre><code class="javascript">api.on('disconnected', (code) =&gt; {
if (code !== 1000) {
console.log('Connection is closed due to error.');
} else {
console.log('Connection is closed normally.');
}
});
</code></pre>
</div>
</main>
</div>

View File

@@ -97,10 +97,11 @@ pages:
category: References
html: reference-rippleapi.html
# Currently this is the only page that's fetched remotely.
md: https://raw.githubusercontent.com/ripple/ripple-lib/0.16.7/docs/index.md
md: https://raw.githubusercontent.com/ripple/ripple-lib/0.16.10/docs/index.md
ripple.com: https://ripple.com/build/rippleapi/
filters:
- remove_doctoc
- add_version
sidebar: true
targets:
- local

View File

@@ -155,7 +155,7 @@ def parse_markdown(page, target=None, pages=None):
for filter_name in page_filters:
if "filter_markdown" in dir(filters[filter_name]):
logging.info("... applying markdown filter %s" % filter_name)
md = filters[filter_name].filter_markdown(md)
md = filters[filter_name].filter_markdown(md, target=target, page=page)
# Actually parse the markdown
logger.info("... parsing markdown...")
@@ -166,7 +166,7 @@ def parse_markdown(page, target=None, pages=None):
for filter_name in page_filters:
if "filter_html" in dir(filters[filter_name]):
logging.info("... applying HTML filter %s" % filter_name)
html = filters[filter_name].filter_html(html)
html = filters[filter_name].filter_html(html, target=target, page=page)
# Some filters would rather operate on a soup than a string.
# May as well parse once and re-serialize once.
@@ -176,7 +176,7 @@ def parse_markdown(page, target=None, pages=None):
for filter_name in page_filters:
if "filter_soup" in dir(filters[filter_name]):
logging.info("... applying soup filter %s" % filter_name)
filters[filter_name].filter_soup(soup)
filters[filter_name].filter_soup(soup, target=target, page=page)
# ^ the soup filters apply to the same object, passed by reference
# Replace links for any non-default target

View File

@@ -0,0 +1,31 @@
################################################################################
## Add version to markdown filter ##
## Author: Rome Reginelli ##
## Copyright: Ripple Labs, Inc. 2016 ##
## ##
## Adds a message to the beginning of a file with a version number, based on ##
## the URL of the remotely-fetched markdown. ##
################################################################################
import re
import logging
def filter_markdown(md, target=None, page=None):
"""Finds the version number and adds it to the start of the page."""
version_regex = r"https://raw.githubusercontent.com/([A-Za-z0-9_.-]+)/([A-Za-z0-9_.-]+)/([A-Za-z0-9_-]+\.[A-Za-z0-9_.-]+)/.+\.md"
try:
version_match = re.match(version_regex, page["md"])
except (TypeError, KeyError):
logging.warning("couldn't get MD path from page %s" % page)
return md
try:
github_owner = version_match.group(1)
github_project = version_match.group(2)
vnum = version_match.group(3)
url = "https://github.com/%s/%s/releases/%s" % (github_owner, github_project, vnum)
md = ("<p style='margin-top: 1em; font-style: italic'>Updated for <a href='%s' title='view on GitHub'>version %s</a></p>"%(url, vnum))+md
except AttributeError:
logging.warning("version regex didn't match: %s" % version_match)
return md

View File

@@ -8,7 +8,7 @@
################################################################################
import re
def filter_soup(soup):
def filter_soup(soup, target=None, page=None):
"""make links ending in > render like buttons"""
buttonlinks = soup.find_all("a", string=re.compile(">$"))
for link in buttonlinks:

View File

@@ -9,7 +9,7 @@
## compatibility with those. ##
################################################################################
def filter_markdown(md):
def filter_markdown(md, target=None, page=None):
"""Python markdown requires markdown="1" on HTML block elements
that contain markdown. AND there's a bug where if you use
markdown.extensions.extra, it replaces code fences in HTML

View File

@@ -10,7 +10,7 @@
################################################################################
import re
def filter_html(html):
def filter_html(html, target=None, page=None):
"""Uncomment multicode tab divs"""
MC_START_REGEX = re.compile("<!-- *<div class=['\"]multicode['\"][^>]*> *-->")
MC_END_REGEX = re.compile("<!-- *</div> *-->")

View File

@@ -8,7 +8,7 @@
################################################################################
def filter_markdown(md):
def filter_markdown(md, target=None, page=None):
"""Strip out doctoc Table of Contents for RippleAPI"""
DOCTOC_START = "<!-- START doctoc generated TOC please keep comment here to allow auto update -->"
DOCTOC_END = "<!-- END doctoc generated TOC please keep comment here to allow auto update -->"

View File

@@ -9,7 +9,7 @@
################################################################################
import re
def filter_soup(soup):
def filter_soup(soup, target=None, page=None):
"""replace underscores with dashes in h1,h2,etc. for backwards compatibility"""
headers = soup.find_all(name=re.compile("h[0-9]"), id=True)
for h in headers: