Domanda

I am using requirejs + jquery + sammy.js + hamljs. The template engine haml is not working : it runs sammy.haml, but Haml is defined for main.js but not for sammy.haml and cannot run in it. After the page is completely loaded, Haml exists for the console. Why Sammy does not get on well with HAML whereas it should be ?

requirejs.config({
     baseUrl: '../../components/',
     paths: {
         dropkick: 'jquery-dropkick2/jquery.dropkick-1.0.0',
         Ladda: 'Ladda/dist/ladda.min',
         'jquery-autosize': 'jquery-autosize/jquery.autosize',
         mixitup: 'mixitup/jquery.mixitup.min',
         jquery: 'jquery/jquery',
         sammy: 'sammy/lib/sammy',
         'sammy.haml': 'sammy/lib/plugins/sammy.haml',
         haml: 'haml/lib/haml',
         browser: 'jquery.browser/jquery.browser.min'
     },
     shim: {
         dropkick: {
             deps: ['jquery']
         },
         browser: {
             deps: ['jquery']
         },
         'sammy.haml': {
             deps: ['haml']
         }
     }

 });
 requirejs(['jquery', 'haml'], function($, Haml) { // They are to be loaded first
     requirejs(['sammy', 'sammy.haml', 'browser', 'markdown'], function(sammy, shaml, markdow) { // Then the others
            console.log(Haml); // WORK

            var app = sammy('#main', function() {
            var self = this;
            self.use(sammy.Haml);
            self.get('/upload', function(context) {
            context.app.swap('');
            var s = context.render('app/templates/upload.haml', {});
            s.appendTo(context.$element())




            });
        });


         });
         app.run();

     });
 });     
È stato utile?

Soluzione

Finally found the solution ! I defined window.Haml = haml in the main file, and modified sammy.haml.js to get window.Haml function instead of Haml function.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top