From e56e62b255e97cd7e5fb914c4e40c27b294e57d6 Mon Sep 17 00:00:00 2001 From: Sander Spies Date: Mon, 30 Sep 2019 19:23:30 +0200 Subject: [PATCH] Changes for tutorials. --- .../docs/language-basics/entrypoints.md | 4 +-- .../docs/language-basics/functions.md | 4 +-- gitlab-pages/docs/language-basics/types.md | 2 +- .../get-started/tezos-taco-shop-payout.md | 19 ++++++------ .../tezos-taco-shop-smart-contract.md | 20 ++++++------- gitlab-pages/website/pages/en/index.js | 29 ------------------- gitlab-pages/website/siteConfig.js | 29 ++++++++++++++++++- gitlab-pages/website/static/css/custom.css | 4 +++ 8 files changed, 57 insertions(+), 54 deletions(-) diff --git a/gitlab-pages/docs/language-basics/entrypoints.md b/gitlab-pages/docs/language-basics/entrypoints.md index e666f8c10..30ba46b65 100644 --- a/gitlab-pages/docs/language-basics/entrypoints.md +++ b/gitlab-pages/docs/language-basics/entrypoints.md @@ -13,7 +13,7 @@ Contract below is effectively an empty contract, that takes a `unit` as a parame -```Pascal +```pascaligo function main (const p : unit ; const s : unit) : (list(operation) * unit) is block {skip} with ((nil : list(operation)), s) ``` @@ -27,7 +27,7 @@ In the example below we have a simple counter contract, that can be either `Incr -```Pascal +```pascaligo // variant defining pseudo multi-entrypoint actions type action is | Increment of int diff --git a/gitlab-pages/docs/language-basics/functions.md b/gitlab-pages/docs/language-basics/functions.md index fc6895383..15574aea0 100644 --- a/gitlab-pages/docs/language-basics/functions.md +++ b/gitlab-pages/docs/language-basics/functions.md @@ -9,7 +9,7 @@ Body of a function consists of two parts, the first part (**`block {}`** or **`b -```Pascal +```pascaligo const availableSupply: nat = 15n; const totalSupply: nat = 100n; @@ -30,7 +30,7 @@ A short hand syntax for the same function as above can inline the price calculat While this approach can have it's benefits, it can decrease readability. -```Pascal +```pascaligo const availableSupply: nat = 15n; const totalSupply: nat = 100n; diff --git a/gitlab-pages/docs/language-basics/types.md b/gitlab-pages/docs/language-basics/types.md index 1de9076ab..5dc56aaec 100644 --- a/gitlab-pages/docs/language-basics/types.md +++ b/gitlab-pages/docs/language-basics/types.md @@ -13,7 +13,7 @@ Type aliasing is a great choice when working towards a readable / maintainable s -```Pascal +```pascaligo type animalBreed is string; const dogBreed: animalBreed = "Saluki"; diff --git a/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-payout.md b/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-payout.md index f22f59452..f0d70fe4a 100644 --- a/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-payout.md +++ b/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-payout.md @@ -17,14 +17,15 @@ In the [previous tutorial](tutorials/get-started/tezos-taco-shop-smart-contract. ## Analyzing the current contract ### **`taco-shop.ligo`** -``` +```pascaligo type taco_supply is record current_stock : nat; max_price : tez; end type taco_shop_storage is map(nat, taco_supply); -function buy_taco (const taco_kind_index: nat ; var taco_shop_storage : taco_shop_storage) : (list(operation) * taco_shop_storage) is +function buy_taco (const taco_kind_index: nat ; var taco_shop_storage : taco_shop_storage) : + (list(operation) * taco_shop_storage) is begin // Retrieve the taco_kind from the contract's storage const taco_kind : taco_supply = get_force(taco_kind_index, taco_shop_storage); @@ -46,7 +47,7 @@ function buy_taco (const taco_kind_index: nat ; var taco_shop_storage : taco_sho ### Purchase price formula Pedro's Taco Shop contract currently enables customers to buy tacos, at a computed price based on a simple formula. -``` +```pascaligo const current_purchase_price : tez = taco_kind.max_price / taco_kind.current_stock; ``` @@ -66,7 +67,7 @@ This means that after all the *purchase conditions* of our contract are met - e. ### Defining the recipient In order to send tokens, we will need a receiver address - which in our case will be Pedro's personal account. Additionally we'll wrap the given address as a *`contract(unit)`* - which represents either a contract with no parameters, or an implicit account. -``` +```pascaligo const ownerAddress : address = "tz1TGu6TN5GSez2ndXXeDX6LgUDvLzPLqgYV"; const receiver : contract(unit) = get_contract(ownerAddress); ``` @@ -77,7 +78,7 @@ const receiver : contract(unit) = get_contract(ownerAddress); Now we can transfer the `amount` received by `buy_taco` to Pedro's `ownerAddress`. We will do so by forging a `transaction(unit, amount, receiver)` within a list of operations returned at the end of our contract. -``` +```pascaligo const payoutOperation : operation = transaction(unit, amount, receiver) ; const operations : list(operation) = list payoutOperation @@ -89,7 +90,7 @@ end; ## Finalizing the contract ### **`taco-shop.ligo`** -``` +```pascaligo type taco_supply is record current_stock : nat; max_price : tez; @@ -129,7 +130,7 @@ function buy_taco (const taco_kind_index: nat ; var taco_shop_storage : taco_sho To confirm that our contract is valid, we can dry run it. As a result we see a *new operation* in the list of returned operations to be executed subsequently. -``` +```pascaligo ligo dry-run taco-shop.ligo --syntax pascaligo --amount 1 buy_taco 1n "map 1n -> record current_stock = 50n; @@ -157,12 +158,12 @@ end" Because Pedro is a member of the (STA) Specialty Taco Association, he has decided to donate **10%** of the earnings to the STA. We'll just add a `donationAddress` to the contract, and compute a 10% donation sum from each taco purchase. -``` +```pascaligo const ownerAddress: address = "tz1TGu6TN5GSez2ndXXeDX6LgUDvLzPLqgYV"; const donationAddress: address = "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"; ``` -``` +```pascaligo const receiver : contract(unit) = get_contract(ownerAddress); const donationReceiver : contract(unit) = get_contract(donationAddress); diff --git a/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-smart-contract.md b/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-smart-contract.md index 079dbb239..8dadb49cd 100644 --- a/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-smart-contract.md +++ b/gitlab-pages/docs/tutorials/get-started/tezos-taco-shop-smart-contract.md @@ -35,7 +35,7 @@ Each taco kind, has its own `max_price` that it sells for, and a finite supply f Current purchase price is calculated with the following equation: -``` +```pascaligo current_purchase_price = max_price / available_stock ``` @@ -71,8 +71,8 @@ The best way to install the dockerized LIGO is as a **global executable** throug To begin implementing our smart contract, we need an entry point. We'll call it `main` and it'll specify our contract's storage (`int`) and input parameter (`int`). Of course this is not the final storage/parameter of our contract, but it's something to get us started and test our LIGO installation as well. ### `taco-shop.ligo` -```Pascal -function main (const parameter : int; const contractStorage : int) : (list(operation) * int) is +```pascaligo +function main (const parameter: int; const contractStorage: int) : (list(operation) * int) is block {skip} with ((nil : list(operation)), contractStorage + parameter) ``` @@ -129,7 +129,7 @@ ligo dry-run taco-shop.ligo --syntax pascaligo main 4 3 We know that Pedro's Taco Shop serves two kinds of tacos, so we'll need to manage stock individually, per kind. Let's define a type, that will keep the `stock` & `max_price` per kind - in a record with two fields. Additionally, we'll want to combine our `taco_supply` type into a map, consisting of the entire offer of Pedro's shop. **Taco shop's storage** -```Pascal +```pascaligo type taco_supply is record current_stock : nat; max_price : tez; @@ -141,7 +141,7 @@ type taco_shop_storage is map(nat, taco_supply); Next step is to update the `main` entry point to include `taco_shop_storage` as its storage - while doing that let's set the `parameter` to `unit` as well to clear things up. **`taco-shop.ligo`** -```Pascal +```pascaligo type taco_supply is record current_stock : nat; max_price : tez; @@ -208,7 +208,7 @@ Let's start by customizing our contract a bit, we will: - change `taco_shop_storage` to a `var` instead of a `const`, because we'll want to modify it **`taco-shop.ligo`** -```Pascal +```pascaligo type taco_supply is record current_stock : nat; max_price : tez; @@ -231,7 +231,7 @@ In order to decrease the stock in our contract's storage for a specific taco kin **`taco-shop.ligo`** -```Pascal +```pascaligo type taco_supply is record current_stock : nat; max_price : tez; @@ -266,7 +266,7 @@ To make sure we get paid, we will: - if yes, stock for the given `taco_kind` will be decreased and the payment accepted **`taco-shop.ligo`** -```Pascal +```pascaligo type taco_supply is record current_stock : nat; max_price : tez; @@ -327,11 +327,11 @@ end" If you'd like to accept tips in your contract as well, simply change the following line, depending on which behavior do you prefer. **Without tips** -```Pascal +```pascaligo if amount =/= current_purchase_price then ``` **With tips** -```Pascal +```pascaligo if amount >= current_purchase_price then ``` diff --git a/gitlab-pages/website/pages/en/index.js b/gitlab-pages/website/pages/en/index.js index 5a8ba07dc..95f57ca35 100644 --- a/gitlab-pages/website/pages/en/index.js +++ b/gitlab-pages/website/pages/en/index.js @@ -15,35 +15,6 @@ const MarkdownBlock = CompLibrary.MarkdownBlock; /* Used to read markdown */ const Container = CompLibrary.Container; const GridBlock = CompLibrary.GridBlock; -function pascaligo(hljs) { - return { - // case_insensitive: true, - beginKeywords: '', - keywords: { - keyword: 'and begin block case const contains down else end fail for ' + - 'from function if in is list map mod nil not of or patch ' + - 'procedure record remove set skip step then to type var while with', - literal: 'true false unit int string some none bool nat list' - }, - lexemes: '[a-zA-Z][a-zA-Z0-9_]*', - contains: [ - hljs.C_LINE_COMMENT_MODE, - - { - className: 'type', - begin: /[A-Z][a-z]+/ - }, - { - begin: /[*+-:;\(\)\{\}|\>\<]/, - // className: 'ignore' - } - ] - } -} - -hljs.registerLanguage('pascaligo', pascaligo); - - const pre = "```"; const pascaligoExampleSmall = `${pre}pascaligo diff --git a/gitlab-pages/website/siteConfig.js b/gitlab-pages/website/siteConfig.js index 5829acdff..80da6af85 100644 --- a/gitlab-pages/website/siteConfig.js +++ b/gitlab-pages/website/siteConfig.js @@ -144,7 +144,34 @@ const siteConfig = { highlight: { // Highlight.js theme to use for syntax highlighting in code blocks. - theme: "default" + theme: "default", + hljs: function (hljs) { + hljs.registerLanguage('pascaligo', function (hljs) { + return { + // case_insensitive: true, + beginKeywords: '', + keywords: { + keyword: 'and begin block case const contains down else end fail for ' + + 'from function if in is list map mod nil not of or patch ' + + 'procedure record remove set skip step then to type var while with', + literal: 'true false unit int string some none bool nat list' + }, + lexemes: '[a-zA-Z][a-zA-Z0-9_]*', + contains: [ + hljs.C_LINE_COMMENT_MODE, + + { + className: 'type', + begin: /[A-Z][a-z]+/ + }, + { + begin: /[*+-:;\(\)\{\}|\>\<]/, + // className: 'ignore' + } + ] + } + }); + } }, // Add custom scripts here that would be placed in