<commit_before>var postcss = require('postcss');

module.exports = postcss.plugin('postcss-shopify-settings-variables',
  function (opts) {
    opts = opts || {};

    // Work with options here

    return function (css) {

        // Transform CSS AST here
        css.eachInside(function (node) {
            if ( node.type === 'decl' ) {
                if ( node.value.toString().indexOf('$(') >= 0 ) {
                    node.value = node.value
                        .replace(/^([^\$]*)(\$\()([^\)]+)(\))(.*)$/,
                            function(match, $1, $2, $3, $4, $5) {
                                return $1 + '{{ settings.' + $3 + " }}" + $5;
                            });
                }
            }
        });
    };
});<commit_msg>support replace relative background url path with shopify asset url filter<commit_after>var postcss = require('postcss');

var bgUrlRegex = /url\(\s?['"]?(.*?)['"]?\s?\)/g;
var protocolRegex = /(https?:)?\/\/|data:/g;

module.exports = postcss.plugin('postcss-shopify-settings-variables',
  function (opts) {
    opts = opts || {};

    // Work with options here

    return function (css) {

        // Transform CSS AST here
        css.eachInside(function (node) {
            if ( node.type === 'decl' ) {
                var value = node.value.toString();
                if ( value.indexOf('$(') >= 0 ) {
                    node.value = node.value
                        .replace(/^([^\$]*)(\$\()([^\)]+)(\))(.*)$/,
                            function(match, $1, $2, $3, $4, $5) {
                                return $1 + '{{ settings.' + $3 + ' }}' + $5;
                            });
                }
                if ( bgUrlRegex.test(value) && !protocolRegex.test(value) ) {
                    node.value = value.replace(bgUrlRegex,
                        'url({{ "$1" | asset_url }})');
                }
            }
        });
    };
});
{'fraction_non_alphanumeric': 0.19304618578100674, 'fraction_numerical': 0.009859885832900882, 'mean_word_length': 1.3598531211750307, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2152792', 'n_tokens_mistral': 581, 'n_tokens_neox': 549, 'n_words': 111}