Comparing version 1.2.3 to 2.0.0
@@ -37,2 +37,1 @@ import { EngineMap } from "./engineMap"; | ||
} | ||
export declare function create(opts?: any): Ecto; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.create = exports.Ecto = void 0; | ||
exports.Ecto = void 0; | ||
const engineMap_1 = require("./engineMap"); | ||
@@ -167,6 +167,2 @@ const markdown_1 = require("./engines/markdown"); | ||
exports.Ecto = Ecto; | ||
function create(opts) { | ||
return new Ecto(opts); | ||
} | ||
exports.create = create; | ||
//# sourceMappingURL=ecto.js.map |
@@ -5,3 +5,3 @@ "use strict"; | ||
const baseEngine_1 = require("../baseEngine"); | ||
const marked_1 = require("marked"); | ||
const markdoc_1 = require("@markdoc/markdoc"); | ||
class Markdown extends baseEngine_1.BaseEngine { | ||
@@ -14,19 +14,9 @@ constructor(opts) { | ||
} | ||
else { | ||
this.opts = { | ||
pedantic: false, | ||
gfm: true, | ||
breaks: false, | ||
sanitize: false, | ||
smartLists: true, | ||
smartypants: false, | ||
xhtml: false | ||
}; | ||
} | ||
this.engine = marked_1.marked; | ||
this.engine.setOptions(this.opts); | ||
this.engine = markdoc_1.default; | ||
this.setExtensions(["md", "markdown"]); | ||
} | ||
async render(source, data) { | ||
return this.engine.parse(source); | ||
const ast = this.engine.parse(source); | ||
const content = this.engine.transform(ast, this.opts); | ||
return this.engine.renderers.html(content); | ||
} | ||
@@ -33,0 +23,0 @@ } |
{ | ||
"name": "ecto", | ||
"version": "1.2.3", | ||
"version": "2.0.0", | ||
"description": "Modern Template Consolidation Engine for EJS, Markdown, Pug, Nunjucks, and Handlebars", | ||
"main": "./dist/ecto.js", | ||
"types": "./dist/ecto.d.ts", | ||
"type": "module", | ||
"repository": "https://github.com/jaredwray/ecto.git", | ||
@@ -38,2 +39,3 @@ "author": "Jared Wray <me@jaredwray.com>", | ||
"dependencies": { | ||
"@markdoc/markdoc": "^0.1.2", | ||
"ejs": "^3.1.8", | ||
@@ -45,6 +47,5 @@ "fs-extra": "^10.1.0", | ||
"liquidjs": "^9.37.0", | ||
"marked": "^4.0.16", | ||
"nunjucks": "^3.2.3", | ||
"pug": "^3.0.2", | ||
"underscore": "^1.13.3", | ||
"underscore": "^1.13.4", | ||
"winston": "^3.7.2" | ||
@@ -57,11 +58,11 @@ }, | ||
"@types/handlebars-helpers": "^0.5.3", | ||
"@types/jest": "^27.5.1", | ||
"@types/jest": "^28.1.1", | ||
"@types/marked": "^4.0.3", | ||
"@types/mustache": "^4.1.2", | ||
"@types/mustache": "^4.1.3", | ||
"@types/nunjucks": "^3.2.1", | ||
"@types/pug": "^2.0.6", | ||
"@types/underscore": "^1.11.4", | ||
"jest": "^28.1.0", | ||
"ts-jest": "^28.0.2", | ||
"typescript": "^4.6.4" | ||
"jest": "^28.1.1", | ||
"ts-jest": "^28.0.4", | ||
"typescript": "^4.7.3" | ||
}, | ||
@@ -68,0 +69,0 @@ "files": [ |
150
README.md
@@ -5,4 +5,4 @@ ![Ecto](ecto_logo.png "Ecto") | ||
[![Build Status](https://github.com/jaredwray/ecto/workflows/ecto-build/badge.svg)](https://github.com/jaredwray/ecto/actions) | ||
[![Release Status](https://github.com/jaredwray/ecto/workflows/ecto-release/badge.svg)](https://github.com/jaredwray/ecto/actions) | ||
[![Build Status](https://github.com/jaredwray/ecto/workflows/build/badge.svg)](https://github.com/jaredwray/ecto/actions) | ||
[![Release Status](https://github.com/jaredwray/ecto/workflows/release/badge.svg)](https://github.com/jaredwray/ecto/actions) | ||
[![GitHub license](https://img.shields.io/github/license/jaredwray/ecto)](https://github.com/jaredwray/ecto/blob/master/LICENSE) | ||
@@ -28,35 +28,16 @@ [![codecov](https://codecov.io/gh/jaredwray/ecto/branch/main/graph/badge.svg?token=dpbFqSW5Kh)](https://codecov.io/gh/jaredwray/ecto) | ||
Follow these steps to add Ecto to a new or existing JavaScript project: | ||
1. Ensure Node.js is installed. For macOS and Linux, you can install Node.js in the terminal using Homebrew: | ||
``` | ||
brew install node | ||
``` | ||
The [Node.js package manager documentation](https://nodejs.org/en/download/package-manager/) provides the commands needed to complete the install on Windows and other operating systems. | ||
2. Open the terminal for your project and run `npm install ` to ensure all project dependencies are correctly installed. | ||
1. Open the terminal for your project and run `npm install` to ensure all project dependencies are correctly installed. | ||
``` | ||
npm install | ||
npm install ecto | ||
``` | ||
3. Add Ecto to your Project. `yarn` is a package manager you can learn about [here.](https://yarnpkg.com/) | ||
2. Declare and Initialize. | ||
``` | ||
yarn add ecto | ||
``` | ||
4. Declare and Initialize. | ||
```javascript | ||
const Ecto = require("ecto").Ecto; | ||
let ecto = new Ecto(); | ||
``` | ||
import { Ecto } from `ecto`; | ||
OR | ||
```javascript | ||
const ecto = require("ecto").create(); | ||
const ecto = new Ecto(); | ||
``` | ||
@@ -67,4 +48,4 @@ | ||
```javascript | ||
let source = "<h1>Hello <%= firstName%> <%= lastName %>!</h1>"; | ||
let data = {firstName: "John", lastName: "Doe"} | ||
const source = "<h1>Hello <%= firstName%> <%= lastName %>!</h1>"; | ||
const data = {firstName: "John", lastName: "Doe"} | ||
ecto.render(source, data).then((output) => { | ||
@@ -146,4 +127,3 @@ console.log(output); | ||
```javascript | ||
const Ecto = require("Ecto").Ecto; | ||
let ecto = new Ecto(); | ||
const ecto = new Ecto(); | ||
//ecto.<API> -- functions and parameters | ||
@@ -177,6 +157,6 @@ ``` | ||
```javascript | ||
let ecto = require("ecto").create(); | ||
const ecto = new Ecto(); | ||
let source = "<h1>Hello <%= firstName%> <%= lastName %>!</h1>"; | ||
let data = {firstName: "John", lastName: "Doe"}; | ||
const source = "<h1>Hello <%= firstName%> <%= lastName %>!</h1>"; | ||
const data = {firstName: "John", lastName: "Doe"}; | ||
ecto.render(source, data).then((output) => { | ||
@@ -190,6 +170,6 @@ console.log(output); | ||
```javascript | ||
let ecto = require("ecto").create(); | ||
const ecto = new Ecto(); | ||
let source = "<h1>Hello {{firstName}} {{lastName}}!</h1>"; | ||
let data = {firstName: "John", lastName: "Doe"} | ||
const source = "<h1>Hello {{firstName}} {{lastName}}!</h1>"; | ||
const data = {firstName: "John", lastName: "Doe"} | ||
ecto.render(source, data, "handlebars").then((output) => { | ||
@@ -204,6 +184,6 @@ console.log(output); | ||
```javascript | ||
let ecto = require("ecto").create(); | ||
const ecto = new Ecto(); | ||
let source = "<h1>Hello <%= firstName%> <%= lastName %>!</h1><%- include('/relative/path/to/partial'); %>"; | ||
let data = {firstName: "John", lastName: "Doe"}; | ||
const source = "<h1>Hello <%= firstName%> <%= lastName %>!</h1><%- include('/relative/path/to/partial'); %>"; | ||
const data = {firstName: "John", lastName: "Doe"}; | ||
ecto.render(source, data, undefined, "./path/to/templates").then((output) => { | ||
@@ -218,6 +198,6 @@ console.log(output); | ||
```javascript | ||
let ecto = require("ecto").create(); | ||
const ecto = new Ecto(); | ||
let source = "<h1>Hello <%= firstName%> <%= lastName %>!</h1>"; | ||
let data = {firstName: "John", lastName: "Doe"}; | ||
const source = "<h1>Hello <%= firstName%> <%= lastName %>!</h1>"; | ||
const data = {firstName: "John", lastName: "Doe"}; | ||
ecto.render(source, data, undefined, undefined, "./path/to/output/file.html").then((output) => { | ||
@@ -251,4 +231,4 @@ console.log(output); | ||
```javascript | ||
let ecto = require("ecto").create(); | ||
let data = { firstName: "John", lastName: "Doe"}; | ||
const ecto = new Ecto(); | ||
const data = { firstName: "John", lastName: "Doe"}; | ||
@@ -260,4 +240,4 @@ ecto.renderFromFile("./path/to/template.ejs", data).then((output) => {console.log(output)}); | ||
```javascript | ||
let ecto = require("ecto").create(); | ||
let data = { firstName: "John", lastName: "Doe"}; | ||
const ecto = new Ecto(); | ||
const data = { firstName: "John", lastName: "Doe"}; | ||
@@ -272,4 +252,4 @@ ecto.renderFromFile("./path/to/template.ejs", data, undefined, "./path/to/output/yourname.html") | ||
```javascript | ||
let ecto = require("ecto").create(); | ||
let data = { firstName: "John", lastName: "Doe"}; | ||
const ecto = new Ecto(); | ||
const data = { firstName: "John", lastName: "Doe"}; | ||
@@ -290,9 +270,9 @@ ecto.renderFromFile("./path/to/template.ejs", data, undefined, | ||
- `const ecto = require("ecto").create({defaultEngine: "ejs"});` | ||
- `const ecto = require("ecto").create({defaultEngine: "markdown"});` | ||
- `const ecto = require("ecto").create({defaultEngine: "pug"});` | ||
- `const ecto = require("ecto").create({defaultEngine: "nunjucks"});` | ||
- `const ecto = require("ecto").create({defaultEngine: "mustache"});` | ||
- `const ecto = require("ecto").create({defaultEngine: "handlebars"});` | ||
- `const ecto = require("ecto").create({defaultEngine: "liquid"});` | ||
- `const ecto = new Ecto({defaultEngine: "ejs"});` | ||
- `const ecto = new Ecto({defaultEngine: "markdown"});` | ||
- `const ecto = new Ecto({defaultEngine: "pug"});` | ||
- `const ecto = new Ecto({defaultEngine: "nunjucks"});` | ||
- `const ecto = new Ecto({defaultEngine: "mustache"});` | ||
- `const ecto = new Ecto({defaultEngine: "handlebars"});` | ||
- `const ecto = new Ecto({defaultEngine: "liquid"});` | ||
@@ -304,4 +284,3 @@ ##### Set the default engine as a parameter | ||
```javascript | ||
const Ecto = require("ecto").Ecto; | ||
let ecto = new Ecto(); | ||
const ecto = new Ecto(); | ||
ecto.defaultEngine = "mustache"; | ||
@@ -313,4 +292,3 @@ ``` | ||
```javascript | ||
const Ecto = require("ecto").Ecto; | ||
let ecto = new Ecto({defaultEngine: "liquid"}); | ||
const ecto = new Ecto({defaultEngine: "liquid"}); | ||
ecto.defaultEngine = "mustache"; | ||
@@ -324,5 +302,5 @@ ``` | ||
```javascript | ||
let ecto = require("ecto").create(); | ||
let source = "<h1>Hello {{firstName}} {{lastName}}!</h1>"; | ||
let data = {firstName: "John", lastName: "Doe"}; | ||
const ecto = new Ecto(); | ||
const source = "<h1>Hello {{firstName}} {{lastName}}!</h1>"; | ||
const data = {firstName: "John", lastName: "Doe"}; | ||
ecto.render(source, data, "handlebars").then((output) => { | ||
@@ -338,4 +316,4 @@ console.log(output); | ||
```javascript | ||
let ecto = new Ecto(); | ||
let data = { firstName: "John", lastName: "Doe"}; | ||
const ecto = new Ecto(); | ||
const data = { firstName: "John", lastName: "Doe"}; | ||
ecto.renderFromFile("./path/to/template.ejs", data, undefined, "./path/to/output/yourname.html", "pug").then((output) => { | ||
@@ -349,3 +327,3 @@ console.log(output) | ||
```javascript | ||
let ecto = Ecto(); | ||
const ecto = Ecto(); | ||
console.log(ecto.Handlebars.name); // will return "handlebars" | ||
@@ -358,3 +336,3 @@ console.log(ecto.Handlebars.opts); // will return "handlebars" options object | ||
```javascript | ||
let ecto = Ecto(); | ||
const ecto = Ecto(); | ||
ecto.Handlebars.engine.SafeString("<div>HTML Content!</div>"); | ||
@@ -371,5 +349,5 @@ ``` | ||
```javascript | ||
let ecto = Ecto(); | ||
let source = "# markdown rulezz!"; | ||
let output = await ecto.render(source, undefined, "markdown"); | ||
const ecto = Ecto(); | ||
const source = "# markdown rulezz!"; | ||
const output = await ecto.render(source, undefined, "markdown"); | ||
console.log(output) //should be <h1 id="markdown-rulezz">markdown rulezz!</h1> | ||
@@ -387,4 +365,4 @@ ``` | ||
```javascript | ||
let ecto = Ecto(); | ||
let source = "# markdown rulezz!"; | ||
const ecto = Ecto(); | ||
const source = "# markdown rulezz!"; | ||
ecto.render(source, undefined, "markdown").then((output) => { | ||
@@ -397,3 +375,3 @@ console.log(output) //should be <h1 id="markdown-rulezz">markdown rulezz!</h1> | ||
```javascript | ||
let ecto = Ecto(); | ||
const ecto = Ecto(); | ||
ecto.renderByFile("/path/to/file.md").then((output) => { | ||
@@ -404,15 +382,3 @@ console.log(output) | ||
With Markdown we have added the following options as they are the most common: | ||
```javascript | ||
{ | ||
pedantic: false, | ||
gfm: true, | ||
breaks: false, | ||
sanitize: false, | ||
smartLists: true, | ||
smartypants: false, | ||
xhtml: false | ||
} | ||
``` | ||
You can read more about them [here](https://marked.js.org/using_advanced#options). | ||
We are using [Markdoc](https://markdoc.io/) which has a ton of powerful features. | ||
@@ -426,4 +392,4 @@ #### Handlebars | ||
```javascript | ||
let ecto = Ecto(); | ||
let source = "{{year}}"; | ||
const ecto = Ecto(); | ||
const source = "{{year}}"; | ||
@@ -546,4 +512,2 @@ ecto.render(source, undefined, "handlebars").then((output) => { | ||
## The Template Engines we support | ||
@@ -639,4 +603,4 @@ | ||
```javascript | ||
let ecto = Ecto(); | ||
let source = "{{year}}"; | ||
const ecto = Ecto(); | ||
const source = "{{year}}"; | ||
@@ -657,1 +621,5 @@ ecto.render(source, undefined, "handlebars").then((output) => { | ||
The double curly brace delimiters `{{ }}` denote output, and the curly brace percentage delimiters `{% %}` denote logic. You'll become very familiar with these as every Liquid construct begins with one, or the other. Another way of thinking of delimiters is as placeholders. A placeholder can be viewed as a piece of code that will ultimately be replaced by data when the compiled file is sent to the browser. | ||
# License | ||
[MIT License - Copyright (c) 2021-2022 Jared Wray](LICENSE) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Yes
62892
523
599
+ Added@markdoc/markdoc@^0.1.2
+ Added@markdoc/markdoc@0.1.13(transitive)
+ Added@types/linkify-it@5.0.0(transitive)
+ Added@types/markdown-it@14.1.2(transitive)
+ Added@types/mdurl@2.0.0(transitive)
+ Added@types/prop-types@15.7.13(transitive)
+ Added@types/react@18.3.9(transitive)
+ Addedcsstype@3.1.3(transitive)
- Removedmarked@^4.0.16
- Removedmarked@4.3.0(transitive)
Updatedunderscore@^1.13.4