Coder Social home page Coder Social logo

jonschlinkert / dry Goto Github PK

View Code? Open in Web Editor NEW
70.0 4.0 1.0 707 KB

Dry is a new template engine and language, and is a superset of Shopify's Liquid, with first-class support for advanced inheritance features, and more. From the creators of Enquirer, Assemble, Remarkable, and Micromatch.

Home Page: https://github.com/jonschlinkert

License: MIT License

JavaScript 98.78% HTML 1.22%
liquid shopify template templating engine render templates headless email cms

dry's Introduction

dry NPM version NPM monthly downloads NPM total downloads

Dry is superset of the Liquid templating language, with first-class support for advanced inheritance features, and more.

Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your โค๏ธ and support.

Install

Install with npm (requires Node.js >=14):

$ npm install --save dry

Getting started

The simplest way to get started is with the render method, which takes a template string and a data object (the "context").

const { render } = require('dry'); // render is async
console.log(await render('Hello, {{ name }}!', { name: 'Brian' })); //=> Hello, Brian!

Using the code above, you can do almost everything you need to do with Dry.

Tags, Filters, Variables, and more!

See the docs for Shopify's Liquid to learn about all of the features in the Liquid templating language. If you can do it with Liquid, you should be able to do it with Dry. (and if you can't do it with Dry, it's a bug, and we kindly ask that you please create an issue, thanks!)


Full Documentation

Docs are on the way. In the meantime, you can use this Liquid docs to learn about all language features, and use the code snippet above to render your templates!


2.0 Notes

๐ŸŽ‰ This release took a while. Here are some highlights!

First things first

I'm back! I know I haven't been around a lot lately, but all of that is about to change! Thank you to @doowb all of my sponsors and friends on GitHub who have provided the encouragement and support I needed to begin making this comeback.

Please consider following me and this repository to receive updates, and consider contributing to Dry so we can make this the most powerful templating library in Node.js!

Why Dry? Aren't React and Vue the future?

Yes, yes they are. Dry doesn't compete with them. We use Dry the same way Shopify and Jekyll use Liquid, many end-users don't know how to write JavaScript, and many developers would prefer not to write JavaScript - I love writing JavaScript, and I enjoy Vue and React, but there is something satisfying about deploying a site in 5 minutes using plain text html templates. We also use Dry to design and render email templates, configuration-based system messages, and so on.

What's different about Dry?

Dry is A Superset of Shopify's Liquid with first-class support for template inheritance (ahem... so you don't have to repeat yourself. So it's "dry". I know... it's all I have at the moment).

Highlights of this PR

  • Ported directly from Shopify/liquid - Wherever possible, and practical, I attempted to retain the same structure and code decisions as Shopify's Liquid. Since Ruby has a number of language features that aren't available in JavaScript, I had to find arounds or do things differently in a few places.
  • Powerful template inheritance: layouts, extends, blocks, macros, embed, imports, and even complex reassignments like {% from 'fields' import input as input_field, textarea %}
  • More than 750 unit tests so far
  • Filters: >70 filters, including all Liquid filters and more
  • Tags: >30 Tags, including all Liquid tags and a several new ones! See the list below!
  • More powerful comparisons and conditionals (more about this soon!)

Lots more!


Tags

The tags with leading + were added to Dry:

(We'll be adding more tags soon! Like section and other tags used by Shopify)

+Apply
Assign
+Block
Break
Capture
Case
Comment
+Content
Continue
Cycle
Decrement
Echo
+Embed
+Extends
For
+From
If
Ifchanged
+Import
Include
Increment
+Layout
Liquid
+Macro
+Paginate
Raw
Render
+Set
+Switch
TableRow
Unless
+Verbatim
+With

About

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Please read the contributing guide for advice on opening issues, pull requests, and coding standards.

Running Tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test
Building docs

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Author

Jon Schlinkert

License

Copyright ยฉ 2021, Jon Schlinkert. Released under the MIT License.


This file was generated by verb-generate-readme, v0.8.0, on July 20, 2021.

dry's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

dry's Issues

wishlist

I'd like to make dry a full template engine, so that we can have the engine we've always wanted:

Here is what I'd like to see (anyone else is more than welcome to add to this wishlist):

  • async rendering/helpers
  • first-class inheritance support (layouts, blocks, etc)
  • partials support
  • inline blocks/partials
  • declare variables inside templates
  • helpers
  • custom tags
  • great error handling / pretty error messages

cc @doowb

Async file system

Thanks for creating this library, it seems to solve several problems I've encountered with other JS templating libraries. ๐Ÿ‘

One feature that would be useful is fetching template files asynchronously - for example, to allow retrieving them directly from an S3 bucket. I suppose this would make the entire parse step async as well, which might not be desirable, but is there an alternative way to achieve this? Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.