lib/scss_beautifier/convert.rb in scss_beautifier-0.1.16 vs lib/scss_beautifier/convert.rb in scss_beautifier-0.1.17

- old
+ new

@@ -30,12 +30,12 @@ # Visit rule-level nodes and return their conversion with appropriate # whitespace added. def visit_rule_level(nodes) Sass::Util.enum_cons(nodes + [nil], 2).map do |child, nxt| - visit(child) + - if nxt && + child_value = visit(child) + spacing = if nxt && (child.is_a?(Sass::Tree::CommentNode) && child.line + child.lines + 1 == nxt.line) || (child.is_a?(Sass::Tree::ImportNode) && nxt.is_a?(Sass::Tree::ImportNode) && child.line + 1 == nxt.line) || (child.is_a?(Sass::Tree::VariableNode) && nxt.is_a?(Sass::Tree::VariableNode) && child.line + 1 == nxt.line) || @@ -50,9 +50,26 @@ "" else "\n" end end + if inline_comment?(child, nxt) + child_value.rstrip! + spacing = "" + nxt.scss_beautifier_options[:inline] = true + elsif child.scss_beautifier_options[:inline] + spacing = "" + end + child_value + spacing end.join.rstrip + "\n" + end + + def visit_comment(node) + value = super + node.scss_beautifier_options[:inline] ? ' ' + value.lstrip! : value + end + + def inline_comment?(node, comment_node) + comment_node.is_a?(Sass::Tree::CommentNode) && node.line == comment_node.line end end