The thing that worries me about where the template is rendered, is not
so much the template or its semantics, but the model that populates
the variables driving the templates.
However, that being said, if the model boundaries are constrained so
that it can be created and/or exists on either client or server then
processing can take place in either place. In the work we have been
doing elsewhere we have been using client side templates using
trimpath (on google code, not xml friendly), which has a format close
to smarty and velocity, and so could be processed with relative ease
on the server. We have not found the need to process on the server...
mainly because trimpath compiles the template on the client using
string manipulation rather than dom manipulation and so is lightning
fast. It uses eval on the client, but this compilation could be
performed on the server with a dom-less js implementation, so that a
template library could be compiled once on the server and delivered
for rendering in the client... building on the first-class content
type Kevin suggested (if I read that part right).
I can think of a number of ways of delivering client and/or server
side rendering of templates that dont have the performance penalty of
slow operations on the client or the server..... but its very possible
I have missed a real blocker in my reading of the template spec
proposed.
Ian
2008/6/10 Kevin Brown <et...@google.com>:
One observation on reading the template spec, it looks quite simple,
with variables, loops and conditionals and a xml friendly way of
expressing them, so it would be possible to convert them into a
template that could be processed efficiently on the server or the
client. So any of the off the shelf template libraries that have the
necessary concepts could be used for server site.
The thing that worries me about where the template is rendered, is not
so much the template or its semantics, but the model that populates
the variables driving the templates.
However, that being said, if the model boundaries are constrained so
that it can be created and/or exists on either client or server then
processing can take place in either place. In the work we have been
doing elsewhere we have been using client side templates using
trimpath (on google code, not xml friendly), which has a format close
to smarty and velocity, and so could be processed with relative ease
on the server. We have not found the need to process on the server...
mainly because trimpath compiles the template on the client using
string manipulation rather than dom manipulation and so is lightning
fast. It uses eval on the client, but this compilation could be
performed on the server with a dom-less js implementation, so that a
template library could be compiled once on the server and delivered
for rendering in the client... building on the first-class content
type Kevin suggested (if I read that part right).
So what gets delivered to the client is a single compiled template
library for that gadget as a block of text/javascript and the end of a
URL.
In the client templates get invoked as JS calls, though a wrapper
class to isolate the Gadget writer from the compiled template.
On the server the compiled template library is cached with all the
other artifacts associated with the gadget, only recompiled when the
gadget is update or the cache expires, but the same library served to
all used of the gadget.
In terms of processing, the server is compiling rarely and mainly
serving bytes. And the client is processing native code binding to the
open social apis and not interpreting.
Is that what you were thinking of ?
Ian
Fast client-side processing should be possible with the proposal as it stands. Per Ian's note, as long as we avoid DOM manipulation and can precompile the templates, the display can be as fast as we want it to be. <Preload> adds the missing piece.
I think we're going to end up with <Content view="canvas" type="template" href="canvas.tpl"/>, but I don't think we should lock this down yet - there are too many cases where developers need to re-render templates on the client, and I'd like to see usage patterns first. We likely will need a syntax for declaring which external template libraries are used - this should probably go into the <Require> tag as a param.
Regarding server-side processing - there are a few things we'd need to add to make this work:
- Declarative query syntax - you'd need to be able to specify the parameters to a call to newFetchPeopleRequest() declaratively. Chris at MySpace has some good ideas in this area
- Reserved variable namespace for variables that are commonly available, i.e. ${OpenSocial.Viewer}, ${OpenSocial.CurView}, etc.
I agree with Evan -- in the interest of making progress, let's identify the parts of the spec that *preclude* server-side processing and make sure we flag the things where we'll need to add detail (either now or later).
Kevin, is your concern addressed by clarifying which variables the server would need to know in order to process the template?
If the aim is to compile the template on the server so that no
template processing libraries are needed on the client, then variables
that are resolvable and deterministic on the server offer an
opportunity for optimization of the compiled template; but those
variables that are only resolvable on the client or non deterministic
over multiple requests can remain as variables in the compiled
template that is delivered to the client.
Hence the lack of a variable on the server is unlikely to prevent the
compilation of the template, although it could conceivably result in a
compiled template being less efficient.
As long as not expensive or bulky template library is present on the
client, then its all is Ok. I am naively thinking a compiled template
is a javascript function suitably packaged.
Ian
2008/6/11 Kevin Brown <et...@google.com>:
Please tell me if I am being dumb or disruptive here..... (and I will
listen and learn)
If the aim is to compile the template on the server so that no
template processing libraries are needed on the client, then variables
that are resolvable and deterministic on the server offer an
opportunity for optimization of the compiled template; but those
variables that are only resolvable on the client or non deterministic
over multiple requests can remain as variables in the compiled
template that is delivered to the client.
Hence the lack of a variable on the server is unlikely to prevent the
compilation of the template, although it could conceivably result in a
compiled template being less efficient.
As long as not expensive or bulky template library is present on the
client, then its all is Ok. I am naively thinking a compiled template
is a javascript function suitably packaged.
Ian & Kevin answered this well - you can evaluate what's possible on the server and send the rest down to the client.
Also, if the server doesn't support templates or if you are in active dev and want to iterate quickly, you can render only client side - server is mostly for performance and security.
+1
+1 for high-level design
We’re very interested in is the <os:Message> tag, which makes it a whole lot easier to write localized apps. Of course, you can simply pass the current language to your server and handle the message bundles on the backend, but for beginning OpenSocial developers, it provides a standard way of localizing.
Evan, I forget if there is a way to specify a div that your template will process in, similar to Ajax.Updater? For example, opensocial.template.render(‘my-div’, ‘my-template’, myData).
We also mentioned the ability to implicitly use tags in attributes with some sort of “set” tag, for example:
<os:Set var=”tooltip” value=”<os:Message key=”background-color-help”/>
<img title=”${tooltip}” alt=”${tooltip}”/>
And compared to all the injected HTML that is included in an open social app, I don’t think rendering time is much of a challenge, unless you have one huge template. You can break them up and display them as your data comes in, and you update certain sections of your pages like Ajax driven sites. This is possible, correct?
Mike Austin
From: opensocial-an...@googlegroups.com
[mailto:opensocial-an...@googlegroups.com]
On Behalf Of Evan Gilbert
Sent: Monday, June 09, 2008 6:04
PM
To: opensocial-an...@googlegroups.com
Subject: [Spec Proposal]
OpenSocial Templates
I've incorporated feedback from a number of discussions and now am looking for +1s on the high-level design for OpenSocial templates.
+1
From:
opensocial-an...@googlegroups.com [mailto:opensocial-an...@googlegroups.com]
On Behalf Of Evan Gilbert
Sent: Wednesday, June 18, 2008 1:17 PM
To: opensocial-an...@googlegroups.com
Subject: [Spec Proposal] OpenSocial Templates
Hi everyone - I believe we resolved the open issues on the previous thread... all in favor, please +1.
+1 for high-level design
We're very interested in is the <os:Message> tag, which makes it a whole lot easier to write localized apps. Of course, you can simply pass the current language to your server and handle the message bundles on the backend, but for beginning OpenSocial developers, it provides a standard way of localizing.
Evan, I forget if there is a way to specify a div that your template will process in, similar to Ajax.Updater? For example, opensocial.template.render('my-div', 'my-template', myData).
We also mentioned the ability to implicitly use tags in attributes with some sort of "set" tag, for example:
<os:Set var="tooltip" value="<os:Message key="background-color-help"/>
<img title="${tooltip}" alt="${tooltip}"/>
And compared to all the injected HTML that is included in an open social app, I don't think rendering time is much of a challenge, unless you have one huge template. You can break them up and display them as your data comes in, and you update certain sections of your pages like Ajax driven sites. This is possible, correct?
However the one thing that still puzzles me a bit is -how- we are
going to do that. Meaning: how are we going to get these pages to the
gadget?
Either it's a gadget view with a content type='url', however then
there's no social information present on their server, or you pull in
content through makeRequest, but then it's still no simple 'get your
pages (with template tags in it) to the server', they have to be
documents without any head, body etc tags in it (problem 1 when
'hosting your app' on googlepages.com), and probably people who do use
makeRequest will probably want to disable caching since otherwise
nothing is 'generated on their server', which would be a real blow for
the fighting gadget latency perspective.
Perhaps it would be an idea to pull the template out of the view
block, and put it in it's own name space, and have a type=url option
for them too? That would solve at least one of the problems (how are
we going to get 'pages' into the gadget)
That could look something like:
<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs title="Hello World" height="100">
<Require feature="opensocial-0.7"/>
<Require feature="opensocial-templates"/>
</ModulePrefs>
<Templates>
<template name="example-one">
<div style="font-size: 20px">Hello world!</div>
</template>
<template url="http://myhost.com" name="example-two"/>
<template url="http://myhost.com" name="example-three"
authz="signed"/>
</Templates>
<Content type="html">
<![CDATA[
<script type="text/javascript">
// loadSocialData() is a function that calls OpenSocial APIs
and returns your data
loadSocialData(function(socialData) {
opensocial.template.processAll(socialData);
});
</script>
]]>
</Content>
</Module>
It wouldn't be a complete solution, but atleast brings us a step
closer to our goal of simplicity for (ex) FBML users :)
-- Chris
We have the requisite number of +1s here.
However, there are still are two separate group threads I'd like to touch base on before claiming consensus:
- Reinoud had a concern about undefined escaping semantics. Resolution was that we will escape strings based on context, and add full details on escaping semantics before the spec is complete. I updated http://groups.google.com/group/opensocial-and-gadgets-spec/web/expressions with details.
- There also is an active markup discussion, covering a number of topics:
- My key takeaway was that we need to support a model in OpenSocial where developers dynamically create HTML / markup from their own servers. I believe that we can define a subset of the full templating spec that is useable for these cases.
- This thread also touched on alternative templating syntax choices (XSL, PHP were mentioned). I couldn't tell if these
Yea that would be a more consistent naming indeed :)People could have 'static' html files included with a normal type="html" href="foo", which already makes live a lot easier for the hobbyists with a great idea and googlepages.com.However if you also add a signed option to it, you would force dynamically loaded / non cached files (signed requests are never cached) .. at least you would have the container, owner and viewer available on your gadget's server (ie: the gadget developers server), and they could output content including the opensocial template tags which then get filled in by the gadget server.. and you have a pretty much working system that allows a more classic development style?
On Wed, Jun 25, 2008 at 5:02 PM, Chris Chabot <cha...@xs4all.nl> wrote:Yea that would be a more consistent naming indeed :)People could have 'static' html files included with a normal type="html" href="foo", which already makes live a lot easier for the hobbyists with a great idea andgooglepages.com.However if you also add a signed option to it, you would force dynamically loaded / non cached files (signed requests are never cached) .. at least you would have the container, owner and viewer available on your gadget's server (ie: the gadget developers server), and they could output content including the opensocial template tags which then get filled in by the gadget server.. and you have a pretty much working system that allows a more classic development style?
That's exactly my proposal, actually:
<Content type="html" href="app.php" authz="signed"/>
Viola, mainstream web development.
As long as we parse the document and inject it into it ... yep that
would work great and save some error margin.
I'm actually really excited about this, this sounds like a great
solution for all the cases we discussed, and has the potential to be
really, really fast too.
If we could make the gadget server smart enough to recognize the
social information it required to complete the template (by looking at
the tags it needs to process) and request those from the social
server, it could even fill those in tags server sided, and lead to the
'server sided processing' people have been clamoring for.
-- Chris
Chris / Kevin - I really like the spec extensions you're proposing - we definitely need to support a model in OpenSocial where developers dynamically create HTML / markup from their own servers.
Part of the reason the proposal needs to make things work in an AJAXy model is that's how *all* OpenSocial apps are built today.
We need a bridge to a new model instead of having people throw away all of the code they just built because we told them that this is how OpenSocial works. A solution that didn't address this pain point would negligent (the examples at http://docs.google.com/Presentation?id=dg6csr2s_5cgx7bkhf seem pretty compelling to me).
Even for advanced developers, having templates that can be rendered without going to 3rd party servers may be important for performance:
- Containers may require cached markup for profile views. This can't be flexibly personalized without templating
- Developers may want faster canvas views by using app data + templating. Even if a developer has their own servers, they might push data into the container so that canvas views don't make a round trip.
- Note: the round trip is *very* slow, because it goes from browser -> container -> developer server -> RESTful API to container -> developer server -> container -> browser (6 hops).
I agree that the proposal is a superset of what is needed (on the templating/markup side) for the use case where developers create HTML/markup on their own servers. However I think it supports this use case with the extensions you both are proposing as well as supporting the existing AJAXy model.
Sounds reasonable and correct. So a 'template' could probably look like:
<html><body>
<os:PreloadData key="Viewer" type="VIEWER" params="..."/>
<os:PreloadData key="Owner" type="OWNER" params="..."/>
Hello <os:ShowPerson person="${Viewer.Name.UNSTRUCTURED}"/> welcome on
<os:ShowPerson person="${Owner.Name.UNSTRUCTURED}"/>'s hello world
gadget.
</body></html>
If so, that sounds great tbh. Plus this can be implemented both server
and client side, so hits all the right notes for me!
-- Chris
Yep, let us code. +1
Kevin kicked off a very productive discussion on another thread, quick summary is that we want to support a "proxied" mode that sends a request through to gadget developer's servers every time.
I think the template proposal as it stands works for "proxied" mode. We will have a choice to make whether proxied mode supports full flow control (i.e. if/repeat statements), but I'd like to defer that discussion to the proxied-mode thread if possible. The core syntax and extensibility model seem to work well both for proxied and non-proxied mode.
Chris - for your example I think some form of data request syntax is appropriate, i.e. <os:PreloadData key="Viewer" type="VIEWER" params="..."/>. Although "Viewer" could be automatically determined, as soon as we make requests for friends or app data we need the developer to specify the input parameters, so I don't think this is onerous. Chris Bissell (@ MySpace) has been thinking about this issue I think should have a proposal ready for the group soon.
So... have we resolved open issues on the high-level design? We can tweak the syntax and tags as we go, but I'd like to lock on the high-level agreement so we can start iterating in code to find the real issues.
On Mon, Jun 30, 2008 at 10:05 AM, Evan Gilbert <uid...@google.com> wrote:Kevin kicked off a very productive discussion on another thread, quick summary is that we want to support a "proxied" mode that sends a request through to gadget developer's servers every time.
I think the template proposal as it stands works for "proxied" mode. We will have a choice to make whether proxied mode supports full flow control (i.e. if/repeat statements), but I'd like to defer that discussion to the proxied-mode thread if possible. The core syntax and extensibility model seem to work well both for proxied and non-proxied mode.
Chris - for your example I think some form of data request syntax is appropriate, i.e. <os:PreloadData key="Viewer" type="VIEWER" params="..."/>. Although "Viewer" could be automatically determined, as soon as we make requests for friends or app data we need the developer to specify the input parameters, so I don't think this is onerous. Chris Bissell (@ MySpace) has been thinking about this issue I think should have a proposal ready for the group soon.
So... have we resolved open issues on the high-level design? We can tweak the syntax and tags as we go, but I'd like to lock on the high-level agreement so we can start iterating in code to find the real issues.
I do wonder if certain elements are necessary at all if we support templates as a more "first class" part of the spec -- specifically:
- Do we need the JavaScript element? (why not just script tags?)
- Is the js bootstrapping necessary? (it could juts be a "standard" thing that gets done automatically)
Also, I'm still unconvinced about the need for two different ways to do many of the operators (flow control + localization). Can you explain why we need both attributes and tags for this? It's my understanding that you went with attributes in the interest of making a cleaner schema, but the tags are in there now anyway, so it seems like that's not an important issue anymore. Do we really need the attributes?
responses below...On Mon, Jun 30, 2008 at 3:05 PM, Kevin Brown <et...@google.com> wrote:On Mon, Jun 30, 2008 at 10:05 AM, Evan Gilbert <uid...@google.com> wrote:Kevin kicked off a very productive discussion on another thread, quick summary is that we want to support a "proxied" mode that sends a request through to gadget developer's servers every time.
I think the template proposal as it stands works for "proxied" mode. We will have a choice to make whether proxied mode supports full flow control (i.e. if/repeat statements), but I'd like to defer that discussion to the proxied-mode thread if possible. The core syntax and extensibility model seem to work well both for proxied and non-proxied mode.
Chris - for your example I think some form of data request syntax is appropriate, i.e. <os:PreloadData key="Viewer" type="VIEWER" params="..."/>. Although "Viewer" could be automatically determined, as soon as we make requests for friends or app data we need the developer to specify the input parameters, so I don't think this is onerous. Chris Bissell (@ MySpace) has been thinking about this issue I think should have a proposal ready for the group soon.
So... have we resolved open issues on the high-level design? We can tweak the syntax and tags as we go, but I'd like to lock on the high-level agreement so we can start iterating in code to find the real issues.
I do wonder if certain elements are necessary at all if we support templates as a more "first class" part of the spec -- specifically:
- Do we need the JavaScript element? (why not just script tags?)
For standalone XML tag libraries, this is needed. If you're embedding templates, you can just use <script type="text/javascript"> in a separate block on the page.
- Is the js bootstrapping necessary? (it could juts be a "standard" thing that gets done automatically)
There are two bootstrap pieces, I think we should support both but also work towards an XML-only variant.
The bootstrap pieces:
- <script type="text/os-template">. It is a strong goal for templating to be possible in standalone HTML pages with just the inclusion of a JS library. For this to work, all XML tags need to be inside an unprocessable HTML element (<script> or <xmp> were the two we found).
- opensocial.template.processAll(). We definitely need the ability to render templates from JavaScript (for AJAXy solutions and just for testing), and currently there isn't an <os:PreloadData> call. Seemed to be a good starting point to attach templates to the existing JS API
The XML variant (roughly)
- <Content type="text/os-template"> with only XML content. This would both avoid the <script> tag and processAll() call.
- Note that this requires equivalent of<os:PreloadData key="Viewer" type="VIEWER" params="..."/>
Also, I'm still unconvinced about the need for two different ways to do many of the operators (flow control + localization). Can you explain why we need both attributes and tags for this? It's my understanding that you went with attributes in the interest of making a cleaner schema, but the tags are in there now anyway, so it seems like that's not an important issue anymore. Do we really need the attributes?
There are enough people passionate on both sides that it seemed to make sense to just support both. We had a breakout session on OpenSocial templates at the OpenSocial API summit, and everyone seemed to think this was a fair compromise and it wasn't too confusing.
Here's the quick list of pros on each side:
Attributes
- Less typing
- Don't require an extra level of nesting
- May allow for schema validation
Elements
- People are more familiar with elements
- Close to necessary for a couple of use cases.
Having written a lot of XSL code, I would not be in favor of an element-only solution (happy to paste some examples in if this would help clarify :))
Hi,
I would like to know, why the spec should be taking care of templates, when they are already implemented in some JS toolkits as Prototype for example.
On Wed, Jun 18, 2008 at 2:58 PM, Mike Austin <mau...@hi5.mi8.com> wrote:+1 for high-level design
We're very interested in is the <os:Message> tag, which makes it a whole lot easier to write localized apps. Of course, you can simply pass the current language to your server and handle the message bundles on the backend, but for beginning OpenSocial developers, it provides a standard way of localizing.
Evan, I forget if there is a way to specify a div that your template will process in, similar to Ajax.Updater? For example, opensocial.template.render('my-div', 'my-template', myData).
We definitely need to support this functionality, the specific API signature isn't specified. There are a number of these JS API details that I hope can be fleshed out and proposed back into the spec as we work through the implementation.
We also mentioned the ability to implicitly use tags in attributes with some sort of "set" tag, for example:
<os:Set var="tooltip" value="<os:Message key="background-color-help"/>
<img title="${tooltip}" alt="${tooltip}"/>
Definetely want to support a <Set> tag, not positive we need it in first iteration.
The idea I was thinking for localizable attributes was to use on of the following mechanisms, hidden under nicer API:
Load using a message ID:<img oncreate="this.title=opensocial.template.renderMessage('background-color-help');/>,
Or if you need default text, Load from contents of another element:<img oncreate="this.title = document.getElementById('img-text').innerHTML"/>
<div style="display-none" id="img-text"><os:Message key="background-color-help">Hello</os:Message></div>
For common use cases, we can hide these under OpenSocial tags:<os:Image src="...">
<os:Title msg="background-color-help">Some default text</os:Title>
</os:Image>
Is this sufficient to handle the messaging use cases?
And compared to all the injected HTML that is included in an open social app, I don't think rendering time is much of a challenge, unless you have one huge template. You can break them up and display them as your data comes in, and you update certain sections of your pages like Ajax driven sites. This is possible, correct?
Yes, app developer has flexibility to do this. Depending on how the data comes in, it may make sense to wait for all the data and render once, or if there are straggler requests to render in stages.
The rendering time should be good in JS but needs to be watched - creating HTML using JavaScript can be shockingly slow
From: opensocial-an...@googlegroups.com [mailto:opensocial-an...@googlegroups.com] On Behalf Of Evan Gilbert
Sent: Monday, June 09, 2008 6:04 PM
To: opensocial-an...@googlegroups.com
Subject: [Spec Proposal] OpenSocial Templates
I've incorporated feedback from a number of discussions and now am looking for +1s on the high-level design for OpenSocial templates.
Spec proposal: http://groups.google.com/group/opensocial-and-gadgets-spec/web/opensocial-templates
Single document version: http://docs.google.com/Doc?id=dg6csr2s_3gttjwjzz
The definition of <os:> tags is not covered yet - we will cover each tag as a separate spec enhancement, and I expect there to be a fair number clarifications and minor revisions to the proposal over the course of implementation.
Thanks for all the feedback, and looking forward to getting templates up and running!
Evan
Thanks for the (2nd) prompt. I've been using OpenSocial templates for
over a month now and have nothing but good things to say about the
current spec and implementation. Thanks to the folks behind the
templates effort for some very useful tech.
> Is it using templates inside a gadget? Is it using the templates
> as per the spec below?
Yes. Except for our Admin Console, all UI in SocialSite is implemented
as OpenSocial Gadgets. Our newest Gadgets use OpenSocial templates and
YUI components and I've been very happy with the results. Our Gadget
code is much easier to write, understand and maintain now. Here are
some examples.
First, our Dashboard, which allows a user to browse and interact with
friends, groups, activities and messages. You can send messages,
create groups, request and accept friendships. This is all implemented
via the SocailSite API, OpenSocial templates and YUI.
More information about the Dashboard and screenshots here:
http://blogs.sun.com/socialsite/entry/a_little_more_about_socialsite
http://blogs.sun.com/socialsite/resource/dashboard-activities.png
http://blogs.sun.com/socialsite/resource/dashboard-people.png
Code for the Dashboard here:
dashboard.xml - http://tinyurl.com/5zms2g
dashboard.js - http://tinyurl.com/56w295
And second, we have a Gadget Directory, which allows you to browse
available Gadgets and install them for either a user or for a group
(we support Gadgets "owned" by a group via the SocialSite API). This
is templates and YUI too:
Screenshot of the Gadget Directory
http://www.flickr.com/photos/snoopdave/3059025664
Code for the Gadget Directory
gadget_directory.xml - http://tinyurl.com/5blb47
gadget_directory.js - http://tinyurl.com/69o4c4
I haven't used any template library features yet, so I can't comment
on them, but I suspect they'll be very helpful as we rewrite more of
our Gadgets to use templates. Same goes for I18N.
- Dave
> ---------- Forwarded message ----------
> From: Lane LiaBraaten <llia...@google.com>
> Date: Wed, Nov 26, 2008 at 10:20 AM
> Subject: [opensocial-and-gadgets-spec] Re: [Spec Proposal] OpenSocial
> Templates