facebook / react

The library for web and native user interfaces.
https://react.dev
MIT License
228.69k stars 46.81k forks source link

Jade? #424

Closed Charuru closed 11 years ago

Charuru commented 11 years ago

All my DOM code is written in jade. Any easy way to use jade in react?

chenglou commented 11 years ago

@Charuru Jade parses strings like most other templating engines. React doesn't, since under the hood the HTML-like tags are desugared into function calls. So I don't think these two work together.

Charuru commented 11 years ago

@chenglou Thanks I'm aware that it wouldn't be possible out of the box but what about some kind of preprocessing? Do you think it's feasible or pointless to think about?

zpao commented 11 years ago

If you would like to write a parser that allows you to write Jade in JS and desugars to plain JS, be my guest. I think it will likely prove difficult. One advantage we have with JSX right now is that we've added some simple semantics on top of an existing JS parser (esprima) and use that to convert to vanilla JS. You could probably make that work, though I'm not personally convinced it's worth the effort. Regardless, we won't be adding support for that but feel free to explore it yourself!

yanivtal commented 10 years ago

For the record: React with coffeescript and jade (or haml) like syntax would be heaven. You guys don't know what you're missing.

yocontra commented 10 years ago

Just to be clear: There is no way to turn an HTML string into a React DOM object?

sophiebits commented 10 years ago

@Contra Correct, unless you count <div dangerouslySetInnerHTML={{__html: ... }} /> which sidesteps almost all of React.

petehunt commented 10 years ago

Not correct anymore! You can use this to do it: http://facebook.github.io/react/html-jsx.html

However I certainly would not recommend using this at runtime.

Charuru commented 10 years ago

Anyone working on a compiler?

yocontra commented 10 years ago

@Charuru I worked on a project that lets you hook into the jade compiler and modify the way everything works. I had written a plugin previously that compiled it to rivets data bindings so theoretically you could do the same for React https://github.com/wearefractal/jaded

Rivets plugin:

https://github.com/wearefractal/jaded/blob/master/lib/processors.coffee https://github.com/wearefractal/jaded/blob/master/lib/main.coffee#L21

kevbook commented 10 years ago

I am converting my project to use React. I dont want to change my workflow for front end engineers. So they write Jade -> JSX -> Reactified (used in front end). I'll code it up if it doesnt exist.

duncanbeevers commented 10 years ago

I sketched out a custom Jade compiler for generating React code. https://github.com/duncanbeevers/jade-react

It turns this

.container-fluid.readme
  .row
    h1= this.storeName
    ul
    each product in this.products
      li
        | Product
        = product.title

Into this

function () {
  function map (obj, fn) {
    if ('number' === typeof obj.length) return obj.map(fn);
    var result = [], key, hasProp = {}.hasOwnProperty;
    for (key in obj) hasProp.call(obj, key) && result.push(fn(key, obj[key]));
    return result;
  }

  return React.DOM.div({
    "className": "container-fluid readme"
  },
    React.DOM.div({
      "className": "row"
    },
      React.DOM.h1(null,
        this.storeName
      ),
      React.DOM.ul(null),
        map(this.products, function (product, $index) {
          return React.DOM.li(null,
            "Product",
            product.title
          );
        }
      )
    )
  );
}
syranide commented 10 years ago

@duncanbeevers + doesn't seem quite right though.

duncanbeevers commented 10 years ago

@syranide Yeah, it was a rough first pass. I'm working on it in the the context of a green-field hobby project so there are number of tooling questions around it that are currently unanswered.

I'm also making a sister tool, duncanbeevers/gulp-jade-react for integrating this into Gulp workflows along with gulp-wrap to capture and expose the expressions as functions.

I'll no longer be commenting on this thread, but work in jade-react will be on-going.

syrusakbary commented 10 years ago

@Charuru I'm working on a Reactive version of Jade, I will write here again once is ready :smiley_cat:

sibsfinx commented 10 years ago

Maybe https://github.com/concordusapps/grunt-haml can help:

I use this approach in Angular project so it may help with React

sfarthin commented 9 years ago

I agree React with Coffeescript and jade would be perfect. I think this approach is the only viable one.

derrybirkett commented 9 years ago

Somebody please solve this - I need Coffee and Jade .....

crapthings commented 9 years ago

meteor + coffeescript + react + jade +1

rodriced commented 9 years ago

:+1:

jiku commented 8 years ago

Haven't tried it yet, but this could be of interest.

lamuertepeluda commented 8 years ago

:+1: +1

sergeysova commented 8 years ago

@zpao open issue, please

gaearon commented 8 years ago

React team has no plans to implement template engine integrations, whether Jade or any other system.

As communicated above, we see plain JS (or in case of JSX, superset of JS) nature of React components as an advantage rather than a downside. If you feel strongly about it you are welcome to create a Jade-to-createElement transform but we will not be working on this.

Adding +1’s to this issue or asking to reopen it doesn’t help anyone and has an unfortunate side effect of clobbering everyone’s notifications. Please don’t do this.

sferoze commented 8 years ago

meteor + coffeescript + react + jade +1