Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Enable serveClient() accept second parameters and forward it to view engine #341

Closed
wants to merge 5 commits into from

3 participants

@lge88

Make it similar to Express's render method:

res.render('main', [locals]);

In socketstream:

res.serveClient('main', {
  title : 'main',
  version : '1.0',
  ...
});

Corresponding view engine wrappers need to be modified to enable this feature. For example, in ss-jade/wrapper.js, compile function needs to be modified.

compile: function(path, options, cb) {

  // locals now can be accessed by options.locals. 
  var locals = (options && options.locals) ? options.locals : {};
  ...

  var output = parser(locals);
  cb(output);
}
@lge88 lge88 referenced this pull request in socketstream/ss-jade
Open

make ss-jade accept locals from serveClient #5

@owenb

Hey there

Sorry for taking an age to get back to you. I was considering this request for some time, then got really busy with other work and, during the last month, 0.4 development.

As the first alpha version of 0.4 will be out very soon, I no longer want to make any changes to 0.3 - unless it's a critical bug or something similar.

However, your elegant solution has inspired me to do something similar with 0.4. What it will be exactly, I'm not sure yet (I was working all day yesterday on the new asset builder), but rest assured I see the need to render jade file server-side and I'll make sure it's possible.

Again, sorry for taking so long to reply.

Cheers,

Owen

@owenb owenb closed this
@lge88

Sounds good. I am looking forward to seeing the 0.4 version!

@helozjisky

https://github.com/socketstream/ss-jade

ss.client.formatters.add(require('ss-jade'), {locals: {countries: {}}});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 19, 2013
  1. @lge88
Commits on Jan 26, 2013
  1. @lge88
Commits on Mar 14, 2013
  1. @lge88
Commits on Mar 19, 2013
  1. @lge88
Commits on Mar 20, 2013
  1. @lge88

    enable symlink in templates

    lge88 authored
This page is out of date. Refresh to see the latest.
View
5 lib/client/http.js
@@ -16,7 +16,7 @@ cache = {};
res = http.ServerResponse.prototype;
module.exports = function(ss, clients, options) {
- res.serveClient = function(name) {
+ res.serveClient = function(name, locals) {
var client, fileName, self, sendHTML;
self = this;
sendHTML = function(html, code) {
@@ -29,6 +29,9 @@ module.exports = function(ss, clients, options) {
});
return self.end(html);
};
+ if (typeof locals === 'object') {
+ options.locals = locals;
+ }
try {
client = typeof name === 'string' && clients[name];
if (client == null) {
View
3  lib/client/view.js
@@ -78,5 +78,8 @@ module.exports = function(ss, client, options, cb) {
compress: options.packedAssets,
filename: client.paths.view
};
+ if (options.locals) {
+ htmlOptions.locals = options.locals;
+ }
return asset.html(client.paths.view, htmlOptions, cb);
};
View
6 lib/utils/file.js
@@ -5,7 +5,11 @@ var fs = require('fs'),
exports.readDirSync = function(start) {
try {
// Use lstat to resolve symlink if we are passed a symlink
- var stat = fs.lstatSync(start);
+ // var stat = fs.lstatSync(start);
+
+ // I don't see why to disable symlink
+ var stat = fs.statSync(start);
+
var found = {dirs: [], files: []}, total = 0, processed = 0;
function isHidden(path){ return path.match(/(^_|^\.|~$)/); }
function isDir(abspath) {
View
5 src/client/http.coffee
@@ -21,7 +21,7 @@ res = http.ServerResponse.prototype
module.exports = (ss, clients, options) ->
# Append the 'serveClient' method to the HTTP Response object
- res.serveClient = (name) ->
+ res.serveClient = (name, locals) ->
self = this
@@ -32,6 +32,9 @@ module.exports = (ss, clients, options) ->
})
self.end(html)
+ if typeof(locals) == 'object'
+ options.locals = locals
+
try
client = typeof(name) == 'string' && clients[name]
View
4 src/client/view.coffee
@@ -94,6 +94,10 @@ module.exports = (ss, client, options, cb) ->
# Output HTML
htmlOptions = {headers: includes.join(''), compress: options.packedAssets, filename: client.paths.view}
+
+ if options.locals
+ htmlOptions.locals = options.locals
+
asset.html(client.paths.view, htmlOptions, cb)
View
6 src/utils/file.js
@@ -5,7 +5,11 @@ var fs = require('fs'),
exports.readDirSync = function(start) {
try {
// Use lstat to resolve symlink if we are passed a symlink
- var stat = fs.lstatSync(start);
+ // var stat = fs.lstatSync(start);
+
+ // I don't see why to disable symlink
+ var stat = fs.statSync(start);
+
var found = {dirs: [], files: []}, total = 0, processed = 0;
function isHidden(path){ return path.match(/(^_|^\.|~$)/); }
function isDir(abspath) {
Something went wrong with that request. Please try again.