pascalduez / postcss-map

PostCSS plugin enabling configuration maps
The Unlicense
121 stars 7 forks source link

Map function based on map name #4

Open pascalduez opened 9 years ago

pascalduez commented 9 years ago
var opts = {
  basePath: 'css/',
  maps: [ 'breakpoint.yml', 'font.yml' ]
};
.sowieso {
  font-family: font(text);
}
@media (min-width: breakpoint(medium)) {
  .sowieso {
    width: 100%;
  }
}
thedeeno commented 9 years ago

Hmm, can we reopen this? I frequently define a function to access my maps in sass. It'd be great if this plugin provided the same by default (or supplied an option to turn it on).

Imo, color: colors(green) reads much nicer than color: map(colors, green). If I rely on the default map feature linked above I lose organizational control. Plus it's less semantic: color: map(green).

pascalduez commented 9 years ago

Hi,

this issue is not closed, and I still like the idea so there are pretty good chances it will land. I'll try to find a free slot this week.

pascalduez commented 9 years ago

Just thinking out loud:

think of some sort of alias configuration.

var opts = {
  basePath: 'css/',
  maps: [ 
    { file: 'breakpoints.yml', alias: 'bp' },
    'fonts.yml' 
  ]
};

Or

var opts = {
  basePath: 'css/',
  maps: { 
    'bp': 'breakpoints.yml',
    'fonts': 'fonts.yml' 
  }
};

Usage

.sowieso {
  font-family: fonts(text);
}
@media (min-width: bp(medium)) {
  .sowieso {
    width: 100%;
  }
}
thedeeno commented 9 years ago

Aha! My mistake I misread the closing.

As for the purposed api I prefer the alias method over the hash method. It's quite possible the default map(font, text) is enough for people so I wouldn't want to force them to use an alias function, and the hash implies the alias is required.

My favorite API was the your original proposal though: implicit alias from the filename.

thedeeno commented 9 years ago

I'm actually leaning toward an API like #12. There's something nice about having a single entry point (namely map) for this plugin.

TrySound commented 9 years ago

@pascalduez It's not so fast to detect such props, caz it should iterate arrays with names on every declaration.

TrySound commented 9 years ago

@pascalduez And name extending is pollution of constructions. Better use just one identifier: map

safareli commented 8 years ago

+1 I'm also creating functions like that in sass and it will a good feature

TrySound commented 8 years ago

@safareli Use this for custom functions. And we don't need to create sass clone.