| <!-- |
| Licensed to the Apache Software Foundation (ASF) under one |
| or more contributor license agreements. See the NOTICE file |
| distributed with this work for additional information |
| regarding copyright ownership. The ASF licenses this file |
| to you under the Apache License, Version 2.0 (the |
| "License"); you may not use this file except in compliance |
| with the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, |
| software distributed under the License is distributed on an |
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| KIND, either express or implied. See the License for the |
| specific language governing permissions and limitations |
| under the License. |
| --> |
| <!DOCTYPE html> |
| <html> |
| <head> |
| <title>Example</title> |
| </head> |
| <body> |
| <script> |
| function validationPromise(yaml) { |
| const promise = new Promise(function (resolve, reject) { |
| const worker = new Worker("../dist/yard-validator-worker.js"); |
| console.log("Starting web worker."); |
| worker.postMessage("ENABLE_LOGGING"); |
| worker.postMessage(yaml); |
| worker.onmessage = (e) => { |
| if (e.data.startsWith("Log")) { |
| console.log(e.data); |
| } else { |
| resolve(e.data); |
| worker.terminate(); |
| } |
| }; |
| }); |
| return promise; |
| } |
| |
| function validate() { |
| let message = document.getElementById("text-area").value; |
| validationPromise(message).then( |
| function (result) { |
| document.getElementById("result-area").value = "Done\n" + result; |
| }, |
| function (error) {} |
| ); |
| } |
| </script> |
| <textarea id="text-area" style="height: 800px; width: 600px"> |
| |
| specVersion: alpha |
| kind: YaRD |
| name: "Traffic Violation" |
| expressionLang: alpha |
| inputs: |
| - name: "Driver" |
| type: "http://myapi.org/jsonSchema.json#Driver" |
| - name: "Violation" |
| type: "http://myapi.org/jsonSchema.json#Violation" |
| elements: |
| - name: "Fine" |
| type: Decision |
| requirements: ["Violation"] |
| logic: |
| type: DecisionTable |
| inputs: ["Violation.type", "Violation.Actual Speed - Violation.Speed Limit"] |
| outputComponents: ["Amount", "Points"] |
| rules: |
| - ['="speed"', "[10..30)", 500, 3] |
| - ['="speed"', ">= 30", 1000, 7] |
| - ['="speed"', ">= 60", 1000, 7] |
| - ['="parking"', "-", 100, 1] |
| - ['="driving under the influence"', "-", 1000, 5] |
| - name: "Should the driver be suspended?" |
| type: Decision |
| requirements: ["Driver", "Fine"] |
| logic: |
| type: LiteralExpression |
| expression: 'if Driver.Points + Fine.Points >= 20 then "Yes" else "No"' |
| |
| </textarea> |
| <button onclick="validate()" style="vertical-align: top">Validate</button> |
| <textarea id="result-area" style="height: 800px; width: 600px" readonly></textarea> |
| </body> |
| </html> |