Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ariables add a newline
  • Loading branch information
yisibl committed Sep 9, 2015
1 parent 07047a4 commit 76e6d3b
Show file tree
Hide file tree
Showing 18 changed files with 194 additions and 25 deletions.
7 changes: 5 additions & 2 deletions lib/formatAtRuleParams.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
function formatAtRuleParams (atrule) {
var params = atrule.params
var atName = atrule.name

if (atrule.name === 'media') {
if (atName === 'media' || atName === 'include' || atName === 'mixin') {
params = params.replace(/\s*:\s*/g, ': ')
params = params.replace(/\s*,\s*/g, ', ')
params = params.replace(/\s+/g, ' ')
if (params.match(/^\(\s*/)) {
params = params.replace(/^\(\s*/g, '(')
} else {
params = params.replace(/\s*\(\s*/g, ' (')
}
params = params.replace(/\s*\)\s*/g, ')')
params = params.replace(/\s*\)/g, ')')
params = params.replace(/\)\s*{/g, ') ')
}

Expand Down
21 changes: 19 additions & 2 deletions lib/formatAtRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,32 @@ function formatAtRules (root) {
}

if (atrule.name === 'mixin') {
atrule.params = atrule.params.replace(/(^[A-Za-z0-9]+)\s*\(/, "$1 (")
atrule.params = atrule.params.replace(/(^[\w|-]+)\s*\(/, "$1(")
}

if (atrule.name === 'extend') {
if (atrule.name === 'extend' ||
atrule.name === 'debug' ||
atrule.name === 'warn' ||
atrule.name === 'error' ) {
atrule.params = atrule.params.replace(/\s+/g, " ")
atrule.raws.before = '\n' + getIndent(atrule)
atrule.raws.between = ''
}

if (atrule.name === 'warn' || atrule.name === 'error') {
atrule.params = atrule.params.replace(/("|')\s*/g, '"')
atrule.params = atrule.params.replace(/\s*("|')/g, '"')
}

if (atrule.name === 'content') {
atrule.raws.before = '\n' + getIndent(atrule)
atrule.raws.between = ''
atrule.raws.afterName = ''
}

if (atrule.name === 'include') {
atrule.params = atrule.params.replace(/(^[\w|-]+)\s*\(/, "$1(")
atrule.params = atrule.params.replace(/\)\s*{/g, ') ')
atrule.raws.before = '\n' + getIndent(atrule)
atrule.raws.between = ''
}
Expand Down
2 changes: 1 addition & 1 deletion lib/formatSassVariables.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function formatSassVariables (root) {
root.walkDecls(function (decl) {
if (isSassVariable(decl)) {
decl.raws.before = ''
decl.raws.before = '\n'
decl.raws.between = ': '
}
})
Expand Down
12 changes: 12 additions & 0 deletions test/fixtures/at-media.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@media ( max-width:600px ) {}
@media ( min-width:700px) and ( orientation: landscape){}
@media (min-width: 700px), handheld and (orientation: landscape) {}
@media not all and ( monochrome ) {}
@media ( not all ) and ( monochrome ) {}
@media ( not ( screen and ( color ) ) ) , print and ( color ){}
@media screen and ( device-aspect-ratio: 16/9 ), screen and (device-aspect-ratio:16/10 ) {}

@media ( -webkit-min-device-pixel-ratio:2),
(min--moz-device-pixel-ratio: 2 ),
(min-resolution: 2dppx),
(min-resolution: 192dpi ){}
23 changes: 23 additions & 0 deletions test/fixtures/at-media.out.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@media (max-width: 600px) {
}

@media (min-width: 700px) and ( orientation: landscape) {
}

@media (min-width: 700px), handheld and (orientation: landscape) {
}

@media not all and (monochrome) {
}

@media (not all) and ( monochrome) {
}

@media (not ( screen and ( color))), print and ( color) {
}

@media screen and (device-aspect-ratio: 16/9), screen and (device-aspect-ratio: 16/10) {
}

@media (-webkit-min-device-pixel-ratio: 2), (min--moz-device-pixel-ratio: 2), (min-resolution: 2dppx), (min-resolution: 192dpi) {
}
2 changes: 1 addition & 1 deletion test/fixtures/readme.out.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// mixin for clearfix
@mixin clearfix () {
@mixin clearfix() {
&:before,
&:after {
content: " ";
Expand Down
19 changes: 19 additions & 0 deletions test/fixtures/sass-content.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* https://robots.thoughtbot.com/sasss-content-directive */

@mixin apply-to-ie6-only {
* html { @content ;}
}

@include apply-to-ie6-only {
#logo { background-image: url(/logo.gif); }
}


@mixin media($width) {
@media only screen and (max-width: $width) { @content; }
}


@include media(320px) {
background: red;
}
20 changes: 20 additions & 0 deletions test/fixtures/sass-content.out.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* https://robots.thoughtbot.com/sasss-content-directive */
@mixin apply-to-ie6-only {
* html {
@content;
}
}
@include apply-to-ie6-only{

This comment has been minimized.

Copy link
@yisibl

yisibl Sep 9, 2015

Author Contributor

@morishitter I don't know why there is no space?

This comment has been minimized.

Copy link
@matype

matype Sep 9, 2015

Owner

@yisibl Because of here.
https://github.com/morishitter/cssfmt/blob/master/lib/formatAtRules.js#L91

If we write this atrule.raws.between = ' ', format @include cleafix(); to @include clearfix() ; ;(

This comment has been minimized.

Copy link
@yisibl

yisibl Sep 9, 2015

Author Contributor

Can you fix it?

This comment has been minimized.

Copy link
@matype

matype Sep 9, 2015

Owner

I try to fix it. But, now you have an idea to fix it, please send PR :)

This comment has been minimized.

Copy link
@yisibl

yisibl Sep 9, 2015

Author Contributor

I don't know what to do for a while.:joy:

This comment has been minimized.

Copy link
@matype

matype Sep 9, 2015

Owner

OK, I try to fix it :D

This comment has been minimized.

Copy link
@matype

matype Sep 10, 2015

Owner

@yisibl Fixed. 1108bc4

#logo {
background-image: url(/logo.gif);
}
}

@mixin media($width) {
@media only screen and (max-width: $width) {
@content;
}
}
@include media(320px){
background: red;
}
9 changes: 9 additions & 0 deletions test/fixtures/sass-include.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
.class
{
padding:10px;@include clearfix();}


.class
{@include rounded ( top,left, 5px);
padding:10px;@include clearfix ();}

.class
{
padding:10px;@include horizontal-line---foo__bar ( 1px solid #ccc ) ; }
11 changes: 11 additions & 0 deletions test/fixtures/sass-include.out.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,14 @@
padding: 10px;
@include clearfix();
}

.class {
@include rounded(top, left, 5px);
padding: 10px;
@include clearfix();
}

.class {
padding: 10px;
@include horizontal-line---foo__bar(1px solid #ccc);
}
10 changes: 3 additions & 7 deletions test/fixtures/sass-mixin.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
@mixin clearfix () { &:before,
&:after {
content:" ";
display : table; }

&:after {clear: both;}
}
@mixin horizontal-line ( $border: 1px dashed #ccc, $padding:10px ) {
border-bottom:$border;
}
12 changes: 2 additions & 10 deletions test/fixtures/sass-mixin.out.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
@mixin clearfix () {
&:before,
&:after {
content: " ";
display: table;
}

&:after {
clear: both;
}
@mixin horizontal-line($border: 1px dashed #ccc, $padding: 10px) {
border-bottom:$border;
}
26 changes: 26 additions & 0 deletions test/fixtures/sass-single-at-rule.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.foo {
position: absolute; @debug 10px + 20px ;
display: inline-block;
@error ' Sorry, but `#{$variable}` is not a valid value for $variable. ';
}


@debug 10px + 20px; $wrn:20px;


@warn
" The `border-radius()`
mixin will be deprecated in version 2.0. ";


.bar {
position: absolute;
$wrn: 20px; @warn ' #{$wrn} '; display: inline-block;
}

/* http://www.sitepoint.com/using-sasss-error-warn-and-debug-directives/ */
@if unit($input) == 'px' {
@warn
"Please remember to use rem values in the `do-math()` function.";
// do px math and @return a value;
}
23 changes: 23 additions & 0 deletions test/fixtures/sass-single-at-rule.out.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.foo {
position: absolute;
@debug 10px + 20px;
display: inline-block;
@error "Sorry, but `#{$variable}` is not a valid value for $variable.";
}
@debug 10px + 20px;
$wrn: 20px;
@warn "The `border-radius()` mixin will be deprecated in version 2.0.";

.bar {
position: absolute;
$wrn: 20px;
@warn "#{$wrn}";
display: inline-block;
}

/* http://www.sitepoint.com/using-sasss-error-warn-and-debug-directives/ */
@if unit($input) == 'px' {
@warn "Please remember to use rem values in the `do-math()` function.";

// do px math and @return a value;
}
8 changes: 7 additions & 1 deletion test/fixtures/sass-variables.css
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
$font-small :10px;
h2 {display: inline-block;}

$font-small: 10px;
$foo:'fooooo';
.bar {
font-size: $font-small; content: $foo;
}
9 changes: 9 additions & 0 deletions test/fixtures/sass-variables.out.css
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
h2 {
display: inline-block;
}
$font-small: 10px;
$foo: 'fooooo';

.bar {
font-size: $font-small;
content: $foo;
}
2 changes: 1 addition & 1 deletion test/fixtures/scss.out.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// mixin for clearfix
@mixin clearfix () {
@mixin clearfix() {
&:before,
&:after {
content: " ";
Expand Down
3 changes: 3 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ test('nested-atrule')
test('font-face')
test('import')
test('pseudo-element')
test('at-media')

test('sass-mixin')
test('sass-extend')
Expand All @@ -39,3 +40,5 @@ test('inline-comment')
test('sass-function')
test('scss')
test('sass-comment')
test('sass-content')
test('sass-single-at-rule')

0 comments on commit 76e6d3b

Please sign in to comment.