-
Notifications
You must be signed in to change notification settings - Fork 7
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
Update Ricardian spec to version 0.2 #22
Changes from 4 commits
d294ba3
ad4a02e
e94f197
a1df6ec
9999a4c
02962b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
## EOSIO.CDT Ricardian Contract Specification ![EOSIO Alpha](https://img.shields.io/badge/EOSIO-Alpha-blue.svg) | ||
|
||
**Spec Version**: v0.1.1 | ||
**Spec Version**: v0.2.0 | ||
|
||
### General Information | ||
In conjunction with [Ricardian Template Toolkit](https://github.com/EOSIO/ricardian-template-toolkit/), this specification is a new addition to the [EOSIO.CDT](https://github.com/EOSIO/eosio.cdt) suite of tooling. | ||
|
@@ -83,9 +83,9 @@ For styling purposes, by default interpolated variables in the output will be wr | |
* Action values will be given the `action` class (e.g., `<div class="variable action">value</div>`) | ||
* Clause values will be given the `clauses` class (e.g., `<div class="variable clauses">value</div>`) | ||
|
||
In cases where this default variable wrapping can cause problems (e.g. a variable containing a URL that becomes the value of an HREF attribute) there are additional Handlebars handlers to override the default behavior. | ||
In cases where this default variable wrapping can cause problems (e.g. a variable containing a URL that becomes the value of an HREF attribute) there are additional Handlebars helpers to override the default behavior. | ||
|
||
* To prevent an individual variable from being wrapped, use the `nowrap` handler. | ||
* To prevent an individual variable from being wrapped, use the `nowrap` helper. | ||
|
||
For example, to create a link with unwrapped individual variables: | ||
|
||
|
@@ -97,6 +97,115 @@ In cases where this default variable wrapping can cause problems (e.g. a variabl | |
|
||
`{{#wrap}}[{{nowrap link.text}}]({{nowrap link.url}}){{/wrap}}` | ||
|
||
#### Handlebars helpers | ||
|
||
In addition to the standard helpers which are part of Handlebars, there are a number of additional helpers defined to assist with Ricardian contract specific issues. | ||
|
||
___Since v0.0___ | ||
* `wrap` - Takes no parameters. Block level helper to wrap the contents with `<div>` tags for highlighting. See [Variables](#Variables) section above for more details. | ||
|
||
* `nowrap` - Takes a variable. Indicates that the specified variable *should not* be wrapped with `<div>` tags. See [Variables](#Variables) section above for more details. | ||
|
||
* `symbol_to_symbol_code` - Given a variable containing a 'symbol' string, extract and return only the symbol code. | ||
|
||
Example: | ||
``` | ||
Given: | ||
symbol = '4,EOS' | ||
|
||
{{ symbol_to_symbol_code symbol }} --> 'EOS'. | ||
``` | ||
|
||
* `asset_to_symbol_code` - Given a variable containing an 'asset' string, extract and return only the symbol code. | ||
|
||
Example: | ||
``` | ||
Given: | ||
asset = '2.001 EOS' | ||
|
||
{{ asset_to_symbol_code asset }} --> 'EOS'. | ||
``` | ||
|
||
___Since v0.1___ | ||
* `account_in_permission_level` - Given a variable containing a permission level object, extract and return the account name. | ||
arhag marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Example: | ||
``` | ||
Given Permission level / authorization: | ||
auth = { | ||
"actor": "alicejones", | ||
"permission": "active" | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation could be improved here. |
||
|
||
In Ricardian contract: | ||
{{ account_in_permission_level auth }} --> 'alicejones' | ||
``` | ||
|
||
* `permission_in_permission_level` - Given a variable containing a permission level object, extract and return the permission name. | ||
|
||
Example: | ||
``` | ||
Given Permission level / authorization: | ||
auth = { | ||
actor: 'alicejones', | ||
permission: 'active' | ||
} | ||
|
||
In Ricardian contract: | ||
{{ permission_in_permission_level auth }} --> 'active' | ||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation could be improved here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because these two helpers are being documented for the first time and they're deprecated, can we just drop them? |
||
|
||
* `amount_from_asset` - Given a variable containing an asset, extract and return the amount. | ||
|
||
Example: | ||
``` | ||
Given: | ||
asset = '2.001 EOS' | ||
|
||
{{ amount_from_asset asset }} --> '2.001'. | ||
``` | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like you might be missing a closing ``` here for the example above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TIL that VSCode markdown preview masks when closing ``` are missing. |
||
* `symbol_name_from_asset` - Given a variable containing an asset, extract and return the symbol name. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is redundant with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either one. Personally I prefer this one - the name seems more descriptive, and it's nicely symmetric with the |
||
|
||
Example: | ||
``` | ||
Given: | ||
asset = '2.001 EOS' | ||
|
||
{{ symbol_name_from_asset asset }} --> 'EOS'. | ||
``` | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like the closing ``` is missing here as well |
||
___Since v0.2___ | ||
* `to_json` - Takes the given variable and renders it as a preformatted JSON string. Note that the resulting string is also surrounded by `<pre><code>` tags as well. This is intended as a debugging aid. | ||
|
||
Example: | ||
``` | ||
{{to_json nameObj}} | ||
|
||
<pre><code> | ||
{ | ||
"firstname": "John", | ||
"lastname": "Doe" | ||
} | ||
</pre></code> | ||
``` | ||
|
||
* `if_has_value` - A block level helper which checks the given variable and if it is defined __AND__ not null then renders the content. If the variable is `undefined` __OR__ null render nothing or the contents of the `{{ else }}` clause if specified. | ||
|
||
Example: | ||
``` | ||
{{#if_has_value myVar}} | ||
Render if myVar has a non-null value | ||
{{/if_has_value}} | ||
|
||
Or | ||
|
||
{{#if_has_value myVar}} | ||
Render if myVar has a non-null value | ||
{{ else }} | ||
Render if myVar is undefined or null | ||
{{/if_has_value}} | ||
``` | ||
#### HTML in variables | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's go ahead and uppercase "variables" too. |
||
|
||
By default, any `{{variables}}` that contain HTML will have that HTML escaped. This may not be the desired outcome, as the `ricardian_clauses` may have HTML that the author wants rendered rather than escaped. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're using Title Case throughout; let's uppercase "helpers".