MohammadYounes / rtlcss

Framework for transforming Cascading Style Sheets (CSS) from Left-To-Right (LTR) to Right-To-Left (RTL)
https://rtlcss.com
MIT License
1.68k stars 129 forks source link

Processing declarations without comments #37

Closed aymanrady closed 9 years ago

aymanrady commented 9 years ago

Right now RTLCSS only processes declarations with comments in the value

// rtlcss.js
for (var x = 0; x < config.instructions.declarations.length; x++) {
  var pi = config.instructions.declarations[x];
  if (decl._value && decl._value.raw && decl._value.raw.match(pi.expr) && pi.action(decl)) {
    util.logDeclAction(decl, pi);
    return;
  }
}

decl._value is only populated by postcss when the value is not clean

// postcss/lib/parser.js
// Parser.prototype.raw
for (token of tokens) {
  if (token[0] === 'comment') {
    clean = false;
  } else {
    value += token[1];
  }
}
if (!clean) {
  let origin = '';
  for (token of tokens) origin += token[1];
  node['_' + prop] = {
    value: value,
    raw: origin
  };
}

I propose that we run the PI on all declarations with or without comments

my use case: Sass strips out comments inside declarations, rendering declaration PIs useless. my workaround is to use escaped sequences of the original PIs and introduce new regex to RTLCSS

MohammadYounes commented 9 years ago

The comment is what makes the directive! Executing the PI without comments is useless.

Does this SO post match your case ?

aymanrady commented 9 years ago

I don't know why this SO post didn't show up in my search, but this solves my use case perfectly, thank you

The comment is what makes the directive!

the comment makes the internal processing directive, but processing declarations based on value cannot be implemented ( I can't think of a use case right now )

if you don't think this fits the scope of this plugin feel free to close the issue

MohammadYounes commented 9 years ago

but processing declarations based on value cannot be implemented

Not sure I understand your point here, and how does this apply to declaration level directives! Or are you referring to Properties ?

aymanrady commented 9 years ago

declaration level directives apply the regex when there is a comment in the declaration and property level directives apply regex on the property name my point is if I'm interested in the declaration value not the name, I cannot implement this feature

I think it is the same as stringMap but for arbitrary values not just urls

thinking about this further, this is hypothetical and without a use-case its just a waste of time

MohammadYounes commented 9 years ago

Thanks for the clarification!