YUILibrary - Open source JavaScript and CSS for building richly interactive software.
Fork YUI on GitHub
  [ 6 posts ]

Michael Hasenstein

  • Username: hasenstein
  • Joined: Fri Mar 20, 2009 7:22 am
  • Posts: 32
  • Location: Nuernberg, Germany
  • Offline
  • Profile

module loading

Post Posted: Mon Jul 19, 2010 7:32 am
+0-
So I've made lots of modules of my app and they all load automagically, fine.

What I don't quite like is that I have (to have???) lots of directories with one file each. For example, I do a

Y.use('module-x', ...)

so in the load path I have (to have?) ./module-x/module-x.js

(How) can I get several related files into one directory?

Similar question, (how) can I have sub-directories?

I know I could add a configuration for all modules, just would like to know if that's my only option.

Caridy Patino

YUI Contributor

  • Username: caridy
  • Joined: Mon Dec 08, 2008 5:40 pm
  • Posts: 362
  • Location: Miami, FL
  • Twitter: caridy
  • GitHub: caridy
  • Gists: caridy
  • IRC: caridy
  • YUI Developer
  • Offline
  • Profile

Re: module loading

Post Posted: Mon Jul 19, 2010 9:36 am
+0-
Hey Michael,

You can define a group (with a prefix), which means that any module that you try to load with that prefix (aka my-module-x) will be loaded using a global configuration.

http://developer.yahoo.com/yui/3/api/Lo ... d_addGroup

A simple example will be:

Code:
YUI_config = {
    groups: {
        my: {
            base: '/my-local-modules/',

            // If you have a combo service, you can configure that as well
            // combine: true,
            // comboBase: 'http://myserver.com/combo?',
            // root: '/build/'
        }
    }
};

// then
YUI().use('my-module-x', function (Y) {
    // ready
};


Best Regards,
Caridy

Michael Hasenstein

  • Username: hasenstein
  • Joined: Fri Mar 20, 2009 7:22 am
  • Posts: 32
  • Location: Nuernberg, Germany
  • Offline
  • Profile

Re: module loading

Post Posted: Mon Jul 19, 2010 10:31 am
+0-
Oh I HAVE defined such a group of course, but that does not change the described problem :-)

Caridy Patino

YUI Contributor

  • Username: caridy
  • Joined: Mon Dec 08, 2008 5:40 pm
  • Posts: 362
  • Location: Miami, FL
  • Twitter: caridy
  • GitHub: caridy
  • Gists: caridy
  • IRC: caridy
  • YUI Developer
  • Offline
  • Profile

Re: module loading

Post Posted: Mon Jul 19, 2010 10:43 am
+1-
Hey Michael,

Defining the group give you a way to define patterns for your modules, changing the way the url for the module gets generated. Like this:

Code:
YUI_config = {
    groups: {
        my: {
            base: '/my-local-modules/',
            patterns:  {
                'my-submodule-': {
                    configFn: function(me) {
                        me.path = me.path.replace(/my-submodule/, 'my-submodules/my-submodule');
                    }
                }
            }
        }
    }
};


So, basically, you can match the name of the module, and correct the full path (first argument "me") to generate the correct path for a particular module or a set of module. I think that's flexible enough to achieve your goal.

Best Regards,
Caridy

Michael Hasenstein

  • Username: hasenstein
  • Joined: Fri Mar 20, 2009 7:22 am
  • Posts: 32
  • Location: Nuernberg, Germany
  • Offline
  • Profile

Re: module loading

Post Posted: Mon Jul 19, 2010 10:50 am
+0-
Ah, that's useful! I didn't see (find???) that particular feature in the documentation. Thanks!

Caridy Patino

YUI Contributor

  • Username: caridy
  • Joined: Mon Dec 08, 2008 5:40 pm
  • Posts: 362
  • Location: Miami, FL
  • Twitter: caridy
  • GitHub: caridy
  • Gists: caridy
  • IRC: caridy
  • YUI Developer
  • Offline
  • Profile
Tags:

Re: module loading

Post Posted: Mon Jul 19, 2010 12:37 pm
+0-
Here is the doc:

http://developer.yahoo.com/yui/3/api/Lo ... y_patterns

A group supports the same set of properties that the global loader :)

Best Regards,
Caridy
  [ 6 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum