<?xml version="1.0" encoding="utf-8" ?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <id>http://pauldijou.fr/</id>
  <title>Paul Dijou Blog</title>
  <updated>2015-06-06T23:26:35+02:00</updated>
  <link href="http://pauldijou.fr/feed.atom" rel="self" type="application/atom+xml" />
  <link href="http://pauldijou.fr/" rel="alternate" type="text/html" />
  <entry>
    <id>http://pauldijou.fr/blog/2015/06/07/wtf-npm-update/</id>
    <title>WTF npm update?!</title>
    <updated>2015-06-06T23:26:35+02:00</updated>
    <published>2015-06-07T00:00:00+00:00</published>
    <link href="http://pauldijou.fr/blog/2015/06/07/wtf-npm-update/" rel="alternate" type="text/html" />
    <category term="npm"></category>
    <category term="tooling"></category>
    <summary>
      
      tl;dr
      
      Do not use npm update with any package which use custom dist-tags.
      
      Dist-tags
      
      This package has officially those 3 last versions: 1.0.0, 1.0.1 and 1.0.2. But inside the dist-tags (read more), we have two of them: the classic latest which refers to the latest stable release of the package and a custom one, named canary, indicating the last non-stable release of the package. If you are wondering if real projects are using such tags, the answer is yes, the npm package is using latest and next tags for it's weekly pre-release (read more).
      
      Currently, latest points to 1.0.1 and canary to 1.0.2. Meaning...
    </summary>
    <content type="html">
      
      &lt;h3 id=&quot;tldr&quot;&gt;tl;dr&lt;/h3&gt;
      
      &lt;p&gt;Do not use &lt;code&gt;npm update&lt;/code&gt; with any package which use custom dist-tags.&lt;/p&gt;
      
      &lt;h3 id=&quot;dist-tags&quot;&gt;Dist-tags&lt;/h3&gt;
      
      &lt;p&gt;This package has officially those 3 last versions: &lt;code&gt;1.0.0&lt;/code&gt;, &lt;code&gt;1.0.1&lt;/code&gt; and &lt;code&gt;1.0.2&lt;/code&gt;. But inside the &lt;code&gt;dist-tags&lt;/code&gt; (&lt;a href=&quot;https://docs.npmjs.com/cli/dist-tag&quot;&gt;read more&lt;/a&gt;), we have two of them: the classic &lt;code&gt;latest&lt;/code&gt; which refers to the latest stable release of the package and a custom one, named &lt;code&gt;canary&lt;/code&gt;, indicating the last non-stable release of the package. If you are wondering if real projects are using such tags, the answer is &lt;strong&gt;yes&lt;/strong&gt;, the &lt;code&gt;npm&lt;/code&gt; package is using &lt;code&gt;latest&lt;/code&gt; and &lt;code&gt;next&lt;/code&gt; tags for it's weekly pre-release (&lt;a href=&quot;https://github.com/npm/npm/wiki/Release-Process&quot;&gt;read more&lt;/a&gt;).&lt;/p&gt;
      
      &lt;p&gt;Currently, &lt;code&gt;latest&lt;/code&gt; points to &lt;code&gt;1.0.1&lt;/code&gt; and &lt;code&gt;canary&lt;/code&gt; to &lt;code&gt;1.0.2&lt;/code&gt;. Meaning that if you run &lt;code&gt;npm view test-npm-update&lt;/code&gt;, you will have something like:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;{
        name: 'test-npm-update',
        description '...',
        'dist-tags': { latest: '1.0.1', canary: '1.0.2' },
        versions: ['1.0.0', '1.0.1', '1.0.2'],
        version: '1.0.1',
        ...
      }
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;h3 id=&quot;versions&quot;&gt;Versions&lt;/h3&gt;
      
      &lt;p&gt;It's important to realize a few things here. &lt;code&gt;1.0.2&lt;/code&gt; is a released version just as &lt;code&gt;1.0.0&lt;/code&gt; and &lt;code&gt;1.0.1&lt;/code&gt; and we will say it's the &lt;strong&gt;greatest&lt;/strong&gt; one (as in the biggest number according to semver) but not the &lt;strong&gt;latest&lt;/strong&gt; one (as in the one tagged with the &lt;code&gt;latest&lt;/code&gt; dist-tag). We need to make such distinction to fully understand what will happen after that.&lt;/p&gt;
      
      &lt;p&gt;So, when you run &lt;code&gt;npm view test-npm-update&lt;/code&gt;, it actually runs &lt;code&gt;npm view test-npm-update@latest&lt;/code&gt;, meaning it will grab the informations of the &lt;strong&gt;latest&lt;/strong&gt; version. But maybe some other versions have been released with a custom tag after this one. For me, so far, so good. NPM is doing exactly what I would expect. If I want a custom release such as the canary one, I can run &lt;code&gt;npm view test-npm-update@canary&lt;/code&gt; and it will display infos about the &lt;code&gt;1.0.2&lt;/code&gt; version. In fact, but I might be wrong but I except NPM to always use the &lt;strong&gt;latest&lt;/strong&gt; version (aka the &lt;code&gt;latest&lt;/code&gt; dist-tag) by default if I don't specify anything. That's what you can mostly read all over the NPM documentation.&lt;/p&gt;
      
      &lt;p&gt;But remember, &lt;code&gt;1.0.2&lt;/code&gt; is inside the &lt;code&gt;versions&lt;/code&gt; array just like any other version. So first warning, if you use such metadata for whatever stuff you are doing, do not assume that the &lt;strong&gt;greatest&lt;/strong&gt; version inside the &lt;code&gt;versions&lt;/code&gt; array is the &lt;strong&gt;latest&lt;/strong&gt; one.&lt;/p&gt;
      
      &lt;h3 id=&quot;install&quot;&gt;Install&lt;/h3&gt;
      
      &lt;p&gt;Now, what if I run &lt;code&gt;npm install test-npm-update&lt;/code&gt;? What would you expect to be installed? &lt;code&gt;1.0.1&lt;/code&gt;right? And of course it will be this version, the &lt;strong&gt;latest&lt;/strong&gt; one. That's normal, after all, &lt;strong&gt;latest&lt;/strong&gt; is the default one. All good here.&lt;/p&gt;
      
      &lt;p&gt;What if I clean my folder and then run &lt;code&gt;npm install test-npm-update@^1.0.0&lt;/code&gt;? Guess what, &lt;code&gt;1.0.1&lt;/code&gt; will be installed. And I'm totally ok with that. I asked for the best 1.x.x version and I'm glad to have the &lt;strong&gt;latest&lt;/strong&gt; one since it matches.&lt;/p&gt;
      
      &lt;h3 id=&quot;packagejson&quot;&gt;package.json&lt;/h3&gt;
      
      &lt;p&gt;But most of the time, you don't install or update from command line, you have a &lt;code&gt;package.json&lt;/code&gt; file with a range inside it. Let's say we have the following one:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;{
        &quot;name&quot;: &quot;awesome-project&quot;,
        &quot;version&quot;: &quot;0.0.0&quot;,
        &quot;dependencies&quot;: {
          &quot;test-npm-update&quot;: &quot;^1.0.0&quot;
        }
      }
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;Pretty classic, right? Now, for the purpose of the demo, let's say we currently have the &lt;code&gt;1.0.0&lt;/code&gt; version of &lt;code&gt;test-npm-update&lt;/code&gt; locally installed. If you want to reproduce, just create an empty folder, then create a &lt;code&gt;package.json&lt;/code&gt; inside it with the previous content and run &lt;code&gt;npm install test-npm-update@1.0.0&lt;/code&gt; to force the install of an old version.&lt;/p&gt;
      
      &lt;p&gt;Done? Cool, let's move forward. NPM has a command to test if you have outdated versions locally installed. Which is our case. Let's check that by running &lt;code&gt;npm outdated&lt;/code&gt;. You should have something like:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;Package          Current  Wanted  Latest  Location
      test-npm-update  1.0.0    1.0.2   1.0.1
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;Wait a minute? I'm ok with &lt;em&gt;current&lt;/em&gt; (the locally installed) being &lt;code&gt;1.0.0&lt;/code&gt; and &lt;em&gt;latest&lt;/em&gt; (matching the dist-tag) being &lt;code&gt;1.0.1&lt;/code&gt; but &lt;em&gt;wanted&lt;/em&gt; is supposed to be the best matching version I should install according to &lt;code&gt;package.json&lt;/code&gt;. How can it be greater than &lt;em&gt;latest&lt;/em&gt;?&lt;/p&gt;
      
      &lt;p&gt;Actually, it's all ok according to the NPM documentation. After all, the &lt;code&gt;package.json&lt;/code&gt; range is &lt;code&gt;^1.0.0&lt;/code&gt; which means the greatest possible version without changing the first non-zero digit. And among &lt;strong&gt;all&lt;/strong&gt; our versions (see the &lt;code&gt;versions&lt;/code&gt; array from &lt;code&gt;npm view&lt;/code&gt;), both &lt;code&gt;1.0.1&lt;/code&gt; and &lt;code&gt;1.0.2&lt;/code&gt; match this range, but since &lt;code&gt;1.0.2&lt;/code&gt; is greater than &lt;code&gt;1.0.1&lt;/code&gt;, the &lt;em&gt;wanted&lt;/em&gt; version is &lt;code&gt;1.0.2&lt;/code&gt;.&lt;/p&gt;
      
      &lt;p&gt;I didn't expect that to be honest. That's not wrong but I can't help myself finding that strange.&lt;/p&gt;
      
      &lt;h3 id=&quot;install-again&quot;&gt;Install again&lt;/h3&gt;
      
      &lt;p&gt;Quick mention to the fact that if I run &lt;code&gt;npm install&lt;/code&gt; with my &lt;code&gt;package.json&lt;/code&gt; in an empty folder (aka without the &lt;code&gt;1.0.0&lt;/code&gt; version already installed), it will still install &lt;code&gt;1.0.1&lt;/code&gt; version. That's ok according to &lt;strong&gt;latest&lt;/strong&gt; being the default one. Back to our outdated &lt;code&gt;1.0.0&lt;/code&gt; version.&lt;/p&gt;
      
      &lt;h3 id=&quot;update&quot;&gt;Update&lt;/h3&gt;
      
      &lt;p&gt;Things start to get really ugly now. So, &lt;code&gt;npm outdated&lt;/code&gt; just told me I have an old local version. I should probably update it, and NPM has a command for that. Let's run &lt;code&gt;npm update&lt;/code&gt;. To be honest, I wasn't sure anymore what would be installed locally. I mean, I would have normally expected the &lt;code&gt;1.0.1&lt;/code&gt; version. My brain was like &quot;It should be the greatest &lt;strong&gt;stable&lt;/strong&gt; version which match the range&quot;, with &lt;strong&gt;stable&lt;/strong&gt; meaning lower or equal to the &lt;code&gt;latest&lt;/code&gt; tag, but for NPM, it's more like &quot;It should be the greatest version which match the range. Period.&quot;. And it makes all the difference. My brain stops at &lt;code&gt;1.0.1&lt;/code&gt; as the latest stable but NPM browse &lt;strong&gt;all&lt;/strong&gt; version, including any custom dist-tags, including the &lt;code&gt;canary&lt;/code&gt; version.&lt;/p&gt;
      
      &lt;p&gt;At the end, running &lt;code&gt;npm update&lt;/code&gt; will install &lt;code&gt;1.0.2&lt;/code&gt; version. This is &lt;strong&gt;wrong&lt;/strong&gt;. According to &lt;a href=&quot;https://docs.npmjs.com/cli/update&quot;&gt;documentation&lt;/a&gt;:&lt;/p&gt;
      
      &lt;blockquote&gt;
        &lt;p&gt;This command will update all the packages listed to the latest version (specified by the tag config), respecting semver.&lt;/p&gt;
      &lt;/blockquote&gt;
      
      &lt;p&gt;I read that as the &lt;strong&gt;latest&lt;/strong&gt; version according to &lt;code&gt;latest&lt;/code&gt; dist-tag. But we just updated to a version beyond this &lt;strong&gt;latest&lt;/strong&gt; version. In any case, this is super dangerous! It means you can update to non-stable versions without even noticing it.&lt;/p&gt;
      
      &lt;p&gt;What if we didn't have the &lt;code&gt;1.0.0&lt;/code&gt; already installed? Since &lt;code&gt;npm update&lt;/code&gt; also install missing packages, it will indeed install &lt;code&gt;test-npm-update&lt;/code&gt; according to &lt;code&gt;package.json&lt;/code&gt; and, of course, to the &lt;code&gt;1.0.2&lt;/code&gt; version.&lt;/p&gt;
      
      &lt;h3 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h3&gt;
      
      &lt;p&gt;IMHO, I think this is way too dangerous, &lt;code&gt;npm update&lt;/code&gt; should be capped by the &lt;strong&gt;latest&lt;/strong&gt; version, and so should &lt;code&gt;npm outdated&lt;/code&gt;. By default, no command should target versions beyond &lt;code&gt;latest&lt;/code&gt; dist-tag. Also, it seems inconsistent to have &lt;code&gt;install&lt;/code&gt; and &lt;code&gt;update&lt;/code&gt; both capable of installing a missing package from a &lt;code&gt;package.json&lt;/code&gt; file but not to the same version.&lt;/p&gt;
      
      &lt;p&gt;I raised an issue on &lt;a href=&quot;https://github.com/npm/npm/issues/8476&quot;&gt;Github&lt;/a&gt;, we will see. Be careful from now on.&lt;/p&gt;
      
      &lt;p&gt;Thanks for reading! Spread the word.&lt;/p&gt;
      
      &lt;h3 id=&quot;personal-ad&quot;&gt;Personal ad&lt;/h3&gt;
      
      &lt;p&gt;It might be a bit too early to speak about that, but if you need an &lt;code&gt;outdated&lt;/code&gt; command which is actually capped by the &lt;code&gt;latest&lt;/code&gt; tag and also support other package managers (like Bower), please check my &lt;a href=&quot;https://github.com/pauldijou/outdated&quot;&gt;outdated&lt;/a&gt; project. It's not ready at all yet but it will be in the next few days, promise.&lt;/p&gt;
    </content>
  </entry>
  <entry>
    <id>http://pauldijou.fr/blog/2014/08/05/browser-sync-play-framework/</id>
    <title>BrowserSync proxy in top of a Play Framework server</title>
    <updated>2015-06-06T15:40:57+02:00</updated>
    <published>2014-08-05T00:00:00+00:00</published>
    <link href="http://pauldijou.fr/blog/2014/08/05/browser-sync-play-framework/" rel="alternate" type="text/html" />
    <category term="play"></category>
    <category term="browserSync"></category>
    <category term="gulp"></category>
    <category term="tooling"></category>
    <summary>
      
      TL;DR 'coz I'm a h4k3r
      
      Full source code of the demo is on GitHub with a nice and simple README on how to bootstrap the project.
      
      What are you talking about dude?
      
      Play Framework is an HTTP server written in Scala. It is super cool and you should probably give it a try. Let's say you are using it, you really enjoy how productive it is, only having to refresh your browser to see all your code modifications, but you want to go further, you want live-reloading! There are several tools doing that.
      
      Introducing BrowserSync. It provides 2 killers features. One is live-reloading: it...
    </summary>
    <content type="html">
      
      &lt;h3 id=&quot;tldr-coz-im-a-h4k3r&quot;&gt;TL;DR 'coz I'm a h4k3r&lt;/h3&gt;
      
      &lt;p&gt;Full source code of the demo is &lt;a href=&quot;https://github.com/blogsamples/play-browserSync&quot;&gt;on GitHub&lt;/a&gt; with a nice and simple README on how to bootstrap the project.&lt;/p&gt;
      
      &lt;h3 id=&quot;what-are-you-talking-about-dude&quot;&gt;What are you talking about dude?&lt;/h3&gt;
      
      &lt;p&gt;&lt;a href=&quot;http://www.playframework.com&quot;&gt;Play Framework&lt;/a&gt; is an HTTP server written in Scala. It is super cool and you should probably give it a try. Let's say you are using it, you really enjoy how productive it is, only having to refresh your browser to see all your code modifications, but you want to go further, you want live-reloading! There are several tools doing that.&lt;/p&gt;
      
      &lt;p&gt;Introducing &lt;a href=&quot;http://www.browsersync.io&quot;&gt;BrowserSync&lt;/a&gt;. It provides 2 killers features. One is live-reloading: it can monitor resources, and when it detects some modifications, it will reload the browser page to load them. Even better, if possible, it will hot deploy them, meaning they will be loaded without reloading the page. That's the case for CSS files which are loaded and the page repainted to display the new design without any refresh. The second one is to keep synchronized several browsers across devices. And we are not talking about resources only but about all user actions. If you scroll on one browser, it will scroll on all connected browsers, same for clicking on a button, and so on…&lt;/p&gt;
      
      &lt;p&gt;Let me say it again with a concrete example. You are on your computer, one screen with your source code, another one with Chrome opened and a last one with Firefox. You also have an iPad tablet and an Android smartphone connected to your computer. All of those have your application main page opened. Each time your edit your code, they will all reload and display the new result (hot deploy in case of CSS). When you are ready to test interactions, you just go to, let's say, your Chrome browser and start scrolling and clicking. All your screens will start moving and doing the actions everywhere. Talk about increasing productivity!!&lt;/p&gt;
      
      &lt;p&gt;What about assets that require compilation? Such as SCSS, LESS, Stylus, CoffeeScript, etc… No biggy bro (or sis), we have you covered. In this demo, we will use &lt;a href=&quot;http://gulpjs.com/&quot;&gt;Gulp&lt;/a&gt; to monitor those resources, compile them, and pass them to BrowserSync for live-reloading (obviously not losing the hot deploy if possible). You can freely use whatever build tool you want, be it Grunt, Broccoli, …&lt;/p&gt;
      
      &lt;h3 id=&quot;magic-proxy&quot;&gt;Magic proxy&lt;/h3&gt;
      
      &lt;p&gt;BrowserSync could be used as the web server, that's the easiest way to use it, and I'm actually doing it when my Play server is only here to provide a REST API. Consider doing that when you don't need Scala templates or when you cannot use them (for example if you want to embed all your standalone HTML files inside a Cordova / PhoneGap application).&lt;/p&gt;
      
      &lt;p&gt;But here, we want to use Play as the web server, meaning it will be responsible to serve all our assets: HTML, CSS and JavaScript. For that, we will need to use the &lt;code&gt;proxy&lt;/code&gt; feature of BrowserSync. Long story short, it will start another web server, on its own port, and will display the exact content from the Play server but adding a bit of JavaScript magic in it so it can enable all its features. It is just like opening your Play application, just on a different port. By default, you would use the port &lt;code&gt;9000&lt;/code&gt; for Play, in this demo, we will set the proxy on port &lt;code&gt;9001&lt;/code&gt; (it would have been around &lt;code&gt;3000&lt;/code&gt; by default, but I didn't want anyone to freak out so I put it as close as possible to Play default one).&lt;/p&gt;
      
      &lt;p&gt;We also want to live-reload some of our resources. I kept it simple for this demo, but you are free to add as many as your want. We will use the &lt;code&gt;files&lt;/code&gt; property of BrowserSync configuration and set and array of files to monitor (it supports wildcards). Here, we are monitoring all CSS files from &lt;code&gt;public/stylesheets&lt;/code&gt;, JavaScript files from &lt;code&gt;public/javascripts&lt;/code&gt; and HTML files from  &lt;code&gt;app/views&lt;/code&gt;. There are two important points to notice here. First, we are referencing files based on their path on the source code, not on their actual url. For example, &lt;code&gt;public/stylesheets/main.css&lt;/code&gt; will be served by Play as &lt;code&gt;assets/stylesheets/main.css&lt;/code&gt;, but BrowserSync only needs to know the real path, after that, you can map it to whatever url you want. Second, we are monitoring Scala templates, and it's fine because when BrowserSync will detect a modification, it will reload the page, and Play will re-compile the template before serving it, so it will display the new version. It works just fine with both &lt;code&gt;run&lt;/code&gt; and &lt;code&gt;~run&lt;/code&gt; , the latest being faster.&lt;/p&gt;
      
      &lt;p&gt;Here is a super small configuration for BrowserSync to enable such a proxy. You can read the &lt;a href=&quot;http://www.browsersync.io/docs/options/&quot;&gt;online documentation&lt;/a&gt; to extend it.&lt;/p&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;var browserSync = require('browser-sync');
      
      browserSync({
        // By default, Play is listening on port 9000
        proxy: 'localhost:9000',
        // We will set BrowserSync on the port 9001
        port: 9001,
        // Reload all assets
        // Important: you need to specify the path on your source code
        // not the path on the url
        files: ['public/stylesheets/*.css', 'public/javascripts/*.js', 'app/views/*.html'],
        open: false
      });
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;h3 id=&quot;what-about-compiled-assets&quot;&gt;What about compiled assets?&lt;/h3&gt;
      
      &lt;p&gt;Right… right… there are assets that you cannot serve directly, you need to preprocess them. The easiest way to do that is using a build tool, just pick one among the best ones (Gulp, Grunt, Broccoli, Brunch, …) and enjoy. There is a really simple separation of concern here: the build tool only manage assets that are not served directly (LESS, CoffeeScript, …) and compile them into assets that are actually handled by BrowserSync (CSS, JavaScript, images, …) which then live-reload them.&lt;/p&gt;
      
      &lt;p&gt;It's so easy that it's nearly frustrating. In the demo, the &lt;code&gt;main.css&lt;/code&gt; file is generated from &lt;code&gt;main.less&lt;/code&gt;. I have two Gulp task to handle that: one for compilation and one to monitor any modification.&lt;/p&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;var gulp        = require('gulp');
      var less        = require('gulp-less');
      
      // Registering a 'less' task that just compile our LESS files to CSS
      gulp.task('less', function() {
        return gulp.src('./resources/less/main.less')
          .pipe(less())
          .pipe(gulp.dest('./public/stylesheets'));
      });
      
      // Let's watch our LESS files and compile them at each modification
      gulp.task('watch', function () {
        gulp.watch(['./resources/less/*.less'], ['less']);
      });
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;h3 id=&quot;wait-where-are-sbt-web-and-webjars&quot;&gt;Wait, where are sbt-web and webjars?&lt;/h3&gt;
      
      &lt;p&gt;Yeaaaaah… so lately, Play has introduced all those stuff on managing assets using SBT, some plugins and webjars. It works just fine but for me, it's just as strange as if I would install Play from NPM. It's cool if people want to try to merge two super different worlds (front-end and back-end), be it Node.js or scala.js, but I'm totally not ready for that. As a full stack developer, I want to enjoy each world with its own ecosystem, not trying to bend one into the other.&lt;/p&gt;
      
      &lt;p&gt;That's why in all my projects, front-end assets are handled by front-end tooling (mostly Gulp and NPM lately) and my back-end resources by back-end tools (SBT, Ivy, Maven, …). Not only do I get the best of each, but I do not have some limitations. For example, the other day, I came across a bug on a JavaScript library I was using. No biggy: fork the repo, correct the bug, do a pull request. And while waiting for the author to merge it (which can take some time), I am free to directly use my fork inside my &lt;code&gt;package.json&lt;/code&gt; so it's not blocking at all. It tooks me less than an hour. I would be curious on how to do that using webjars? Anyway, sorry for not planning any proof of concept using webjars if that's what you are using.&lt;/p&gt;
      
      &lt;p&gt;And that's it! As I said at the beginning of the article, the demo is &lt;a href=&quot;https://github.com/blogsamples/play-browserSync&quot;&gt;on GitHub&lt;/a&gt;, feel free to clone and play with it. Enjoy and thanks for reading.&lt;/p&gt;
    </content>
  </entry>
  <entry>
    <id>http://pauldijou.fr/blog/2014/08/04/prismicio-responsive-images-inside-structured-text/</id>
    <title>Prismic.io: responsive images inside a StructuredText</title>
    <updated>2015-06-06T15:40:57+02:00</updated>
    <published>2014-08-04T00:00:00+00:00</published>
    <link href="http://pauldijou.fr/blog/2014/08/04/prismicio-responsive-images-inside-structured-text/" rel="alternate" type="text/html" />
    <category term="prismic"></category>
    <summary>
      
      Once again, I will not explain what prismic.io is (but it's a tool to manage your website content), I will only focus on one limitation and how to solve it. If you don't know about prismic.io, you should quickly check its website before reading any further.
      
      What's the problem?
      
      In prismic.io, you are creating Documents which are composed of Fragments. A fragment is data organized in a more or less semantic way. For example, a fragment can be a Number, or a Date, … Among them, there is the type Image which is really nice because you can not only fully resize...
    </summary>
    <content type="html">
      
      &lt;p&gt;Once again, I will not explain what &lt;a href=&quot;http://prismic.io&quot;&gt;prismic.io&lt;/a&gt; is (but it's a tool to manage your website content), I will only focus on one limitation and how to solve it. If you don't know about prismic.io, you should quickly check its website before reading any further.&lt;/p&gt;
      
      &lt;h3 id=&quot;whats-the-problem&quot;&gt;What's the problem?&lt;/h3&gt;
      
      &lt;p&gt;In prismic.io, you are creating Documents which are composed of Fragments. A fragment is data organized in a more or less semantic way. For example, a fragment can be a Number, or a Date, … Among them, there is the type Image which is really nice because you can not only fully resize / crop your raw picture, but also add smaller images based on the original one for responsive purpose. You can upload your awesome photo of this beautiful sunset, fully sized at 4000 x 3000 pixels, resize it for desktop at 1920 x 1080, and finally add a mobile version at 320 * 480. Note that the last one doesn't respect the ratio at all, but that's the goal: you are creating a subset of your image with the best match possible regarding the targeted screen.&lt;/p&gt;
      
      &lt;p&gt;Another really powerful fragment in prismic is the StructuredText. It allows you to have a nice WYSIWYG editor inside which you will put new fragments (paragraphs, links, titles, images, …). It would be perfect if the image fragment inside a StructuredText was a real Image fragment, but it is not. You cannot specify any thumbnail. Meaning your content cannot be responsive at all. Your choice is: consume all the bandwith for mobiles with awesome full HD images or make the eyes of your desktop users bleed with super compressed images.&lt;/p&gt;
      
      &lt;h3 id=&quot;you-dont-want-to-do-that&quot;&gt;You don't want to do that!&lt;/h3&gt;
      
      &lt;p&gt;And me neither! I want to have responsive images inside my StructuredText for God sake. I love tools which make my life easier, but they never should stand on my way to craft the best website possible. I will not lie to you, I couldn't find any solution that integrates nicely with the WYSIWYG editor since there is no way to extend it. The following solution will be a bit of hacking and your writers might complain about it at first.&lt;/p&gt;
      
      &lt;p&gt;So, what's the idea? The only way to have responsive images is to use a real Image fragment, no choice here. So let's create one, and let's put it inside a Group fragment. This way, you can add and remove as many images as you want and they will all be responsive. Wait, you can't do that inside the StructuredText, right? Indeed, that's why we will do outside of it and then find a way to bring back the images inside of it. Here is the mask for such a group:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&quot;Images&quot; : {
        &quot;images&quot; : {
          &quot;type&quot; : &quot;Group&quot;,
          &quot;fieldset&quot; : &quot;Images&quot;,
          &quot;config&quot; : {
            &quot;fields&quot; : {
              &quot;name&quot; : {
                &quot;type&quot; : &quot;Text&quot;,
                &quot;config&quot; : {
                  &quot;label&quot; : &quot;Name&quot;
                }
              },
              &quot;caption&quot; : {
                &quot;type&quot; : &quot;Text&quot;,
                &quot;config&quot; : {
                  &quot;label&quot; : &quot;Caption&quot;
                }
              },
              &quot;image&quot; : {
                &quot;type&quot; : &quot;Image&quot;,
                &quot;config&quot; : {
                  &quot;thumbnails&quot; : [ {
                    &quot;name&quot; : &quot;mobile&quot;
                  }, {
                    &quot;name&quot; : &quot;tablet&quot;
                  } ]
                }
              }
            }
          }
        }
      }
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;p class=&quot;alert alert-info&quot;&gt;&lt;strong&gt;Pro Tip&lt;/strong&gt; - When creating thumbnails for an Image fragment, the &lt;a href=&quot;https://developers.prismic.io/documentation/UjBeuLGIJ3EKtgBV/repository-administrators-manual#document-masks&quot;&gt;offical documentation&lt;/a&gt; states that both width and height are mandatory. This is &lt;strong&gt;wrong&lt;/strong&gt;, you can specify only one of the two or even none of them. Your UI might be a bit ugly (the resized thumbnails will only display after saving your draft) and sometimes you will have to click twice on a button (this one, I really don't understand) but otherwise, it works just fine. I hope prismic guys will make those attributes optional because… well… how can you anticipate how the writer wants to resize its image?&lt;/p&gt;
      
      &lt;p&gt;As you can see, I added two more fields. One is &lt;code&gt;name&lt;/code&gt; and we will use it to reference our images inside the StructuredText. The other one is &lt;code&gt;caption&lt;/code&gt;, that's because I want to put one on my images but prismic didn't allow me to do that at all by default. Thanks God, using this solution, I can finally do it, killing two birds with one stone. Now we can add as many responsive images as we want, yeah! Let's grab some orange juice to celebrate!&lt;/p&gt;
      
      &lt;h3 id=&quot;lets-hack-some-html&quot;&gt;Let's hack some HTML&lt;/h3&gt;
      
      &lt;p&gt;As I already said it, the next step will be to bring those images inside the StructuredText. We cannot do that directly inside the WYSIWYG editor but we can do it when rendering the final HTML. We will need two more things here:&lt;/p&gt;
      
      &lt;ul&gt;
        &lt;li&gt;having a placeholder inside the StructuredText to indicate we should insert an image&lt;/li&gt;
        &lt;li&gt;extend the default HTML renderer to support such placeholder&lt;/li&gt;
      &lt;/ul&gt;
      
      &lt;p&gt;As for the placeholder, I decided to use a simple format like &lt;code&gt;{image-[name of the image]}&lt;/code&gt;. Meaning that if the content of a paragraph inside my StructuredText is &lt;code&gt;{image-sunset}&lt;/code&gt;, it will actually render the image named &lt;code&gt;sunset&lt;/code&gt; from the group of images when generating the final HTML. Pretty easy right? Your writers might find it ugly, having to write those strange tags, and not seeing their images directly inside the StructuredText, but just tell them that's for the greater good. You could, of course, use another syntax, eventually support attributes, whatever.&lt;/p&gt;
      
      &lt;p&gt;The final task, and probably the hardest one, is to extend the HTML rendering system. Each primisc fragment has its own way to render as HTML. Unfortunately, there is no way to extend it, you can only, eventually, override it. And the one for StructuredText is by far the most complex one. The easiest way to do that is to copy/paste the default one from the kit you are using (if you are not using any kit, you are free to do whatever you want, so it's fine) and edit it. You will then edit the part responsible for rendering a paragraph, test if its content match our placeholder syntax, if so, render an image, if not, just render the text as it is. Since I'm using the JavaScript kit, here is the &lt;a href=&quot;https://github.com/pauldijou/farewell/blob/9a744565d7e66f06aa9a3edf7e360db0f00c70aa/scripts/prismic.js#L65-L159&quot;&gt;full copy/paste&lt;/a&gt; but that's the &lt;a href=&quot;https://github.com/pauldijou/farewell/blob/9a744565d7e66f06aa9a3edf7e360db0f00c70aa/scripts/prismic.js#L105-L117&quot;&gt;important part&lt;/a&gt; where we are rendering the image. My &lt;code&gt;model&lt;/code&gt; is actually a JavaScript class extracted from the original prismic Document, but you could use the raw Document of course.&lt;/p&gt;
      
      &lt;h3 id=&quot;conclusion-and-limitations&quot;&gt;Conclusion and limitations&lt;/h3&gt;
      
      &lt;p&gt;That's pretty much it. Here is a quick summary of what to do:&lt;/p&gt;
      
      &lt;ul&gt;
        &lt;li&gt;inside the mask, add a Group of Images with, at least, a Text fragment for the name.&lt;/li&gt;
        &lt;li&gt;choose a naming convention to write placeholders inside a StructuredText, ex: &lt;code&gt;{image-[name]}&lt;/code&gt;
      &lt;/li&gt;
        &lt;li&gt;override the StructuredText HTML rendering function with a custom one inserting images from the Document when finding a placeholder&lt;/li&gt;
        &lt;li&gt;you can add more attributes and render them (like a caption)&lt;/li&gt;
      &lt;/ul&gt;
      
      &lt;p&gt;What are the bad points / limitations of the solution?&lt;/p&gt;
      
      &lt;ul&gt;
        &lt;li&gt;writers need to write placeholders rather than having a nice UI to insert images&lt;/li&gt;
        &lt;li&gt;images do not display natively in the WYSIWYG editor anymore&lt;/li&gt;
        &lt;li&gt;you cannot re-order a Group fragment right now, meaning images will be sorted based on their created date and not on their place inside the StructuredText&lt;/li&gt;
      &lt;/ul&gt;
    </content>
  </entry>
  <entry>
    <id>http://pauldijou.fr/blog/2014/08/01/doing-conference-website-two-days/</id>
    <title>Doing a conference website in two days</title>
    <updated>2015-06-06T15:40:57+02:00</updated>
    <published>2014-08-01T00:00:00+00:00</published>
    <link href="http://pauldijou.fr/blog/2014/08/01/doing-conference-website-two-days/" rel="alternate" type="text/html" />
    <category term="web"></category>
    <summary>
      
      Last week, on Wednesday, I had a meeting with some colleagues at Movio about the Scala Downunder conference. It's a Scala conference in Auckland, New Zealand, with speakers from Typesafe and local ones, and some replay from Scala Days. I discovered that we were doing the website for the conference here at Movio, and also that it was due for the following Friday in order to send it to Typesafe for feedback…. Ah, and also I would be crafting it.
      
      (Pssst… okay, there has been some commits on the repo after the deadline, but that's only because the schedule totally changed,...
    </summary>
    <content type="html">
      
      &lt;p&gt;Last week, on Wednesday, I had a meeting with some colleagues at &lt;a href=&quot;http://pauldijou.fr//movio.co&quot;&gt;Movio&lt;/a&gt; about the &lt;a href=&quot;http://scaladownunder.org&quot;&gt;Scala Downunder&lt;/a&gt; conference. It's a Scala conference in Auckland, New Zealand, with speakers from Typesafe and local ones, and some replay from Scala Days. I discovered that we were doing the website for the conference here at Movio, and also that it was due for the following Friday in order to send it to Typesafe for feedback…. Ah, and also I would be crafting it.&lt;/p&gt;
      
      &lt;p&gt;(Pssst… okay, there has been some commits on the repo after the deadline, but that's only because the schedule totally changed, not my fault!)&lt;/p&gt;
      
      &lt;h3 id=&quot;lets-get-started&quot;&gt;Let's get started!&lt;/h3&gt;
      
      &lt;p&gt;So, deadline is 2 days from now, the website is only one long page with all classic stuff: presentation, speakers, schedule, location and sponsors. Really good point: both the design and the content are nearly fully done. Otherwise, it would have been impossible.&lt;/p&gt;
      
      &lt;p&gt;My first step was to pick my tooling. I truly hate copy/pasting anything so it was out of question to copy/paste HTML when it comes to iterable data. I needed a static HTML website generator. Since the plan was to publish it on GitHub Pages, I choose &lt;a href=&quot;http://jekyllrb.com&quot;&gt;Jekyll&lt;/a&gt;. This way, I would have the build for free, only needing to push on the &lt;code&gt;gh-pages&lt;/code&gt; branch my source code (at the end, that didn't work at all, but Jekyll is still a good choice). Bootstraping with Jekyll is super fast as long as you already have Ruby installed on your machine.&lt;/p&gt;
      
      &lt;p&gt;Next I picked &lt;a href=&quot;http://gulpjs.com/&quot;&gt;Gulp&lt;/a&gt; as my build tool. I love both &lt;a href=&quot;http://gruntjs.com/&quot;&gt;Grunt&lt;/a&gt; and Gulp, but I'm trying to be more familiar with Gulp lately (at some point, I will switch to &lt;a href=&quot;https://github.com/broccolijs/broccoli&quot;&gt;Broccoli&lt;/a&gt; anyway). Here is one &lt;strong&gt;important point&lt;/strong&gt;: you should have snippets for each Gulp (or Grunt) task ready somewhere so you can do your setup in minutes. For example, here, I wanted to use &lt;a href=&quot;http://lesscss.org/&quot;&gt;LESS&lt;/a&gt; as CSS preprocessor, &lt;a href=&quot;http://browserify.org/&quot;&gt;Browserify&lt;/a&gt; for JavaScript packaging and &lt;a href=&quot;http://www.browsersync.io/&quot;&gt;BrowserSync&lt;/a&gt; for live-reloading. I already got all those snippets, so I just needed to copy/paste them once in order to have my server running live and compiling all my assets.&lt;/p&gt;
      
      &lt;h3 id=&quot;be-semantic-with-your-content&quot;&gt;Be semantic with your content&lt;/h3&gt;
      
      &lt;p&gt;Remember, what's the most important is your content, not the design nor the funky JavaScript effects. And don't try to rush to apply funny colors or amazing transitions before having a real content behind them or you might not see the real behaviour when implementing them. Since I already have it, I wrote only HTML during the first hour. It allows me to be 100% semantic with my content. I don't care about CSS selectors or whatever, if this is a paragraph, I create a &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; tag, if this is a section, let's use a &lt;code&gt;&amp;lt;section&amp;gt;&lt;/code&gt; tag. And at the end, you can already see the 0.0.1 version of you website, fully &quot;usable&quot; (just a bit ugly, and tons of typos).&lt;/p&gt;
      
      &lt;p&gt;&lt;img src=&quot;http://pauldijou.fr/blog/assets/2014-07-30/downunder001.png&quot; alt=&quot;downunder001&quot;&gt;&lt;/p&gt;
      
      &lt;p&gt;After that, I worked to all dynamic parts of my HTML. I really wanted to have full content before starting doing any LESS. I used the &lt;code&gt;_data&lt;/code&gt; folder of Jekyll that allow me to structured data in YAML files. I put all speakers and schedule in it. After that, it's all about the &lt;a href=&quot;http://docs.shopify.com/themes/liquid-documentation/basics&quot;&gt;Liquid templating&lt;/a&gt; system to render it. You have &lt;code&gt;for&lt;/code&gt; loops and &lt;code&gt;if&lt;/code&gt; blocks, you have filers to render Markdown or whatever, for such a simple website, it was more than enough.&lt;/p&gt;
      
      &lt;p&gt;At this point, we are something like nearly half a day in the project and we have all the content and a nice setup allowing us to be super productive. It could have been faster, but there was quite some content to write and it took me a bit more time than planned to implement all my templating. That's cool!&lt;/p&gt;
      
      &lt;h3 id=&quot;do-it-with-style&quot;&gt;Do it with style&lt;/h3&gt;
      
      &lt;p&gt;As you can image, the next step is doing all the website design. If possible, I prefer to write all CSS classes first, staying close to the HTML semantic and then implement them rather than inventing crazy CSS selectors and then bind them to your HTML. It's important to know what's your browser target. Because, trust me, you want to use &lt;code&gt;flexbox&lt;/code&gt; but that means IE10+ (using a LESS mixins for old syntax). Lucky me, I could do that. If not, consider using a grid system.&lt;/p&gt;
      
      &lt;p&gt;When doing the design, never &lt;strong&gt;ever&lt;/strong&gt; think &quot;Oh, it looks already pretty good… I shouldn't be far away from the end&quot;. There is this &lt;a href=&quot;http://en.wikipedia.org/wiki/Pareto_principle&quot;&gt;Pareto principle&lt;/a&gt; that apply a lot to CSS in my opinion. It means that in just two hours, I had a decent design, but in the and, it costs me a full day to have the final thing. Why? Because after having done the main style, you will start testing on other browsers, on other devices, find small bugs, and spend way too much time to correct them. Also, at some point, if you can, you should review the website with the designer, and this is vital but sometime really hard. He will probably want to reach pixel perfection and nobody can blame him for that, take time and probably some refactoring, and also some hacks. At the end, you will have spent 20% of your time having a nice (but not perfect) design on Chrome, and 80% having a pixel perfect design on most modern browsers, being responsive, and having a decent fallback on old ones.&lt;/p&gt;
      
      &lt;p&gt;It was a pretty simple design so it was quite straightforward. Just remember you can do magic with pseudo-elements. I use them a lot for all those forms (circles, traits, …). Flexbox is doing an awesome job to overcome old CSS limitations (Who said vertical align?) and being responsive. This way, I didn't have do use any open-source CSS project except for my reset, using the awesome &lt;a href=&quot;http://necolas.github.io/normalize.css/&quot;&gt;normalize.css&lt;/a&gt;.&lt;/p&gt;
      
      &lt;p&gt;I also decided to use pure SVG rather than a font for my icons. This decision was based on reading great articles from Chris Coyier, like &lt;a href=&quot;http://css-tricks.com/svg-sprites-use-better-icon-fonts/&quot;&gt;this one&lt;/a&gt;, &lt;a href=&quot;http://css-tricks.com/svg-symbol-good-choice-icons/&quot;&gt;that one&lt;/a&gt; and finally &lt;a href=&quot;http://css-tricks.com/icon-fonts-vs-svg/&quot;&gt;this battle one&lt;/a&gt;. All worked fine.&lt;/p&gt;
      
      &lt;h3 id=&quot;finish-the-script&quot;&gt;Finish the script&lt;/h3&gt;
      
      &lt;p&gt;During the last half day, I focused on writing the small JavaScript needed for the website. There really wasn't much of it: double sticky navigation bar, nice scrolling between sections and modal panel for each talk description. Let's be honest, since I am targeting IE10+, I totally didn't need jQuery. But if you check the source code, you will find it. Why? I was starting to run out of time and I really wanted to use some nice plugins to leverage all the grunt work. Also, using one of the last version of jQuery, it will be fast enough and will not add too much of a payload. So… it's fine.&lt;/p&gt;
      
      &lt;p&gt;I finally had the chance to use &lt;a href=&quot;http://julian.com/research/velocity/&quot;&gt;Velocity&lt;/a&gt;, a jQuery plugin for animations. It works just great, super fast even on mobile. You should try it. It powers both the scrolling and the modal animation. For the stick navs, I choose the &lt;a href=&quot;http://stickyjs.com/&quot;&gt;Sticky plugin&lt;/a&gt; which is simple and great. Nothing more to add. I packaged all that stuff with Browserify, but more because I love this tool rather than because it was needed.&lt;/p&gt;
      
      &lt;h3 id=&quot;going-further&quot;&gt;Going further&lt;/h3&gt;
      
      &lt;p&gt;So, why didn't it work to only push to &lt;code&gt;gh-pages&lt;/code&gt;? It did at first, but then I started to use more complex features with Jekyll 2.x and, guess what? GitHub Pages still use a 1.x Jekyll version, so it didn't match. Also, I wanted to do post generation stuff, like &lt;a href=&quot;https://www.npmjs.org/package/gulp-usemin&quot;&gt;usemin&lt;/a&gt; to minify all my assets and append then with a hash version, also updating the index HTML file. I just had to wrote a simple &lt;a href=&quot;https://github.com/movio/scala-downunder/blob/master/_gulp/deploy.js&quot;&gt;deploy script&lt;/a&gt; in order to overcome the problem.&lt;/p&gt;
      
      &lt;p&gt;I don't really want to go through all the details, but you can see the &lt;a href=&quot;http://scaladownunder.org/&quot;&gt;final result&lt;/a&gt;, read the &lt;a href=&quot;https://github.com/movio/scala-downunder&quot;&gt;full source code&lt;/a&gt;, and here are a few highlights:&lt;/p&gt;
      
      &lt;ul&gt;
        &lt;li&gt;
      &lt;a href=&quot;https://github.com/movio/scala-downunder/blob/master/resources/scripts/map.js&quot;&gt;integrate a nice Google maps&lt;/a&gt; based on &lt;a href=&quot;http://snazzymaps.com/&quot;&gt;Snazzy Maps&lt;/a&gt; design.&lt;/li&gt;
        &lt;li&gt;Diplay and hide &lt;a href=&quot;https://github.com/movio/scala-downunder/blob/master/resources/scripts/track.js&quot;&gt;the modal&lt;/a&gt; for talk descriptions&lt;/li&gt;
        &lt;li&gt;
      &lt;a href=&quot;https://github.com/movio/scala-downunder/blob/master/_gulp/sprites.js&quot;&gt;Package SVG icons&lt;/a&gt;, enjoy the &lt;a href=&quot;https://github.com/movio/scala-downunder/blob/master/_includes/icons.svg&quot;&gt;result&lt;/a&gt;, use them &lt;a href=&quot;https://github.com/movio/scala-downunder/blob/ee90ff5dbf/_includes/sponsors.html#L2-L4&quot;&gt;in HTML&lt;/a&gt; and &lt;a href=&quot;https://github.com/movio/scala-downunder/blob/ee90ff5dbf/resources/styles/global.less#L31-L36&quot;&gt;style them&lt;/a&gt;.&lt;/li&gt;
        &lt;li&gt;Do &lt;a href=&quot;https://github.com/movio/scala-downunder/blob/master/_includes/schedule.html&quot;&gt;crazy templating madness&lt;/a&gt;
      &lt;/li&gt;
      &lt;/ul&gt;
      
      &lt;p&gt;Hope you liked it! Thanks for reading.&lt;/p&gt;
    </content>
  </entry>
  <entry>
    <id>http://pauldijou.fr/blog/2014/07/26/prismicio-javascript-kit-from-callbacks-to-promises/</id>
    <title>Prismic.io JavaScript kit: from callbacks to promises</title>
    <updated>2015-06-06T15:40:57+02:00</updated>
    <published>2014-07-26T00:00:00+00:00</published>
    <link href="http://pauldijou.fr/blog/2014/07/26/prismicio-javascript-kit-from-callbacks-to-promises/" rel="alternate" type="text/html" />
    <category term="prismic"></category>
    <summary>
      
      Holy cow, callbacks!
      
      For the last (and only) website I did using prismic.io, I didn't want any back-end, all client-side, pure JavaScript man. This way, I could host it nearly anywhere for pretty much free (GitHub pages FTW). To ease stuff, I decided to use the JavaScript kit from the prismic.io team.
      
      One choice they made and that I don't really like is using callbacks in it. For example, you have to write stuff like:
      
      // Get the current API
      Prismic.Api('/my/awesome/url', function (err, api) {
        if (err) {
          // handle error
          return;
        }
      
        // Use...
    </summary>
    <content type="html">
      
      &lt;h3 id=&quot;holy-cow-callbacks&quot;&gt;Holy cow, callbacks!&lt;/h3&gt;
      
      &lt;p&gt;For the last (and only) website I did using prismic.io, I didn't want any back-end, all client-side, pure JavaScript man. This way, I could host it nearly anywhere for pretty much free (GitHub pages FTW). To ease stuff, I decided to use the &lt;a href=&quot;https://github.com/prismicio/javascript-kit&quot;&gt;JavaScript kit&lt;/a&gt; from the prismic.io team.&lt;/p&gt;
      
      &lt;p&gt;One choice they made and that I don't really like is using callbacks in it. For example, you have to write stuff like:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;// Get the current API
      Prismic.Api('/my/awesome/url', function (err, api) {
        if (err) {
          // handle error
          return;
        }
      
        // Use the API there, retrieving documents
        api.form('articles').ref(api.master()).submit(function (err, articles) {
          if (err) {
            // Also error again
            return;
          }
      
          // But I also need authors...
          api.form('authors').ref(api.master()).submit(function (err, authors) {
            if (err) {
              // One more time, handle error
              return;
            }
      
            // Now I got all my data
            // I can finally display it on my page
          }
        });
      }, 'my_token_far_below_at_the_end');
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;Can you see it? This ugly thing JavaScript experts name &quot;callback hell&quot;? And that's a super simple example. In 2014, the way to do that is using Promises. That's what's hype (and readable, and nice, and cool, and swag). But I quite understand why they made this choice. Promises are not native everywhere yet, so going with it mean either writing your own implementation or imposing an existing one. Fair enough to have callbacks in the kit then, but we are hackers here, we can override it to use Promises!&lt;/p&gt;
      
      &lt;p class=&quot;alert alert-danger&quot;&gt;I will use the last spec Promise syntax, native way baby!, but it is really important to keep in mind that it has &lt;a href=&quot;http://caniuse.com/#search=promises&quot;&gt;a really poor support&lt;/a&gt; right now. You should probably be using a Javascript library as Promise implementation. I will link a snippet of code using the &lt;a href=&quot;http://documentup.com/kriskowal/q/&quot;&gt;Q library&lt;/a&gt; at the end of the article. But I wanted this article to be future proof.&lt;/p&gt;
      
      &lt;h3 id=&quot;omg-promises-o&quot;&gt;OMG, promises \o/&lt;/h3&gt;
      
      &lt;p&gt;There are two main callbacks in the kit: when retrieving the API and when making a &lt;code&gt;submit&lt;/code&gt;. What I want to write is something like:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;Api('/my/awesome/url', 'my_token_right_here_at_the_start')
        .then(function (api) {
          return Promise.all([
            api.form('articles').ref(api.master()).submit(),
            api.form('authors').ref(api.master()).submit()
          ]);
        })
        .then(function (data) {
          var articles = data[0];
          var authors = data[1];
          // Display the results
        })
        .catch(function (error) {
          // Handle error
        });
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;Sooooo much more readable and swag… Overriding the Api callback is really simple:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;// Remove the callback from the function signature
      function Api(url, accessToken, maybeRequestHandler, maybeApiCache) {
        return new Promise(function (resolve, reject) {
          // Put a callback that will only resolve/reject the deferred depending
          // on the presence of an error or not
          Prismic.Api(url, function (err, resolvedApi) {
            if (err) {
              reject(err);
            } else {
              // Save point 1 (see below)
              resolve(resolvedApi);
            }
          }, accessToken, maybeRequestHandler, maybeApiCache);
        });
      }
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;Overriding the &lt;code&gt;submit&lt;/code&gt; call is a bit more tricky because it is a prototype function of the &lt;code&gt;SearchForm&lt;/code&gt; object, which is totally hidden inside Prismic clojure. This is a bit (super) sad but we can deal with it by creating a fake form and not submitting it. The easiest way I found so far is doing it right after getting the Api. Let's add the following code at &lt;code&gt;Save point 1&lt;/code&gt; (see previous code).&lt;/p&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;// You might need a polyfill for 'getPrototypeOf' if you support old browser
      var SearchFormProto = Object.getPrototypeOf(resolvedApi.forms('everything'));
      // We are saving the original function so we can call it inside our override
      var originalSubmit = SearchFormProto.submit;
      
      // Let's override!
      SearchFormProto.submit = function () {
        return new Promise(function (resolve, reject) {
          // As before, the callback will only resolve / reject the deferred
          // depending on the returned value
          originalSubmit.call(this, function (err, docs) {
            if (err) {
              reject(err);
            } else {
              resolve(docs);
            }
          });
        });
      };
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;And after that, you just need to use the new &lt;code&gt;Api&lt;/code&gt; function in place of &lt;code&gt;Prismic.Api&lt;/code&gt;. You can see &lt;a href=&quot;https://github.com/pauldijou/farewell/blob/9a744565d7/scripts%2Fapi.js#L8-L32&quot;&gt;the full code here&lt;/a&gt; using &lt;code&gt;Q&lt;/code&gt; library. This refers to a particular commit to ensure the line highlight is correct but you can freely switch to the master branch to see the most recent code (which shouldn't be much different… but who knows…).&lt;/p&gt;
      
      &lt;p&gt;Thanks for reading. Next time we will talk about responsive images inside StructuredText.&lt;/p&gt;
    </content>
  </entry>
  <entry>
    <id>http://pauldijou.fr/blog/2014/07/17/prismicio-when-happiness-met-disappointment/</id>
    <title>Prismic.io: when happiness met disappointment</title>
    <updated>2015-06-06T15:40:57+02:00</updated>
    <published>2014-07-17T00:00:00+00:00</published>
    <link href="http://pauldijou.fr/blog/2014/07/17/prismicio-when-happiness-met-disappointment/" rel="alternate" type="text/html" />
    <category term="prismic"></category>
    <summary>
      
      TL;DR
      
      If you don't know about prismic.io, it's a nice tool providing both a super clean web interface to write content and an API to retrieve it. No front-end provided, eventually some kits to help you and some examples, but no more. Which is cool because, if you are a web developer, you can focus on crafting an awesome optimized website and then easily put some content in it… well, that's the theory…
      
      But for me, after using it for a new website, as good as the idea can be, I have found way too much limitations to consider it production ready....
    </summary>
    <content type="html">
      
      &lt;h3 id=&quot;tldr&quot;&gt;TL;DR&lt;/h3&gt;
      
      &lt;p&gt;If you don't know about &lt;a href=&quot;https://prismic.io/&quot;&gt;prismic.io&lt;/a&gt;, it's a nice tool providing both a super clean web interface to write content and an API to retrieve it. No front-end provided, eventually some kits to help you and some examples, but no more. Which is cool because, if you are a web developer, you can focus on crafting an awesome optimized website and then easily put some content in it… well, that's the theory…&lt;/p&gt;
      
      &lt;p&gt;But for me, after using it for a new website, as good as the idea can be, I have found way too much limitations to consider it production ready. The team behind prismic.io is working on most of them so I really hope the implementation will become as awesome as its concept at some point in the future.&lt;/p&gt;
      
      &lt;p&gt;The rest of the article will focus on bashing all those limitations, so there will be way more bad than good, but don't get me wrong, prismic.io has tons of good stuff, and it's still in beta, I just want to talk about what I don't like in this article. And since I'm not all about trolling, I will try to consider how to solve them at the end. I will not explain what prismic.io is exactly, so it might be for the best that you quickly check their website before continuing reading. Enjoy.&lt;/p&gt;
      
      &lt;h3 id=&quot;do-you-remember-how-happy-we-were-at-the-beginning&quot;&gt;Do you remember how happy we were at the beginning?&lt;/h3&gt;
      
      &lt;p&gt;I will never forget… it all started on this windy saturday… I was looking for a solution to create a new blog about traveling. I didn't want to use an all-in-one tool because I love crafting my UI from scratch, with exactly what I want on it (this point is super important for the rest of the story). I said bybye to Wordpress and all its friends. If I were alone, I would have probably go with raw Markdown or whatever, but I am not… I have other people that travel with me and want to write articles without learning a super complex geek syntax. I will call them… &lt;em&gt;writers&lt;/em&gt;. Some colleagues of mine told me about you… that you might be the future of content management, that I would be free for the UI, that you had WISIWIG editors and stuff for… &lt;em&gt;writers&lt;/em&gt;, sounds like a perfect match, and so our adventure began.&lt;/p&gt;
      
      &lt;p&gt;I still can't believe how fast it all went… in a couple of hours, we were able to write new articles and display them in a custom website hosted in GitHub pages. Using one of your kits, it was so easy to query your API, retrieve the content as JSON and inject it inside Handlebars templates in order to render the final HTML. Oh man… it was so good.&lt;/p&gt;
      
      &lt;h3 id=&quot;and-then-fictions-appeared&quot;&gt;And then fictions appeared&lt;/h3&gt;
      
      &lt;p&gt;A few days later, I wanted to go further, moving forward to more crazy stuff. I know that sometimes I try to do complex features just for the fun of the challenge it provides me, but still, how could you do that to me… Remember this conversation?&lt;/p&gt;
      
      &lt;ul&gt;
        &lt;li&gt;Hey prismic.io, I would like to query documents that does not match this predicate&lt;/li&gt;
        &lt;li&gt;Ahahah, you so funny, no way…&lt;/li&gt;
        &lt;li&gt;Thanks! Wait… what? Why not?&lt;/li&gt;
        &lt;li&gt;I don't have a &lt;code&gt;NO&lt;/code&gt; operator or whatever close to it.&lt;/li&gt;
        &lt;li&gt;Whyyyyyy? You have crazy operators like &lt;code&gt;similar&lt;/code&gt; to retrieve similar documents based on God know which algorithm and you cannot do a simple negation?&lt;/li&gt;
        &lt;li&gt;Nope. Deal with it.&lt;/li&gt;
        &lt;li&gt;Okay… I think I can manage something if the query match this &lt;code&gt;OR&lt;/code&gt; that. That's fine, right?&lt;/li&gt;
        &lt;li&gt;No.&lt;/li&gt;
        &lt;li&gt;Cool! Wait… what?&lt;/li&gt;
        &lt;li&gt;I only have &lt;code&gt;AND&lt;/code&gt; operators between predicates.&lt;/li&gt;
        &lt;li&gt;You gotta be kidding me…&lt;/li&gt;
      &lt;/ul&gt;
      
      &lt;p&gt;I was a bit sad, but I could manage it, retrieving too much documents and filtering client-side. Still, that was the starting point were all went wrong.&lt;/p&gt;
      
      &lt;h3 id=&quot;my-biggest-mistake-using-structuredtext&quot;&gt;My biggest mistake: using StructuredText&lt;/h3&gt;
      
      &lt;p&gt;All contents in prismic.io must be typed. This is an image, this is a number, etc… A StructuredText is probably the most powerful type since it allows writers to enter complex content through a WISIWIG editor, using paragraphes, images, lists, embedded stuff, … They can style it using bold, italic, and so on. It looks nice, right? So I decided to use it for the main content of my articles. Fair enough. As always, it was so great to have writers doing their own design using the editor, and so easy to render it automatically as HTML (except for some bugs here and there, but that's what pull requests are for, isn't it?). At some point, I just wanted to have a lightbox on some images: clicking on them should expand it to its full sized version with a caption. I don't know for you, but for me, this is a really basic requirement and you should be able to do it in less than 2 hours.&lt;/p&gt;
      
      &lt;p&gt;First problem: I wanted to tag images that should have lightbox with &lt;code&gt;[data-lightbox]&lt;/code&gt; HTML attribute, all images didn't need one. Since I was using the JavaScript kit to render my HTML, I couldn't do that at all. There is no way to add custom rendering or plugins in the HTML renderer from the kit. Dammit. So I rewrote the full renderer so I could customize it… Wait, how can I indicate which image has a lightbox and which hasn't inside a StructuredText? Oh, right, I just can't. Inside a StructuredText, you can only drop raw images and resize them, that's it. Does that mean I cannot put nor caption or title? Yep, no way to do it. So I started to hack: if after an image, the following paragraph would begin with &lt;code&gt;[caption]&lt;/code&gt;, the image would be a lightbox, the content of the paragraph would be its legend, and the paragraph itself would be removed from the final rendering.&lt;/p&gt;
      
      &lt;p&gt;Guess what? Writers didn't really like having to manually write &lt;code&gt;[caption]&lt;/code&gt;, they wanted a nice UI to do that… but that was just impossible… They throw some tomatoes at me and we tried to move on but we couldn't… Solving one problem to discover a new one: when you define a type &lt;code&gt;image&lt;/code&gt; in a Document, you can tell that it will have different sizes: one for desktop, one for tablet and one for smartphone for example. And that's awesome because you can fully optimize for mobile, which is super important nowadays. Do you think you can do that with image inside StructuredText? Indeed, the answer is no! Once again, a great idea not fully supported. Is there a workaround? Sadly, no easy one. You can upload the same image several times, one for each size, then find a way to retrieve its generated ID by prismic.io and use the same hack as &lt;code&gt;[caption]&lt;/code&gt; to specify it and hack a bit more the HTML renderer. I couldn't find the courage to do it… pretty sure tomatoes would have been replaced by rocks from writers. I can only hope my mobile users have 4G now.&lt;/p&gt;
      
      &lt;p&gt;Want more? No biggy, I have tons of stories like that. A writer wanted to have blockquotes: a whole paragraph should be displayed in a custom design and have an author. I had to kill him really fast and bury his body deep. Another one wanted semantic distinction between paragraphs, something like: this one should be red and this one blue just because. Thrown him into a bucket full of piranhas. At some point, a writer became a madman and deleted half of documents… no way to find him since the delete operation does not appear in the timeline. But who cares? I mean, the document are gone anyway. I18N, do you speak it? I hope not because there is &lt;a href=&quot;https://qa.prismic.io/29/will-multi-lingual-sites-be-supported-in-the-future&quot;&gt;no support for it… yet&lt;/a&gt;. Want to put some tables? Could you please &lt;a href=&quot;https://qa.prismic.io/25/how-do-we-best-support-tables&quot;&gt;stop joking&lt;/a&gt;, it hurts me to laugh so much. Want do  &lt;a href=&quot;https://qa.prismic.io/55/improve-the-media-library&quot;&gt;manage hundred of images&lt;/a&gt; in the media library? Might be less painful to jump from the top of the &lt;a href=&quot;http://en.wikipedia.org/wiki/Eiffel_Tower&quot;&gt;Eiffel tower&lt;/a&gt;. And so on, and so on…&lt;/p&gt;
      
      &lt;h3 id=&quot;we-didnt-fully-link-anymore&quot;&gt;We didn't fully link anymore&lt;/h3&gt;
      
      &lt;p&gt;Writers are generally really proud of their work, so they want everybody to know about it. I couldn't just display &quot;Title of the article&quot;. If I wanted to stay alive, I needed to display &quot;Title of the article, by an awesome author&quot;, and if you would click on the name, you would access to a page saying how incredible the author was. As always, I was like &quot;No biggy dudes, this is gonna be easy&quot;. I wasn't bluffing at that point since there is this nice feature that allow you to link documents between them. So every author would now have a dedicated document of type Author, where he could write whatever description he wanted, and each document of type Article would be linked to an Author. So far, so good.&lt;/p&gt;
      
      &lt;p&gt;And then the problem: if I get a list of Articles, I only got ids and a link to the Author resources, but I do not actually have the data on the Author document, which means I cannot display the real name of the author. And guess what? There is no aggregation or join possible in the API. You just cannot say that you want the 20 most recent articles with their authors. Solutions are: request all authors and then retrieve the good ones from ids (that's 2 requests, and I did that since I don't have that many authors), or do N+1 request (1 for articles, N for authors, one per author id from articles), or generate dynamically a request for authors using &lt;code&gt;any&lt;/code&gt; operator (something like &lt;code&gt;[:d = any(my.author.id, [id1, id2, ...])]&lt;/code&gt;). In any case, you need multiple requests, eventually not running in parallel, and with too much payload… mobile first, right?&lt;/p&gt;
      
      &lt;h3 id=&quot;i-never-though-you-would-mask-it-from-me&quot;&gt;I never though you would mask it from me…&lt;/h3&gt;
      
      &lt;p&gt;One core concept in prismic.io is Document Mask. Each document must have one and it represents its pattern, how it will be persisted in prismic.io database and how it will be served by the API. So you start creating masks, easy. It directly provides a slick UI for writers to enter content. Nice! And at some point, you realize you could have done better, the mask can be improved. Just don't do that, keep going with your broken mask, trust me!&lt;/p&gt;
      
      &lt;p&gt;Let's say you don't trust me (that's fair enough, you don't even really know me). If you rename any property of the mask, you are screwed. The new property will be empty since it doesn't consider it a renaming but the suppression of the previous property and the creation of a new empty one. But you are super courageous, so you migrate all your documents to the new property, yeah! Now you have duplicate a property in your API. Hell yeah! Just check the raw JSON, you will see the new property (thanks God) but also the old one. Properties just keep adding, prismic.io never forget… &lt;strong&gt;never!&lt;/strong&gt; Your payload will just increase. And be sure that your front-end developers always only rely on the mask definition, never on the data from the API, because… it doesn't mean anything anymore.&lt;/p&gt;
      
      &lt;h3 id=&quot;my-heart-was-so-fragmented&quot;&gt;My heart was so fragmented…&lt;/h3&gt;
      
      &lt;p&gt;So, let's summarize what's the biggest problem with prismic.io: you can only do what the tool allow you to do. And right now, it allows you only super basic features. Which are needed obviously, but when you go to the real world, you know, outside of the matrix, those are just not enough. Imagine being Mario, you need to save the princess but you can only move forward, no jump, no strange mushroom, no yoshi… Good luck! Direct consequence, the killer feature that would make prismic.io really powerful, in my humble opinion, is what I will call &quot;custom fragments&quot;. The idea is to allow developers to create their own type of fragments and plug them both in the UI of the writing room and in the HTML renderer. That might sounds a bit challenging but it isn't that hard in fact.&lt;/p&gt;
      
      &lt;p&gt;So first, how to create a custom fragment? Let's use the mask system. When defining a document, you are creating a mask saying &quot;this document will have an image and some text as title&quot;. Why not doing the same for custom fragments? Remember the lightbox problem? I would create a custom fragment &lt;code&gt;lightbox&lt;/code&gt; which is composed of an image and some text as its caption. Even better, since I am now using a real &lt;code&gt;image&lt;/code&gt; type, I can specify several sizes for the image. Big win here.&lt;/p&gt;
      
      &lt;p&gt;Next, inside the writing room, how to render a custom fragments? Well, you already know how to render all its pieces, just group them together with an indentation or a left border or whatever. The &lt;code&gt;lightbox&lt;/code&gt; fragment would be an image selector and a text input. Of course, you should be able to put a custom fragment both inside a document (like any other fragment) and inside a StructuredText if possible (just like you are allowing &lt;code&gt;em&lt;/code&gt; or &lt;code&gt;h2&lt;/code&gt; inside a StructuredText)&lt;/p&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;// Let's define our custom fragment for lightbox,
      // just the same syntax as a Document Mask
      {
        &quot;title&quot; : {
          &quot;type&quot; : &quot;Text&quot;,
          &quot;fieldset&quot; : &quot;Title&quot;,
          &quot;config&quot; : {
            &quot;placeholder&quot; : &quot;A short caption for the image&quot;
          }
        },
        &quot;image&quot;: {
          &quot;fieldset&quot; : &quot;Image&quot;,
          &quot;type&quot; : &quot;Image&quot;,
          &quot;config&quot; : {
            &quot;thumbnails&quot; : [ {
              &quot;name&quot; : &quot;Icon&quot;,
              &quot;width&quot; : 100,
              &quot;height&quot; : 100
            }, {
              &quot;name&quot; : &quot;Column&quot;,
              &quot;width&quot; : 320,
              &quot;height&quot; : 320
            }, {
              &quot;name&quot; : &quot;Wide&quot;,
              &quot;width&quot; : 600,
              &quot;height&quot; : 300
            } ]
          }
        }
      }
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;Finally, each kit should have a &lt;code&gt;renderFragment(type, json =&amp;gt; html)&lt;/code&gt; method that allow you, for a specific fragment type (here &lt;code&gt;lightbox&lt;/code&gt;), to pass a function that know how to render the final HTML from its raw JSON.&lt;/p&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;// Define how to render your custom fragment
      // from JSON to HTML (which is a String)
      kit.renderFragment('lightbox', function (json) {
        var html = '&amp;lt;img src=&quot;';
        html += json.image.url;
        html += '&quot; data-lightbox title=&quot;';
        html += json.title;
        html += '&quot;&amp;gt;';
        return html;
      });
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;Hey, we can do even better, let's add a second argument to the rendering function, this one will be the original rendering function for &quot;native&quot; fragments in prismic.io. This way, you can override just one or two &quot;native&quot; fragments. For example, if you want to render &lt;code&gt;image&lt;/code&gt; with a &lt;code&gt;&amp;lt;picture&amp;gt;&lt;/code&gt; HTML tag because that's super hype. Just do something like:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;// Override an already existing fragment
      kit.renderFragment('image', function (json, original) {
        var html = '';
        html += '&amp;lt;picture&amp;gt;';
        // Keep it easy, only one source...
        html += '&amp;lt;source src=&quot;' + json.image.url + '&quot;&amp;gt;'
        // Fallback using the default renderer
        html += original(json);
        // And the alt text
        html += '&amp;lt;p&amp;gt;' + json.image.alt + '&amp;lt;/p&amp;gt;'
        html += '&amp;lt;/picture&amp;gt;';
        return html;
      });
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;And that's it! You just solved so many limitations…&lt;/p&gt;
      
      &lt;h3 id=&quot;i-didnt-understand-your-semantic-anymore&quot;&gt;I didn't understand your semantic anymore…&lt;/h3&gt;
      
      &lt;p&gt;Ok, next step. Inside a StructuredText, I need to have semantic distinction between fields of the same type. This paragraph is &lt;em&gt;important&lt;/em&gt;, this one is &lt;em&gt;a blockquote&lt;/em&gt; and all the rest are &lt;em&gt;normal&lt;/em&gt;. Let's go the easy way: I just need a hash of key -&amp;gt; value, as strings, to reach a limitless world. This way, I could tag one paragraphe &lt;code&gt;important: true&lt;/code&gt;, and another with with both &lt;code&gt;blockquote: true&lt;/code&gt; and &lt;code&gt;author: Someone&lt;/code&gt;. At last but not least, expose it in the API:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;// Since all fields have a common structure to expose their type
      // it's easy to have a new key like 'attributes' at this level
      // to expose the semantic hash
      // (btw, it would be cool to map to primitives rather than only string for values)
      {
        &quot;type&quot;: &quot;paragraph&quot;,
        &quot;text&quot;: &quot;bla bla bla...&quot;,
        &quot;spans&quot;: [],
        &quot;attributes&quot;: {
          &quot;blockquote&quot;: true,
          &quot;author&quot;: &quot;Someone&quot;
        }
      }
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;I have no idea how to integrate that in the UI of the writing room, but I know its designer, he will figure out something awesome, no doubt.&lt;/p&gt;
      
      &lt;p&gt;By adding that, you leverage tons of possibilities for developers to customize the rendering of a StructuredText without any heavy hack. Writers would still need to manually write each key name, but its way better than paragraphs starting with &lt;code&gt;[caption]&lt;/code&gt; or &lt;code&gt;[author]&lt;/code&gt;. Following a snippet on how to render a blockquote, using the previous &lt;code&gt;renderFragment&lt;/code&gt; method of course:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;kit.renderFragment('paragraph', function (json, original) {
        if (json.attributes.blockquote) {
          var html = '&amp;lt;blockquote&amp;gt;';
          // Previously private (at least in the JavaScript kit),
          // I hope this method will be available in all kits
          // it applies all span styles to the raw text
          html += kit.insertSpans(json.text, json.spans);
          html += '&amp;lt;footer&amp;gt;';
          html += json.attributes.author;
          html += '&amp;lt;/footer&amp;gt;';
          html += '&amp;lt;/blockquote&amp;gt;';
          return html;
        } else {
          return original(json);
        }
      });
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;This feature is for &quot;quick and dirty&quot; hacks if you could say, and allowing you to customize &quot;native&quot; fragments. Because otherwise, you could also have done that with a custom fragment. Rather than having two attributes, a &lt;code&gt;blockquote&lt;/code&gt; could be a custom fragment grouping a StructuredText for the content and a simple text for the author. It is way more intuitive in the UI and it's easier to create its own &lt;code&gt;renderFragment&lt;/code&gt;.&lt;/p&gt;
      
      &lt;p&gt;I like a lot this &lt;code&gt;renderFragment&lt;/code&gt; method, but I think we can make it even better! Right know, we can only specify / override for all the application. That's super cool but limited… and if you have read carefully until now, you should know that I don't like limitations. This method should be at least at 3 different levels:&lt;/p&gt;
      
      &lt;ul&gt;
        &lt;li&gt;Document instance&lt;/li&gt;
        &lt;li&gt;Document type&lt;/li&gt;
        &lt;li&gt;(Collection?)&lt;/li&gt;
        &lt;li&gt;Application&lt;/li&gt;
      &lt;/ul&gt;
      
      &lt;p&gt;Here is the idea: when an instance of a Document wants to render some fields (or fragments) as HTML, it will do the following simple procedure:&lt;/p&gt;
      
      &lt;ul&gt;
        &lt;li&gt;Hey, do I have a custom renderer method for this type of field on myself? (yeah, because now each Document instance have the method). If so, use it, if not, continue.&lt;/li&gt;
        &lt;li&gt;I am a Document of type Article, does this type of Document has such a method on it? (yeah, because now you can call this method for just a particular type of Document). Yes, use, no continue.&lt;/li&gt;
        &lt;li&gt;Eventually, does my Collection have the method?&lt;/li&gt;
        &lt;li&gt;Nearly finished, does the method is defined at the application level?&lt;/li&gt;
        &lt;li&gt;If nothing found so far, if it is a native prismic.io field, render it as it should be, otherwise just crash or return empty string, I don't know, it shouldn't happen anyway.&lt;/li&gt;
      &lt;/ul&gt;
      
      &lt;p&gt;Holy crap… we just created a &quot;rendering context with awesomeness inheritance&quot; or something like that. Can you imagine all the things you could do with that? Can you ?! I can't… it's too big…&lt;/p&gt;
      
      &lt;h3 id=&quot;lets-break-up&quot;&gt;Let's break up&lt;/h3&gt;
      
      &lt;p&gt;I could say more, but since it's a miracle that you are still reading and it would not be as relevant as what I already said, I will stop here.&lt;/p&gt;
      
      &lt;p&gt;My conclusion so far: prismic.io is not ready for the real world and for real websites but there is a lot of work going on by its team so, as they say on half of their responses: stay tuned! It might become super awesome at some point (I hope it will).&lt;/p&gt;
      
      &lt;p&gt;Thanks for reading! See you soon for more hacky coding posts.&lt;/p&gt;
    </content>
  </entry>
  <entry>
    <id>http://pauldijou.fr/blog/2013/02/17/angularjs-routing-playframework/</id>
    <title>AngularJS HTML5 routing on PlayFramework</title>
    <updated>2015-06-06T15:40:57+02:00</updated>
    <published>2013-02-17T00:00:00+00:00</published>
    <link href="http://pauldijou.fr/blog/2013/02/17/angularjs-routing-playframework/" rel="alternate" type="text/html" />
    <category term="angular"></category>
    <category term="play"></category>
    <category term="html5"></category>
    <summary>
      
      The problem
      
      AngularJS provides a nice $location service which allows you to deal with routing and url inside your application. It supports both a fallback mode using hashbang and a real HTML5 routing using the new History API. Since we love bleeding edge technologies, that's obvious we want to use the History API if possible. Lucky us, it appears it's quite easy to do so with a Play Framework application. Let's see how to do that.
      
      The full code of the demo is available on GitHub.
      
      Simple configuration
      
      Let's keep things simple. Creating a new Play Framework application with play new. We will use...
    </summary>
    <content type="html">
      
      &lt;h3 id=&quot;the-problem&quot;&gt;The problem&lt;/h3&gt;
      
      &lt;p&gt;AngularJS provides a nice &lt;code&gt;$location&lt;/code&gt; service which allows you to deal with routing and url inside your application. It supports both a fallback mode using hashbang and a real HTML5 routing using the new &lt;a href=&quot;http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html&quot;&gt;History API&lt;/a&gt;. Since we love bleeding edge technologies, that's obvious we want to use the History API if possible. Lucky us, it appears it's quite easy to do so with a Play Framework application. Let's see how to do that.&lt;/p&gt;
      
      &lt;p&gt;The full code of the demo is available &lt;a href=&quot;https://github.com/blogsamples/angularjs-play21-html5-routing&quot;&gt;on GitHub&lt;/a&gt;.&lt;/p&gt;
      
      &lt;h3 id=&quot;simple-configuration&quot;&gt;Simple configuration&lt;/h3&gt;
      
      &lt;p&gt;Let's keep things simple. Creating a new Play Framework application with &lt;code&gt;play new&lt;/code&gt;. We will use a Scala application in this article, but it should as easy with a Java one. Then add AngularJS using CDN (see &lt;a href=&quot;https://github.com/blogsamples/angularjs-play21-html5-routing/blob/master/app/views/main.scala.html#L19&quot;&gt;main.scala.html#L19&lt;/a&gt;). Then we will create an Angular module for our app and enable the HTML5 routing mode which is disable by default.&lt;/p&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;var app = angular.module(&quot;app&quot;, [&quot;ngResource&quot;])
        .config([&quot;$routeProvider&quot;, function($routeProvider) {
            return $routeProvider.when(&quot;/&quot;, {
              templateUrl: &quot;/views/index&quot;,
              controller: &quot;AppCtrl&quot;
            }).otherwise({
              redirectTo: &quot;/&quot;
            });
          }
        ])
        .config([&quot;$locationProvider&quot;, function($locationProvider) {
            return $locationProvider.html5Mode(true).hashPrefix(&quot;!&quot;);
          }
        ]);
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;Nice. Now we will make some modification to the default views generated by Play. We want a single-page application, which means our root url must map to a main page which will contains all resource dependencies and includes the &lt;code&gt;ng-view&lt;/code&gt; of AngularJS. I've done that by editing the &lt;code&gt;main.scala.html&lt;/code&gt; file as you can &lt;a href=&quot;https://github.com/blogsamples/angularjs-play21-html5-routing/blob/master/app/views/main.scala.html&quot;&gt;see here&lt;/a&gt; and add a new Play route:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;GET     /                           controllers.Application.main(any = &quot;none&quot;)
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;And a new &lt;code&gt;Action&lt;/code&gt; in my Application controller:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-scala&quot;&gt;def main(any: String) = Action {
        Ok(views.html.main())
      }
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;Wait. Why is there a String param for the main method? And why do we pass a default &lt;code&gt;any = &quot;none&quot;&lt;/code&gt; value? It seems a bit useless… Fair enough, I will explain it later on the article, don't mind it for now. So, we have our main page. Let's add some content for the landing page. As we have specified in the AngularJS routing, our root url, which is defined with &lt;code&gt;$routeProvider.when(&quot;/&quot;, ...)&lt;/code&gt; is pointing to &lt;code&gt;/views/index&lt;/code&gt;. So we need a Play route for that… but before, let's talk about all those routes.&lt;/p&gt;
      
      &lt;h3 id=&quot;routes-routes-routes&quot;&gt;Routes, routes, routes…&lt;/h3&gt;
      
      &lt;p&gt;As we advance in our coding, we can see that the term &quot;route&quot; is used in different contexts. It's important to fully understand them all. Play routes, which are defined in the &lt;code&gt;conf/routes&lt;/code&gt; file, are the core of your application. It's those routes which will answer to the HTTP requests, serving either HTML, JSON, or whatever. But you, as the developer, will be the only one to know about them. Users of your application will only use and see AngularJS routes, which are defined in your main module using the &lt;code&gt;$routeProvider&lt;/code&gt;.&lt;/p&gt;
      
      &lt;p&gt;The idea is that when a user land on your site, it should use AngularJS routing which will then use Play routes to load the template (= the content) of the page. So why not using the exact same url for both the AngularJS route and the templateUrl route? Well, in the case of the root, it's obvious: the Play &quot;/&quot; route is already required for our main page. Ok. But in a more general case, could we do:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;$routeProvider.when(&quot;/page&quot;, {
        templateUrl: &quot;/page&quot;,
        controller: &quot;PageCtrl&quot;
      })
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;Nope, you can't. Well, that's a small lie… you could do that, and it would work if your user &lt;strong&gt;always&lt;/strong&gt; open your main page first. If he does that, then all AngularJS routing is loaded, and when the user will go to &quot;/page&quot; url, it will be catch by AngularJS which will ask for the &quot;/page&quot; on Play routes which will give him the content of the page. So what's the problem? If you user &lt;strong&gt;directly&lt;/strong&gt; land on the &quot;/page&quot; url, because he arrived for the first time on your application after having clicked on a link somewhere which was pointing at &quot;/page&quot;, then the Play route will be directly called since there is no AngularJS routing initialized at all… And that's bad, right? The user would have the raw content of the page without any JavaScript or CSS from the main page. It's a fail.&lt;/p&gt;
      
      &lt;p&gt;In order to prevent that, I have chosen to use some conventions. There is nothing official, you can use your own, the only thing to keep in mind is that AngularJS routes and Play routes should &lt;strong&gt;never&lt;/strong&gt; be equals. My solution to do that is to prefix all Play routes serving HTML with a &quot;/views/&quot; prefix, all Play routes serving JSON with a &quot;/api/&quot; prefix and, as it is by default, all Play routes serving resources with a &quot;/assets/&quot; prefix. Meaning I can now use all routes I want inside AngularJS routing but never starts them with one of those prefix.&lt;/p&gt;
      
      &lt;p&gt;Of course, it will just modify the problem without solving it. Now, if a user land directly on &quot;/page&quot;, he will have a huge orange Play error telling him that the route doesn't exist. As before, AngularJS routing isn't loaded, so it's Play routing which try to handle that and, since there is no longer any &quot;/page&quot; route in Play, it crash.&lt;/p&gt;
      
      &lt;p&gt;So what's the point of having different routes? The next trick is to redirect all unknow routes to our main page. By doing so, if the user land on &quot;/page&quot;, Play will say &lt;em class=&quot;talk red&quot;&gt;&quot;I don't know that route, go to the main page&quot;&lt;/em&gt;, so the user will indeed go to your main page, but then, all AngularJS routing will be loaded and super awesome AngularJS will say &lt;em class=&quot;talk green&quot;&gt;&quot;Hey, I do know that route, and I need the /views/page template&quot;&lt;/em&gt;, and then Play will respond &lt;em class=&quot;talk red&quot;&gt;&quot;Oh yeah, I can serve you /views/page, here is the HTML to display&quot;&lt;/em&gt;, and your user will see the correct &quot;/page1&quot; content, even if he lands directly on it.&lt;/p&gt;
      
      &lt;p&gt;Another question? Why didn't we use this trick before and then have the same routes for both AngularJS and Play? Because it's important that the trick apply only to unknow routes. We cannot redirect to the main page an existing Play route because it needs to serve its own content. So by using different routes, we can intercept AngularJS routes inside Play as &quot;unknown routes&quot; and redirect them to the main page so AngularJS can handle them. I hope I'm clear enough here, that might be the hardest part of the article. In order to achieve that, we just need to put a Play route at the end of the route file which intercept all routes and redirect them to the main page:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;GET     /*any                       controllers.Application.main(any)
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;And now you should understand why we had a &lt;code&gt;any: String&lt;/code&gt; for our main page at the beginning.&lt;/p&gt;
      
      &lt;h3 id=&quot;first-pages&quot;&gt;First pages&lt;/h3&gt;
      
      &lt;p&gt;Enough with all the theory, let's do two concrete pages: creating &quot;page1.scala.html&quot; and &quot;page2.scala.html&quot; files with basic content (see source code, I'm using a template to stay DRY about the title and the menu but that's not important), add then as Play routes (with a &quot;/views/&quot; as stated before) and also add them inside our controller:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-markup&quot;&gt;@()
      
      @template() {
        &amp;lt;h2&amp;gt;Page1&amp;lt;/h2&amp;gt;
      }
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;GET     /views/page1                controllers.Application.page1
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-scala&quot;&gt;def page1 = Action {
        Ok(views.html.page1())
      }
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;And then add the AngularJS routing:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;.when(&quot;/page1&quot;, {
        templateUrl: &quot;/views/page1&quot;
      })
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;That's it. We can now create a link, using a &lt;code&gt;a&lt;/code&gt; tag, to point to the url &quot;/page1&quot; and AngularJS will do the rest, loading the &quot;/views/page1&quot; template using Play route which will return the HTML code generated from our Scala template. Nice isn't it? The url is correct: &lt;a href=&quot;http://localhost:9000/page1&quot;&gt;http://localhost:9000/page1&lt;/a&gt;, you can use the back button to return to the index page, no ugly hashbang, but all in Ajax with a single-page application.&lt;/p&gt;
      
      &lt;h3 id=&quot;handling-url-parameters&quot;&gt;Handling url parameters&lt;/h3&gt;
      
      &lt;p&gt;So, we have our url working by using the History API thanks to the HTML5 mode of the AngularJS $routeProvider. But that's only for raw url. What if we want to have dynamic parameters inside them? Just like REST, having url as &quot;/colors/1&quot; and &quot;/colors/2&quot; if we deal with colors (yeah, why not?). Do you think that's easy? Well, you could, after all, both AngularJS and Play know how to handle parameters in their url. We could do something like:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;.when(&quot;/colors/:id&quot;, {
        templateUrl: &quot;/views/color/:id&quot;,
        controller: &quot;ColorCtrl&quot;
      })
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;GET     /views/color/:id             controllers.Application.color(id: String)
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;Nope, we can't. Why? Because the &quot;templateUrl&quot; cannot handle url parameters. It's just a template. And of course, using &lt;code&gt;templateUrl: &quot;/views/color&quot;&lt;/code&gt; will not pass any &quot;id&quot; parameter to the Play route. Damn…&lt;/p&gt;
      
      &lt;p&gt;That's not a problem in fact. Just keep to the AngularJS way of doing things: it's not Play who should handle the data any longuer, it's AngularJS who rules the world now, so you don't need any params in your Scala code, just trust AngularJS. Ok, but we need a way to load the correct color depending on the id in the url right? Sure thing. It's the role of AngularJS controller to that. That's why there is a &quot;ColorCtrl&quot; along with our template, and guess what, the AngularJS controller know about the url params. Here is the code of the controller:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;app.controller(&quot;ColorCtrl&quot;, [&quot;$scope&quot;, &quot;$routeParams&quot;, function($scope, $routeParams) {
        // Thanks to scope inheritance, we can access the &quot;db&quot; from the AppCtrl scope
        $scope.color = $scope.db[$routeParams.id];
        if (!$scope.color) {
          $scope.msg = &quot;There is no color for id &quot;+$routeParams.id;
        } else {
          $scope.msg = undefined;
        }
      }])
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;And just for fun, I've defined the fake database in the &quot;AppCtrl&quot;:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;app.controller(&quot;AppCtrl&quot;, [&quot;$scope&quot;, function($scope) {
        $scope.db = {
          1: {
            name: &quot;black&quot;,
            hex: &quot;000000&quot;
          },
          2: {
            name: &quot;white&quot;,
            hex: &quot;FFFFFF&quot;
          }
        };
      }]);
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;So as we can see, using the &lt;code&gt;$routeParams&lt;/code&gt; service, we can retrieve the url params and then load the correct color in the &lt;code&gt;$scope&lt;/code&gt;. At the end, it's just a matter of displaying that color in our view using AngularJS data-binding:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-markup&quot;&gt;@()
      
      @template() {
        &amp;lt;div data-ng-show=&quot;msg&quot;&amp;gt;
          &amp;lt;h2&amp;gt;{{msg}}&amp;lt;/h2&amp;gt;
        &amp;lt;/div&amp;gt;
      
        &amp;lt;div data-ng-hide=&quot;msg&quot;&amp;gt;
          &amp;lt;h2&amp;gt;Color {{color.name}}: # {{color.hex}}&amp;lt;/h2&amp;gt;
        &amp;lt;/div&amp;gt;
      }
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;And that's it! you can now display some data depending of params inside your url (and show an error message in case the data doesn't exist). Cool isn't it?&lt;/p&gt;
      
      &lt;h3 id=&quot;want-more&quot;&gt;Want more?&lt;/h3&gt;
      
      &lt;p&gt;Oh God, you are still reading? You should already be able to do anything you need. But if you want, we can dive in a more complex example, using AngularJS &lt;code&gt;$resource&lt;/code&gt; service and serve JSON from Play like a REST API would do. Sounds good for you? Ok, let's do that. First, we will create a &quot;Users&quot; controller and it will have two methods: &quot;all()&quot; and &quot;find(id: String)&quot; which will return an Array of Json and a Json object representing our list of users and one particular user based on its id. I will not use a real database, but something like MongoDB would fit really good in there. Here is the code:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-scala&quot;&gt;package controllers
      
      import play.api._
      import play.api.mvc._
      import play.api.libs.json._
      
      object Users extends Controller {
        val db = Json.arr(
          Json.obj( &quot;id&quot; -&amp;gt; &quot;1&quot;, &quot;name&quot; -&amp;gt; &quot;John&quot; ),
          Json.obj( &quot;id&quot; -&amp;gt; &quot;2&quot;, &quot;name&quot; -&amp;gt; &quot;Suzanne&quot; )
        )
      
        def all() = Action {
          Ok(db)
        }
      
        def find(id: String) = Action {
          Ok(db.value.filter(v =&amp;gt; (v \ &quot;id&quot;).as[JsString].value == id).headOption.getOrElse(new JsUndefined(&quot;&quot;)))
        }
      }
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;If you don't fully understand it, you can check the PlayFramework documentation about handling Json (&lt;a href=&quot;http://www.playframework.com/documentation/2.1.0/ScalaJsonRequests&quot;&gt;ScalaJsonRequests&lt;/a&gt;). I am using the new Json API from Play 2.1 (&lt;a href=&quot;http://www.playframework.com/documentation/api/2.1.0/scala/index.html#play.api.libs.json.package&quot;&gt;play.api.libs.json.package&lt;/a&gt;). Next we need our &quot;UserCtrl&quot; which will use the `$resource&amp;lt;/code&amp;gt; service to retrieve the data:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;app.controller(&quot;UserCtrl&quot;, [&quot;$scope&quot;, &quot;$routeParams&quot;, &quot;$resource&quot;, &quot;apiUrl&quot;, function($scope, $routeParams, $resource, apiUrl) {
        var Users = $resource(apiUrl + &quot;/users/:id&quot;, {id:&quot;@id&quot;});
      
        if($routeParams.id) {
          $scope.user = Users.get({id: $routeParams.id}, function() {
            if (!$scope.user.id) {
              $scope.msg = &quot;There is no user for id &quot;+$routeParams.id;
            } else {
              $scope.msg = undefined;
            }
          });
        } else {
          $scope.users = Users.query();
        }
      }])
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;To learn more about AngularJS $resource definition, see: &lt;a href=&quot;http://docs.angularjs.org/api/ngResource.%24resource&quot;&gt;ngResource.$resource&lt;/a&gt;. What is that &quot;apiUrl&quot; by the way? It's a constant I've defined in my AngularJS app:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;var app = angular.module(&quot;app&quot;, [&quot;ngResource&quot;])
        .constant(&quot;apiUrl&quot;, &quot;http://localhost:9000\:9000/api&quot;)
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;p class=&quot;alert alert-info&quot;&gt;&lt;strong&gt;Pro tip&lt;/strong&gt; Why is there the 9000 port twice? That's because if we had written &lt;code&gt;http://localhost:9000/api&lt;/code&gt;, AngularJS syntax would have analyzed that as a url with a dynamic parameter named &quot;9000&quot; because it's placed right after a &lt;code&gt;:&lt;/code&gt; character. So we need that strange syntax to tell AngularJS that this is not a parameter but a real value in our url.&lt;/p&gt;
      
      &lt;p&gt;Next, we are creating our resource by extending this apiUrl with our routing &quot;/users/:id&quot;. This time, &quot;:id&quot; is a real parameter. We can now use &quot;get&quot; and &quot;query&quot; methods on the resource, passing or not a value to the id, in order to retrieve our Json code and assign it to the &lt;code&gt;$scope&lt;/code&gt;. We will need two Scala views: one for the list and one for the detail of course.&lt;/p&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-markup&quot;&gt;@()
      
      @template() {
        &amp;lt;h2&amp;gt;Users&amp;lt;/h2&amp;gt;
      
        &amp;lt;ul&amp;gt;
          &amp;lt;li data-ng-repeat=&quot;u in users&quot;&amp;gt;
            &amp;lt;a data-ng-href=&quot;/users/{{u.id}}&quot;&amp;gt;User# {{u.id}}: {{u.name}}&amp;lt;/a&amp;gt;
          &amp;lt;/li&amp;gt;
        &amp;lt;/ul&amp;gt;
      }
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-markup&quot;&gt;@()
      
      @template() {
        &amp;lt;div data-ng-show=&quot;msg&quot;&amp;gt;
          &amp;lt;h2&amp;gt;{{msg}}&amp;lt;/h2&amp;gt;
        &amp;lt;/div&amp;gt;
      
        &amp;lt;div data-ng-hide=&quot;msg&quot;&amp;gt;
          &amp;lt;h2&amp;gt;User# {{user.id}} {{user.name}}&amp;lt;/h2&amp;gt;
        &amp;lt;/div&amp;gt;
      }
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;And that's it. We now have a list of users and links to each user detail, and all that data is fetch from a REST API using Json.&lt;/p&gt;
      
      &lt;p class=&quot;alert alert-info&quot;&gt;&lt;strong&gt;Pro tip&lt;/strong&gt; By the way, since our Play routes doesn't clash with AngularJS routes, you can load them directly in your browser. It will works because the Play route handling the redirection to the main page is at the end of the route file, so any real Play route will be loaded before the redirection. If you have the demo running, check &lt;a href=&quot;http://localhost:9000/api/users&quot;&gt;http://localhost:9000/api/users&lt;/a&gt; and &lt;a href=&quot;http://localhost:9000/api/users/1&quot;&gt;http://localhost:9000/api/users/1&lt;/a&gt; to see your REST API working nicely.&lt;/p&gt;
      
      &lt;h3 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h3&gt;
      
      &lt;p&gt;I hope this article will help you bootstrap your next awesome application using awesome tools like AngularJS and PlayFramework. Your next step (if that's not already the case) would be to learn more about the new PlayFramework Json API so you can have typesafe Json (if I can say so). You would also probably need to plug a database on it. One choice could be a &lt;a href=&quot;http://www.mongodb.org/&quot;&gt;MongDB&lt;/a&gt; database since it can store raw Json, and interact with it using a nice driver like &lt;a href=&quot;http://reactivemongo.org/&quot;&gt;ReactiveMongo&lt;/a&gt; if you want to go all the way down to asynchronous application.&lt;/p&gt;
      
      &lt;p&gt;It's up to you!&lt;/p&gt;
    </content>
  </entry>
  <entry>
    <id>http://pauldijou.fr/blog/2012/11/27/some-pocs-to-share/</id>
    <title>Some POCs to share</title>
    <updated>2015-06-06T15:40:57+02:00</updated>
    <published>2012-11-27T00:00:00+00:00</published>
    <link href="http://pauldijou.fr/blog/2012/11/27/some-pocs-to-share/" rel="alternate" type="text/html" />
    <category term="angular"></category>
    <category term="coffeescript"></category>
    <category term="yeoman"></category>
    <summary>
      
      Some POCs
      
      Hi there,
      
      I've been a bit busy lately but I'm back on game. Looking for a job in Paris, I've been asked to do some code over more or less funny subjects and now that it's done, I will share them, maybe it could help people to see some code around some technologies. It's not at all perfect code, more experiments I've done.
      
      Mowing is mainly a CoffeeScript project about giving orders to some automatic mowers and see the result. My goal was to test that new syntax around JavaScript and I have to admit it's quite cool. You can see...
    </summary>
    <content type="html">
      
      &lt;h3 id=&quot;some-pocs&quot;&gt;Some POCs&lt;/h3&gt;
      
      &lt;p&gt;Hi there,&lt;/p&gt;
      
      &lt;p&gt;I've been a bit busy lately but I'm back on game. Looking for a job in Paris, I've been asked to do some code over more or less funny subjects and now that it's done, I will share them, maybe it could help people to see some code around some technologies. It's not at all perfect code, more experiments I've done.&lt;/p&gt;
      
      &lt;p&gt;&lt;strong&gt;Mowing&lt;/strong&gt; is mainly a &lt;code&gt;CoffeeScript&lt;/code&gt; project about giving orders to some automatic mowers and see the result. My goal was to test that new syntax around JavaScript and I have to admit it's quite cool. You can see &lt;a href=&quot;http://pauldijou.fr/mowing/&quot;&gt;the result here&lt;/a&gt; (don't ever do it in large grids). The source code is &lt;a href=&quot;https://github.com/pauldijou/mowing/&quot;&gt;here on GitHub&lt;/a&gt;&lt;/p&gt;
      
      &lt;p&gt;&lt;strong&gt;Mowing-java&lt;/strong&gt; is the &lt;code&gt;Java&lt;/code&gt; version of &lt;strong&gt;Mowing&lt;/strong&gt;. So in fact, it's nearly the same syntax since you can create class in CoffeeScript but this one runs on a JVM. &lt;a href=&quot;https://github.com/pauldijou/mowing-java&quot;&gt;See here&lt;/a&gt; for source code.&lt;/p&gt;
      
      &lt;p&gt;Finally, &lt;strong&gt;GSearch&lt;/strong&gt; is an &lt;code&gt;AngularJS&lt;/code&gt; application built using &lt;code&gt;Yeoman&lt;/code&gt;. Its goal is to plug on GitHub API and allow you to search through repositories and users and display informations and stats about them. &lt;a href=&quot;http://pauldijou.fr/gsearch/&quot;&gt;Here is the result&lt;/a&gt; and &lt;a href=&quot;https://github.com/pauldijou/gsearch/&quot;&gt;go there&lt;/a&gt; for source code.&lt;/p&gt;
      
      &lt;p&gt;Of course, &lt;strong&gt;any feedback&lt;/strong&gt; is welcome! I can be bugs, features, questions, anything…&lt;/p&gt;
      
      &lt;h3 id=&quot;nigthhacking-tour-2012&quot;&gt;NigthHacking Tour 2012&lt;/h3&gt;
      
      &lt;p&gt;I've given a small quicky about &lt;code&gt;RichFaces Bootstrap&lt;/code&gt; and &lt;code&gt;RichFaces 5&lt;/code&gt; on Paris a few weeks ago. Just so you know…&lt;/p&gt;
      
      &lt;h3 id=&quot;are-you-in-paris&quot;&gt;Are you in Paris?&lt;/h3&gt;
      
      &lt;p&gt;Let's finish with a personal note. I will be living in Paris from now and for quite some time. So if you living there or just passing by and want to grab a beer and talk about Java EE, HTML5, RichFaces, or anything cool, just let me now! Also if you are giving conferences or doing dojos or katas in the area, be sure to notice me so I can come to the next one. Thanks.&lt;/p&gt;
    </content>
  </entry>
  <entry>
    <id>http://pauldijou.fr/blog/2012/08/07/news-richfaces-bootstrap/</id>
    <title>News about RichFaces Bootstrap</title>
    <updated>2015-06-06T15:40:57+02:00</updated>
    <published>2012-08-07T00:00:00+00:00</published>
    <link href="http://pauldijou.fr/blog/2012/08/07/news-richfaces-bootstrap/" rel="alternate" type="text/html" />
    <category term="richfaces"></category>
    <category term="bootstrap"></category>
    <category term="jquery"></category>
    <summary>
      
      What's new in RichFaces Bootstrap?
      
      Red Alert! The RichFaces Bootstrap project is still under heavy development, tag and attribute names can change at any time and if you find something missing or buggy, there is high chance it's not a bug but just hasn't been done yet (… or it's a real bug). So only use it for fun and prototype purposes.
      
      Semantic components are a brand new concept. I need to present it first so I can use it when talking next about the new components. Most of the time, for one JSF tag, you have one and only one HTML...
    </summary>
    <content type="html">
      
      &lt;h3 id=&quot;whats-new-in-richfaces-bootstrap&quot;&gt;What's new in RichFaces Bootstrap?&lt;/h3&gt;
      
      &lt;p class=&quot;alert alert-danger&quot;&gt;&lt;strong&gt;Red Alert!&lt;/strong&gt; The RichFaces Bootstrap project is still under heavy development, tag and attribute names can change at any time and if you find something missing or buggy, there is high chance it's not a bug but just hasn't been done yet (… or it's a real bug). So only use it for fun and prototype purposes.&lt;/p&gt;
      
      &lt;p&gt;&lt;strong&gt;Semantic components&lt;/strong&gt; are a brand new concept. I need to present it first so I can use it when talking next about the new components. Most of the time, for one JSF tag, you have one and only one HTML renderer, it's a oneToOne relation (according to JSF naming convention). It seems logical: for one component, you should always have (nearly) the same generated HTML code. But with HTML5, the web is becoming more semantic and that's good. Why not have the same with RichFaces? But before we dive into it, what is &quot;semantic&quot;? For a real definition see &lt;a href=&quot;http://en.wikipedia.org/wiki/Semantic_Web&quot;&gt;Wikipedia&lt;/a&gt; but here, we will say it's when a component serves a global purpose like being a header or a footer but shouldn't always render in the same way, instead the rendered result should depend on the context (like a table header isn't the same as a column header).&lt;/p&gt;
      
      &lt;p&gt;With RichFaces, a semantic component is a component &lt;strong&gt;with no renderer&lt;/strong&gt;! Yeah yeah, if you use a semantic component on its own, it will throw an exception because it doesn't know how to render itself. The concept is that a semantic component will ask its parent in the JSF tree: &quot;Hey dad, do you know how I can render myself?&quot;, if it knows, the parent will provide the correct renderer to the semantic component which will render it, otherwise, the semantic component will ask one level higher the same question, and so on until the root element. If no one answers yes to the question, it will throw an exception. That means we also have components that accept semantic components in order to provide them the correct renderer.&lt;/p&gt;
      
      &lt;p&gt;Let's take a concrete example. The &lt;strong&gt;modal&lt;/strong&gt; component in RichFaces Bootstrap can support 3 semantic components: a header, a body and a footer. You can see that by looking at which interfaces the &lt;code&gt;AbstractModal&lt;/code&gt; implements (see &lt;a href=&quot;https://github.com/richfaces/sandbox/blob/develop/bootstrap/ui/src/main/java/org/richfaces/bootstrap/component/AbstractModal.java#L49&quot;&gt;GitHub&lt;/a&gt;). All interfaces with the syntax &lt;code&gt;Render{1}Capable&lt;/code&gt; are components that support the semantic component &lt;code&gt;{1}&lt;/code&gt;, so here, it's &lt;strong&gt;headerFacet&lt;/strong&gt;, &lt;strong&gt;bodyFacet&lt;/strong&gt; and &lt;strong&gt;footerFacet&lt;/strong&gt;. And if you look at the rest of the code of the &lt;code&gt;AbstractModal&lt;/code&gt;, you will see methods with the syntax &lt;code&gt;public String get{1}RendererType()&lt;/code&gt; which are the methods giving the right renderer to use by semantic components. Inside a &lt;strong&gt;modal&lt;/strong&gt;, the &lt;strong&gt;headerFacet&lt;/strong&gt; component will render as a &lt;code&gt;div class=&quot;modal-header&quot;&lt;/code&gt; according to &lt;a href=&quot;https://github.com/richfaces/sandbox/blob/develop/bootstrap/ui/src/main/templates/org/richfaces/bootstrap/modalHeaderFacet.template.xml&quot;&gt;the renderer provided&lt;/a&gt; by the &lt;strong&gt;modal&lt;/strong&gt;. But inside another component, it could have been totally different HTML code.&lt;/p&gt;
      
      &lt;p class=&quot;alert alert-info&quot;&gt;&lt;strong&gt;Pro tip&lt;/strong&gt; If you take a more accurate look to all current semantic components, you will see that they all follow the same syntax: first their purpose (like &lt;strong&gt;header&lt;/strong&gt; or &lt;strong&gt;footer&lt;/strong&gt;) and then a generic &lt;strong&gt;Facet&lt;/strong&gt; suffix. That give us the full list of semantic components: headerFacet, bodyFacet, footerFacet, menuFacet and positionFacet. Why using a suffix? Because we want to keep the no-suffix name for the real HTML tag. The RichFaces &lt;strong&gt;header&lt;/strong&gt; tag will always generate the HTML &lt;strong&gt;header&lt;/strong&gt; tag like a classic JSF tag (the oneToOne relation) but the &lt;strong&gt;headerFacet&lt;/strong&gt; tag is a semantic component so it can generate anything depending of the context. Also, it makes it easier to see if a RichFaces component is a semantic one or not by just looking at its name.&lt;/p&gt;
      
      &lt;p class=&quot;alert alert-danger&quot;&gt;&lt;strong&gt;Warning&lt;/strong&gt; Even if the suffix is &lt;strong&gt;Facet&lt;/strong&gt; keep in mind that semantic components &lt;strong&gt;are not facets&lt;/strong&gt;, they don't have the same limitations: they have attributes, you can use the same semantic component several time inside the same parent, a semantic component doesn't have to be a direct child of a component supporting it and a semantic component can have several children.&lt;/p&gt;
      
      &lt;p&gt;Now, let's dive into the new components. &lt;a href=&quot;http://bootstrap-richfaces.rhcloud.com/component/input/&quot;&gt;input&lt;/a&gt; tag is a basic input with all Bootstrap features like prepend and append and several new attributes in order to support new HTML features. By the way, this &lt;strong&gt;input&lt;/strong&gt; centralizes and supports all HTML5 input types, you will no longer need one JSF component for each type, just use the &lt;code&gt;type&lt;/code&gt; attribute (default is &quot;text&quot; of course).&lt;/p&gt;
      
      &lt;p&gt;&lt;a href=&quot;http://bootstrap-richfaces.rhcloud.com/component/modal/&quot;&gt;modal&lt;/a&gt; is like &lt;code&gt;rich:modalPanel&lt;/code&gt; or &lt;code&gt;rich:popupPanel&lt;/code&gt;, it will display a popup layout on top of your page, potentially covering your page with a dark layer to block any action outside of the modal. The default usage of the modal has a header, specified by using &lt;code&gt;header&lt;/code&gt; attribute or &lt;code&gt;header&lt;/code&gt; facet, a footer specified with &lt;code&gt;footer&lt;/code&gt; facet and a &lt;code&gt;body&lt;/code&gt; which will be the code inside the modal component. Concretely, what's happening is that each part, header - body - footer, will be wrapped inside a &lt;code&gt;div class=&quot;modal-xxx&quot;&lt;/code&gt; where &quot;xxx&quot; is the name of the section in order to align with the Bootstrap syntax. Using footer as a facet might be limiting because you cannot have &lt;strong&gt;a form inside the modal&lt;/strong&gt; wrapping both body and footer because footer, as a facet, will always be outside. The default usage should be &lt;strong&gt;the modal inside the form&lt;/strong&gt; since you will probably not need several forms inside a modal most of the time.&lt;/p&gt;
      
      &lt;p&gt;What if that isn't enough? What if you do want the form inside and not outside? Even if this behavior should be enough in most of use-cases, you can still fully customize your modal the way you want! The moment you use one of the following semantic components, headerFacet - bodyFacet - footerFacet, it considers you are doing a custom modal and it will not generate the &lt;code&gt;div class=&quot;modal-xxx&quot;&lt;/code&gt; anymore. I'm talking about the modal itself. Because the semantic components will generate the corresponding &lt;code&gt;div&lt;/code&gt;. However using real components and not facets will allow you to put both bodyFacet and footerFacet inside a form for example.&lt;/p&gt;
      
      &lt;p&gt;&lt;a href=&quot;http://bootstrap-richfaces.rhcloud.com/component/tooltip/&quot;&gt;tooltip&lt;/a&gt; and &lt;a href=&quot;http://bootstrap-richfaces.rhcloud.com/component/popover/&quot;&gt;popover&lt;/a&gt; are two new ways to display bonus info when the mouse moves over particular content. The first one is for small texts and labels only, the second one can support custom content and a title. Right now, content can only be text but we are planning to improve this.&lt;/p&gt;
      
      &lt;p class=&quot;alert alert-info&quot;&gt;&lt;strong&gt;Pro tip&lt;/strong&gt; Even if &lt;strong&gt;popover&lt;/strong&gt; content only supports text, you can still put some light HTML in it. You just need to escape chevrons with &lt;code&gt;&amp;amp;lt;&lt;/code&gt; and &lt;code&gt;&amp;amp;gt;&lt;/code&gt;.&lt;/p&gt;
      
      &lt;p&gt;Finally, &quot;orderingList&quot;:http://bootstrap-richfaces.rhcloud.com/component/orderingList/ is the new RichFaces ordering list to allow you to re-arrange the order of some items. It already supports single drag-and-drop, multiple selection and &quot;table&quot; layout. Next features will be multiple drag-and-drop, maybe keyboard selection using SHIFT (CTRL is already supported). Thanks to Brian work, it is the first component mixing the power of the jQuery UI widget factory with Bootstrap design. If we can do it once, we can do it for lots of other widgets!&lt;/p&gt;
      
      &lt;p&gt;New EL functions are also there. &lt;a href=&quot;https://github.com/richfaces/components/blob/develop/misc/ui/src/main/java/org/richfaces/function/RichFunction.java#L156&quot;&gt;jQuery&lt;/a&gt; and &lt;a href=&quot;https://github.com/richfaces/components/blob/develop/misc/ui/src/main/java/org/richfaces/function/RichFunction.java#L126&quot;&gt;jQuerySelector&lt;/a&gt; are part of RichFaces Core but have been created to help RichFaces Bootstrap. They will allow you to retrieve a jQuery object or the jQuery selector from a server-side JSF id.&lt;/p&gt;
      
      &lt;p&gt;Next are more &lt;a href=&quot;http://bootstrap-richfaces.rhcloud.com/component/el/&quot;&gt;specific Bootstrap EL functions&lt;/a&gt;. If you have take a look at Bootstrap JavaScript API, you might have noticed that lots of JavaScript components have a set of functions with the following syntax: &lt;code&gt;$(sel).compName('singleParameter');&lt;/code&gt;, like for example: &lt;code&gt;$('#myModal').modal('show');&lt;/code&gt; for a &lt;strong&gt;modal&lt;/strong&gt;. The first approach to use it in JSF component was to use the previous &lt;strong&gt;jQuery&lt;/strong&gt; function like: &lt;code&gt;onclick=&quot;#{rich:jQuery( 'myModal' )}.modal('show')&quot;&lt;/code&gt;. It works fine but obviously, that wasn't enough for Lukas since he built a different approach from scratch.&lt;/p&gt;
      
      &lt;p&gt;The new concept is that the &lt;code&gt;compName&lt;/code&gt; part of the call is nearly useless if you can retrieve it from the component returned from the jQuery call. In the previous example, if you know that &lt;code&gt;#{rich:jQuery('myModal')}&lt;/code&gt; is actually a &lt;strong&gt;modal&lt;/strong&gt; component, then you also know that you will have to call the &lt;strong&gt;modal&lt;/strong&gt; function, only remains with importance the &lt;strong&gt;singleParameter&lt;/strong&gt;. So here is the new syntax: &lt;code&gt;#{b:singleParameter(sel)}&lt;/code&gt;. The previous example becomes: &lt;code&gt;onclick=&quot;#{b:show('myModal')}&quot;&lt;/code&gt;. Much more concise and readable, isn't it? Right now, RichFaces Bootstrap supports &lt;strong&gt;show&lt;/strong&gt;, &lt;strong&gt;hide&lt;/strong&gt; and &lt;strong&gt;toggle&lt;/strong&gt; functions but others will follow soon.&lt;/p&gt;
      
      &lt;p class=&quot;alert alert-info&quot;&gt;&lt;strong&gt;Pro tip&lt;/strong&gt; Want to know how the EL function retrieves the name of the component? Easy. When the selector will be used to find the JSF component, it will find a &lt;strong&gt;UIComponent&lt;/strong&gt; (like a &lt;strong&gt;UIModal&lt;/strong&gt;) which, according to RichFaces CDK design, will extend an &lt;strong&gt;AbstractComponent&lt;/strong&gt; (like &lt;a href=&quot;https://github.com/richfaces/sandbox/blob/develop/bootstrap/ui/src/main/java/org/richfaces/bootstrap/component/AbstractModal.java&quot;&gt;AbstractModal&lt;/a&gt;). And if the &lt;strong&gt;AbstractComponent&lt;/strong&gt; supports Bootstrap EL functions, it will be annotated with &lt;code&gt;@BootstrapJSPlugin&lt;/code&gt; (like at &lt;a href=&quot;https://github.com/richfaces/sandbox/blob/develop/bootstrap/ui/src/main/java/org/richfaces/bootstrap/component/AbstractModal.java#L43&quot;&gt;line 43 of AbstractModal&lt;/a&gt;) and it's the &lt;code&gt;name&lt;/code&gt; attribute of that annotation that will give us the &lt;code&gt;componentName&lt;/code&gt;. As I told you, really easy!&lt;/p&gt;
      
      &lt;p&gt;&lt;strong&gt;LESS support&lt;/strong&gt; is no longer a dream (for those who doesn't know LESS, it's a more powerful way to write CSS, see the &lt;a href=&quot;http://lesscss.org/&quot;&gt;project website&lt;/a&gt; for more infos). Thanks to Lukas' awesome work, a first prototype of that feature is already working. You can &lt;a href=&quot;http://rik-ansikter.blogspot.fr/2012/08/jsf-meets-skinning-awesomeness-of-less.html&quot;&gt;read his post&lt;/a&gt; to know more about that. There is still work to do but it's an incredible starting point.&lt;/p&gt;
      
      &lt;h3 id=&quot;whats-coming&quot;&gt;What's coming?&lt;/h3&gt;
      
      &lt;p&gt;Want more? Great, because we have tons of other plans to improve RichFaces!&lt;/p&gt;
      
      &lt;p&gt;&lt;strong&gt;New build design&lt;/strong&gt; is currently under &lt;a href=&quot;https://community.jboss.org/wiki/RichFaces43BuildRedesign&quot;&gt;discussion on RichFaces wiki&lt;/a&gt; so be sure to take a look and give feedback if you care about the future of RichFaces.&lt;/p&gt;
      
      &lt;p&gt;&lt;strong&gt;Theming all current components&lt;/strong&gt; from RichFaces Core with Bootstrap design is planned so you can use both projects at the same time.&lt;/p&gt;
      
      &lt;p&gt;The orderingList is just a beginning. &lt;strong&gt;More jQuery UI widget factory based components&lt;/strong&gt; are incoming. Feel free to comment &lt;a href=&quot;https://community.jboss.org/thread/200343&quot;&gt;here&lt;/a&gt; to propose the ones you would like to see supported in RichFaces Bootstrap.&lt;/p&gt;
    </content>
  </entry>
  <entry>
    <id>http://pauldijou.fr/blog/2012/08/01/news-richfaces-cdk/</id>
    <title>News about RichFaces CDK</title>
    <updated>2015-06-06T15:40:57+02:00</updated>
    <published>2012-08-01T00:00:00+00:00</published>
    <link href="http://pauldijou.fr/blog/2012/08/01/news-richfaces-cdk/" rel="alternate" type="text/html" />
    <category term="richfaces"></category>
    <category term="cdk"></category>
    <summary>
      
      RichFaces CDK new features
      
      As the RichFaces Bootstrap project grows, we need more tools to achieve new goals and keep the code clean and readable. More tools means a stronger CDK and here are the last features.
      
      Fragments are small portions of code inside the template that are defined outside of the main implementation but can be called inside it or inside other fragments or even inside itself! Say hello to recursion in RichFaces CDK templates. In term of Java, fragments are methods. So when you write a fragment, it will generates a Java method in the final renderer. Knowing that makes...
    </summary>
    <content type="html">
      
      &lt;h3 id=&quot;richfaces-cdk-new-features&quot;&gt;RichFaces CDK new features&lt;/h3&gt;
      
      &lt;p&gt;As the RichFaces Bootstrap project grows, we need more tools to achieve new goals and keep the code clean and readable. More tools means a stronger CDK and here are the last features.&lt;/p&gt;
      
      &lt;p&gt;&lt;strong&gt;Fragments&lt;/strong&gt; are small portions of code inside the template that are defined outside of the main implementation but can be called inside it or inside other fragments or even inside itself! Say hello to recursion in RichFaces CDK templates. In term of Java, fragments are methods. So when you write a fragment, it will generates a Java method in the final renderer. Knowing that makes fragments really easy to understand and to use. See the &lt;a href=&quot;https://issues.jboss.org/browse/RF-12226&quot;&gt;JIRA issue 12226&lt;/a&gt; for a fully explained example.&lt;/p&gt;
      
      &lt;p class=&quot;alert alert-info&quot;&gt;&lt;strong&gt;Pro tip&lt;/strong&gt; Notice that in the signature of the generated Java method, 3 arguments are always passed without having to specify them inside the template : ResponseWriter, FacesContext and UIComponent.&lt;/p&gt;
      
      &lt;p class=&quot;alert alert-danger&quot;&gt;&lt;strong&gt;Warning&lt;/strong&gt; Currently, if you want to use a fragment1 inside a fragment2, you need to write fragment1 first in your template so its signature has been parsed before calling it in fragment2. Problem is reported in &lt;a href=&quot;https://issues.jboss.org/browse/RF-12326&quot;&gt;JIRA issue 12326&lt;/a&gt;.&lt;/p&gt;
      
      &lt;p&gt;&lt;code&gt;cc:renderFacet&lt;/code&gt; is a new tag you can use inside a CDK template, equivalent of the same tag from JSF composite component. Its usage is quite straightforward: it will render the facet that you will specify in the &lt;code&gt;name&lt;/code&gt; attribute. If you put some content inside the tag, it will be used as default value in case the facet is missing. See &lt;a href=&quot;https://issues.jboss.org/browse/RF-12260&quot;&gt;JIRA issue 12260&lt;/a&gt; for full description.&lt;/p&gt;
      
      &lt;p&gt;&lt;code&gt;varStatus&lt;/code&gt; is a new attribute for the &lt;code&gt;c:forEach&lt;/code&gt; CDK tag. It will perform the exact same thing as the one in the original &lt;code&gt;c:forEach&lt;/code&gt; tag, giving you more tools inside a forEach loop. See &lt;a href=&quot;https://issues.jboss.org/browse/RF-12232&quot;&gt;JIRA issue 12232&lt;/a&gt;.&lt;/p&gt;
      
      &lt;p&gt;&lt;strong&gt;wildcard&lt;/strong&gt; can now be used inside &lt;code&gt;cdk:passThrough&lt;/code&gt; and &lt;em&gt;cdk:passThroughWithExclusions&lt;/em&gt; attributes in order to pass all attributes starting with the same prefix. Especially useful with JavaScript events &lt;code&gt;on*&lt;/code&gt;. Wildcard can be use with attribute mapping like &lt;code&gt;onkey*:oninputkey*&lt;/code&gt;. See &lt;a href=&quot;https://issues.jboss.org/browse/RF-12200&quot;&gt;JIRA issue 12200&lt;/a&gt;.&lt;/p&gt;
      
      &lt;p&gt;&lt;em&gt;component&lt;/em&gt; variable is now directly casted to the correct class based on &lt;code&gt;cdk:class&lt;/code&gt; tag in the template. You will no longer need to write explicitly the cast inside 95% of your templates. Enjoy less verbose code and see &lt;a href=&quot;https://issues.jboss.org/browse/RF-12248&quot;&gt;JIRA issue 12248&lt;/a&gt; for more details.&lt;/p&gt;
      
      &lt;p&gt;In general, CDK has been improved to be more type-safe which allows to catch more issues at compilte-time.&lt;/p&gt;
      
      &lt;h3 id=&quot;whats-next&quot;&gt;What's next?&lt;/h3&gt;
      
      &lt;p&gt;There are still a few points undone in the &lt;a href=&quot;https://community.jboss.org/wiki/CDKWish-List&quot;&gt;CDK wish-list&lt;/a&gt; and I hope some of them will be realized. One of the most important is probably generating methods from interfaces! See &lt;a href=&quot;https://issues.jboss.org/browse/RF-12339&quot;&gt;JIRA issue 12339&lt;/a&gt; to fully understand the concept.&lt;/p&gt;
      
      &lt;p&gt;In another topic, another post will follow next week to talk about what's new in &lt;a href=&quot;http://bootstrap-richfaces.rhcloud.com&quot;&gt;RichFaces Bootstrap project&lt;/a&gt;.&lt;/p&gt;
    </content>
  </entry>
  <entry>
    <id>http://pauldijou.fr/blog/2012/05/08/jsf-bootstrap-render-all/</id>
    <title>JSF, Bootstrap and calling render=@all</title>
    <updated>2015-06-06T15:40:57+02:00</updated>
    <published>2012-05-08T00:00:00+00:00</published>
    <link href="http://pauldijou.fr/blog/2012/05/08/jsf-bootstrap-render-all/" rel="alternate" type="text/html" />
    <category term="jsf"></category>
    <category term="bootstrap"></category>
    <summary>
      The problem
      
      So, the other day, I was playing with Twitter Bootstrap on a JSF application. Everything was fine until I decide to use a render="@all" somewhere in the page in order to refresh all my components after quite an heavy operation. Working fine.
      
      But Bootstrap was no longer fully healthy. The CSS and design were ok, but the JavaScript was all broken : nearly all effects didn't appear anymore. It was a bit strange so I hit F5 and everything was fine, all JavaScript events were back. But the moment my render="@all" was called, they disappear again.
      
      Why?
      
      After some investigations, the reason...
    </summary>
    <content type="html">
      &lt;h3 id=&quot;the-problem&quot;&gt;The problem&lt;/h3&gt;
      
      &lt;p&gt;So, the other day, I was playing with &lt;a href=&quot;http://twitter.github.com/bootstrap/index.html&quot;&gt;Twitter Bootstrap&lt;/a&gt; on a JSF application. Everything was fine until I decide to use a &lt;code&gt;render=&quot;@all&quot;&lt;/code&gt; somewhere in the page in order to refresh all my components after quite an heavy operation. Working fine.&lt;/p&gt;
      
      &lt;p&gt;But Bootstrap was no longer fully healthy. The CSS and design were ok, but the JavaScript was all broken : nearly all effects didn't appear anymore. It was a bit strange so I hit F5 and everything was fine, all JavaScript events were back. But the moment my &lt;code&gt;render=&quot;@all&quot;&lt;/code&gt; was called, they disappear again.&lt;/p&gt;
      
      &lt;h3 id=&quot;why&quot;&gt;Why?&lt;/h3&gt;
      
      &lt;p&gt;After some investigations, the reason was that Bootstrap calls a JavaScript function that will attach most of its events to the &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; when the HTML DOM is ready. Its doing so in order to catch all user interactions when they bubble up to the &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; tag which wrap the whole page. With that, you can use Ajax as much as you want and update your DOM since there is no event attach to a particular HTML tag, they are all in the &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; tag.&lt;/p&gt;
      
      &lt;p&gt;That's really good but that's also the reason of the problem. I said Ajax is always fine, and it's true as long as you don't touch the @&amp;lt;body&amp;gt;@ tag. The moment you update this tag, it will probably be reset to it's initial state, without any JavaScript event, and since the Bootstrap JavaScript function is only called once when the DOM is ready the first time, JavaScript events will not come back. Guess what, &lt;code&gt;render=&quot;@all&quot;&lt;/code&gt; will render your &lt;code&gt;&amp;lt;h:body&amp;gt;&lt;/code&gt; and so will broke all Bootstrap JavaScript events.&lt;/p&gt;
      
      &lt;h3 id=&quot;a-workaround&quot;&gt;A workaround&lt;/h3&gt;
      
      &lt;p&gt;The true solution would be to call the Bootstrap JavaScript function after each &lt;code&gt;render=&quot;@all&quot;&lt;/code&gt; in order to attach all JavaScript events again. But since I have no idea how to do that right now, I have chosen to use an easier workaround.&lt;/p&gt;
      
      &lt;p&gt;Just wrapping your whole page in a JSF panel and render it instead of &lt;code&gt;render=&quot;@all&quot;&lt;/code&gt; should be enough in most use case. It is not exactly the same behaviour, but in most case, when calling &lt;code&gt;render=&quot;@all&quot;&lt;/code&gt;, what you really want is just refreshing your whole page using Ajax. For example:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code class=&quot;language-markup&quot;&gt;&amp;lt;!DOCTYPE html&amp;gt;
      &amp;lt;html lang=&quot;en-US&quot;
            xmlns=&quot;http://www.w3.org/1999/xhtml&quot;
            xmlns:h=&quot;http://java.sun.com/jsf/html&quot;
            xmlns:f=&quot;http://java.sun.com/jsf/core&quot;
            xmlns:ui=&quot;http://java.sun.com/jsf/facelets&quot;&amp;gt;
      &amp;lt;h:head&amp;gt;
          &amp;lt;title&amp;gt;Site title&amp;lt;/title&amp;gt;
      &amp;lt;/h:head&amp;gt;
      &amp;lt;h:body&amp;gt;
          &amp;lt;h:panelGroup id=&quot;all&quot;&amp;gt;
              ... your code...
          &amp;lt;/h:panelGroup&amp;gt;
      &amp;lt;/h:body&amp;gt;
      &amp;lt;/html&amp;gt;
      &lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;And replace all your &lt;code&gt;render=&quot;@all&quot;&lt;/code&gt; with &lt;code&gt;render=&quot;all&quot;&lt;/code&gt;.&lt;/p&gt;
    </content>
  </entry>
</feed>
