pilif / sacy

Smarty Asset Compiler (warning: all branches but master are subject to force pushes)
http://pilif.github.com/sacy
MIT License
34 stars 12 forks source link

Jsx support #20

Closed brainlock closed 10 years ago

brainlock commented 10 years ago

This PR includes:

Sometimes we need to know which assets were generated by a given sacy block (for example to retrieve jsx components to pre-render on the server).

In this case the smarty template can call asset_compile like this:

{asset_compile block_ref="react-components"}
  <script type="text/x-jsx" src="/jslib/a_component.jsx"></script>
  ...
{/asset_compile}

Sacy will assign the generated assets into $smarty.sacy.rendered_assets:

[ 'react-components' => [ // src relative to the document root ['type' => 'file', 'src' => '/assetcache/components-d141caabeb4e87ff2bd021da49e7305c-content.js'], ['type' => 'string', 'content' => '...rendered content...'], ], ... ]

We use this to fetch the sacy-compiled js when pre-rendering jsx-components on the server.

pilif commented 10 years ago

the reference thing is probably very much non-encouraged by Smarty itself, but as long as people don't use it, who cares? :p