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

specialization seems to be broken #72

Open
Ampakinetic opened this issue Aug 12, 2015 · 24 comments
Open

specialization seems to be broken #72

Ampakinetic opened this issue Aug 12, 2015 · 24 comments

Comments

@Ampakinetic
Copy link

Hi, I've followed http://krakenjs.com/2015/07/09/upgrading-makara.html and upgraded my v1.0 app running on Windows. Now the specialization rules don't seem to be processed any more, I've verified the values are still being set, but the correct specialized partials no longer show, only the default one does. Any ideas? Let me know if you need any snippets. Thanks.

@aredridel
Copy link
Contributor

I'd love to know what your config looks like -- things moved around a bit.

@Ampakinetic
Copy link
Author

Thanks, here is my current config.json:

{
  "express": {
    "view cache": false,
    "view engine": "dust",
    "views": "path:./.build/templates"
  },

  "view engines": {
    "dust": {
        "module": "makara",
        "renderer": {
            "method": "dust",
            "arguments": [
                { "cache": false, "helpers": "config:dust.helpers" }
            ]
        }
    }
  },
  "bundle engine": "dust",
  "specialization": "import:./specialization.json",
  "i18n": {
    "contentPath": "path:./locales",
    "fallback": "en-US"
  },
  "databaseConfig": {
    "host": "localhost",
    "database": "shocart"
  },
  "dust": {
       "helpers": [
           "dust-makara-helpers"
       ]
   },
  "paypalConfig": {
    "host": "api.sandbox.paypal.com",
    "port": "",
    "client_id": "EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM",
    "client_secret": "EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM"
  },
  "middleware": {
    "expressView": {
            "priority": 100,
            "enabled": true,
            "module": {
                "name": "makara",
                "arguments": [
                    {
                        "i18n": "config:i18n",
                        "specialization": "config:specialization"
                    }
                ]
            }
        },
    "static": {
      "module": {
        "arguments": [ "path:./.build" ]
      }
    },

    "router": {
      "module": {
        "arguments": [ { "directory": "path:./controllers" } ]
      }
    },

    "fileNotFound": {
      "enabled": true,
      "priority": 130,
      "module": {
        "name": "kraken-js/middleware/404",
        "arguments": [ "errors/404" ]
      }
    },

    "serverError": {
      "enabled": true,
      "priority": 140,
      "module": {
        "name": "kraken-js/middleware/500",
        "arguments": [ "errors/500" ]
      }
    },

    "locale": {
      "priority": 95,
      "enabled": true,
      "module": {
        "name": "path:./lib/locale"
      }
    }
  }
}

And the specialization.json file:

{
    "noprods": [
        {
            "is": "shopsite/noprods",
            "when": {
                "template.is": "shopsite"
            }
        }
    ]
}

I am passing the config like this:

 model.template = {
    is: "shopsite"
};

res.render('index', model);

And before the upgrade shopsite/noprods.dust was getting rendered, now only ./noprods.dust seems to come up.

@aredridel
Copy link
Contributor

Hrm. At a glance that looks right -- you don't need the indirection of using both import: and config: handlers, you could just import it right into the config, but I see no error there.

Can you run your app with the NODE_DEBUG=engine-munger environment variable? That should print out debug tracing and show where it went wrong.

@Ampakinetic
Copy link
Author

ENGINE-MUNGER 14116: specialization mapped 'index.dust' to 'index.dust'
ENGINE-MUNGER 14116: lookup "index.dust"
ENGINE-MUNGER 14116: stat "M:\web\node\webtrade\public\templates\index.dust"
ENGINE-MUNGER 14116: found "M:\web\node\webtrade\public\templates\index.dust"
ENGINE-MUNGER 14116: render "M:\web\node\webtrade\public\templates\index.dust"
ENGINE-MUNGER 14116: specialization mapped 'index.properties' to 'index.properti
es'
ENGINE-MUNGER 14116: trying locales ["US/en"]
ENGINE-MUNGER 14116: lookup "index.properties"
ENGINE-MUNGER 14116: stat "M:\web\node\webtrade\locales\US\en\index.properties"
ENGINE-MUNGER 14116: found "M:\web\node\webtrade\locales\US\en\index.properties"

ENGINE-MUNGER 14116: specialization mapped 'index.properties' to 'index.properti
es'
ENGINE-MUNGER 14116: trying locales ["US/en"]
ENGINE-MUNGER 14116: lookup "index.properties"
ENGINE-MUNGER 14116: stat "M:\web\node\webtrade\locales\US\en\index.properties"
ENGINE-MUNGER 14116: found "M:\web\node\webtrade\locales\US\en\index.properties"

ENGINE-MUNGER 14116: specialization mapped 'layouts/master.dust' to 'layouts/mas
ter.dust'
ENGINE-MUNGER 14116: lookup "layouts/master.dust"
ENGINE-MUNGER 14116: stat "M:\web\node\webtrade\public\templates\layouts\master.
dust"
ENGINE-MUNGER 14116: found "M:\web\node\webtrade\public\templates\layouts\master
.dust"
ENGINE-MUNGER 14116: specialization mapped 'layouts/master.properties' to 'layou
ts/master.properties'
ENGINE-MUNGER 14116: trying locales ["US/en"]
ENGINE-MUNGER 14116: lookup "layouts/master.properties"
ENGINE-MUNGER 14116: stat "M:\web\node\webtrade\locales\US\en\layouts\master.pro
perties"
ENGINE-MUNGER 14116: found "M:\web\node\webtrade\locales\US\en\layouts\master.pr
operties"
ENGINE-MUNGER 14116: specialization mapped 'layouts/master.properties' to 'layou
ts/master.properties'
ENGINE-MUNGER 14116: trying locales ["US/en"]
ENGINE-MUNGER 14116: lookup "layouts/master.properties"
ENGINE-MUNGER 14116: stat "M:\web\node\webtrade\locales\US\en\layouts\master.pro
perties"
ENGINE-MUNGER 14116: found "M:\web\node\webtrade\locales\US\en\layouts\master.pr
operties"
ENGINE-MUNGER 14116: specialization mapped 'noprods.dust' to 'noprods.dust'
ENGINE-MUNGER 14116: lookup "noprods.dust"
ENGINE-MUNGER 14116: stat "M:\web\node\webtrade\public\templates\noprods.dust"
ENGINE-MUNGER 14116: found "M:\web\node\webtrade\public\templates\noprods.dust"
ENGINE-MUNGER 14116: specialization mapped 'noprods.properties' to 'noprods.prop
erties'
ENGINE-MUNGER 14116: trying locales ["US/en"]
ENGINE-MUNGER 14116: lookup "noprods.properties"
ENGINE-MUNGER 14116: stat "M:\web\node\webtrade\locales\US\en\noprods.properties
"
ENGINE-MUNGER 14116: found "M:\web\node\webtrade\locales\US\en\noprods.propertie
s"
ENGINE-MUNGER 14116: specialization mapped 'noprods.properties' to 'noprods.prop
erties'
ENGINE-MUNGER 14116: trying locales ["US/en"]
ENGINE-MUNGER 14116: lookup "noprods.properties"
ENGINE-MUNGER 14116: stat "M:\web\node\webtrade\locales\US\en\noprods.properties
"
ENGINE-MUNGER 14116: found "M:\web\node\webtrade\locales\US\en\noprods.propertie
s"

@Ampakinetic
Copy link
Author

if I put {template.is} into the index.dust file it shows the value of "shopsite", which should trigger the alternate partial if I have all the bits lined up correctly.

@aredridel
Copy link
Contributor

Oh! I bet I know what it is. Change your specialization map to include the extension on the filename of the template.

@Ampakinetic
Copy link
Author

Thanks, but still the same (but different) - there's a lot of 404 stuff in the debug log now, but the rendered output looks the same.

ENGINE-MUNGER 3888: specialization mapped 'errors/404.dust' to 'errors/404.dust'

ENGINE-MUNGER 3888: lookup "errors/404.dust"
ENGINE-MUNGER 3888: stat "M:\web\node\webtrade\public\templates\errors\404.dust"

ENGINE-MUNGER 3888: found "M:\web\node\webtrade\public\templates\errors\404.dust
"
ENGINE-MUNGER 3888: render "M:\web\node\webtrade\public\templates\errors\404.dus
t"
ENGINE-MUNGER 3888: specialization mapped 'errors/404.properties' to 'errors/404
.properties'
ENGINE-MUNGER 3888: trying locales ["US/en"]
ENGINE-MUNGER 3888: lookup "errors/404.properties"
ENGINE-MUNGER 3888: stat "M:\web\node\webtrade\locales\US\en\errors\404.properti
es"
ENGINE-MUNGER 3888: found "M:\web\node\webtrade\locales\US\en\errors\404.propert
ies"
ENGINE-MUNGER 3888: specialization mapped 'errors/404.properties' to 'errors/404
.properties'
ENGINE-MUNGER 3888: trying locales ["US/en"]
ENGINE-MUNGER 3888: lookup "errors/404.properties"
ENGINE-MUNGER 3888: stat "M:\web\node\webtrade\locales\US\en\errors\404.properti
es"
ENGINE-MUNGER 3888: found "M:\web\node\webtrade\locales\US\en\errors\404.propert
ies"
ENGINE-MUNGER 3888: specialization mapped 'layouts/master.dust' to 'layouts/mast
er.dust'
ENGINE-MUNGER 3888: lookup "layouts/master.dust"
ENGINE-MUNGER 3888: stat "M:\web\node\webtrade\public\templates\layouts\master.d
ust"
ENGINE-MUNGER 3888: found "M:\web\node\webtrade\public\templates\layouts\master.
dust"
ENGINE-MUNGER 3888: specialization mapped 'layouts/master.properties' to 'layout
s/master.properties'
ENGINE-MUNGER 3888: trying locales ["US/en"]
ENGINE-MUNGER 3888: lookup "layouts/master.properties"
ENGINE-MUNGER 3888: stat "M:\web\node\webtrade\locales\US\en\layouts\master.prop
erties"
ENGINE-MUNGER 3888: found "M:\web\node\webtrade\locales\US\en\layouts\master.pro
perties"
ENGINE-MUNGER 3888: specialization mapped 'layouts/master.properties' to 'layout
s/master.properties'
ENGINE-MUNGER 3888: trying locales ["US/en"]
ENGINE-MUNGER 3888: lookup "layouts/master.properties"
ENGINE-MUNGER 3888: stat "M:\web\node\webtrade\locales\US\en\layouts\master.prop
erties"
ENGINE-MUNGER 3888: found "M:\web\node\webtrade\locales\US\en\layouts\master.pro
perties"

My spec file is now

{
    "noprods": [
        {
            "is": "shopsite/noprods.dust",
            "when": {
                "template.is": "shopsite"
            }
        }
    ]
}

@aredridel
Copy link
Contributor

try

{
    "noprods.dust": [
        {
            "is": "shopsite/noprods.dust",
            "when": {
                "template.is": "shopsite"
            }
        }
    ]
}

@Ampakinetic
Copy link
Author

ENGINE-MUNGER 3300: specialization mapped 'index.dust' to 'index.dust'
ENGINE-MUNGER 3300: lookup "index.dust"
ENGINE-MUNGER 3300: stat "M:\web\node\webtrade\public\templates\index.dust"
ENGINE-MUNGER 3300: found "M:\web\node\webtrade\public\templates\index.dust"
ENGINE-MUNGER 3300: render "M:\web\node\webtrade\public\templates\index.dust"
ENGINE-MUNGER 3300: specialization mapped 'index.properties' to 'index.propertie
s'
ENGINE-MUNGER 3300: trying locales ["US/en"]
ENGINE-MUNGER 3300: lookup "index.properties"
ENGINE-MUNGER 3300: stat "M:\web\node\webtrade\locales\US\en\index.properties"
ENGINE-MUNGER 3300: found "M:\web\node\webtrade\locales\US\en\index.properties"
ENGINE-MUNGER 3300: specialization mapped 'index.properties' to 'index.propertie
s'
ENGINE-MUNGER 3300: trying locales ["US/en"]
ENGINE-MUNGER 3300: lookup "index.properties"
ENGINE-MUNGER 3300: stat "M:\web\node\webtrade\locales\US\en\index.properties"
ENGINE-MUNGER 3300: found "M:\web\node\webtrade\locales\US\en\index.properties"
ENGINE-MUNGER 3300: specialization mapped 'layouts/master.dust' to 'layouts/mast
er.dust'
ENGINE-MUNGER 3300: lookup "layouts/master.dust"
ENGINE-MUNGER 3300: stat "M:\web\node\webtrade\public\templates\layouts\master.d
ust"
ENGINE-MUNGER 3300: found "M:\web\node\webtrade\public\templates\layouts\master.
dust"
ENGINE-MUNGER 3300: specialization mapped 'layouts/master.properties' to 'layout
s/master.properties'
ENGINE-MUNGER 3300: trying locales ["US/en"]
ENGINE-MUNGER 3300: lookup "layouts/master.properties"
ENGINE-MUNGER 3300: stat "M:\web\node\webtrade\locales\US\en\layouts\master.prop
erties"
ENGINE-MUNGER 3300: found "M:\web\node\webtrade\locales\US\en\layouts\master.pro
perties"
ENGINE-MUNGER 3300: specialization mapped 'layouts/master.properties' to 'layout
s/master.properties'
ENGINE-MUNGER 3300: trying locales ["US/en"]
ENGINE-MUNGER 3300: lookup "layouts/master.properties"
ENGINE-MUNGER 3300: stat "M:\web\node\webtrade\locales\US\en\layouts\master.prop
erties"
ENGINE-MUNGER 3300: found "M:\web\node\webtrade\locales\US\en\layouts\master.pro
perties"
ENGINE-MUNGER 3300: specialization mapped 'noprods.dust' to 'noprods.dust'
ENGINE-MUNGER 3300: lookup "noprods.dust"
ENGINE-MUNGER 3300: stat "M:\web\node\webtrade\public\templates\noprods.dust"
ENGINE-MUNGER 3300: found "M:\web\node\webtrade\public\templates\noprods.dust"
ENGINE-MUNGER 3300: specialization mapped 'noprods.properties' to 'noprods.prope
rties'
ENGINE-MUNGER 3300: trying locales ["US/en"]
ENGINE-MUNGER 3300: lookup "noprods.properties"
ENGINE-MUNGER 3300: stat "M:\web\node\webtrade\locales\US\en\noprods.properties"

ENGINE-MUNGER 3300: found "M:\web\node\webtrade\locales\US\en\noprods.properties
"
ENGINE-MUNGER 3300: specialization mapped 'noprods.properties' to 'noprods.prope
rties'
ENGINE-MUNGER 3300: trying locales ["US/en"]
ENGINE-MUNGER 3300: lookup "noprods.properties"
ENGINE-MUNGER 3300: stat "M:\web\node\webtrade\locales\US\en\noprods.properties"

ENGINE-MUNGER 3300: found "M:\web\node\webtrade\locales\US\en\noprods.properties
"

With spec file:

{ "noprods.dust": [ { "is": "shopsite/noprods.dust", "when": { "template.is": "shopsite" } } ] }

Same rendered output as before

@aredridel
Copy link
Contributor

Well nuts! that should work!

@Ampakinetic
Copy link
Author

This is running on Windows Server 2012 with latest node.js if that helps

@aredridel
Copy link
Contributor

I'll have to try later -- I've my job to get to at the moment, but I may see if I can delve into this in the kraken specialization sample app and upgrade that to makara 2.

@Ampakinetic
Copy link
Author

Ok cool, yes it would be good to have a standard example to work with. Can confirm a rollback to earlier code works as expected on the same machine.

@Ampakinetic
Copy link
Author

Quick question (I'm still a bit of a node noob) is it possible to have a dynamic specialization, so that the controller defines the mapping so I don't need to restart the app every time I make a change?

@aredridel
Copy link
Contributor

Not as it stands -- might be able to tweak the map if you can get a reference to it, but I'd have to see if it's cleanly exposed or not.

@Ampakinetic
Copy link
Author

Ok thanks, have had a quick look and can see it being assigned in engine-munger but any hints or tips as to when and where to hook into the render process would be welcome :)

@aredridel
Copy link
Contributor

I'm up to my elbows in the guts right now and it looks like the main templates should be working properly, but partials aren't passing the full information, and therefore aren't being specialized.

@Ampakinetic
Copy link
Author

Yes, that sounds like what was happening

@aredridel
Copy link
Contributor

So yes, I can confirm this is a bug. It's actually a bug in adaro, which should be fixed by krakenjs/adaro#92

@Ampakinetic
Copy link
Author

Cool, great, thanks for fixing it so fast :) What do I need to do to test it? Can I do an npm update, or manually patch the code my side?

@aredridel
Copy link
Contributor

You can install the module from the git branch to test, or apply my changes -- they're simple -- to your existing copy.

@Ampakinetic
Copy link
Author

ok I'll apply your changes directly. Also I'm very keen on setting up dynamic specialization if you have any pointers in that regard. Thank you very much for your help.

@aredridel
Copy link
Contributor

kraken is going to fight you a bit on the dynamic specialization. It does a bit of extra work to keep people from using the config as a data store shared among modules -- so mutating it is hard.

How hard on your workflow is it to just restart the server on change with something like nodemon?

@Ampakinetic
Copy link
Author

Ok thanks I'll give that a go, I haven't used nodemon before, so appreciate the tip

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