<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description></description><title>Martin Ottenwaelter</title><generator>Tumblr (3.0; @martinottenwaelter)</generator><link>http://martinottenwaelter.fr/</link><item><title>Testing and auto-generated ids in SproutCore</title><description>&lt;p&gt;If you’re trying to automate tests of your &lt;a href="http://sproutcore.com"&gt;SproutCore&lt;/a&gt; application with &lt;a href="http://seleniumhq.org/"&gt;Selenium&lt;/a&gt;, for example, you’ll realise that the HTML element ids are automatically generated. They change every now and then and break all your tests.&lt;/p&gt;

&lt;p&gt;To get rid of this problem, you can override the &lt;code&gt;layerId&lt;/code&gt; method of certain view classes to generate a stable, and human readable, id.&lt;/p&gt;

&lt;p&gt;The following code takes the view hierarchy, and generates an id based on the parents’ names. For example, the &lt;code&gt;mainPage.mainView.someOtherView.theTargetView&lt;/code&gt; view will be given the &lt;code&gt;mmsome.theTargetView&lt;/code&gt; id.&lt;/p&gt;

&lt;script src="https://gist.github.com/287668.js"&gt;&lt;/script&gt;</description><link>http://martinottenwaelter.fr/post/355872976</link><guid>http://martinottenwaelter.fr/post/355872976</guid><pubDate>Wed, 27 Jan 2010 09:55:00 +0100</pubDate><category>sproutcore</category></item><item><title>Monkey patching SproutCore</title><description>&lt;p&gt;You can add or overwrite a class property using the &lt;code&gt;mixin&lt;/code&gt; method on the class &lt;code&gt;prototype&lt;/code&gt;. The following example dynamically adds a &lt;code&gt;keyForParentView&lt;/code&gt; method on the SC.View class without modifying SproutCore’s source code:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;SC.View.prototype.mixin({
  keyForParentView: function() {
    var parentView = this.get('parentView'),
        key;   
    for (key in parentView) {
      if (this === parentView[key]) return key;
    }
    return null;
  }
});
&lt;/code&gt;&lt;/pre&gt;</description><link>http://martinottenwaelter.fr/post/246077079</link><guid>http://martinottenwaelter.fr/post/246077079</guid><pubDate>Mon, 16 Nov 2009 16:22:05 +0100</pubDate><category>sproutcore</category></item><item><title>SC.Response and JSON</title><description>&lt;p&gt;SproutCore’s &lt;code&gt;SC.Response&lt;/code&gt; was &lt;a href="http://github.com/sproutit/sproutcore/commit/3ac172b2559e85a0a7c8a260fcf5f1dab2de9773"&gt;recently rewritten&lt;/a&gt; and I &lt;a href="http://github.com/sproutit/sproutcore/commit/d380ed008e0cd42b6b05e21a179a4de390550c1d"&gt;patched&lt;/a&gt; it to avoid an exception to be thrown when a malformed JSON string was parsed. The standard way to write your data source &lt;code&gt;didFetch&lt;/code&gt; method is now:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;didFetch: function(response, params) {
  var results, query = params.query;
  if (SC.ok(response) &amp;&amp; SC.ok(results = response.get('body'))) {
    ...
  } else {
    store.dataSourceDidErrorQuery(query);
  }
}
&lt;/code&gt;&lt;/pre&gt;</description><link>http://martinottenwaelter.fr/post/242665340</link><guid>http://martinottenwaelter.fr/post/242665340</guid><pubDate>Fri, 13 Nov 2009 17:15:00 +0100</pubDate><category>sproutcore</category></item><item><title>Alternate row colors in SC.ListViews</title><description>&lt;p&gt;This post will show you how to create a SproutCore ListView with alternate row colors.&lt;/p&gt;

&lt;p&gt;Let’s add alternate row colors to the &lt;a href="http://wiki.sproutcore.com/Todos%C2%A0Intro"&gt;Todos tutorial&lt;/a&gt;’s list view. Clone the source code, then switch to the &lt;code&gt;step-5&lt;/code&gt; branch. It should look like this:&lt;/p&gt;

&lt;p&gt;&lt;img src="http://s3.amazonaws.com/ember/ATyKlpt9YbqQm9rfvjF7pEtYVDMOqY8q_o.png" alt="Todos, Step 5"/&gt;&lt;/p&gt;

&lt;p&gt;The code that’s actually responsible for the ListView is in &lt;code&gt;main_page.js:46&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;middleView: SC.ScrollView.design({
  hasHorizontalScroller: NO,
  layout: { top: 36, bottom: 32, left: 0, right: 0 },
  backgroundColor: 'white',
  contentView: SC.ListView.design({
    contentBinding: 'Todos.tasksController.arrangedObjects',
    selectionBinding: 'Todos.tasksController.selection',
    contentValueKey: "description",
    contentCheckboxKey: "isDone",
    canEditContent: YES,
    canReorderContent: YES,
    canDeleteContent: YES,
    destroyOnRemoval: YES,
    rowHeight: 21
  })
}),
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This creates a standard list view whose rows are instances of the SC.ListItemView class. We want to customize the appearance of these rows, so we are going to subclass the SC.ListItemView class and override the &lt;code&gt;render&lt;/code&gt; method:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Todos.ListItemView = SC.ListItemView.extend({
  render: function(context, firstTime) {
    if (this.get('contentIndex') % 2 === 0) {
      context.addClass('even');
    } else {
      context.addClass('odd');
    }
    return sc_super();
  }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Let go through this code snippet step by step:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Todos.ListItemView&lt;/code&gt; is the subclass’ name&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;SC.ListItemView.extend&lt;/code&gt; is the SproutCore syntax for subclassing&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;render: function(context, firstTime)&lt;/code&gt; is the method defined in &lt;code&gt;view.js&lt;/code&gt; that we need to override to customize the view’s appearance&lt;/li&gt;
&lt;li&gt;now, we need to determine the index of the current row and add an ‘odd’ or ‘even’ css class name to the underlying HTML element

&lt;ul&gt;
&lt;li&gt;by looking at SproutCore’s source code, you’ll notice that a ListViewItem has a &lt;code&gt;contentIndex&lt;/code&gt; property, which is exactly the row’s index. The property is obtained by calling the &lt;code&gt;get&lt;/code&gt; method.&lt;/li&gt;
&lt;li&gt;SproutCore renders things using a &lt;code&gt;context&lt;/code&gt; object, instance of &lt;code&gt;SC.RenderContext&lt;/code&gt;. It has an &lt;code&gt;addClass&lt;/code&gt; which adds a css class name to the current HTML element.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;finally, we need to call the superclass’ implementation. This is done with &lt;code&gt;sc_super()&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now, we need to tell the &lt;code&gt;contentView&lt;/code&gt; that it should use the &lt;code&gt;Todos.ListItemView&lt;/code&gt; class for rows. This is done by adding the following line to the &lt;code&gt;contentView&lt;/code&gt;’s parameters:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;exampleView: Todos.ListItemView,
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Finally, we need to add some css code to style the odd and even rows. Create a &lt;code&gt;list_item.css&lt;/code&gt; file in your &lt;code&gt;english.lproj&lt;/code&gt; folder:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;.sc-list-item-view.even {
  background-color: #E4E4E4;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Reload your browser, it should look like that:&lt;/p&gt;

&lt;p&gt;&lt;img src="http://s3.amazonaws.com/ember/ReXNNrPuZ4wu8MoetPZ1KOKw4WVgFgzx_o.png" alt="Todos, with alternate row colors"/&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;EDIT:&lt;/strong&gt; As &lt;em&gt;nexneo&lt;/em&gt; points out, there is a simpler way to get the current row index. I’ve replaced &lt;code&gt;this.owner.contentIndexForLayerId(this.layerId)&lt;/code&gt; by &lt;code&gt;this.get('contentIndex')&lt;/code&gt;. Thanks!&lt;/p&gt;</description><link>http://martinottenwaelter.fr/post/177117947</link><guid>http://martinottenwaelter.fr/post/177117947</guid><pubDate>Tue, 01 Sep 2009 16:16:00 +0200</pubDate><category>sproutcore</category></item><item><title>Safari AdBlock on Snow Leopard</title><description>&lt;p&gt;&lt;a href="http://burgersoftware.com/safariadblock"&gt;Safari AdBlock&lt;/a&gt; 0.4.0 RC3 now works on Snow Leopard.&lt;/p&gt;

&lt;p&gt;To make it work, though, you have to run Safari in 32-bit mode. To do so, select &lt;code&gt;Safari.app&lt;/code&gt; in the &lt;code&gt;Applications&lt;/code&gt; folder, hit ⌘-I to show the “Get Info” window, and check the “Open in 32-bit mode” checkbox:&lt;/p&gt;

&lt;p&gt;&lt;img src="http://s3.amazonaws.com/ember/tBw2fv8NuLm2fq3ImawVW1l835mnyZDT_o.png" alt="Open in 32-bit mode" title="Open in 32-bit mode"/&gt;&lt;/p&gt;

&lt;p&gt;I’m looking into an alternative solution to allow Safari to run in 64-bit with AdBlock (and any InputManager) enabled.&lt;/p&gt;</description><link>http://martinottenwaelter.fr/post/173126110</link><guid>http://martinottenwaelter.fr/post/173126110</guid><pubDate>Thu, 27 Aug 2009 19:59:00 +0200</pubDate><category>safariadblock</category></item><item><title>Lighttpd, mod_magnet and MacPorts</title><description>&lt;p&gt;I installed &lt;a href="http://www.lighttpd.net/"&gt;lighttpd&lt;/a&gt; with &lt;a href="http://www.macports.org/"&gt;MacPorts&lt;/a&gt; using the usual command&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo port install lighttpd
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;But when I try to start it with a custom configuration file, I get the following error:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;(plugin.c.213) mod_magnet plugin init failed 
(server.c.614) loading plugins finally failed
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It looks like the default MacPorts installation didn’t install everything needed for &lt;code&gt;mod_magnet&lt;/code&gt; to work. Ports actually come in different flavours called &lt;a href="http://guide.macports.org/#using.variants"&gt;&lt;em&gt;variants&lt;/em&gt;&lt;/a&gt;. You can either do&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;port variants lighttpd
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;to see the different variants of a port, or directly read &lt;a href="http://trac.macports.org/browser/trunk/dports/www/lighttpd/Portfile"&gt;lighttpd’s portfile&lt;/a&gt; which has more info in it. You see on line 85 that the &lt;code&gt;cml&lt;/code&gt; variant builds lighttpd with lua, which is the scripting language used by mod_magnet:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;variant cml {
    depends_lib-append   port:lua \
                         port:libmemcache \
                         port:memcached \
                         port:pkgconfig

     configure.args-append --with-lua \
                           --with-memcache
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The &lt;code&gt;cml&lt;/code&gt; variant is probably just what we need. While we’re at it, we are also going to add ssl support to our lighttpd installation.&lt;/p&gt;

&lt;p&gt;Now, we first need to remove the previous installation&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo port uninstall lighttpd
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;then do the new installation with the &lt;code&gt;cml&lt;/code&gt; and &lt;code&gt;ssl&lt;/code&gt; variants:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo port install lighttpd +cml +ssl
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Lighttpd now starts without any error.&lt;/p&gt;</description><link>http://martinottenwaelter.fr/post/164088284</link><guid>http://martinottenwaelter.fr/post/164088284</guid><pubDate>Sun, 16 Aug 2009 12:37:00 +0200</pubDate><category>lighttpd</category><category>macports</category></item></channel></rss>
