Giter VIP home page Giter VIP logo

molosser's Introduction

Introduction

About

A concise indentation based templating language that compiles to idiomatic typescript based React function components

Usage

molosser -i <input-directory> -o <output-directory>

This will generate typescript files in the output-directory which will have to be separately compiled through tsc for wrappers over it. Refer typescript documentation for other details.

Syntax

Tags can be composed through indentation:

// hello.mol
div
    | Hello world

The above is automatically converted to a function component exported as default:

// hello.tsx

import * as React from "react";

export default function Hello() {
    return (
        <div>
            Hello
        </div>
    );
}

Typescript can be embedded through script blocks (which are outside the function exported by default) and inline code blocks (which are inside):

// hello.mol
script.
    import * as cowsay from "cowsay";

pre
  = cowsay.say({text: 'Moo...'})

Render Props:

- const Consumer = AppContext.Consumer
Consumer
  = (app) =>
    if app.repositoryRoot
        #workspace Success

Note usage of - for code block which is not an embedded expression.

Also, note that AppContext.Consumer had to be aliased because of conflict with a tag like AppContext.Consumer will compile to element of type AppContext with className as Consumer.

Multiple components in the same file:

script(type="text/molosser")
    - export const SomeComponent = () =>
        div.hello
            | World
    - export const SomeOtherComponent = () =>
        div.lorem
            | Ipsum

Motivation

  • React is awesome, but JSX is verbose and unweildy.
  • Haml/Jade's indented syntax is much cleaner and succint.
  • babel-plugin-transform-react-pug is not typescript friendly.
  • With the introduction of hooks, it is very much possible to restrict ourselves to functional components and get advantage of most of react.

About the name

Molosser is a breed of dog. The name is indicative of a shared lineage with Pug. Molosser is inspired by Pug and borrows the syntax and parts of the compiler code.

Differences from Pug

  1. Pug compiles to HTML/Javascript, Molosser compiles to typescript code which uses React.

  2. Molosser supports embedded typescript

  3. Pug allows fragments of code which are not valid javascript and has some smart detection of blocks:

    - for (var x = 0; x < 3; x++)
      li item
    

    Molosser expects (and validates) code blocks to be valid typescript - so above usage is illegal.

  4. Following pug features are not supported, because they don't blend well with component oriented idioms in React world:

    1. Includes/Extends/Blocks - Just use ES6 imports and Composition of components
    2. Mixins - Use composition of components
    3. Filters - May be implemented someday

TODO

  • Language server plugin
  • Webpack loader

Contributing

Contributions are welcome in form of bug reports and pull requests through github.

License

MIT

molosser's People

Contributors

lorefnon avatar

Stargazers

Roman avatar

Watchers

James Cloos avatar Samuel Vaillant avatar  avatar

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.