An intro into developing Viewbook V3: design for agility.

add a first comment - Bob - January 1, 2012

Our aim with the new viewbook V3 pages framework was to develop a system that builds on our experience with the current viewbook pages tool, while expanding it’s capabilities with a brand new core setup. In essence this meant we wanted to take all the good out of the current tool, and put that into a new framework that was capable of producing any type of portfolio website we wanted.

When you don’t know exactly what needs to be build, but you have to start somewhere
This latter part was actually pretty important. The thing is that we at viewbook work as a small dedicated team (on average between 6 and 10 people), heavily relying on prototyping, user feedback and, most importantly, our own inspiration to fine tune the new V3 system. This meant we could not develop a custom fit system from start based on a clear and defined set of guidelines (which we did not know yet). But rather we needed a system that could quickly adapt to anything we could think of along the way.

Use things as they are, do not ‘hack’ them
The way we achieved this is by using HTML, CSS and the Web browser (DOM) as much as possible as they are in their purest form, without trying to change or improve them (by hacking around with Javascript). On top of that we designed an XML and XSLT based core framework for page (and module) generation, whereby the configuration for a page is made as abstract as possible. Also the framework needed to be loosely tied to our database environment for easy integration and optimal scalability. In essence this means we can now import any piece of data, ‘capture’ any styling, behaviour or content configuration in a generalized way and generate any type and form of output we want (more on how that works in a later post!).

Developing in this manner might be a somewhat slower approach as supposed to working with a fixed plan and feature set, and it means you might have to wait a bit longer for V3 then you’d like. But it also means we can afford to be really flexible when it comes to implementing new features based on our ideas and your feedback.

Importing plugins, feeds, designs, etcetera
The new system also makes it easy to integrate features especially for developers and designers. For Developers things like easily integrating custom jQuery plugins in your page and using V3 components in custom websites or WordPress (and other blogging environments), plus importing data into a component from any source you want. And for designers the importing and exporting of designs from and to your favorite design applications (Adobe Illustrator, Indesign), making custom design templates manageable by your clients or act as a third party reseller of your designs.

In any case the main focus for V3 will be the components you use to fill and style your portfolio. And each component can be made as exactly as we want them to be. So that will be the part where this flexibility will pay off the most, and where your feedback will be most valuable. But more on that later in our next update!

Configuration to the power of XSLT

add a first comment - Bob - March 28, 2011

At Viewbook we are using XSLT (Extensible Stylesheet Language Transformations) to build a new generation of powerful website building tools within the Viewbook framework (more on that later). I have been working with XSLT for about 4 years now, so it came naturally to me to offer it as the preferred approach to get the system working. But using XSLT isn’t exactly a mainstream approach for web development (yet), so why did we choose XSLT for the job?

What does XSLT solve?
Thinking about how we would ideally set up the new range of tools, it quickly came down to one rather fundamental question. How can we easily combine a multitude of configuration and data sources into all the needed output types? And more importantly, how could we keep the overall system agile and scalable?

The configuration method of choice came down to XML (doesn’t it almost always). It’s easy to produce, great for rapid prototyping (just edit a static file) and can be easily generated by any back-end system. XML configuration does however has it downsides when you want to use it to generate the output. It’s pretty verbose and parsing can be a pain and can require a lot of code, and this is exactly where XSLT comes in.

What is XSLT?
So what is XSLT? In short it is a great way to loop through each and every bit of an XML source, and transform that bit into something else on the fly and only if needed. You can use it to generate any type of output from a single XML source: Text, XML, HTML, CSS, Javascript, SVG, a PDF or anything in between. In essence this means with XSLT you can produce any type of content and truly abstract your data and configuration from your output and transforming logic.

What does XSLT look like?
Letís do a concrete example. Suppose you want to render various pieces of HTML into one or more pages, where each bit has the same basic structure but different content and styling. And as a bonus letís keep the database as a flat as possible.

The XML configuration could look something like this:

  1. <data>
  2.    
  3.     <item>
  4.        
  5.         <structure>
  6.            
  7.             <section>
  8.                
  9.                 <header>
  10.                    
  11.                     <h1 id="h-h1"/>
  12.                    
  13.                     <p id="h-p"/>
  14.                    
  15.                 </header>
  16.                
  17.                 <p id="s-p"/>
  18.                
  19.             </section>
  20.            
  21.         </structure>
  22.        
  23.         <options>
  24.            
  25.             <item type="content" id="h-h1">
  26.                 Custom Title
  27.             </item>
  28.            
  29.             <item type="content" id="h-p">
  30.                 Lorem ipsum dolor sit amet, consecteturadipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore
  31.                
  32.                 magna aliqua.
  33.             </item>
  34.            
  35.             <item type="content" id="s-p">
  36.                 Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem
  37.                
  38.                 aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.
  39.                
  40.             </item>
  41.            
  42.             <item type="style" id="h-h1">
  43.                 font-size:24px
  44.             </item>
  45.            
  46.             <item type="style" id="h-p">
  47.                 font-size:14px
  48.             </item>
  49.            
  50.             <item type="style" id="s-p">
  51.                 font-size:12px
  52.             </item>
  53.            
  54.         </options>
  55.        
  56.     </item>
  57. </data>

And with XSLT like this:

  1. <!– load in your data –>
  2.  <xsl:variable name="data" select="document('http://url-to-your-data.xml')" />
  3.  
  4.  <xsl:template match="/">
  5.  
  6.   <!– loop through the basic structure –>
  7.   <xsl:apply-templates select="$data/data/item/structure/*" mode="html" />
  8.  
  9.   <style>
  10.  
  11.    <xsl:comment>
  12.     <!– sum up all css styles –>
  13.     <xsl:apply-templates select="$data/data/item/options/item[@type= 'style']" mode="style" />
  14.    </xsl:comment>
  15.  
  16.   </style>
  17.  </xsl:template>
  18.  
  19.  <!–
  20.   template copy using the "The Ninja Technique"
  21.   http://symphony-cms.com/learn/articles/view/html-ninja-technique/
  22.  –>
  23.  <xsl:template match="*" mode="html">
  24.  
  25.   <!– store the content reference id –>
  26.   <xsl:variable name="el-id" select="@id" />
  27.  
  28.   <xsl:element name="{name()}">
  29.    <xsl:choose>
  30.    <!–
  31.    This matches the elements 'id' from the config structure
  32.    with any possible 'id' in the config options and pasts in the content
  33.    –>
  34.  
  35.     <xsl:when test="$el-id and $data/data/item/options/item[@type = 'content' and @id = $el-id]">
  36.      <xsl:apply-templates select="@*" mode="html" />
  37.      <xsl:value-of select="$data/data/item/options/item[@id = $el-id]" />
  38.     </xsl:when>
  39.     <xsl:otherwise>
  40.      <!– otherwise just copy the config structure –>
  41.      <xsl:apply-templates select="* | @* | text()" mode="html" />
  42.     </xsl:otherwise>
  43.    </xsl:choose>
  44.   </xsl:element>
  45.  </xsl:template>
  46.  
  47.  <xsl:template match="@*" mode="html">
  48.   <xsl:attribute name="{name()}">
  49.          <xsl:value-of select="." />
  50.      </xsl:attribute>
  51.  </xsl:template>
  52.  <!– Template copy –>
  53.  
  54.  
  55.  <!– css style generation –>
  56.  <xsl:template match="item" mode="style">
  57.   <xsl:text>#</xsl:text>
  58.   <xsl:value-of select="@id" />
  59.   <xsl:text>{</xsl:text>
  60.   <xsl:value-of select="." />
  61.   <xsl:text>;}</xsl:text>
  62.  </xsl:template>
  63.  <!– css style generation –>

You would produce:

  1. <section>
  2.    
  3.     <header>
  4.        
  5.         <h1 id="h-h1">
  6.             Custom Title
  7.         </h1>
  8.        
  9.         <p id="h-p">
  10.             Lorem ipsum dolor sit amet,  consecteturadipisicing elit, sed do eiusmod tempor incididunt ut labore  et dolore magna aliqua.
  11.         </p>
  12.        
  13.     </header>
  14.    
  15.     <p id="s-p">
  16.         Sed ut perspiciatis unde omnis iste natus error sit  voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque  ipsa
  17.        
  18.         quae ab illo inventore veritatis et quasi architecto beatae vitae  dicta sunt explicabo.
  19.        
  20.     </p>
  21.    
  22. </section>
  23.  
  24. <style>
  25.     <!–#h-h1{font-size:24px;}#h-p{font-size:14px;}#s-p{font-size:12px;}–>
  26. </style>

Obviously this is a pretty simple example witch could be improved upon, but thatís simply a case of making more specific template matches and adjust your XSLT as needed.

No disadvantages?
XSLT does has it’s downsides of course, like most technologies do. First of all mastering XSLT can be a steep learning curve and requires a different ‘mindset’ to get started. XSLT is a templating language, you loop, match and transform. Whereas other transform languages often use a loaded DOM and ‘paste’ new content in afterwards. The latter generally would be a more familiar approach for most developers.

Secondly XSLT isn’t really known for it’s mathematical prowess, it’s a XML transformation language after all. Although XSLT 2.0 does solve this for a great deal, that version isn’t really widespread yet. External libraries like EXSLT do solve much of the headaches in the mean time though. And finally working with very large XML documents (as in thousands of lines of XML) can pose performance issues if not careful, although I myself never run into this before.

Conclusion
So XSLT is a great way to produce any type of content from your database and really abstracts configuration from output. Besides this XSLT is a platform neutral way of rendering the output. So that means there is always a XSLT processor you can use in the language you’re most familiar with. And of course XSLT is just about transforming XML, nothing more and nothing less. So if you’re working with XML, XSLT is the way to go.