Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LESS variables not resolved properly in markup #546

Closed
cognivator opened this issue Apr 2, 2015 · 0 comments
Closed

LESS variables not resolved properly in markup #546

cognivator opened this issue Apr 2, 2015 · 0 comments
Milestone

Comments

@cognivator
Copy link

UPDATE:

Created Pull request #549.

Original

Loving the tool, so far, with a couple caveats. This is the biggie for us.

LESS variables appear in the styleguide unresolved. This source,

// Colors
//
// @my-favorite-color - Same as everyone else's
//
// markup:
// <div style="background: {$modifiers}" class="styleguide-color">{$modifiers}</div>
//
// Styleguide 1.0
@my-favorite-color: #0000FF;

renders as a white block with the label '@my-favorite-color'.

I've traced the problem to the regular expression in AngularJS filter 'setVariables' in app.js,

  // Replace $variables with values found in variables object
  .filter('setVariables', function() {
    return function(str, variables) {
      if (!str) {
        return '';
      }

      var sortedVariables;
      if (variables) {
        sortedVariables = variables.slice().sort(function(a, b) {
          return b.name.length - a.name.length;
        });
      }

      angular.forEach(sortedVariables, function(variable) {
        str = str.replace(new RegExp('\\$' + variable.name, 'g'), variable.value);
      });
      return str;
    };
  });

This RegEx does the trick for LESS variables,

      angular.forEach(sortedVariables, function(variable) {
        str = str.replace(new RegExp('\[\$\@]' + variable.name, 'g'), variable.value);
      });

I'm happy to create a PULL request if it speeds the resolution (although this would be my first PULL request ever, so some coaching may be necessary...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants