scss_beautifier 0.1.18 → 0.1.19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0617d3cf196fbecb1bc0cc9f6e77b26e057a4578
4
- data.tar.gz: 363ab371cd16d07b6c4071aedd97e55bd4e4fe3a
3
+ metadata.gz: dfc62f9e86557db0032cb11266c1de36596272bf
4
+ data.tar.gz: 0257cd1dcb2b31494bd548e48a4ab0c31ecd899e
5
5
  SHA512:
6
- metadata.gz: 1cf142b7dd2dab6d97a82d8dac1404144c549cb65437e9b91f96ab6d2cbdd416e1b6678b1cbf4c864e9d1231d854d4fdc310bf446c39711535b5b2525c579547
7
- data.tar.gz: 8f9164c52ff0de7d035c95ce510d35fd3add511b7cbe264dfdfa7a063159a7a35441697a8fa7b79d028ffffcd8427f23001b579a4bb9816d53c97ffe3686cb4f
6
+ metadata.gz: 270265eaa20862d367a6f75e94e38cfc87261b567455c3ece4221d54069c06288cd12b648b12b4fae9b1095784cccf194c9b329b9675026a5f04ae910880cd54
7
+ data.tar.gz: 3bc50250f856ea030a0f50063563af059fc8b298eb4ef003d3c4ad235cf5b68926972949bc2943c034e67f3f4d921a7c7414e3630093abf9ee0fd4474cfa7641
data/.gitignore CHANGED
@@ -1,5 +1,5 @@
1
1
  .DS_Store
2
2
  pkg/*
3
- test.scss
3
+ test*.scss
4
4
  *.css.map
5
5
  .sass-cache
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- scss_beautifier (0.1.18)
4
+ scss_beautifier (0.1.19)
5
5
  sass (~> 3.4)
6
6
 
7
7
  GEM
@@ -1,4 +1,9 @@
1
- tab_style: " "
1
+ options:
2
+
3
+ indent: " "
4
+
5
+ else_placement: "same_line"
6
+
2
7
  formatters:
3
8
 
4
9
  border_zero:
@@ -23,9 +28,6 @@ formatters:
23
28
  enabled: true
24
29
  sort_order: ["mixindef", "mixin", "prop", "rule", "extend"]
25
30
 
26
- # else_placement:
27
- # enabled: true
28
-
29
31
  leading_zero:
30
32
  enabled: true
31
33
 
@@ -1,23 +1,21 @@
1
1
  module SCSSBeautifier
2
2
  class CLI
3
- DEFAULT = File.realpath(File.join(File.dirname(__FILE__), "..", "..", "data", "default_config.yml")).freeze
4
- # Takes an array of arguments
5
- # Returns exit code
3
+
6
4
  def run(args)
7
5
  options = Options.new.parse(args)
8
6
  generate_configuration and return if options[:generate_config]
9
7
 
10
- contents = File.read(args.first)
8
+ contents = args.first.nil? ? $stdin.read : File.read(args.first)
11
9
  engine = Sass::Engine.new(contents, cache: false, syntax: :scss)
12
10
 
13
11
  tree = engine.to_tree
14
- config = Config.new(options[:config] || DEFAULT)
12
+ config = Config.new(options[:config])
15
13
 
16
14
  config.formatters.each do |formatter|
17
15
  formatter.send(:visit, tree)
18
16
  end
19
17
 
20
- output = SCSSBeautifier::Convert.visit(tree, {indent: config.tab_style}, :scss)
18
+ output = SCSSBeautifier::Convert.visit(tree, config.options, :scss)
21
19
  if options[:in_place]
22
20
  File.write(args.first, output)
23
21
  else
@@ -28,7 +26,7 @@ module SCSSBeautifier
28
26
  private
29
27
 
30
28
  def generate_configuration
31
- File.write(".scss-beautifier", File.read(DEFAULT))
29
+ File.write(".scss-beautifier", File.read(Config::DEFAULT))
32
30
  end
33
31
 
34
32
  end
@@ -2,13 +2,15 @@ require "yaml"
2
2
 
3
3
  module SCSSBeautifier
4
4
  class Config
5
+ DEFAULT = File.realpath(File.join(File.dirname(__FILE__), "..", "..", "data", "default_config.yml")).freeze
5
6
 
6
7
  def initialize(config_location)
7
- @config = parse_config(config_location)
8
+ @config = parse_config(config_location.to_s)
8
9
  end
9
10
 
10
11
  def parse_config(config_location)
11
- YAML.load(File.read(config_location))
12
+ config_contents = read_config(config_location)
13
+ YAML.load(config_contents)
12
14
  end
13
15
 
14
16
  def formatters
@@ -22,8 +24,19 @@ module SCSSBeautifier
22
24
  enabled_formatters
23
25
  end
24
26
 
25
- def tab_style
26
- @config["tab_style"] || " "
27
+ def options
28
+ options_with_key_symbols = {}
29
+ @config["options"].each do |k, v|
30
+ options_with_key_symbols[:"#{k}"] = v
31
+ end
32
+ options_with_key_symbols
33
+ end
34
+
35
+ private
36
+
37
+ def read_config(config_location)
38
+ location = File.exists?(config_location) ? config_location : DEFAULT
39
+ File.read(location)
27
40
  end
28
41
 
29
42
  end
@@ -1,12 +1,13 @@
1
1
  class SCSSBeautifier::Convert < Sass::Tree::Visitors::Convert
2
2
  def visit_if(node, &block)
3
- if true
3
+ if @options[:else_placement] == "same_line"
4
4
  visit_if_no_newline(node, &block)
5
5
  else
6
6
  super(node)
7
7
  end
8
8
  end
9
- # ElsePlacement
9
+
10
+ # ElsePlacement on same_line
10
11
  def visit_if_no_newline(node)
11
12
  name =
12
13
  if !@is_else
@@ -65,7 +66,7 @@ class SCSSBeautifier::Convert < Sass::Tree::Visitors::Convert
65
66
 
66
67
  def visit_comment(node)
67
68
  value = super
68
- node.scss_beautifier_options[:inline] ? ' ' + value.lstrip! : value
69
+ node.scss_beautifier_options[:inline] ? ' ' + value.lstrip.to_s : value
69
70
  end
70
71
 
71
72
  def inline_comment?(node, comment_node)
@@ -15,7 +15,7 @@ class SCSSBeautifier::Formatters::PropertySortOrder < SCSSBeautifier::Formatters
15
15
  if hash_key == 'comment'
16
16
  seen_comments << child
17
17
  prev_grouping = prop_nodes.last
18
- if prop_node_for(prev_grouping).line == child.line
18
+ if prev_grouping && prop_node_for(prev_grouping).line == child.line
19
19
  prev_grouping << child
20
20
  else
21
21
  comment_array << child
@@ -1,3 +1,3 @@
1
1
  module SCSSBeautifier
2
- VERSION = "0.1.18"
2
+ VERSION = "0.1.19"
3
3
  end
data/tmp/dump.txt CHANGED
@@ -48,7 +48,7 @@ https://github.com/sasstools/sass-lint/blob/master/docs/rules/id-name-format.md
48
48
  https://github.com/sasstools/sass-lint/blob/master/docs/rules/mixin-name-format.md
49
49
 
50
50
  https://github.com/sasstools/sass-lint/blob/master/docs/rules/no-warn.md
51
- how do maps look like? newlines separation?
51
+ how do maps look like? newlines separation? (same with lists)
52
52
  parenthesis around if statements?
53
53
 
54
54
 
data/web/Gemfile.lock CHANGED
@@ -5,7 +5,7 @@ GEM
5
5
  rack-protection (1.5.3)
6
6
  rack
7
7
  sass (3.4.22)
8
- scss_beautifier (0.1.17)
8
+ scss_beautifier (0.1.19)
9
9
  sass (~> 3.4)
10
10
  sinatra (1.4.7)
11
11
  rack (~> 1.5)
data/web/app.rb CHANGED
@@ -22,7 +22,7 @@ class ScssBeautifierApp < Sinatra::Base
22
22
  formatter.send(:visit, tree)
23
23
  end
24
24
 
25
- output = SCSSBeautifier::Convert.visit(tree, {indent: config.tab_style}, :scss)
25
+ output = SCSSBeautifier::Convert.visit(tree, {indent: config.options}, :scss)
26
26
 
27
27
  end
28
28
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scss_beautifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.18
4
+ version: 0.1.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Tse
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-09-27 00:00:00.000000000 Z
12
+ date: 2016-10-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sass