Skip to content

Instantly share code, notes, and snippets.

@eiszfuchs
Created March 5, 2015 13:06
Show Gist options
  • Select an option

  • Save eiszfuchs/772011ef211e40f18e53 to your computer and use it in GitHub Desktop.

Select an option

Save eiszfuchs/772011ef211e40f18e53 to your computer and use it in GitHub Desktop.
(function (value, config) {
var matchbox = /{([^a-z]?)([a-z_]+)([^a-z|]?)(\|[^}]+)?}/g;
var translator = function (match, prefix, value, suffix, defaultValue) {
if (config.hasOwnProperty(value)) {
return prefix + config[value] + suffix;
}
if (defaultValue) {
return defaultValue.replace('|', '');
}
return '';
};
return value.replace(matchbox, translator);
}('server { listen {port|80}; server_name {sub_domain.}{domain}; }', {
// port: 8080,
sub_domain: 'www',
domain: 'example.com'
}));
// "server { listen 80; server_name www.example.com; }"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment