Skip to content

Commit

Permalink
Style changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 committed Jun 7, 2017
1 parent 79c036a commit b6ffd55
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 32 deletions.
6 changes: 1 addition & 5 deletions lib/src/node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,15 @@ NodeResult _renderSync(NodeOptions options) {
}
}

/// Parses a String representation of a [LineFeed] into a value of the enum-like
/// class.
/// Parses the name of a line feed type into a [LineFeed].
LineFeed _parseLineFeed(String str) {
switch (str) {
case 'cr':
return LineFeed.cr;
break;
case 'crlf':
return LineFeed.crlf;
break;
case 'lfcr':
return LineFeed.lfcr;
break;
default:
return LineFeed.lf;
}
Expand Down
4 changes: 0 additions & 4 deletions lib/src/render.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ String render(String path,
bool useSpaces: true,
int indentWidth,
LineFeed lineFeed}) {
indentWidth ??= 2;
lineFeed ??= LineFeed.lf;
RangeError.checkValueInInterval(indentWidth, 0, 10, "indentWidth");

var contents = readFile(path);
var url = p.toUri(path);
var sassTree = p.extension(path) == '.sass'
Expand Down
59 changes: 36 additions & 23 deletions lib/src/visitor/serialize.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,6 @@ import 'interface/css.dart';
import 'interface/selector.dart';
import 'interface/value.dart';

/// A simple enum-like class representing the supported line feed
/// characters.
class LineFeed {
final String _text;

const LineFeed._(this._text);

static final LineFeed cr = const LineFeed._('\r');
static final LineFeed crlf = const LineFeed._('\r\n');
static final LineFeed lf = const LineFeed._('\n');
static final LineFeed lfcr = const LineFeed._('\n\r');
}

/// Converts [node] to a CSS string.
///
/// If [style] is passed, it controls the style of the resulting CSS. It
Expand All @@ -48,7 +35,6 @@ String toCss(CssNode node,
int indentWidth,
LineFeed lineFeed}) {
indentWidth ??= 2;
lineFeed ??= LineFeed.lf;
var visitor = new _SerializeCssVisitor(
style: style,
inspect: inspect,
Expand Down Expand Up @@ -112,7 +98,7 @@ class _SerializeCssVisitor
final int _indentWidth;

/// The characters to use for a line feed.
final String _lineFeed;
final LineFeed _lineFeed;

_SerializeCssVisitor(
{OutputStyle style,
Expand All @@ -125,7 +111,9 @@ class _SerializeCssVisitor
_quote = quote,
_indentCharacter = useSpaces ? $space : $tab,
_indentWidth = indentWidth ?? 2,
_lineFeed = (lineFeed ?? LineFeed.lf)._text;
_lineFeed = lineFeed ?? LineFeed.lf {
RangeError.checkValueInInterval(_indentWidth, 0, 10, "indentWidth");
}

void visitStylesheet(CssStylesheet node) {
CssNode previous;
Expand All @@ -134,8 +122,8 @@ class _SerializeCssVisitor
if (_isInvisible(child)) continue;

if (previous != null) {
_buffer.write(_lineFeed);
if (previous.isGroupEnd) _buffer.write(_lineFeed);
_buffer.write(_lineFeed.text);
if (previous.isGroupEnd) _buffer.write(_lineFeed.text);
}
previous = child;

Expand Down Expand Up @@ -761,7 +749,7 @@ class _SerializeCssVisitor
} else {
_buffer.writeCharCode($comma);
if (complex.lineBreak) {
_buffer.write(_lineFeed);
_buffer.write(_lineFeed.text);
} else {
_buffer.writeCharCode($space);
}
Expand Down Expand Up @@ -824,23 +812,23 @@ class _SerializeCssVisitor
return;
}

_buffer.write(_lineFeed);
_buffer.write(_lineFeed.text);
_indent(() {
CssNode previous;
for (var i = 0; i < children.length; i++) {
var child = children[i];
if (_isInvisible(child)) continue;

if (previous != null) {
_buffer.write(_lineFeed);
if (previous.isGroupEnd) _buffer.write(_lineFeed);
_buffer.write(_lineFeed.text);
if (previous.isGroupEnd) _buffer.write(_lineFeed.text);
}
previous = child;

child.accept(this);
}
});
_buffer.write(_lineFeed);
_buffer.write(_lineFeed.text);
_writeIndentation();
_buffer.writeCharCode($rbrace);
}
Expand Down Expand Up @@ -945,3 +933,28 @@ class OutputStyle {

String toString() => _name;
}

/// An enum of line feed sequences.
class LineFeed {
/// A single carriage return.
static const cr = const LineFeed._('cr', '\r');

/// A carriage return followed by a line feed.
static const crlf = const LineFeed._('crlf', '\r\n');

/// A single line feed.
static const lf = const LineFeed._('lf', '\n');

/// A line feed followed by a carriage return.
static const lfcr = const LineFeed._('lfcr', '\n\r');

/// The name of this sequence..
final String name;

/// The text to emit for this line feed.
final String text;

const LineFeed._(this.name, this.text);

String toString() => name;
}

0 comments on commit b6ffd55

Please sign in to comment.