Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configuration problems #2

Open
jcc2303 opened this issue Jul 27, 2015 · 1 comment
Open

configuration problems #2

jcc2303 opened this issue Jul 27, 2015 · 1 comment

Comments

@jcc2303
Copy link

jcc2303 commented Jul 27, 2015

Hi,

We are having problems trying to get lasso-marko to work for our Koa server.
This is our current lasso setup.

If we run this file with node lasso-config.js it really works :)
However when we try to duplicate this with an identical browser.json file for the marko page, it fails - no script/dependency is inserted. We are pretty lost...

'use strict';

var lasso = require('lasso');

lasso.configure('./lasso-config.json');

lasso.lassoPage({
        name: 'registration',
        dependencies: [
            "./public/registration.js"
        ]
    },
    function(err, lassoPageResult) {
        if (err) {
          console.log(err);
        }

        console.log('lassoPageResult ', lassoPageResult);
        var headHtml = lassoPageResult.getHeadHtml();
        // headHtml will contain something similar to the following:
        // <link rel="stylesheet" type="text/css" href="static/my-page-169ab5d9.css">

        var bodyHtml = lassoPageResult.getBodyHtml();
        // bodyHtml will contain something similar to the following:
        //  <script type="text/javascript" src="static/my-page-2e3e9936.js"></script>
    });

Our marko rendering setup:

{
  "name": "registration",
  "dependencies": [
      "./public/registration.js"
  ]
}

our lasso config

{
  "plugins": [
    "lasso-marko"
  ],
  "outputDir": "static",
  "fingerprintsEnabled": true,
  "minify": false,
  "resolveCssUrls": true,
  "bundlingEnabled": true,
  "bundles": []
}

reference from server

let lasso  = require('lasso');
lasso.configure('./lasso-config.json');

In /views/pages/registration we have a registration.marko page template and a registration.browser.json file as follows:

{
  "name": "registration",
  "dependencies": [
      "./public/registration.js"
  ]
}

Our marko rendering logic

'use strict';

let marko = require('./marko-config');

function findTemplate(template) {
  console.log(template);
  return `../../views/pages/${template}/${template}.marko`
}

function resolveTemplate(templateName) {
  let templatePath = findTemplate(templateName);
  return require.resolve(templatePath);
}

module.exports =  function(response, template, data) {
  console.log('render - template', template);
  let resolvedTemplate = resolveTemplate(template);
  console.log(resolvedTemplate);
  //response.body = marko.load(resolvedTemplate).stream(data);
  //response.type = 'text/html';

  marko.load(resolvedTemplate).render({
          name: 'Frank'
      },
      function(err, output) {
          response.body = output;
          response.type = 'text/html';
      });
}

It renders the html but without the registration.js script injected. What are we missing or doing wrong?
Thanks :)

@patrick-steele-idem
Copy link
Contributor

Hi @jcc2303, you didn't share the code for your page templates but I suspect you missing the required Lasso.js tags for Marko. Are you including the <lasso-page>, <lasso-head> and <lasso-body> tags? Those tags do the work of injecting the required <script> and <link> tags into your rendered HTML. Please see: Using Lasso.js Taglib with Marko

If you are using those tags and are still seeing the problem then please let me know. I hope that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants