Markuper: The Opera Unite Service template library

Forums » Dev.Opera » Archived Article Discussions

This topic has been closed. No new entries allowed.

Reason: You can now post comments on articles on Dev Opera

Forum rules and guidelines

You need to be logged in to post in the forums. If you do not have an account, please sign up first.

Go to last post

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 )

16. June 2009, 11:36:49

exclipy

Posts: 45

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".

16. June 2009, 15:00:32

Opera Software

chrismills

Posts: 379

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!
Chris Mills
Developer Relations Manager
Editor, dev.opera.com and labs.opera.com

18. June 2009, 10:05:10

brothermouzone

Posts: 1

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

18. June 2009, 16:53:13

Opera Software

chrismills

Posts: 379

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.
Chris Mills
Developer Relations Manager
Editor, dev.opera.com and labs.opera.com

25. June 2009, 14:42:22

Opera Software

chrismills

Posts: 379

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.
Chris Mills
Developer Relations Manager
Editor, dev.opera.com and labs.opera.com

28. June 2009, 21:31:08

ZeBrian

Posts: 2

Hello,

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

29. June 2009, 13:58:03

Opera Software

chrismills

Posts: 379

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.
Chris Mills
Developer Relations Manager
Editor, dev.opera.com and labs.opera.com

6. July 2009, 14:02:35

Akbalder

Posts: 59

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.

7. July 2009, 06:40:48

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

7. July 2009, 06:44:53

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.

7. July 2009, 09:31:14

Akbalder

Posts: 59

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 ?

7. July 2009, 09:56:08

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.

13. July 2009, 12:06:23

ZeBrian

Posts: 2

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!

16. July 2009, 08:12:02

Akbalder

Posts: 59

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>

16. July 2009, 09:42:02

Originally posted by Akbalder:

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


  {{peoples[].name}}
  
    {{peoples[].phones[].desc}} : {{peoples[].phones[].value}}



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

16. July 2009, 15:37:26

Originally posted by Akbalder:

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


  {{peoples[].name}}
  
    {{peoples[].phones[].desc}} : {{peoples[].phones[].value}}



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).

19. July 2009, 05:59:25

itanka

Posts: 3

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

{{foo[0].bar}}

19. July 2009, 09:11:00

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.

25. August 2009, 00:10:41

lucideer

a B person

Posts: 5114

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('.') );

25. August 2009, 06:44:37

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 sad

25. August 2009, 14:57:18

lucideer

a B person

Posts: 5114

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 :frown:


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

25. August 2009, 15:21:54

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

25. August 2009, 16:00:44

lucideer

a B person

Posts: 5114

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

26. August 2009, 07:38:26

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.

27. August 2009, 16:34:39

lucideer

a B person

Posts: 5114

Thanks.

16. November 2009, 13:03:36

ELV1S

Posts: 46

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(/{{.*}}/, '');
My code on bitbucket and github. My UserCSS and UserJS.

16. November 2009, 13:17:44

Hi,

Thank you for your comment.
It's actually a feature bigsmile {{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(/{{.*}}/, '');

21. November 2009, 12:03:33

ELV1S

Posts: 46

antonioafonso
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?
My code on bitbucket and github. My UserCSS and UserJS.

21. November 2009, 22:27:14

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.

27. November 2009, 20:56:22

ELV1S

Posts: 46

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?
My code on bitbucket and github. My UserCSS and UserJS.

28. November 2009, 01:20:42

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">

29. November 2009, 03:02:38

ELV1S

Posts: 46

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?
My code on bitbucket and github. My UserCSS and UserJS.

29. November 2009, 12:28:48

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

29. November 2009, 14:38:58 (edited)

ELV1S

Posts: 46

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.
My code on bitbucket and github. My UserCSS and UserJS.

29. November 2009, 15:30:05

I 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.

29. November 2009, 16:59:25

lucideer

a B person

Posts: 5114

This 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.

29. November 2009, 18:20:43

ELV1S

Posts: 46

lucideer
I agree. But I don't want to wait years until spec changes :-)
My code on bitbucket and github. My UserCSS and UserJS.

Forums » Dev.Opera » Archived Article Discussions