Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' into greenkeeper/husky-4.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
nebrelbug committed Jan 29, 2020
2 parents ec6d9f4 + b1ed80b commit bfd89ac
Show file tree
Hide file tree
Showing 8 changed files with 209 additions and 84 deletions.
File renamed without changes.
File renamed without changes.
28 changes: 28 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
name: 🐛 Bug report
about: Create a report to help us improve

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Type in '...'
2. Call function '...'
3. Look at result in '...'

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.


**Package & Environment Details**
- Environment: ex. Node, Chrome, Firefox, etc. and what version
- Version: ex. 8.1.0

**Additional context**
Add any other context about the problem here.
17 changes: 17 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: 🚀 Feature request
about: Suggest an idea for this project

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
42 changes: 21 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<a href="https://squirrelly.js.org"><img src="https://cdn.jsdelivr.net/gh/squirrellyjs/squirrelly-logo@1.0/svg-minified/squirrelly-fit-acorn.svg" align="right" width="30%" alt="Squirrel"></a>
<a href="https://squirrelly.js.org"><img src="https://cdn.jsdelivr.net/gh/squirrellyjs/squirrelly-logo/svg-minified/squirrelly-fit-acorn.svg" align="right" width="30%" alt="Squirrel"></a>

# squirrelly

Expand Down Expand Up @@ -27,28 +27,28 @@ Simply put, Squirrelly is super lightweight, super fast, super powerful, and sup

### 🌟 Features

- &#128295; Custom helpers
- &#128295; Custom filters
- :package: 0 dependencies
- :hammer: Conditionals
- :zap: Exports ES Modules as well as UMD
- :hammer: Loops
- &#128295; Custom delimeters
- :pencil2: Easy template syntax
- &#128295; Precompilation
- :hammer: Partials
- &#128295; Inline JavaScript
- :hammer: Comments
- &#128295; Caching
- :rocket: SUPER fast (look at the performance benchmarks [here](https://github.com/nebrelbug/squirrelly-benchmarks))

## :scroll: Docs
- 🔧 Custom helpers
- 🔧 Custom filters
- 📦 0 dependencies
- 🔨 Conditionals
- ⚡️ Exports ES Modules as well as UMD
- 🔨 Loops
- 🔧 Custom delimeters
- 📝 Easy template syntax
- 🔧 Precompilation
- 🔨 Partials
- 🔧 Inline JavaScript
- 🔨 Comments
- 🔧 Caching
- 🚀 Fast

## 📜 Docs

We know nobody reads through the long and boring documentation in the ReadMe anyway, so head over to the documentation website:

:pencil: [https://squirrelly.js.org](https://squirrelly.js.org)
📝 [https://squirrelly.js.org](https://squirrelly.js.org)

## :notebook: Examples
## 📓 Examples

### Simple Template

Expand Down Expand Up @@ -79,7 +79,7 @@ The current index is {{index}}
{{/each}}
```

## :heavy_check_mark: Tests
## ✔️ Tests

Tests can be run with `npm test`. Multiple tests check that parsing, rendering, and compiling return expected results, formatting follows guidelines, and code coverage is at the expected level.

Expand All @@ -93,7 +93,7 @@ To be added

## Credits

Made with :heart: by [@nebrelbug](https://github.com/nebrelbug) and all these wonderful contributors ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
Made with by [@nebrelbug](https://github.com/nebrelbug) and all these wonderful contributors ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore -->
Expand Down
53 changes: 17 additions & 36 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,14 @@
"name": "squirrelly-next",
"version": "0.0.0",
"description": "Lightweight, fast, and powerful JS template engine. Supports helpers, filters, template inheritance",
"keywords": [
"squirrelly",
"helpers",
"template inheritance",
"handlebars",
"template engine"
],
"keywords": ["squirrelly", "helpers", "template inheritance", "handlebars", "template engine"],
"main": "dist/squirrelly.cjs.js",
"browser": "dist/browser/squirrelly.min.js",
"module": "dist/squirrelly.es.js",
"typings": "dist/squirrelly.d.ts",
"jsdelivr": "dist/browser/squirrelly.min.js",
"unpkg": "dist/browser/squirrelly.min.js",
"files": [
"dist"
],
"files": ["dist"],
"author": "Ben Gubler <nebrelbug@gmail.com>",
"repository": {
"type": "git",
Expand All @@ -42,15 +34,11 @@
"deploy-docs": "ts-node tools/gh-pages-publish",
"report-coverage": "cat ./coverage/lcov.info | coveralls",
"commit": "git-cz",
"precommit": "lint-staged",
"travis-deploy-once": "travis-deploy-once --pro",
"format": "prettier-standard --format '{src,test}/**/*.ts'"
},
"lint-staged": {
"{src,test}/**/*.ts": [
"prettier-standard --lint",
"git add"
]
"{src,test}/**/*.ts": ["prettier-standard --lint"]
},
"config": {
"commitizen": {
Expand All @@ -63,14 +51,8 @@
},
"testEnvironment": "node",
"testRegex": "(/test/.*|\\.(test|spec))\\.(ts|js)$",
"moduleFileExtensions": [
"ts",
"js"
],
"coveragePathIgnorePatterns": [
"/node_modules/",
"/test/"
],
"moduleFileExtensions": ["ts", "js"],
"coveragePathIgnorePatterns": ["/node_modules/", "/test/"],
"coverageThreshold": {
"global": {
"branches": 90,
Expand All @@ -79,38 +61,32 @@
"statements": 95
}
},
"collectCoverageFrom": [
"src/*.{js,ts}"
]
"collectCoverageFrom": ["src/*.{js,ts}"]
},
"standard": {
"ignore": [
"dist"
]
"ignore": ["dist"]
},
"prettier": {
"semi": false,
"singleQuote": true
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
"extends": ["@commitlint/config-conventional"]
},
"devDependencies": {
"@commitlint/cli": "^8.2.0",
"@commitlint/config-conventional": "^8.2.0",
"@types/jest": "^24.0.24",
"@types/node": "^12.12.21",
"@types/jest": "^25.1.0",
"@types/node": "^13.5.1",
"colors": "^1.3.2",
"commitizen": "^4.0.3",
"coveralls": "^3.0.2",
"cross-env": "^6.0.3",
"cross-env": "^7.0.0",
"cz-conventional-changelog": "^3.0.2",
"husky": "^4.2.1",
"jest": "^24.9.0",
"jest-config": "^24.9.0",
"lint-staged": "^9.5.0",
"lint-staged": "^10.0.3",
"prettier-standard": "^16.1.0",
"prompt": "^1.0.0",
"replace-in-file": "^5.0.2",
Expand All @@ -132,5 +108,10 @@
"tslint-config-standard": "^9.0.0",
"typedoc": "^0.16.7",
"typescript": "^3.0.3"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
}
}
77 changes: 72 additions & 5 deletions test/helpers.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Render, Filters } from '../src/index'
import { Render, Compile, Filters, Env, CompileToString } from '../src/index'

var eachTemplate = `
The Daugherty's have 8 kids. Their names are:
Expand Down Expand Up @@ -33,8 +33,7 @@ Key: {{key}}, Val: {{val}}

it('parses a simple helper: foreach', () => {
var res = Render(forEachTemplate, { numbers: { one: 1, two: 2 } })
console.log('RES ===========')
console.log('"' + res + '"')

expect(res).toEqual(`
Key: one, Val: 1
Expand All @@ -53,9 +52,7 @@ Uh-oh, error! Message was '{{err.message}}'
// the above is autoescaped because otherwise it automatically converts it to a string

Filters.define('validate', function (str: string) {
console.log('str is ' + str + 'and its type is ' + typeof str)
if (typeof str !== 'string') {
console.log('gonna error')
throw new Error('str does not fit expected format')
} else {
return str
Expand All @@ -71,4 +68,74 @@ Uh-oh, error! Message was 'str does not fit expected format'
`)
})

var ifTemplate = `{{ ~if (it.number === 3) -}}
Number is three
{{- #elif (it.number === 4) -}}
Number is four
{{- #else -}}
Number is five
{{- /if}}`

it('parses a simple helper: if with elif', () => {
var res = Render(ifTemplate, { number: 4 })

expect(res).toEqual('Number is four')
})

var ifTemplateFilter = `
{{~ if (it.number === 3) | filterThatShouldntBeHere}}
Number is three
{{/if}}
`

var ifTemplateBlock = `
{{~ if (it.number === 3) | filterThatShouldntBeHere}}
Number is three
{{#tomato}}
Uh-oh, If doesn't know what to do
{{/if}}
`

test('throws when if helper has filters', () => {
expect(() => {
CompileToString(ifTemplateFilter, Env.default)
}).toThrow()
})

test('throws when if helper has unrecognized blocks', () => {
expect(() => {
CompileToString(ifTemplateBlock, Env.default)
}).toThrow()
})

var tryTemplateFilter = `
{{~try | filter1}}
Some content
{{#catch => err}}
Uh-oh, error! Message was '{{err.message}}'
{{/try}}
`

var tryTemplateBlock = `
{{~try}}
Some content
{{#catch => err}}
Uh-oh, error! Message was '{{err.message}}'
{{#tomato}}
// The above block isn't recognized
{{/try}}
`

test('throws when try catch has filters', () => {
expect(() => {
CompileToString(tryTemplateFilter, Env.default)
}).toThrow()
})

test('throws when try catch has unrecognized block', () => {
expect(() => {
CompileToString(tryTemplateBlock, Env.default)
}).toThrow()
})
})
Loading

0 comments on commit bfd89ac

Please sign in to comment.