krasimir / absurd

A JavaScript library with superpowers
http://absurdjs.krasimirtsonev.com/
MIT License
1.38k stars 90 forks source link

extending import api #106

Open enigma1 opened 10 years ago

enigma1 commented 10 years ago

I started using absurdjs with the importer but I noticed a couple of things.

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.

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
......
krasimir commented 10 years ago

Hello @enigma1,

thanks for using the library. Here are my comments:

  1. 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.
  2. 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 add method in the parent file. Maybe we may change if the module returns an object and if yes then directly pass it to the add function. From my point of view it is better to leave the APi as it is now.