Dev.Opera - Follow the standards, break the rulesDev.Opera - Follow the standards, break the rules

Login

Lost password?

Forums » Article Discussions

Discuss the articles posted on Dev.Opera.

Note: You need to login to post in the forums. if you don't have an account you first need to sign up.

By antonioafonso O anchor Tuesday, 16. June 2009, 07:01:47

Markuper: The Opera Unite Service template library

This article introduces Markuper, a templating library that allows rapid development of Opera Unite applciations and binding of data from JavaScript straight into the HTML templates.

( Read the article )

By exclipy anchor Tuesday, 16. June 2009, 11:36:49

avatarAn error in the article: in the section "Using JavaScript variables in the Template", the template has the "name" field set to "Template". However, the output shows the corresponding substitution to be "Markuper".

By chrismills O anchor Tuesday, 16. June 2009, 15:00:32

avatar

Originally posted by exclipy:

An error in the article: in the section "Using JavaScript variables in the Template", the template has the "name" field set to "Template". However, the output shows the corresponding substitution to be "Markuper".



Fixed this - thanks!

By brothermouzone anchor Thursday, 18. June 2009, 10:05:10

avatar"It also violates abstraction layers, between logic and separation"...shouldn't that read "presentation" and not "separation"??

By chrismills O anchor Thursday, 18. June 2009, 16:53:13

avatar

Originally posted by brothermouzone:

"It also violates abstraction layers, between logic and separation"...shouldn't that read "presentation" and not "separation"??



Yup - you're right! I've changed it now - thanks for pointing that out.

By dantesoft anchor Thursday, 25. June 2009, 13:39:22

avatarSome anchors are linked to http://ops/svn/proj/alien/documentation/api-ref/

By chrismills O anchor Thursday, 25. June 2009, 14:42:22

avatar

Originally posted by dantesoft:

Some anchors are linked to http://ops/svn/proj/alien/documentation/api-ref/



Aaaargh - sorry about that! I've pointed them to the right place now.

By ZeBrian anchor Sunday, 28. June 2009, 21:31:08

avatarHello,

I've read this article and I have some questions... First of all, none of the example codes seem to be accessible, I only get 404 errors, why is that? Also, I tried to use the Markuper function, but my webpage just keeps loading without any error message (no firewall problem, and the issue is both on Linux and Windows). To see my source code : http://web2master.com/unite/test.zip

Am I doing something wrong?

Thanks,


Brian

By chrismills O anchor Monday, 29. June 2009, 13:58:03

avatar

Originally posted by ZeBrian:

I've read this article and I have some questions... First of all, none of the example codes seem to be accessible, I only get 404 errors, why is that? Also, I tried to use the Markuper function, but my webpage just keeps loading without any error message (no firewall problem, and the issue is both on Linux and Windows). To see my source code : http://web2master.com/unite/test.zip




My apologies - I have no idea how those paths got messed up. Fixed now - let me know if you have any more luck now you can get to the example code.

By Akbalder anchor Monday, 6. July 2009, 14:02:35

avatarIt seems that in a template, we have to write something like {{data.name}} instead of {{name}}.
If I'm right, there are a few things to correct within the article.

By antonioafonso O anchor Tuesday, 7. July 2009, 06:40:48

avatar

Originally posted by ZeBrian:

I tried to use the Markuper function, but my webpage just keeps loading without any error message (no firewall problem, and the issue is both on Linux and Windows). To see my source code : http://web2master.com/unite/test.zip

Am I doing something wrong?

Thanks,


Brian


Hi Brian,

First of all, thanks for your feedback.
I took at look at your code and what's missing is the inclusion of the template library itself with
<script src="script/template.js"></script>
on the index.html if you put the template.js in the script/ directory.
However you should have seen this error message (as I saw when I tested your code):
message: Statement on line 16: Undefined variable: Markuper

By antonioafonso O anchor Tuesday, 7. July 2009, 06:44:53

avatar

Originally posted by Akbalder:

It seems that in a template, we have to write something like {{data.name}} instead of {{name}}.
If I'm right, there are a few things to correct within the article.



All variables given on the Markuper contructor are accessible without a "namespace" i.e. {{name}} instead of {{data.name}}.
But the object given to the parse() function will be "plugged" under the data namespace, making you having to prefix your variable accesses with a data. namespace.
Example:
var tmpl = new Markuper( 'template.html', {name1: 'value1'} );
tmpl.parse( {name2: 'value2'} );

In template.html you'll have to use {{name1}} and {{data.name2}} to access those variables given in the constructor and parse() function respectively.

By Akbalder anchor Tuesday, 7. July 2009, 09:31:14

avatarThanks for your answer.
Using a different namespace depending on the way we call the template is a bit strange !
Is there a reason for that ?

By antonioafonso O anchor Tuesday, 7. July 2009, 09:56:08

avatar

Originally posted by Akbalder:

Thanks for your answer.
Using a different namespace depending on the way we call the template is a bit strange !
Is there a reason for that ?


It's not how you call the template, it's on creation and on parsing.
I wanted to be able to parse the document using different data while maintaing some "global" data.
The one you give on construction is the root one and the most important, you probably only want to use that.
The different namespace might be useful if you want to give the template to a third party like we do in Yusef and don't want any name clashing.

By ZeBrian anchor Monday, 13. July 2009, 12:06:23

avatar

Originally posted by antonioafonso:

Originally posted by ZeBrian:

I tried to use the Markuper function, but my webpage just keeps loading without any error message (no firewall problem, and the issue is both on Linux and Windows). To see my source code : http://web2master.com/unite/test.zip

Am I doing something wrong?

Thanks,


Brian


Hi Brian,

First of all, thanks for your feedback.
I took at look at your code and what's missing is the inclusion of the template library itself with
<script src="script/template.js"></script>
on the index.html if you put the template.js in the script/ directory.
However you should have seen this error message (as I saw when I tested your code):
message: Statement on line 16: Undefined variable: Markuper



Thanks for your answer, you were right :smile: I thought this was a built-in library which comes with the File I/O API. Maybe a direct link to template.js from the article would make it even clearer?

Thanks for your time!

By Akbalder anchor Thursday, 16. July 2009, 08:12:02

avatarI tried to nest data-lists.
It doesn't seem to function.
Is it possible ?

<p data-list="peoples">
  {{peoples[].name}}
  <ul>
    <li data-list="peoples[].phones">
      {{peoples[].phones[].desc}} : {{peoples[].phones[].value}}
    </li>
  </ul>
</p>

By antonioafonso O anchor Thursday, 16. July 2009, 09:42:02

avatar

Originally posted by Akbalder:

I tried to nest data-lists.
It doesn't seem to function.
Is it possible ?

<p data-list="peoples">
  {{peoples[].name}}
  <ul>
    <li data-list="peoples[].phones">
      {{peoples[].phones[].desc}} : {{peoples[].phones[].value}}
    </li>
  </ul>
</p>



It should work, I'll give it a look.

By antonioafonso O anchor Thursday, 16. July 2009, 15:37:26

avatar

Originally posted by Akbalder:

I tried to nest data-lists.
It doesn't seem to function.
Is it possible ?

<p data-list="peoples">
  {{peoples[].name}}
  <ul>
    <li data-list="peoples[].phones">
      {{peoples[].phones[].desc}} : {{peoples[].phones[].value}}
    </li>
  </ul>
</p>



Of course, I didn't notice at the time, you have a block element (<ul>) inside a paragraph (<p>) which is not allowed by the HTML spec:

Originally posted by http://www.w3.org/TR/html401/struct/text.html#h-9.3.1:


The P element represents a paragraph. It cannot contain block-level elements (including P itself).

By itanka anchor Sunday, 19. July 2009, 05:59:25

avatarIs it possible to address to variables in the following way?

{{foo[0].bar}}

By antonioafonso O anchor Sunday, 19. July 2009, 09:11:00

avatar

Originally posted by itanka:

Is it possible to address to variables in the following way?

{{foo[0].bar}}

Hi, not yet, in the near future.

By lucideer anchor Tuesday, 25. August 2009, 00:10:41

avatarSeems to be an error on line 319 (in the version that I downloaded just now):
            return argument.callee( data[keys[0]], keys.slice(1).join('.') );

should be
            return arguments.callee( data[keys[0]], keys.slice(1).join('.') );

By antonioafonso O anchor Tuesday, 25. August 2009, 06:44:37

avatar

Originally posted by lucideer:

Seems to be an error on line 319 (in the version that I downloaded just now):

            return argument.callee( data[keys[0]], keys.slice(1).join('.') );

should be
            return arguments.callee( data[keys[0]], keys.slice(1).join('.') );


wow, you're absolutely right, I'm amazed no one noticed it before :|
That is a very old version of Markuper btw, we haven't had the time to update the documentation for the latest revisions, I'm sorry :frown:

By lucideer anchor Tuesday, 25. August 2009, 14:57:18

avatar

Originally posted by antonioafonso:

That is a very old version of Markuper btw, we haven't had the time to update the documentation for the latest revisions, I'm sorry <IMG class="smilie" src="/community/graphics/smilies/frown.gif" alt=":frown:" width="17" height="17">


Any chance we could get the latest version sans-documentation anyway?

By antonioafonso O anchor Tuesday, 25. August 2009, 15:21:54

avatar

Originally posted by lucideer:

Any chance we could get the latest version sans-documentation anyway?


Well, you can get it from the latest services on unite.opera.com

By lucideer anchor Tuesday, 25. August 2009, 16:00:44

avatar

Originally posted by antonioafonso:

Well, you can get it from the latest services on unite.opera.com


Thank you. I'll try it later on - any chance of a brief informal changelog? :wink:

By antonioafonso O anchor Wednesday, 26. August 2009, 07:38:26

avatar

Originally posted by lucideer:

Originally posted by antonioafonso:

Well, you can get it from the latest services on unite.opera.com


Thank you. I'll try it later on - any chance of a brief informal changelog? :wink:

If memory serves me right they were mostly bugfixing, but the new features that I have here on the timeline are:

* ternary operation like: {{expr ? true [: false]}}
* hability to add data- attributes with wildcards like data-*-attribute (meaning that when you register a data attribute using this string every attribute with this name scheme - data-<something>-attribute - will make the callback be called)
* data-*-attribute to create attributes <p data-style-attribute="key"> will create the style attribute with the contents of key, if key is undefined the attribute will not be created so you can do stuff like data-class-attribute="key ? className" that wil add class="<className>" if there is such a key.

I hope this can answer your question.

By lucideer anchor Thursday, 27. August 2009, 16:34:39

avatarThanks.

By ELV1S anchor Monday, 16. November 2009, 13:03:36

avatarI found a bug.

var template = new Markuper('templates/index.html', {});
e.connection.response.write( template.parse().html() );
e.connection.response.close();

templates/index.html:
Hi {{username}}

Output will be "Hi {{username}}" because variable username not passed to template.

I think it's wrong. User should never see template variables such as {{username}}. I've fixed it:
975a976
>                     node.textContent = node.textContent.replace(/{{.*}}/, '');

By antonioafonso O anchor Monday, 16. November 2009, 13:17:44

avatarHi,

Thank you for your comment.
It's actually a feature :D {{key}}'s that turn out to be non-existent are not parsed on purpose.
I guess I'll add a parameter to parse() where you can specify that as an option!

Originally posted by ELV1S:

I found a bug.

var template = new Markuper('templates/index.html', {});
e.connection.response.write( template.parse().html() );
e.connection.response.close();

templates/index.html:
Hi {{username}}

Output will be "Hi {{username}}" because variable username not passed to template.

I think it's wrong. User should never see template variables such as {{username}}. I've fixed it:
975a976
>                     node.textContent = node.textContent.replace(/{{.*}}/, '');

By ELV1S anchor Saturday, 21. November 2009, 12:03:33

avatarantonioafonso
Could you put Markuper to some public repository such as github or bitbucket?

I don't see progress on this library. http://dev.opera.com/libraries/markuper/markuper.js has version 0.3, but latest fileSharing.ua bundled with template.js version 0.5. What changed? Why this link http://dev.opera.com/libraries/markuper/markuper.js not updated?

By antonioafonso O anchor Saturday, 21. November 2009, 22:27:14

avatar

Originally posted by ELV1S:

antonioafonso
Could you put Markuper to some public repository such as github or bitbucket?


Maybe in the future :smile:, but not for now no..

Originally posted by ELV1S:


I don't see progress on this library. http://dev.opera.com/libraries/markuper/markuper.js has version 0.3, but latest fileSharing.ua bundled with template.js version 0.5. What changed? Why this link http://dev.opera.com/libraries/markuper/markuper.js not updated?


Yeah, there were quite some changes, those documents will be updated very soon.

By ELV1S anchor Friday, 27. November 2009, 20:56:22

avatar
var template = new Markuper('template.html', {is_checked: 'checked'});
e.connection.response.write( template.parse().html() );


template.html:
<input type="checkbox" {{is_checked}}>


Output will be '<input type="checkbox" {{is_checked}}>', not '<input type="checkbox" checked>' as I expected. Checkbox will be unchecked.

So, how could I deal with checkboxes?

By antonioafonso O anchor Saturday, 28. November 2009, 01:20:42

avatar

Originally posted by ELV1S:

var template = new Markuper('template.html', {is_checked: 'checked'});
e.connection.response.write( template.parse().html() );


template.html:
<input type="checkbox" {{is_checked}}>


Output will be '<input type="checkbox" {{is_checked}}>', not '<input type="checkbox" checked>' as I expected. Checkbox will be unchecked.

So, how could I deal with checkboxes?

With:
<input type="checkbox" checked="{{is_checked}}">

But what you really want is something like
<input type="checkbox" data-set-checked-attribute="is_checked">

By ELV1S anchor Sunday, 29. November 2009, 03:02:38

avatar

Originally posted by antonioafonso:

With:

<input type="checkbox" checked="{{is_checked}}">


This doesn't work.
checked="" --> checked
checked="off" --> checked
checked="whatever" --> checked


Originally posted by antonioafonso:

But what you really want is something like <input type="checkbox" data-set-checked-attribute="is_checked">


Should I make this work via registerDataAttribute? It's a little bit complicated for this task, isn't it?

By antonioafonso O anchor Sunday, 29. November 2009, 12:28:48

avatar

Originally posted by ELV1S:

This doesn't work. checked="" --> checked
checked="off" --> checked
checked="whatever" --> checked


Correct, it was just an example.

Originally posted by ELV1S:

Should I make this work via registerDataAttribute? It's a little bit complicated for this task, isn't it?


It's already there...
(registerDataAttribute( 'set-*-attribute', ...)

I've noticed that the version in dev.opera.com is very very old (v0.3 while we're using v0.5) I'll see what I can do regarding that as I'm not the maintainer of those docs/libs.
In the meanwhile I've uploaded the latest version here: http://files.myopera.com/antonioafonso/unite/template.js

Sorry for the inconvenience.
In the future you can post dev related questions/comments here http://dev.opera.com/forums/forum/15906

By ELV1S anchor Sunday, 29. November 2009, 14:10:03

avatar

Originally posted by antonioafonso:

<input type="checkbox" data-set-checked-attribute="is_checked">

This doesn't work either.

{is_checked: 'checked'}

<input type="checkbox" data-set-checked-attribute="is_checked"> --> <input type="checkbox" checked="checked"> --> Checkbox checked



{is_checked: ''}

<input type="checkbox" data-set-checked-attribute="is_checked"> --> <input type="checkbox" checked=""> --> Checkbox checked again!


I think <input {{is_checked}}> should work. It's simple and easy to discover instead of data-do-something-with-attribute="is_checked". I'm planning to patch Markuper to do so.


Originally posted by antonioafonso:

In the future you can post dev related questions/comments here http://dev.opera.com/forums/forum/15906

OK, my next comment will be there.

Post edited Sunday, 29. November 2009, 14:38:58

By antonioafonso O anchor Sunday, 29. November 2009, 15:30:05

avatarI believe it will only omit the attribute if is_checked doesn't exist.

Originally posted by ELV1S:

I think <input {{is_checked}}> should work. It's simple and easy to discover instead of data-do-something-with-attribute="is_checked". I'm planning to patch Markuper to do so.


It's just a matter of reading the documentation :smile: Unfortunately there is no up to date documentation :\ so it's to anyone's guess..
I'll incorporate your patch if you make it available.

By lucideer anchor Sunday, 29. November 2009, 16:59:25

avatarThis issue with checkboxes is really more of an issue with the html spec, than with the Markuper library. Some form of <input type="checkbox" checked="false"/> (or something similar) has been requested fairly often by the web development community for some time - it's a massive oversight.

By ELV1S anchor Sunday, 29. November 2009, 18:20:43

avatarlucideer
I agree. But I don't want to wait years until spec changes :-)

Moderators: pepelsbey | dstorey | mcx | operadev | chrismills | shwetankdixit | brucelawson | iheni | andreasbovens | zibin | mollydotcom