'use strict';

const Path        = require('path');
const _           = require('lodash');
const Theme       = require('@frctl/fractal').WebTheme;
const packageJSON = require('./package.json');

module.exports = function(options){

    options = _.clone(options || {});

    const theme = new Theme({
        views: Path.join(__dirname, 'views'),
        error: 'pages/error.nunj',
        static: {
            path: Path.join(__dirname, 'dist'),
            mount: '/theme'
        },
        options: _.defaultsDeep(options, {
            skin: 'default',
            rtl: false,
            lang: 'en',
            stylesheet: null,
            head: null,
            foot: null,
            contextFormat: 'json'
        })
    });

    theme.route('/', {
        handle: 'overview',
        view: 'pages/page.nunj',
    });

    theme.route('/docs', {
        redirect: '/'
    });

    theme.route('/components', {
        redirect: '/'
    });

    theme.route('/components/preview/:handle', {
        handle: 'preview',
        view: 'pages/components/preview.nunj'
    });

    theme.route('/components/detail/:handle', {
        handle: 'component',
        view: 'pages/components/detail.nunj'
    });

    theme.route('/docs/:path([^\?]+?)', {
        handle: 'page',
        view: 'pages/page.nunj'
    });

    theme.onBuild(function(builder, app){

        const components = app.components;
        const docs       = app.docs;

        for (let comp of components.flatten()) {
            if (!comp.isHidden){
                builder.addRoute('preview', {'handle':comp.handle});
                builder.addRoute('component', {'handle':comp.handle});
            }
            for (let variant of comp.variants()) {
                builder.addRoute('preview', {'handle':variant.handle});
                if (!comp.isCollated){
                    builder.addRoute('component', {'handle':variant.handle});
                }
            }
        }

        builder.addRoute('overview');
        for (let page of docs.flatten()) {
            if (!page.isHidden && page.path !== '') {
                builder.addRoute('page', {'path':page.path});
            }
        }

    });

    return theme;
};

@@ -296,25 +296,8 @@
 eme(
-%7B%0A        views: 
 Path
@@ -326,165 +326,8 @@
 s'),
-%0A        error: 'pages/error.nunj',%0A        static: %7B%0A            path: Path.join(__dirname, 'dist'),%0A            mount: '/theme'%0A        %7D,%0A        options:
  _.d
@@ -357,20 +357,16 @@
         
- 
-   
 skin: 'd
@@ -382,20 +382,16 @@
         
-    
 rtl: fal
@@ -402,20 +402,16 @@
         
-  
-  
 lang: 'e
@@ -414,20 +414,16 @@
 : 'en',%0A
-    
         
@@ -448,20 +448,16 @@
         
-   
- 
 head: nu
@@ -452,36 +452,32 @@
     head: null,%0A
-    
         foot: nu
@@ -476,28 +476,24 @@
 foot: null,%0A
-    
         cont
@@ -518,20 +518,107 @@
     
-    %7D)%0A    %7D
+%7D));%0A%0A    theme.error('pages/error.nunj');%0A%0A    theme.static(Path.join(__dirname, 'dist'), '/theme'
 );%0A%0A

Change initialisation style