3/14/2009

携帯電話を変更しました

僕は何ヶ月かに一度の割合で長期の休みを取るのですが、今日から恒例の大型連休に入りました。
父親に、「今日からしばらく OFF です」、と話をしたところ、「俺の若い頃は月に一度しか休まず働いた」、と呆れられてしまいました笑

さて、プライベート携帯電話の機種変更をしました。
これまで利用していた AU を思いきって解約し、Softbank の iPhone (8GB) にしました。
外出時に iPod と、携帯電話の 2 つのデバイスを持って行動することを鬱陶しく感じていましたし、今の時期に国内の携帯電話を持たず、iPhone だけで生活すると、どの程度の便利さ、あるいは不便さを感じるのかを、身をもって知りたかったこともありました。

まだ 1 日しか経っていませんが、想像していたより遥かに快適に iPhone を利用できています。
携帯電話自体の完成度、サポートは今のところ国内の携帯電話に軍配が上がりますが、Apple が開発環境を世界中の開発者に開放してくれたおかげで、アプリケーションの数が多く、またその幅も広いため、僕にとっては、すぐにこれまで利用していた携帯電話の何倍もの価値を提供してくれるデバイスにカスタマイズできました (いまのところ、無料のアプリケーションしか利用していません)。
iPhone OS のアップデートサイクルは (国内の携帯電話と比較すると) 大変早いため、現在の不便もすぐに解決されていくでしょうし、すぐに強い相棒になってくれそうです。

利用しているキャリアを変更したため、メールアドレスが変更になりましたので、すぐにでも連絡先をお知らせしたいのですが、iPhone は今のところ、文字のコピーがサポートされていないこともあり、沢山のメール打つのが非常に大変で、連絡を送信するまで、何日かかかってしまうと思います。
電話番号はこれまでと変更ありませんので、もし連絡等ございましたら、しばらくはお手数ですが、電話にてお願い致します。

iPhone より撮影。
作り中の曲の構成を書いていく山本さん。
スタジオにて。

3/12/2009

Convert template string to HTML for JavaScript

Hi, long time no see...

I created the very simple module called "template2Html" for JavaScript to create the HTML String from "template" String.
As you can see below, this module can converts the template string to HTML:

From:

"${id}<div>${name}</div><div>${age}</div><div>${gender}</div>"
To:
1<div>john</div><div>32</div><div>man</div>
When parameters like below are given.
{id: 1, name: 'john', age: 281, gender: 'men'}

The usage of the template2Html are like below:
var template = "<div>${name}</div><div>${age}</div><div>${gender}</div>";
var params = {
name: 'john',
age: 281,
gender: 'man',
};
// generate HTML
var html = template2Html(template, params);

Fixed problem by the scripts

As you know, modern web application requires developers to create more and more HTMLs by JavaScripts.
When we create the HTML in native JavaScript, we have to write scripts like below:
id + '<div>' + name + '</div><div>' + age + '</div><div>' + gender + '</div>'
It's very mess and annoying. HTML often use double quote, in fact its very hard to read and write.
More complicated the HTML become, harder to read and write the scripts.
'<div style="top: ' + $(window).scrollTop() + 'px;"><iframe class="' + overlayClass + '" scrolling="no" frameborder="0" style="' + 
'width: ' + $(document).width() + 'px; height: ' + $(document).height() + 'px; ' +
'z-index: 999; display: block; background-color: black; opacity: 0.5;' +
'"></iframe></div>'
It can become simpler.
template2Html(
'<div style="top:${top}px;"><iframe class="${overlayClass}" scrolling="no" frameborder="0" style="width:${width}px; height:${height}px; z-index: 999; display: block; background-color: black; opacity: 0.5;"></iframe></div>',
{
top: $(window).scrollTop(),
overlayClass: 'overlay',
width: $(document).width(),
heidht: $(document).height()
}
);

This scripts I introduced to you does not only make easy to write scripts and make easy to read, also it separate data from HTML. (Good news for designers!)
It could make object more lighter.

Source Codes

The source code of the template2Html are like below:
/**
* Crate html from template to separate data from html.
* It converts the template string to html.
* From : "${id}<div>${name}</div><div>${age}</div><div>${gender}</div>"
* To : 1<div>john</div><div>281</div><div>man</div>
* when parameters like below are given.
* {id: 1, name: 'john', age: 281, gender: 'men'}
*
* Author Haida
* Version 0.0.1
* @param {String} templateString
* @param {Object} Hash containing parameter.
* @return {String} Return html string.
*/
/*
//---------------- For testing the template2Html ---------------- //
function testTemplate2Html(templateString) {
var params = {
id: 1,
name: 'whoisme',
age: 281,
gender: 'man',
mail: 'haida@example.com'
};
console.log(template2Html(templateString, params));
};
testTemplate2Html("<div>${name}</div><div>${age}</div><div>${gender}</div>");
testTemplate2Html("${id}<div>${name}</div><div>${age}</div><div>${gender}</div>");
testTemplate2Html("<div>${name}</div><div>${age}</div><div>${gender}</div>${mail}");
testTemplate2Html('<div><span>${name}</span><a href="#">Add</a></div>');
testTemplate2Html('<li>${name}</li>');
//---------------- For testing the template2Html ---------------- //
*/
var template2Html = function (templateString, params) {
var __h = function (template, html) {
/* "<div>${name}</div><div>${age}</div><div>${mine}</div>" >> ["${name}", "name"] */
var _match = template.match(/\$\{([^\s\}]+)\}/);
if (_match != null) {
var _idx = template.indexOf(_match[0]);
html += template.substr(0, _idx);
html += params[_match[1]]; // params
return __h(template.substr(_idx + _match[0].length), html);
}
return html + template;
};
return __h(templateString, '');
};
Any comments and advice to improve this scripts are welcome.
Thank you for your reading.

Share it