<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>kswebdev</title>
	<atom:link href="http://kswebdev.de/feed" rel="self" type="application/rss+xml" />
	<link>http://kswebdev.de</link>
	<description>Kai Schaper, Webentwickler</description>
	<lastBuildDate>Thu, 10 Nov 2011 18:49:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Buchtipp: Dive into HTML5</title>
		<link>http://kswebdev.de/508</link>
		<comments>http://kswebdev.de/508#comments</comments>
		<pubDate>Thu, 13 Jan 2011 14:23:58 +0000</pubDate>
		<dc:creator>Kai Schaper</dc:creator>
				<category><![CDATA[HTML/CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Buch]]></category>
		<category><![CDATA[HTML5]]></category>

		<guid isPermaLink="false">http://kswebdev.de/?p=508</guid>
		<description><![CDATA[Mark Pilgrim hat freundlicherweise sein Buch &#8220;HTML5: Up and Running&#8221; auf der Website Dive into HTML5 kostenlos bereitgestellt. Hier eine unvollständige Übersicht des Inhalts: Feature Detection und Fallback-Methoden Doctype, Elemente, Attribute, Microdata Das &#60;canvas&#62; Element Video Geolocation API Web Storage &#8230; <a href="http://kswebdev.de/508">Weiterlesen <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://kswebdev.de/wp-content/uploads/2011/01/html5.gif"><img class="alignright size-full wp-image-511" title="html5" src="http://kswebdev.de/wp-content/uploads/2011/01/html5.gif" alt="" width="180" height="236" /></a>Mark Pilgrim hat freundlicherweise sein Buch &#8220;HTML5: Up and Running&#8221; auf der Website <a href="http://diveintohtml5.info/">Dive into HTML5</a> kostenlos bereitgestellt. Hier eine unvollständige Übersicht des Inhalts:</p>
<ul>
<li>Feature Detection und Fallback-Methoden</li>
<li>Doctype, Elemente, Attribute, Microdata</li>
<li>Das <code>&lt;canvas&gt;</code> Element</li>
<li>Video</li>
<li>Geolocation <acronym title="Application Programming Interface">API</acronym></li>
<li>Web Storage aka. Local Storage aka. <acronym title="Document Object Model">DOM</acronym> Storage (Key/Value-Pairs) und Web <acronym title="Structured Query Language">SQL</acronym> Database</li>
<li>Offline Web applications</li>
<li>neue Formularelemente und -attribute</li>
</ul>]]></content:encoded>
			<wfw:commentRss>http://kswebdev.de/508/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Buchtipp: Eloquent JavaScript</title>
		<link>http://kswebdev.de/500</link>
		<comments>http://kswebdev.de/500#comments</comments>
		<pubDate>Wed, 12 Jan 2011 10:44:30 +0000</pubDate>
		<dc:creator>Kai Schaper</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Buch]]></category>

		<guid isPermaLink="false">http://kswebdev.de/?p=500</guid>
		<description><![CDATA[Eloquent JavaScript von Marijn Haverbeke bietet nicht nur eine Einführung, sondern behandelt auch fortgeschrittene Themen wie Browser Events, das Document-Object Model, Funktionale Programmierung und Objektorientierte Programmierung. Teilweise ist es etwas wirr geschrieben, dafür an anderen Stellen sehr nützlich und unterhaltsam. &#8230; <a href="http://kswebdev.de/500">Weiterlesen <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://kswebdev.de/wp-content/uploads/2011/01/ejs.png"><img class="alignright size-medium wp-image-501" title="ejs" src="http://kswebdev.de/wp-content/uploads/2011/01/ejs-227x300.png" alt="" width="227" height="300" /></a> <a href="http://eloquentjavascript.net/">Eloquent JavaScript</a> von Marijn Haverbeke bietet nicht nur eine Einführung, sondern behandelt auch fortgeschrittene Themen wie Browser Events, das Document-Object Model, Funktionale Programmierung und Objektorientierte Programmierung. Teilweise ist es etwas wirr geschrieben, dafür an anderen Stellen sehr nützlich und unterhaltsam. Momentan gibt es verschiedene kostenlose Versionen in digitaler Form auf der Website. Darunter ist auch eine &#8220;interaktive&#8221; Version, in der man die Code-Beispiele direkt ausprobieren und modifizieren kann. Eine gedruckte Version ist wohl noch in Arbeit.</p>
<p><a href="http://eloquentjavascript.net/">eloquentjavascript.net</a></p>]]></content:encoded>
			<wfw:commentRss>http://kswebdev.de/500/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript-Events mit Eventbug analysieren</title>
		<link>http://kswebdev.de/491</link>
		<comments>http://kswebdev.de/491#comments</comments>
		<pubDate>Fri, 19 Nov 2010 05:25:50 +0000</pubDate>
		<dc:creator>Kai Schaper</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://kswebdev.de/?p=491</guid>
		<description><![CDATA[Eventbug ist eine Erweiterung für Firebug, mit deren Hilfe sich JavaScript-Events analysieren lassen. Zum einen werden alle Events der aktuellen Seite aufgelistet und zum anderen lässt sich ermitteln, welche Events einem HTML-Element zugewiesen sind. In der Abbildung sieht man, dass &#8230; <a href="http://kswebdev.de/491">Weiterlesen <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Eventbug ist eine Erweiterung für Firebug, mit deren Hilfe sich JavaScript-Events analysieren lassen. Zum einen werden alle Events der aktuellen Seite aufgelistet und zum anderen lässt sich ermitteln, welche Events einem <acronym title="HyperText Markup Language">HTML</acronym>-Element zugewiesen sind.</p>
<div id="attachment_492" class="wp-caption alignnone" style="width: 438px"><a href="http://kswebdev.de/wp-content/uploads/2010/11/eventbug.png"><img src="http://kswebdev.de/wp-content/uploads/2010/11/eventbug.png" alt="eventbug" title="eventbug" width="428" height="147" class="size-full wp-image-492" /></a><p class="wp-caption-text">Screenshot vom Event-Tab</p></div>
<p>In der Abbildung sieht man, dass es auf der aktuellen Seite zwei Links jeweils ein <code>click</code>-Event zugewiesen wurde. Sehr nützlich! Weitere Informationen finden sich im <a href="http://getfirebug.com/wiki/index.php/Firebug_Extensions#Eventbug">Eventbug im Firebug-Wiki</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://kswebdev.de/491/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby Version Manager (RVM)</title>
		<link>http://kswebdev.de/471</link>
		<comments>http://kswebdev.de/471#comments</comments>
		<pubDate>Sat, 02 Oct 2010 05:58:03 +0000</pubDate>
		<dc:creator>Kai Schaper</dc:creator>
				<category><![CDATA[Ruby/Rails]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://kswebdev.de/?p=471</guid>
		<description><![CDATA[Mit dem Ruby Version Manager lassen sich auf einem System mehrere Ruby-Versionen parallel installieren. Außerdem können Sammlungen von Gems angelegt werden. Auf diese Weise können für einzelne Projekte oder Entwicklungszweige eigene Umgebungen bereitgestellt werden. Hierdurch werden insbesondere Upgrades des Ruby-Interpreters &#8230; <a href="http://kswebdev.de/471">Weiterlesen <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Mit dem <a href="http://rvm.beginrescueend.com/">Ruby Version Manager</a> lassen sich auf einem System mehrere Ruby-Versionen parallel installieren. Außerdem können Sammlungen von Gems angelegt werden. Auf diese Weise können für einzelne Projekte oder Entwicklungszweige eigene Umgebungen bereitgestellt werden. Hierdurch werden insbesondere Upgrades des Ruby-Interpreters oder ausgewählter Gems vereinfacht, da die Änderungen keine Auswirkungen aufs Gesamtsystem haben.</p>
<p>Mein konkreter Anwendungsfall besteht in der Aktualisierung einer Applikation, die momentan auf Rails 2.3.2 basiert und Ruby 1.8.7 nutzt. Zukünftig sollen Rails 3.0 und Ruby 1.9.2 zum Einsatz kommen. Außerdem möchte ich keine globalen Gems mehr nutzen &#8211; vielmehr soll jedes Projekt ein eigenes Gemset bekommen. Das macht alles übersichtlicher und wartbarer.</p>
<h3>Installation</h3>
<p>Als erstes sollten alle nötigen <a href="http://rvm.beginrescueend.com/rvm/prerequisites/">Software-Pakete</a> auf dem System vorhanden sein. Auf meinem Rechner läuft Ubuntu 9.04, wo die Installation des <acronym title="Ruby Version Manager">RVM</acronym> wie folgt abläuft:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">bash</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span> curl http:<span style="color: #000000; font-weight: bold;">//</span>rvm.beginrescueend.com<span style="color: #000000; font-weight: bold;">/</span>releases<span style="color: #000000; font-weight: bold;">/</span>rvm-install-head <span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Als nächstes muss die Datei <code>.profile</code> bearbeitet werden:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">nano</span> ~<span style="color: #000000; font-weight: bold;">/</span>.profile</pre></div></div>

<p>Die folgende Anweisung muss am Ende eingefügt werden:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-s</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$HOME</span>/.rvm/scripts/rvm&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> . <span style="color: #ff0000;">&quot;<span style="color: #007800;">$HOME</span>/.rvm/scripts/rvm&quot;</span></pre></div></div>

<p>Nun muss noch <code>.bashrc</code> angepasst werden:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">nano</span> ~<span style="color: #000000; font-weight: bold;">/</span>.bashrc</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#[ -z &quot;$PS1&quot; ] &amp;&amp; return</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$PS1</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> ; <span style="color: #000000; font-weight: bold;">then</span>
...
<span style="color: #666666; font-style: italic;"># ganz unten</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># am Ende</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-s</span> <span style="color: #007800;">$HOME</span><span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>scripts<span style="color: #000000; font-weight: bold;">/</span>rvm <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> ; <span style="color: #000000; font-weight: bold;">then</span> <span style="color: #7a0874; font-weight: bold;">source</span> <span style="color: #007800;">$HOME</span><span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>scripts<span style="color: #000000; font-weight: bold;">/</span>rvm ; <span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<p>Nach dem öffnen einer neuen Shell kann man die Installation testen:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">type</span> rvm <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">head</span> <span style="color: #660033;">-n1</span></pre></div></div>

<p>Bei Erfolg wird folgende Meldung ausgegeben:</p>

<div class="wp_syntax"><div class="code"><pre class="none" style="font-family:monospace;">rvm is a function</pre></div></div>

<p>Zu guter Letzt muss <acronym title="Ruby Version Manager">RVM</acronym> noch geladen werden:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">source</span> ~<span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>scripts<span style="color: #000000; font-weight: bold;">/</span>rvm</pre></div></div>

<h3>Ruby-Interpreter installieren</h3>
<p>Als nächstes installiere ich zwei Ruby-Versionen: die von der Anwendung aktuell genutzte, sowie die zukünftig zu verwendende. Eigentlich sollte ich auch den genauen Patch-Level angeben, was ich der Einfachheit halber unterlasse.</p>

<div class="wp_syntax"><div class="code"><pre class="none" style="font-family:monospace;">$ rvm install 1.8.7
$ rvm install 1.9.2</pre></div></div>

<p>So kann man eine bestimmte Version zum Default machen &#8211; diese Auswahl gilt für alle Shells und Anwendungen:</p>

<div class="wp_syntax"><div class="code"><pre class="none" style="font-family:monospace;">$ rvm --default 1.9.2
$ ruby -v
ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]</pre></div></div>

<h3>Gemsets anlegen</h3>
<p>Ich lege nun zwei Gemsets an. Das erste ist für die zu aktualisierende Anwendung und das zweite für deren aktuellen Stand. Bevor das zweite erstellt werden kann, muss noch die die alte Ruby-Version ausgewählt werden.</p>

<div class="wp_syntax"><div class="code"><pre class="none" style="font-family:monospace;">$ rvm gemset create my_app
'my_app' gemset created (/home/kai/.rvm/gems/ruby-1.9.2-p0@my_app).
$ rvm 1.8.7
$ rvm gemset create my_app
'my_app' gemset created (/home/kai/.rvm/gems/ruby-1.8.7-p302@my_app).</pre></div></div>

<p>Bevor nun Gems installiert werden, möchte ich unterbinden, dass deren Dokumentationen mitgeladen werden.</p>

<div class="wp_syntax"><div class="code"><pre class="none" style="font-family:monospace;">$ nano ~/.gemrc
# ans Ende der Datei
install: --no-rdoc --no-ri
update: --no-rdoc --no-ri</pre></div></div>

<p>Nun das gewünschte Gemset auswählen und zum Default machen. Danach beginnt die eigentliche Arbeit: Alle benötigten Gems installieren, Anwendung zum Laufen kriegen, testen und dann das Update auf Rails 3 usw. durchführen.</p>

<div class="wp_syntax"><div class="code"><pre class="none" style="font-family:monospace;">$ rvm use 1.8.7@my_app --default 
# Gems istallieren ... Anwendung testen etc.
$ rvm use 1.9.2@my_app --default
# Gems istallieren ... nötige Änderungen an der Anwendung für Rails 3</pre></div></div>

<h3>Fazit</h3>
<p>Bisher bin ich sehr zufrieden mit dem <acronym title="Ruby Version Manager">RVM</acronym>. Beim immer noch laufenden Upgrade-Prozess habe ich häufig Gebrauch von den verschiedenen Funktionen gemacht. Wenn man beispielsweise versehentlich falsche Versionen von Gems samt Abhängigkeiten installiert, kann man mit <code>$ rvm gemset empty my_app</code> das Gemset leeren. Alle Gems werden entfernt und man kann von vorne anfangen. <acronym title="Ruby Version Manager">RVM</acronym> bietet aber noch viel mehr Möglichkeiten, die alle sehr gut in der <a href="http://rvm.beginrescueend.com/#docindex">Dokumentation</a> beschrieben werden.</p>]]></content:encoded>
			<wfw:commentRss>http://kswebdev.de/471/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Web Workers: Hintergrundprozesse in JavaScript</title>
		<link>http://kswebdev.de/397</link>
		<comments>http://kswebdev.de/397#comments</comments>
		<pubDate>Thu, 10 Jun 2010 05:35:53 +0000</pubDate>
		<dc:creator>Kai Schaper</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[HTML5]]></category>

		<guid isPermaLink="false">http://kswebdev.de/?p=397</guid>
		<description><![CDATA[Webanwendungen werden im Browser in einem einzigen Prozess ausgeführt. Falls die Anwendung rechenintensive oder sich wiederholende Operationen durchführt, kann dies zu Performance-Problemen führen oder die Stabilität des Browsers beeinträchtigen. Aus diesem Grund wurden Web Workers erfunden, die Teil von HTML5 &#8230; <a href="http://kswebdev.de/397">Weiterlesen <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Webanwendungen werden im Browser in einem einzigen Prozess ausgeführt. Falls die Anwendung rechenintensive oder sich wiederholende Operationen durchführt, kann dies zu Performance-Problemen führen oder die Stabilität des Browsers beeinträchtigen. Aus diesem Grund wurden Web Workers erfunden, die Teil von HTML5 sind. Damit können Ressourcen-hungrige Skripte ausgelagert werden, so dass sie in eigenen Prozessen laufen.</p>
<p>Als erstes möchte ich die &#8220;herkömmliche&#8221; Herangehensweise demonstrieren. Im folgenden Beispiel wird in regelmäßigen Abständen ein Ajax-Aufruf ausgeführt. Dieser holt die aktuelle Uhrzeit von einem PHP-Skript und schreibt das Ergebnis in ein <code>div</code>-Element.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE html&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span> <span style="color: #000066;">lang</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;en&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">meta</span> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>untitled<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
&nbsp;
function sendRequest() {
  var httpRequest = new XMLHttpRequest();
  httpRequest.open('GET', 'remote.php', true);
  httpRequest.onload = function() {
    $('result').update(httpRequest.responseText);
    httpRequest = null;
  };
  httpRequest.send(null);
}
&nbsp;
setInterval(function() {
  sendRequest();
}, 3 * 1000);
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;result&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div>

<p>Als nächstes soll das Ganze mithilfe eines Workers umgesetzt werden. Dazu wird eine neue Datei benötigt, die ich einfach <code>worker.js</code> genannt habe. Der Inhalt gleicht dem obigen Skript:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> sendRequest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> httpRequest <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> XMLHttpRequest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  httpRequest.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'GET'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'remote.php'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  httpRequest.<span style="color: #000066;">onload</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    postMessage<span style="color: #009900;">&#40;</span>httpRequest.<span style="color: #660066;">responseText</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    httpRequest <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
  httpRequest.<span style="color: #660066;">send</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
setInterval<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  sendRequest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">3</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Der Unterschied liegt in der Behandlung des Ergebnisses aus dem Ajax-Aufruf. Im ersten Beispiel wurde das Ergebnis direkt ins <code>div</code>-Element geschrieben. Web Worker haben jedoch keinen Zugriff aufs Dokument. Stattdessen wird das Ergebnis nun per <code>postMessage()</code> an selbiges zurückgegeben. Im <acronym title="HyperText Markup Language">HTML</acronym>-Dokument muss nun noch die Nachricht angenommen und ausgegeben werden:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> worker <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Worker<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'worker.js'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
worker.<span style="color: #660066;">onmessage</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'result'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">update</span><span style="color: #009900;">&#40;</span>event.<span style="color: #660066;">data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Leider gibt es noch nicht so viele Browser, die diese Technologie unterstützen. Ich habe es mit Firefox 3.5.9 und Chrome 5 erfolgreich getestet. Momentan scheinen die Debugging-Möglichkeiten aber noch etwas begrenzt zu sein. So sieht man in der FireBug-Konsole nicht, dass Ajax-Aufrufe stattfinden &ndash; aber das hängt bestimmt damit zusammen, dass der Worker in einem eigenen Prozess arbeitet. In Chrome gibt es dagegen schon etwas mehr Unterstützung. Man kann dank der Zeitleiste sehen, dass <code>worker.onmessage</code> ausgeführt wird und zudem erscheint der Worker in Chrome&#8217;s Task-Manager.</p>
<p>Fazit: Ich halte dies für eine sehr interessante und notwendige Technologie. Hoffentlich wird sie in absehbarer Zeit von mehr Browsern unterstützt. Dieser Beitrag sollte allerdings nur Grundlegendes vermitteln. Web Worker haben nämlich noch weitere Funktionalitäten. So lassen sich zum Beispiel weitere Worker aus einem Worker heraus starten. Mehrere Dokumente bzw. Tabs können auf ein und den Selben Worker zugreifen. Und es lassen sich externe Skripte und somit auch Bibliotheken in Workern nutzen.</p>
<p>Quellen:</p>
<ul>
<li><a href="http://www.whatwg.org/specs/web-workers/current-work/">Web Workers &#8211; Draft Recommendation (WHATWG)</a></li>
<li><a href="https://developer.mozilla.org/En/Using_web_workers">Using web workers (Mozilla developer center)</a></li>
</ul>]]></content:encoded>
			<wfw:commentRss>http://kswebdev.de/397/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Font API</title>
		<link>http://kswebdev.de/391</link>
		<comments>http://kswebdev.de/391#comments</comments>
		<pubDate>Tue, 08 Jun 2010 05:18:21 +0000</pubDate>
		<dc:creator>Kai Schaper</dc:creator>
				<category><![CDATA[HTML/CSS]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[HTML]]></category>

		<guid isPermaLink="false">http://kswebdev.de/?p=391</guid>
		<description><![CDATA[Im Web von heute kommen nicht sehr viele verschiedene Schriftarten zum Einsatz. Das liegt vor allem daran, dass Webdesigner zumeist Typen wählen, die auf möglichst vielen Systemen vorhanden sind. Dazu gehören etwa Arial oder Verdana. Andere Fonts lassen sich jedoch &#8230; <a href="http://kswebdev.de/391">Weiterlesen <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Im Web von heute kommen nicht sehr viele verschiedene Schriftarten zum Einsatz. Das liegt vor allem daran, dass Webdesigner zumeist Typen wählen, die auf möglichst vielen Systemen vorhanden sind. Dazu gehören etwa Arial oder Verdana. Andere Fonts lassen sich jedoch auch nutzen. Das geht zum Beispiel über die <a href="http://code.google.com/apis/webfonts/">Google Font <acronym title="Application Programming Interface">API</acronym></a>. Wenn eine Schriftdatei beim Aufruf einer Website nicht vorhanden ist, wird sie von Google auf den lokalen Rechner geladen und kann anschließend angezeigt werden. Letzteres wird durch <acronym title="Cascading Style Sheets">CSS</acronym> geregelt.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;</span>
<span style="color: #00bbdd;">  &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span> xmlns<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span> xml:<span style="color: #000066;">lang</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;de&quot;</span> <span style="color: #000066;">lang</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;de&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">meta</span> <span style="color: #000066;">http-equiv</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Content-Type&quot;</span> <span style="color: #000066;">content</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/html; charset=utf-8&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>Google Font API demo<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://fonts.googleapis.com/css?family=Tangerine&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">style</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span>&gt;</span>
  #eins
  {
    font-family: 'Tangerine', serif;
    font-size: 48px;
  }
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">style</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;eins&quot;</span>&gt;</span>Überschrift<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div>

<p>Entscheidend hierbei ist, dass ein spezielles Stylesheet von Google geladen wird. Diesem wird per GET-Parameter mitgeteilt, welche Schriftart verwendet werden soll. Auf diese Weise lassen sich auch mehrere Schriften gleichzeitig laden, sowie Schriftschnitt bzw. -gewicht auswählen. Momentan stehen ein paar <a href="http://code.google.com/webfonts">freie Schriften</a> zur Auswahl; weitere, kommerzielle Schriften finden sich im Angebot von <a href="http://typekit.com/">TypeKit</a>.</p>
<p>Ich weiß leider nicht, wie es mit der Browser-Kompatibilität aussieht. Bei meinem Test hat es allerdings bestens im FF 3.5.9, <acronym title="Internet Explorer">IE</acronym> 6-8, sowie Chrome 5 funktioniert. Opera 10.53 hat die Schrift erst nach einem Reload der Seite angezeigt.</p>
<p>Fazit: Auf den ersten Blick funktioniert das Ganze recht gut. Hoffentlich wird sich diese Technologie noch weiter entwickeln und vor allem in allen gängigen Systemen bzw. deren Browsern etablieren. Desweiteren wäre eine Alternative zu Google wünschenswert &#8211; aber sie haben ja dankenswerter Weise Teile ihres Codes auf GitHub <a href="http://github.com/typekit/webfontloader">gestellt</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://kswebdev.de/391/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unobtrusive JavaScript in Rails 3</title>
		<link>http://kswebdev.de/384</link>
		<comments>http://kswebdev.de/384#comments</comments>
		<pubDate>Fri, 04 Jun 2010 04:25:14 +0000</pubDate>
		<dc:creator>Kai Schaper</dc:creator>
				<category><![CDATA[Ruby/Rails]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://kswebdev.de/?p=384</guid>
		<description><![CDATA[Rails 2 nutzt Prototype per Default. Die JavaScript-Helper generieren Inline-Code, der mit dem HTML verwoben ist. In diesem Beitrag möchte ich beschreiben, wie man in Rails 3 stattdessen jQuery nutzen kann und zudem noch eine saubere Trennung von JavaScript und &#8230; <a href="http://kswebdev.de/384">Weiterlesen <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Rails 2 nutzt Prototype per Default. Die JavaScript-Helper generieren Inline-Code, der mit dem <acronym title="HyperText Markup Language">HTML</acronym> verwoben ist. In diesem Beitrag möchte ich beschreiben, wie man in Rails 3 stattdessen jQuery nutzen kann und zudem noch eine saubere Trennung von JavaScript und <acronym title="HyperText Markup Language">HTML</acronym> erreicht. Als erstes wird hierzu eine neue Rails-Anwendung angelegt. Bei mir ist momentan Version 3.0.0.beta2 installiert.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">rails jsdemo
cd jsdemo</pre></div></div>

<p>Als nächstes wird jQuery heruntergeladen:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">curl http:<span style="color: #000000; font-weight: bold;">//</span>code.jquery.com<span style="color: #000000; font-weight: bold;">/</span>jquery-1.4.2.min.js <span style="color: #000000; font-weight: bold;">&gt;</span> public<span style="color: #000000; font-weight: bold;">/</span>javascripts<span style="color: #000000; font-weight: bold;">/</span>jquery.js</pre></div></div>

<p>Im JavaScript-Verzeichnis befindet sich die Datei <code>rails.js</code>. Dabei handelt es sich quasi um einen Adapter für die genutzte JavaScript-Bibliothek. Momentan bezieht sich dieses noch auf Prototype. Aus diesem Grund wird es nun durch eines für jQuery ersetzt:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">curl http:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>rails<span style="color: #000000; font-weight: bold;">/</span>jquery-ujs<span style="color: #000000; font-weight: bold;">/</span>raw<span style="color: #000000; font-weight: bold;">/</span>master<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>rails.js <span style="color: #000000; font-weight: bold;">&gt;</span> public<span style="color: #000000; font-weight: bold;">/</span>javascripts<span style="color: #000000; font-weight: bold;">/</span>rails.js</pre></div></div>

<p>Als nächstes müssen wir Rails beibringen, dass durch die Helper auch die richtigen Dateien eingebunden werden. Dafür wird die Datei <code>config/initializers/javascript_default_sources.rb</code> angelegt und mit folgendem Code gefüllt:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> <span style="color:#6666ff; font-weight:bold;">ActionView::Helpers::AssetTagHelper</span>
  remove_const <span style="color:#ff3333; font-weight:bold;">:JAVASCRIPT_DEFAULT_SOURCES</span>
  JAVASCRIPT_DEFAULT_SOURCES = <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#40;</span>jquery.<span style="color:#9900CC;">js</span> rails.<span style="color:#9900CC;">js</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  reset_javascript_include_default
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Jetzt brauchen wir noch ein Layout, das eben diese Dateien einbindet. Es wird bewusst HTML5 verwendet. Dazu gleich mehr. Nach einem <code>touch app/views/layouts/application.html.erb</code> füllen wir die neue Datei mit folgendem Inhalt:</p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;">&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
  &lt;meta charset=&quot;utf-8&quot;&gt;
  &lt;title&gt;jsdemo&lt;/title&gt;
  <span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#5A0A0A; font-weight:bold;">javascript_include_tag</span> <span style="color:#ff3333; font-weight:bold;">:defaults</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  <span style="color:#006600; font-weight:bold;">&lt;%</span>= csrf_meta_tag <span style="color:#006600; font-weight:bold;">%&gt;</span>
&lt;/head&gt;
&lt;body&gt;
<span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#9966CC; font-weight:bold;">yield</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>Jetzt wird noch ein Controller mit einer Action benötigt. An dieser Stelle verzichte ich der Einfachheit halber auf REST bzw. Ressourcen.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rails generate controller demo index</pre></div></div>

<p>Nun noch mit <code>rails server</code> den Server starten und die Seite über http://localhost:3000/demo/index aufrufen.</p>
<p>OK, bisher war es noch nicht sonderlich interessant. Das soll sich nun ändern. Dazu wird das <code>index</code>-Template gefüllt und ein weiteres angelegt, der Controller erweitert und eine entsprechende Route ergänzt.</p>
<p>index.html.erb:</p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;">&lt;p id=&quot;result&quot;&gt;result&lt;/p&gt;
&lt;p&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#5A0A0A; font-weight:bold;">link_to</span> <span style="color:#996600;">'eins'</span>, eins_path, <span style="color:#ff3333; font-weight:bold;">:remote</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/p&gt;</pre></div></div>

<p>routes.rb:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">match <span style="color:#996600;">'eins'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'demo#eins'</span></pre></div></div>

<p>demo_controller.rb:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> DemoController <span style="color:#006600; font-weight:bold;">&lt;</span> ApplicationController
  respond_to <span style="color:#ff3333; font-weight:bold;">:html</span>, <span style="color:#ff3333; font-weight:bold;">:js</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> index
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> eins
    respond_with<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:eins</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>neu: app/views/demo/eins.js.erb:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#result'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'color'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'red'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Wenn man sich nun den Quelltext im Browser ansieht, fällt sofort das eigenartige Attribut im Link auf. Dabei handel es sich um ein neues Feature von HTML5. Mit dem <code>data</code>-Attribut lassen sich eigene Schlüssel-Wert-Paare definieren, auf die man per JavaScript zugreifen kann. &#8220;remote&#8221; ist der Schlüssel und &#8220;true&#8221; der entsprechende Wert:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/eins&quot;</span> data-remote<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;true&quot;</span>&gt;</span>eins<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span></pre></div></div>

<p>Nach einem Klick auf den Link wird per Ajax die <code>eins</code>-Action aufgerufen und das gerenderte <code>eins.js.erb</code> zurückgegeben. Der darin enthaltene JavaScript-Schnipsel wird ausgeführt und bewirkt, dass die Schrift in <code>div#result</code> rot wird. Es lassen sich allerdings auch andere Formate verwenden, zum Beispiel HTML:</p>
<p>index.html.erb:</p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;">...
&lt;p&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#5A0A0A; font-weight:bold;">link_to</span> <span style="color:#996600;">'zwei'</span>, zwei_path, <span style="color:#ff3333; font-weight:bold;">:remote</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>, <span style="color:#996600;">'data-type'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'html'</span>, <span style="color:#ff3333; font-weight:bold;">:id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'zwei'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/p&gt;
&lt;script&gt;
$('#zwei').bind('ajax:success', function(type, data, status, xhr) {
  $('#result').append(data);
&nbsp;
  console.log(type);
  console.log(data);
  console.log(status);
  console.log(xhr);
});
&lt;/script&gt;</pre></div></div>

<p>routes.rb:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">match <span style="color:#996600;">'zwei'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'demo#zwei'</span></pre></div></div>

<p>demo_controller.rb:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#9966CC; font-weight:bold;">def</span> zwei
    render <span style="color:#ff3333; font-weight:bold;">:layout</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>neu: app/views/demo/zwei.html.erb:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>Output von <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">em</span>&gt;</span>zwei.html.erb<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">em</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>Das Ereignis wird per <code>bind</code> abgefangen. In der FireBug-Console sieht man das Ergebnis. Desweiteren wird der <acronym title="HyperText Markup Language">HTML</acronym>-Schnipsel aus dem gerenderten <code>zwei.html.erb</code>-Template dem <code>div#result</code> angehängt.</p>
<p><strong>Anmerkung</strong>: Das <code>script</code>-Element gehört natürlich nicht ins Template, sondern in eine eigene JavaScript-Datei. Der Einfachheit halber habe ich aber darauf verzichtet, obwohl dies alles andere als <em>unobtrusive</em> ist.</p>
<p>Welche <strong>Vorteile</strong> bring nun das Ganze? Als erstes wird deutlich, dass sich jQuery sehr einfach einbinden lässt. Ähnliches dürfte auch für andere Bibliotheken gelten. Es muss halt jeweils eine angepasste <code>rails.js</code> geschrieben oder selbige erweitert werden. Diese muss dabei <acronym title="HyperText Markup Language">HTML</acronym>-Elemente mit <code>data-remote</code>-Attributen überwachen und entsprechende Ajax-Calls abfeuern. Desweiteren kann man auf diese Weise sehr schön <acronym title="HyperText Markup Language">HTML</acronym> und JavaScript voneinander trennen &#8211; nie mehr Inline-Skripte! Außerdem lässt sich Ruby-Code in <code>*.js.erb</code>-Templates verwenden &#8211; man hat somit Zugriff auf die Objekte und kann individuelles JavaScript dynamisch erzeugen.</p>
<p>Wie sieht&#8217;s mit <strong>Nachteilen</strong> aus? Nun ja, wenn man nicht aufpasst, verlagert man den Spaghetti-Code aus dem gerenderten <acronym title="HyperText Markup Language">HTML</acronym> in die Views. Nämlich dann, wenn dort ein Gemisch aus JavaScript, <acronym title="HyperText Markup Language">HTML</acronym> und Ruby zu finden ist. Es lassen sich nämlich auch &#8220;<acronym title="HyperText Markup Language">HTML</acronym>&#8221;-Parials in <code>*.js.erb</code>-Templates verwenden. Beispiel:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#result'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;%= escape_javascript(render @some_partial) %&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>Fazit</strong>: Diese Neuerungen stellen ganz klar einen Fortschritt gegenüber Rails 2 dar. Eine klare Trennung von <acronym title="HyperText Markup Language">HTML</acronym> und JavaScript war schon lange nötig. Sicherlich ließ sich das auch schon vorher erreichen, wenn man nämlich weitestgehen auf Rails&#8217; JavaScript-Helper verzichtet hat. Aber wozu braucht man dann ein Framework, wenn doch alles selbst geschrieben wird? Desweiteren sei noch erwähnt, dass die oben beschriebene Technik Geschmackssache ist: JavaScript-Templates, dessen Output direkt ausgeführt wird ist vielleicht gewöhnigungsbedürftig.</p>
<p>Hier noch ein paar <strong>Quellen</strong>:</p>
<ul>
<li><a href="http://www.railsinside.com/tips/451-howto-unobtrusive-javascript-with-rails-3.html">HOWTO: Unobtrusive JavaScript with Rails 3</a></li>
<li><a href="http://github.com/rails/jquery-ujs/">jquery-ujs</a> &#8211; der jQuery-Adapter auf GitHub</li>
<li><a href="http://ryandaigle.com/articles/2009/8/6/what-s-new-in-edge-rails-cleaner-restful-controllers-w-respond_with">What&#8217;s New in Edge Rails: Cleaner RESTful Controllers w/ respond_with</a></li>
</ul>]]></content:encoded>
			<wfw:commentRss>http://kswebdev.de/384/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Bilder einbetten per Data-URL</title>
		<link>http://kswebdev.de/378</link>
		<comments>http://kswebdev.de/378#comments</comments>
		<pubDate>Wed, 02 Jun 2010 05:20:07 +0000</pubDate>
		<dc:creator>Kai Schaper</dc:creator>
				<category><![CDATA[HTML/CSS]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://kswebdev.de/?p=378</guid>
		<description><![CDATA[Mit einer sog. Data-URL kann man Grafiken in HTML oder CSS einbinden. Dazu muss aus der Bilddatei eine base64-kodierte Zeichenkette erzeugt werden, die dann im src-Attribut eines Bildes oder als background-image im CSS genutzt werden kann. Hierdurch kann man HTTP-Requests &#8230; <a href="http://kswebdev.de/378">Weiterlesen <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Mit einer sog. Data-<acronym title="Uniform Resource Locator">URL</acronym> kann man Grafiken in <acronym title="HyperText Markup Language">HTML</acronym> oder <acronym title="Cascading Style Sheets">CSS</acronym> einbinden. Dazu muss aus der Bilddatei eine base64-kodierte Zeichenkette erzeugt werden, die dann im src-Attribut eines Bildes oder als background-image im <acronym title="Cascading Style Sheets">CSS</acronym> genutzt werden kann. Hierdurch kann man <acronym title="HyperText Transfer Protocol">HTTP</acronym>-Requests sparen und somit die Performance erhöhen.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$file</span>    <span style="color: #339933;">=</span> <span style="color: #0000ff;">'image.gif'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$data</span>    <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$encoded</span> <span style="color: #339933;">=</span> <span style="color: #990000;">base64_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE html&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span> <span style="color: #000066;">lang</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;en&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">meta</span> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>untitled<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">style</span>&gt;</span>
  h2 {
    background-image:url(data:image/png;base64,<span style="color: #009900;">&lt;?php echo $encoded; ?&gt;</span>);
  }
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">style</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;data:image/png;base64,&lt;?php echo $encoded; ?&gt;</span></span>&quot; alt=&quot;&quot; /&gt;<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>This is a test<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div>

<p>Weitere Informationen insbesondere zur Browser-Kompatibilität finden sich in der <a href="http://en.wikipedia.org/wiki/Data_URI_scheme">Wikipedia</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://kswebdev.de/378/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby-Objekte vergleichen mit to_yaml</title>
		<link>http://kswebdev.de/368</link>
		<comments>http://kswebdev.de/368#comments</comments>
		<pubDate>Wed, 19 May 2010 05:09:39 +0000</pubDate>
		<dc:creator>Kai Schaper</dc:creator>
				<category><![CDATA[Ruby/Rails]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://kswebdev.de/?p=368</guid>
		<description><![CDATA[Auch auf die Gefahr hin, dass dies bereits zum Allgemeinwissen gehört: Mir ist dieser kleine Trick erst gestern eingefallen und daher poste ich ihn hier. In einem Unit-Test habe ich ein Objekt und speichere dieses in der Datenbank. Anschließend hole &#8230; <a href="http://kswebdev.de/368">Weiterlesen <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Auch auf die Gefahr hin, dass dies bereits zum Allgemeinwissen gehört: Mir ist dieser kleine Trick erst gestern eingefallen und daher poste ich ihn hier. In einem Unit-Test habe ich ein Objekt und speichere dieses in der Datenbank. Anschließend hole ich es wieder heraus. Nun möchte ich meine <code>find</code>-Methode testen und sicherstellen, dass es sich jeweils um den selben Datensatz handelt. Das Problem dabei: Es sind nicht die selben Objekte:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">page     = Page.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Seite 3'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
reloaded = Page.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span>page._id<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#CC0066; font-weight:bold;">p</span> page      <span style="color:#008000; font-style:italic;">#&lt;Page:0xb6b21f68 @title=&quot;Seite 3&quot;, ... &gt;</span>
<span style="color:#CC0066; font-weight:bold;">p</span> reloaded  <span style="color:#008000; font-style:italic;">#&lt;Page:0xb6b1c220 @title=&quot;Seite 3&quot;, ... &gt;</span></pre></div></div>

<p>Wie man sieht, unterscheidet sich die Objekt-ID. Logisch, dass folgendes fehlschlägt:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">assert_equal page, reloaded</pre></div></div>

<p>Stattdessen verwendet ich nun dies:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">assert_equal page.<span style="color:#9900CC;">to_yaml</span>, reloaded.<span style="color:#9900CC;">to_yaml</span></pre></div></div>

<p>Auf diese Weise werden nur die Daten aus der Datenbank miteinander verglichen. Nebenbei: Es handelt sich hierbei nicht um ActiveRecord-Objekte.</p>]]></content:encoded>
			<wfw:commentRss>http://kswebdev.de/368/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Web-Analyse &#8211; Begrifflichkeiten</title>
		<link>http://kswebdev.de/353</link>
		<comments>http://kswebdev.de/353#comments</comments>
		<pubDate>Tue, 18 May 2010 04:55:41 +0000</pubDate>
		<dc:creator>Kai Schaper</dc:creator>
				<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[Tracking]]></category>

		<guid isPermaLink="false">http://kswebdev.de/?p=353</guid>
		<description><![CDATA[In diesem Artikel sollen ein paar wichtige Begriffe aus der Web-Analyse erläutert werden. Dieses Verfahren wird unter anderem auch als Web Analytics oder Webtracking bezeichnet. Und es geht darum, das Verhalten der Besucher einer Website auszuwerten. Hit, page hit Eine &#8230; <a href="http://kswebdev.de/353">Weiterlesen <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In diesem Artikel sollen ein paar wichtige Begriffe aus der Web-Analyse erläutert werden. Dieses Verfahren wird unter anderem auch als <em>Web Analytics</em> oder <em>Webtracking</em> bezeichnet. Und es geht darum, das Verhalten der Besucher einer Website auszuwerten.</p>
<h3>Hit, page hit</h3>
<p>Eine vom Webserver angeforderte Datei (html, jpg, gif usw.) bzw. ein entsprechender Eintrag in der Log-Datei des Webservers.</p>
<h3>Page Impression, PI, Page View, PV, View, Seitenabruf </h3>
<p>Abruf einer Einzelseite innerhalb einer Website. Dabei ist die komplette Seite mit allen eingebundenen Elementen (html, jpg, gif) gemeint.</p>
<h3>Visit, Unique Visit</h3>
<p>Der Besuch einer Website durch einen eindeutigen Client. Die einzelnen Seitenaufrufe (Page Impressions) und heruntergeladenen Dateien (Hits) sind hierbei unerheblich. Entscheidend ist, dass eine Folge von Seitenaufrufen ohne längere Unterbrechung stattfindet. Als Zeitraum werden zumeist 30 Minuten festgelegt. Die Identifizierung des Clients kann beispielsweise über die <acronym title="Internet Protocol">IP</acronym>-Adresse, Cookies und/oder die Signatur des User Agents erfolgen.</p>
<h3>Session</h3>
<p>Diese ähnelt dem Visit: Zum einen ist es wichtig, dass zwischen einzelnen Seitenaufrufen nicht mehr als die festgelegte Zeit vergeht (30 Minuten). Hinzu kommt jedoch, dass zwischen den Aufrufen keine andere Website besucht wird.</p>
<h3>Unique Visitor, Unique User</h3>
<p>Ein Visitor kann mehrere Visits machen. Es wird dabei in längeren Zeiträumen gemessen als bei Visits: zum Beispiel in Tagen oder Wochen. Auch hier wird wieder Bezug auf den Client genommen &#8211; und nicht auf den Menschen dahinter.</p>
<h3>Klick</h3>
<p>Hiermit ist häufig der Klick auf ein Werbemittel (Banner, Sponsorenlink etc.) gemeint. Es gibt hierbei auch die Click-Through-Rate (CTR): Die Anzahl der Klicks auf ein Werbemittel im Verhältnis zu den gesamten Impressionen. Impressionen bzw. <em>Ad Impressions</em> oder <em>Ad Views</em> sind die Aufrufe einzelner Werbemittel vom Adserver. </p>
<p>Allerdings kann auch einfach der Klick auf einen normalen Link gemeint sein. Eine Folge von Klicks durch einen Besucher auf einer Website bezeichnet man dann auch als Klickpfad bzw. <em>click path</em>.</p>
<h3>Lead</h3>
<p>Leads sind gewonnene Kontaktadressen, zum Beispiel Katalogbestellungen oder Newsletter-Abonements. Sie werden für die Kontaktvergütung (Cost per Lead, CPL) gezählt.</p>
<h2>Fazit</h2>
<p>Wer sich ein wenig mit dem Thema auseinander setzt oder setzen muss, merkt schnell, dass es noch viel mehr Begriffe gibt. Oftmals werden auch mehrere für ein und die selbe Sache verwendet, was das Ganze nicht einfacher macht. Die obige Liste erhebt somit keinen Anspruch auf Vollständigkeit.</p>]]></content:encoded>
			<wfw:commentRss>http://kswebdev.de/353/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

