~matsubara/juju-gui/tarmac-test

« back to all changes in this revision

Viewing changes to lib/templates.js

  • Committer: Matthew Scott
  • Date: 2013-01-09 18:36:08 UTC
  • mto: This revision was merged to the branch mainline in revision 312.
  • Revision ID: matthew.scott@canonical.com-20130109183608-4eedacp8dwtsslf3
Plugging recess into generateTemplates

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
    exec = require('child_process').exec,
6
6
    YUI = require('yui').YUI,
7
7
    view = require('./view.js'),
8
 
    less = require('less'),
 
8
    recess = require('recess'),
9
9
    config = require('../config.js').config,
10
10
    cache = {};
11
11
 
159
159
  stylesheet: {
160
160
    output: __dirname + '/../build-shared/juju-ui/assets/juju-gui.css',
161
161
    callback: function(strategy, name) {
162
 
      var parser = new less.Parser({
163
 
        paths: [config.server.view_dir],
164
 
        filename: 'stylesheet.less'
165
 
      }),
166
 
          css_data = fs.readFileSync(
167
 
          path.join(config.server.view_dir, 'stylesheet.less'), 'utf8');
168
 
      parser.parse(css_data, function(e, tree) {
169
 
        if (e) {
170
 
          console.log('LESS Generation Error', e);
171
 
          return;
172
 
        }
173
 
        fs.writeFileSync(strategy.output,
174
 
            tree.toCSS({compress: true}));
175
 
      });
 
162
      // Lint the file without compiling using our config first.
 
163
      var recessConfig = JSON.parse(
 
164
          fs.readFileSync(__dirname + '/../recess.json'));
 
165
      recess(
 
166
          path.join(config.server.view_dir, 'stylesheet.less'),
 
167
          recessConfig,
 
168
          function(err, obj) {
 
169
            if (err) {
 
170
              console.log('LESS Generation Error', err);
 
171
              return;
 
172
            }
 
173
            // Warn of lint errors.
 
174
            console.log(obj.errors);
 
175
          });
176
176
 
 
177
      // Compile the less to the output file without worrying about our config.
 
178
      // This is due to a memory-leak in recess when multiple options are
 
179
      // specified with compile=true.  
 
180
      // See: https://github.com/twitter/recess/issues/22
 
181
      recess(
 
182
          path.join(config.server.view_dir, 'stylesheet.less'),
 
183
          { compile: true },
 
184
          function(err, obj) {
 
185
            if (err) {
 
186
              console.log('LESS Generation Error', err);
 
187
              return;
 
188
            }
 
189
            // Write to output.
 
190
            fs.writeFileSync(strategy.output, obj.output);
 
191
          });
177
192
    }
178
193
  }
179
194
};