solidusjs / solidus

A simple server that generates pages from JSON and Templates
MIT License
28 stars 7 forks source link

Client-side view rendering #116

Closed joanniclaborde closed 9 years ago

joanniclaborde commented 10 years ago

In order to render views on the client, the context preparation done in Solidus needs to be replicated in the browser. This is done by solidus-client.

This PR adds the ability to export the Solidus views to the browser, so solidus-client can use them. This is achieved with a custom Browserify transform, named solidify.

Simple example:

assets/scripts/index.js

var SolidusClient = require('solidus-client');
var view = require('solidus/views/my/view'); // Can end with .js, but not with .hbs

var solidus_client = new SolidusClient();
solidus_client
  .render(view)
  .end(function(html) {
    console.log(html);
  });

gruntfile.js

//...
    browserify: {
      scripts: {
        options: {
          transform: ['solidus/solidify', 'hbsfy']
        },
        files: {
          'assets/compiled/scripts.js': ['assets/scripts/index.js']
        }
      }
    },

//...
  grunt.registerTask( 'compilejs', ['browserify'] );
joanniclaborde commented 9 years ago

Warning: rebased over #119, delete your local branch!

joanniclaborde commented 9 years ago

Warning: rebased over 1.1.0, delete your local branch!

joanniclaborde commented 9 years ago

Warning: rebased over 1.1.1, delete your local branch!