<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Posts on eltimn</title><link>/post/</link><description>Recent content in Posts on eltimn</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Sat, 08 Jun 2013 14:59:45 -0500</lastBuildDate><atom:link href="/post/index.xml" rel="self" type="application/rss+xml"/><item><title>Parallel MongoRecord test execution with ScalaTest</title><link>/post/007-parallel-mongorecord-test-execution/</link><pubDate>Sat, 08 Jun 2013 14:59:45 -0500</pubDate><guid>/post/007-parallel-mongorecord-test-execution/</guid><description>&lt;p&gt;A few weeks ago, I finally figured out a way to enable parallel test execution of Lift MongoRecords using ScalaTest. The problem is when you call &lt;code&gt;MongoDB.defineDb&lt;/code&gt; the entry is added to a Map with the MongoIdentifier as the key. So, you can&amp;rsquo;t add more than one entry for the same MongoIdentifer, which means you can&amp;rsquo;t use a different database for testing without doing them one at a time.&lt;/p&gt;
&lt;p&gt;The solution is rather simple and involves Lift&amp;rsquo;s &lt;a href="http://simply.liftweb.net/index-8.2.html#toc-Section-8.2"&gt;Dependency Injection mechanism&lt;/a&gt;. It allows us to use a different MongoIdentifier for each test suite.&lt;/p&gt;</description></item><item><title>JavaScript Apps With Lift: Build Tools</title><link>/post/006-javascript-apps-with-lift-callback-build-tools/</link><pubDate>Sat, 06 Apr 2013 14:59:45 -0500</pubDate><guid>/post/006-javascript-apps-with-lift-callback-build-tools/</guid><description>&lt;p&gt;Now that we know how to organize and write our JavaScript code, we need a way to build our single file for use in production. There are several ways you can do this.&lt;/p&gt;
&lt;h3 id="scala-build-tool"&gt;Scala Build Tool&lt;/h3&gt;
&lt;p&gt;Most build tools have plugins for this, whether you&amp;rsquo;re using SBT, Maven, or Gradle. I&amp;rsquo;m an SBT user, so I&amp;rsquo;ve been using &lt;a href="https://github.com/eltimn/sbt-closure"&gt;sbt-closure&lt;/a&gt; and &lt;a href="https://github.com/softprops/less-sbt"&gt;less-sbt&lt;/a&gt;. However, these are extremely slow, the SBT plugins, that is. I haven&amp;rsquo;t used the other build tools. Also, it&amp;rsquo;s not necessary to run google closure every time a change is made. This really only needs to be done once, when packaging for deployment.&lt;/p&gt;</description></item><item><title>JavaScript Apps With Lift: JsClass</title><link>/post/005-javascript-apps-with-lift-callback-jsclass/</link><pubDate>Fri, 05 Apr 2013 14:59:45 -0500</pubDate><guid>/post/005-javascript-apps-with-lift-callback-jsclass/</guid><description>&lt;p&gt;The &lt;a href="https://github.com/eltimn/lift-extras"&gt;Lift Extras&lt;/a&gt; module adds some convenience classes to help with interfacing between your Scala snippet code and your JavaScript code.&lt;/p&gt;
&lt;p&gt;In my &lt;a href="http://www.eltimn.com/blog/004-javascript-apps-with-lift-callback-functions"&gt;last post&lt;/a&gt; the code used to initialize the JavaScript code from within the snippet looked like this (minus the knockout binding call):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;val onload: JsCmd =
 SetExp(
 JsVar(&amp;quot;window.koExample&amp;quot;),
 JsExtras.CallNew(
 &amp;quot;App.views.knockout.KnockoutExampleCls&amp;quot;,
 JsExtras.AjaxCallbackAnonFunc(sendSucces),
 JsExtras.JsonCallbackAnonFunc(saveForm),
 )
 )
)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Elsewhere, there&amp;rsquo;s a call to a function on the JavaScript class:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Call(&amp;quot;window.koExample.textInput&amp;quot;, Str(&amp;quot;&amp;quot;))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There are a couple of things that bother me about this. &lt;code&gt;window.koExample&lt;/code&gt; is referenced in multiple places. The &lt;code&gt;SetExp&lt;/code&gt; call is similar for all JavaScript classes.&lt;/p&gt;</description></item><item><title>JavaScript Apps With Lift: Callback Functions</title><link>/post/004-javascript-apps-with-lift-callback-functions/</link><pubDate>Thu, 04 Apr 2013 14:59:45 -0500</pubDate><guid>/post/004-javascript-apps-with-lift-callback-functions/</guid><description>&lt;p&gt;One of my favorite features of Lift is the ability to call functions on the server via ajax. This is mostly achieved using built in features. However, I also like to be able to call these functions via JavaScript directly. So, I created some functions to help with this.&lt;/p&gt;
&lt;p&gt;First, let&amp;rsquo;s take a look at &lt;a href="https://github.com/eltimn/lift-extras/blob/master/library/src/main/scala/net/liftmodules/extras/JsExtras.scala" title="JsExtras"&gt;AjaxCallbackAnonFunc&lt;/a&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; object AjaxCallbackAnonFunc {
 def apply(callback: () =&amp;gt; JsCmd): AnonFunc = {
 val funcCmd = S.fmapFunc(S.SFuncHolder(s =&amp;gt; callback()))(name =&amp;gt;
 SHtml.makeAjaxCall(JsRaw(&amp;quot;'&amp;quot; + name + &amp;quot;=true'&amp;quot;))
 )
 AnonFunc(funcCmd)
 }
 }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This creates an anonymous JavaScript function that calls the callback function via Ajax and executes the return JsCmd on the client.&lt;/p&gt;</description></item><item><title>JavaScript Apps With Lift: Organization</title><link>/post/003-javascript-apps-with-lift-organization/</link><pubDate>Wed, 03 Apr 2013 14:59:45 -0500</pubDate><guid>/post/003-javascript-apps-with-lift-organization/</guid><description>&lt;p&gt;With the goal of putting as much of our JavaScript code in external files and combing them into a single file, there are several ways to organize your code. A lot of developers are moving towards using an &lt;a href="https://github.com/amdjs/amdjs-api/wiki/AMD"&gt;AMD&lt;/a&gt; loader, in particular &lt;a href="http://requirejs.org/"&gt;RequireJS&lt;/a&gt; for webapps. With this, each of your JavaScript files will basically list the files it depends on and they are loaded by the loader. So, only the files you need are loaded. That&amp;rsquo;s only recommended for development, though. For production, all of the files are combined using an optimizer.&lt;/p&gt;</description></item><item><title>JavaScript Apps With Lift: Best Practices</title><link>/post/002-javascript-apps-with-lift-best-practices/</link><pubDate>Tue, 02 Apr 2013 14:59:45 -0500</pubDate><guid>/post/002-javascript-apps-with-lift-best-practices/</guid><description>&lt;p&gt;In this post I will discuss best practices for serving assets within the context of a Lift app. &lt;a href="https://developers.google.com/speed/docs/best-practices/rules_intro" title="Google"&gt;Google&lt;/a&gt; and &lt;a href="http://developer.yahoo.com/performance/rules.html" title="Yahoo"&gt;Yahoo&lt;/a&gt; have both published extensive material on this, so I won&amp;rsquo;t go over all of the details. I will just concentrate on the things directly related to developing webapps with Lift.&lt;/p&gt;
&lt;h4 id="minimize-http-requests"&gt;Minimize HTTP Requests&lt;/h4&gt;
&lt;p&gt;In general you should combine all of your JavaScript files into a single file. For landing pages there may be other things to consider.&lt;/p&gt;</description></item><item><title>Dealing with Boxed values in Lift snippets</title><link>/post/001-dealing-with-boxed-values-in-snippets/</link><pubDate>Tue, 26 Mar 2013 14:59:45 -0500</pubDate><guid>/post/001-dealing-with-boxed-values-in-snippets/</guid><description>&lt;p&gt;This post will demonstrate how to handle Box(ed) values in Lift snippets using for comprehensions. This is what a first attempt might look like:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;object MySnippet {
 object SomeRequestVar extends RequestVar[Box[String]](Full(&amp;quot;nothing&amp;quot;))
 def render =
 for {
 myVar &amp;lt;- SomeRequestVar.is ?~ &amp;quot;MyVar is not defined&amp;quot;
 user &amp;lt;- User.currentUser ?~ &amp;quot;You must be logged in&amp;quot;
 } yield ({
 &amp;quot;#name&amp;quot; #&amp;gt; user.name.is
 }) match {
 case Full(csssel) =&amp;gt; csssel
 case Failure(msg, _, _) =&amp;gt; &amp;quot;*&amp;quot; #&amp;gt; &amp;lt;div class=&amp;quot;error&amp;quot;&amp;gt;{msg}&amp;lt;/div&amp;gt;
 case Empty =&amp;gt; &amp;quot;*&amp;quot; #&amp;gt; &amp;lt;div class=&amp;quot;error&amp;quot;&amp;gt;Empty&amp;lt;/div&amp;gt;
 }
 }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That&amp;rsquo;s rather verbose and the last part that does the matching can be reused in all of your snippets. So, we can add an implicit conversion that will do that part for us.&lt;/p&gt;</description></item></channel></rss>