Skip to content

Commit

Permalink
Merge pull request #8 from Cirru/more-errors
Browse files Browse the repository at this point in the history
exposing more errors
  • Loading branch information
soyaine authored Aug 19, 2020
2 parents dac4a89 + 7da82b4 commit b540be6
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 9 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/npm-publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: npm publish

on:
release:
types: [created]

jobs:
publish-npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
registry-url: https://registry.npmjs.org/

- run: yarn && yarn compile

- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
45 changes: 45 additions & 0 deletions .github/workflows/upload.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Upload Assets

on:
pull_request: {}
push:
branches:
- master

jobs:
upload-assets:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Use Node.js
uses: actions/setup-node@v1

- name: Get yarn cache
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v1
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- run: yarn && yarn release
name: Build web assets

- name: Deploy to server
id: deploy
uses: Pendect/[email protected]
env:
DEPLOY_KEY: ${{secrets.rsync_private_key}}
with:
flags: "-avzr --progress"
options: ""
ssh_options: ""
src: "dist/*"
dest: "[email protected]:/web-assets/repo/${{ github.repository }}"

- name: Display status from deploy
run: echo "${{ steps.deploy.outputs.status }}"
1 change: 1 addition & 0 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ body {
margin: 0px 6px;
border-radius: 3px;
font-family: Source Code Pro, Menlo, Consolas, monospace;
white-space: pre;
}

.test .button {
Expand Down
2 changes: 1 addition & 1 deletion example/cirru/if.cirru
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

@if (@ switcher)
div $ = right
div $ = wrong
div $ = wrong
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cirru-html",
"version": "0.2.2",
"version": "0.2.3-a1",
"description": "Template engine that converts Cirru to HTML",
"main": "js/index.js",
"scripts": {
Expand All @@ -20,7 +20,7 @@
"author": "jiyinyiyong",
"license": "MIT",
"dependencies": {
"cirru-parser": "^0.10.7"
"cirru-parser": "^0.10.8-a1"
},
"repository": {
"type": "git",
Expand Down
1 change: 1 addition & 0 deletions src/abstract.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ exports.makeAbstract = (syntaxTree) ->
args = syntaxTree[1..]

unless func? and func.length > 0 and typeof func is 'string'
console.error("evaluation tree:", JSON.stringify(syntaxTree))
throw new Error "(#{stringify func}) is not valid as func"

if func[0] is '@'
Expand Down
4 changes: 4 additions & 0 deletions src/expression/methods.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

exports.Expression = class
constructor: (tree) ->
@tree = tree
@func = tree[0][1..]
@args = tree[1..]

Expand All @@ -9,4 +10,7 @@ exports.Expression = class

render: (data) ->
list = @args.map (item) -> data[item]
if not data[@func]?
console.error "Evaludatiing tree", JSON.stringify(@tree)
throw new Error('Unknown method')
data[@func] list...
7 changes: 5 additions & 2 deletions src/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ document.body.onclick = (event) ->
parent = event.target.parentElement
file = parent.querySelector('.file').value
data = parent.querySelector('.data').value
html = render file, (eval "(#{data})")
parent.querySelector('.result').value = html
try
html = render file, (eval "(#{data})")
parent.querySelector('.result').value = html
catch err
parent.querySelector('.result').value = err.stack

buttons = document.querySelectorAll('.button')
for button in buttons
Expand Down
3 changes: 3 additions & 0 deletions src/tag/common.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ exports.Tag = class CommonTag
continue

func = item[0]
if not func?
console.error 'args:', @args, 'func:', @func
throw new Error("Empty in args")
matchAttr = func.match /^:([\w-]+)/
if matchAttr?
prop = item[1..]
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b540be6

Please sign in to comment.