Skip to content

Commit

Permalink
chore: rebuild with denoify
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowtime2000 committed Nov 29, 2020
1 parent f8950a7 commit efd3e7f
Show file tree
Hide file tree
Showing 17 changed files with 514 additions and 535 deletions.
44 changes: 43 additions & 1 deletion deno_dist/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</p>

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[logo]: https://img.shields.io/badge/all_contributors-7-orange.svg 'Number of contributors on All-Contributors'
[logo]: https://img.shields.io/badge/all_contributors-8-orange.svg 'Number of contributors on All-Contributors'
<!-- ALL-CONTRIBUTORS-BADGE:END -->

<span align="center">
Expand Down Expand Up @@ -134,6 +134,45 @@ Simply put, Eta is super: super lightweight, super fast, super powerful, and sup

Additionally, Eta is a letter of the Greek alphabet (it stands for all sorts of cool things in various mathematical fields, including efficiency) and is three letters long (perfect for a file extension).

## Integrations

<details>
<summary>
<b>ESLint</b>
</summary>

[eslint-plugin-eta](https://github.com/eta-dev/eslint-plugin-eta) was created to provide an ESLint processor so you can lint your Eta templates.

</details>

<details>
<summary>
<b>CLI</b>
</summary>

An official Eta CLI exists called [etajs-cli](https://github.com/eta-dev/etajs-cli).

</details>

<details>
<summary>
<b>Webpack</b>
</summary>

Currently there is no official Webpack integration but [@clshortfuse](https://github.com/clshortfuse) shared the loader he uses:
```javascript
{
loader: 'html-loader',
options: {
preprocessor(content, loaderContext) {
return eta.render(content, {}, { filename: loaderContext.resourcePath });
},
},
}
```

</details>

## 📜 Docs

We know nobody reads through the long and boring documentation in the ReadMe anyway, so head over to the documentation website:
Expand Down Expand Up @@ -216,6 +255,9 @@ Made with ❤ by [@nebrelbug](https://github.com/eta-dev) and all these wonderfu
<td align="center"><a href="https://shadowtime2000.github.io"><img src="https://avatars1.githubusercontent.com/u/66655515?v=4" width="100px;" alt=""/><br /><sub><b>shadowtime2000</b></sub></a><br /><a href="https://github.com/eta-dev/eta/commits?author=shadowtime2000" title="Code">💻</a> <a href="#ideas-shadowtime2000" title="Ideas, Planning, & Feedback">🤔</a></td>
<td align="center"><a href="https://hamidihamza.com"><img src="https://avatars0.githubusercontent.com/u/22576950?v=4" width="100px;" alt=""/><br /><sub><b>Hamza Hamidi</b></sub></a><br /><a href="https://github.com/eta-dev/eta/commits?author=hamzahamidi" title="Documentation">📖</a></td>
</tr>
<tr>
<td align="center"><a href="http://calumk.com"><img src="https://avatars1.githubusercontent.com/u/1183991?v=4" width="100px;" alt=""/><br /><sub><b>Calum Knott</b></sub></a><br /><a href="#ideas-calumk" title="Ideas, Planning, & Feedback">🤔</a></td>
</tr>
</table>

<!-- markdownlint-enable -->
Expand Down
17 changes: 6 additions & 11 deletions deno_dist/browser.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
export { default as compileToString } from "./compile-string.ts";
export { default as compile } from "./compile.ts";
export { default as parse } from "./parse.ts";
export { default as render } from "./render.ts";
export { templates } from "./containers.ts";
export {
config,
config as defaultConfig,
configure,
getConfig,
} from "./config.ts";
export { default as compileToString } from './compile-string.ts'
export { default as compile } from './compile.ts'
export { default as parse } from './parse.ts'
export { default as render, renderAsync } from './render.ts'
export { templates } from './containers.ts'
export { config, config as defaultConfig, getConfig, configure } from './config.ts'
84 changes: 41 additions & 43 deletions deno_dist/compile-string.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Parse from "./parse.ts";
import Parse from './parse.ts'

/* TYPES */

import type { EtaConfig } from "./config.ts";
import type { AstObject } from "./parse.ts";
import type { EtaConfig } from './config.ts'
import type { AstObject } from './parse.ts'

/* END TYPES */

Expand All @@ -18,40 +18,38 @@ import type { AstObject } from "./parse.ts";
* ```
*/

export default function compileToString(
str: string,
config: EtaConfig,
): string {
var buffer: Array<AstObject> = Parse(str, config);

var res = "var tR='',__l,__lP" +
(config.include ? ",include=E.include.bind(E)" : "") +
(config.includeFile ? ",includeFile=E.includeFile.bind(E)" : "") +
"\nfunction layout(p,d){__l=p;__lP=d}\n" +
(config.useWith ? "with(" + config.varName + "||{}){" : "") +
export default function compileToString(str: string, config: EtaConfig): string {
var buffer: Array<AstObject> = Parse(str, config)

var res =
"var tR='',__l,__lP" +
(config.include ? ',include=E.include.bind(E)' : '') +
(config.includeFile ? ',includeFile=E.includeFile.bind(E)' : '') +
'\nfunction layout(p,d){__l=p;__lP=d}\n' +
(config.useWith ? 'with(' + config.varName + '||{}){' : '') +
compileScope(buffer, config) +
(config.includeFile
? "if(__l)tR=" +
(config.async ? "await " : "") +
? 'if(__l)tR=' +
(config.async ? 'await ' : '') +
`includeFile(__l,Object.assign(${config.varName},{body:tR},__lP))\n`
: config.include
? "if(__l)tR=" +
(config.async ? "await " : "") +
? 'if(__l)tR=' +
(config.async ? 'await ' : '') +
`include(__l,Object.assign(${config.varName},{body:tR},__lP))\n`
: "") +
"if(cb){cb(null,tR)} return tR" +
(config.useWith ? "}" : "");
: '') +
'if(cb){cb(null,tR)} return tR' +
(config.useWith ? '}' : '')

if (config.plugins) {
for (var i = 0; i < config.plugins.length; i++) {
var plugin = config.plugins[i];
var plugin = config.plugins[i]
if (plugin.processFnString) {
res = plugin.processFnString(res, config);
res = plugin.processFnString(res, config)
}
}
}

return res;
return res
}

/**
Expand All @@ -68,47 +66,47 @@ export default function compileToString(
*/

function compileScope(buff: Array<AstObject>, config: EtaConfig) {
var i = 0;
var buffLength = buff.length;
var returnStr = "";
var i = 0
var buffLength = buff.length
var returnStr = ''

for (i; i < buffLength; i++) {
var currentBlock = buff[i];
if (typeof currentBlock === "string") {
var str = currentBlock;
var currentBlock = buff[i]
if (typeof currentBlock === 'string') {
var str = currentBlock

// we know string exists
returnStr += "tR+='" + str + "'\n";
returnStr += "tR+='" + str + "'\n"
} else {
var type = currentBlock.t; // ~, s, !, ?, r
var content = currentBlock.val || "";
var type = currentBlock.t // ~, s, !, ?, r
var content = currentBlock.val || ''

if (type === "r") {
if (type === 'r') {
// raw

if (config.filter) {
content = "E.filter(" + content + ")";
content = 'E.filter(' + content + ')'
}

returnStr += "tR+=" + content + "\n";
} else if (type === "i") {
returnStr += 'tR+=' + content + '\n'
} else if (type === 'i') {
// interpolate

if (config.filter) {
content = "E.filter(" + content + ")";
content = 'E.filter(' + content + ')'
}

if (config.autoEscape) {
content = "E.e(" + content + ")";
content = 'E.e(' + content + ')'
}
returnStr += "tR+=" + content + "\n";
returnStr += 'tR+=' + content + '\n'
// reference
} else if (type === "e") {
} else if (type === 'e') {
// execute
returnStr += content + "\n"; // you need a \n in case you have <% } %>
returnStr += content + '\n' // you need a \n in case you have <% } %>
}
}
}

return returnStr;
return returnStr
}
53 changes: 23 additions & 30 deletions deno_dist/compile.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import compileToString from "./compile-string.ts";
import { getConfig } from "./config.ts";
import EtaErr from "./err.ts";
import compileToString from './compile-string.ts'
import { getConfig } from './config.ts'
import EtaErr from './err.ts'

/* TYPES */

import type { EtaConfig, PartialConfig } from "./config.ts";
import type { CallbackFn } from "./file-handlers.ts";
import { getAsyncFunctionConstructor } from "./polyfills.ts";
export type TemplateFunction = (
data: object,
config: EtaConfig,
cb?: CallbackFn,
) => string;
import type { EtaConfig, PartialConfig } from './config.ts'
import type { CallbackFn } from './file-handlers.ts'
import { getAsyncFunctionConstructor } from './polyfills.ts'
export type TemplateFunction = (data: object, config: EtaConfig, cb?: CallbackFn) => string

/* END TYPES */

Expand All @@ -31,41 +27,38 @@ export type TemplateFunction = (
* ```
*/

export default function compile(
str: string,
config?: PartialConfig,
): TemplateFunction {
var options: EtaConfig = getConfig(config || {});
var ctor; // constructor
export default function compile(str: string, config?: PartialConfig): TemplateFunction {
var options: EtaConfig = getConfig(config || {})
var ctor // constructor

/* ASYNC HANDLING */
// The below code is modified from mde/ejs. All credit should go to them.
if (options.async) {
ctor = getAsyncFunctionConstructor() as FunctionConstructor;
ctor = getAsyncFunctionConstructor() as FunctionConstructor
} else {
ctor = Function;
ctor = Function
}
/* END ASYNC HANDLING */
try {
return new ctor(
options.varName,
"E", // EtaConfig
"cb", // optional callback
compileToString(str, options),
) as TemplateFunction; // eslint-disable-line no-new-func
'E', // EtaConfig
'cb', // optional callback
compileToString(str, options)
) as TemplateFunction // eslint-disable-line no-new-func
} catch (e) {
if (e instanceof SyntaxError) {
throw EtaErr(
"Bad template syntax\n\n" +
'Bad template syntax\n\n' +
e.message +
"\n" +
Array(e.message.length + 1).join("=") +
"\n" +
'\n' +
Array(e.message.length + 1).join('=') +
'\n' +
compileToString(str, options) +
"\n", // This will put an extra newline before the callstack for extra readability
);
'\n' // This will put an extra newline before the callstack for extra readability
)
} else {
throw e;
throw e
}
}
}
Loading

0 comments on commit efd3e7f

Please sign in to comment.