absurd
absurd copied to clipboard
extending import api
I started using absurdjs with the importer but I noticed a couple of things.
- The import api identifies by extension how to process a file and there is no default fallback
var ext = path.split('.').pop().toLowerCase();
So if the file has a non-handled extension I cannot use the import. Perhaps this can be changed having an extra parameter passed to the importer that can override the extension detection. Then if it is not present it will work as it does now.
- The second thing I noticed was I needed to return a function in the module.exports for js files. In many cases I would like to return just an object like:
module.exports = {
body: {
padding: 0,
}
};
instead of how it is currently
module.exports = function(api) {
api.add({
body: {
padding: 0,
}
}};
should be simple to support both I think. Right now I use the node require to load the js file with the add api.
var AbsurdApi = require('absurd');
var absurd = AbsurdApi();
.....
var json = require(resource);
if( typeof json === 'function') json = json(absurd);
// compile or add+compile
......
Hello @enigma1,
thanks for using the library. Here are my comments:
- Good suggestion about the second parameter. It's not that difficult for implementing so I'll leave this issue open and will get back to it later with that addition.
- If you want to return just an object then I think it is better to save your styles in a JSON file. However, if you need some logic and still want to return an object Then you are free to do it and simply use the
addmethod in the parent file. Maybe we may change if the module returns an object and if yes then directly pass it to theaddfunction. From my point of view it is better to leave the APi as it is now.