lib/Preview.js
function generateTemplate(context) {
  let _page;
  let _phantom;
  phantom.create([], { logLevel: 'error' }).then(function (ph) {
    _phantom = ph;
    ph.createPage()
      .then(page => {
        _page = page;
        const url = path.join(context.config.destRoot, context.sample.embed);
        return _page.property('viewportSize', {width: 1024, height: 768})
          .then(() => _page.open(url) );
      })
      .then(status => {
        return _page.evaluate(function() {
          const element = document.querySelector('#source-panel');
          const height = element.getBoundingClientRect().top + element.offsetHeight;
          return height;
        });
      })
      .then(height => {
        context.sample.height = height;
        generate(context.sample.template, templates.template, context);
      })
      .then(() => {
        _page.close();
        _phantom.exit();
      })
      .catch(err => console.log(err));
  });
}
function generateTemplate(context) {
  let _page;
  let _phantom;
  phantom.create([], { logLevel: 'error' }).then(function (ph) {
    _phantom = ph;
    ph.createPage()
      .then(page => {
        _page = page;
        const url = path.join(context.config.destRoot, context.sample.embed);
        return _page.property('viewportSize', {width: 1024, height: 768})
          .then(() => _page.open(url) );
      })
      .then(status => {
        return _page.evaluate(function() {
          const element = document.querySelector('#source-panel');
          const height = element.getBoundingClientRect().top + element.offsetHeight;
          return height;
        });
      })
      .then(height => {
        context.sample.height = height;
        generate(context.sample.template, templates.template, context);
      })
      .then(() => {
        _page.close();
        _phantom.exit();
      })
      .catch(err => console.log(err));
  });
}
function generateTemplate ( context ) { let _page ; let _phantom ; phantom . create ( [ ] , { logLevel : 'error' } ) . then ( function ( ph ) { _phantom = ph ; ph . createPage ( ) . then ( page => { _page = page ; const url = path . join ( context . config . destRoot , context . sample . embed ) ; return _page . property ( 'viewportSize' , { width : 1024 , height : 768 } ) . then ( ( ) => _page . open ( url ) ) ; } ) . then ( status => { return _page . evaluate ( function ( ) { const element = document . querySelector ( '#source-panel' ) ; const height = element . getBoundingClientRect ( ) . top + element . offsetHeight ; return height ; } ) ; } ) . then ( height => { context . sample . height = height ; generate ( context . sample . template , templates . template , context ) ; } ) . then ( ( ) => { _page . close ( ) ; _phantom . exit ( ) ; } ) . catch ( err => console . log ( err ) ) ; } ) ; }
Opens the embed html file in a browser to determine the initial height.
Opens the embed html file in a browser to determine the initial height .