flint-gs 2.0.3 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +27 -24
  3. data/lib/flint.rb +4 -72
  4. data/lib/flint/functions.rb +97 -0
  5. data/lib/flint/version.rb +4 -0
  6. data/stylesheets/flint/functions/lib/_list-to-string.scss +16 -10
  7. data/stylesheets/flint/functions/lib/_string-to-list.scss +2 -2
  8. data/stylesheets/flint/functions/lib/_support-syntax-bem.scss +4 -4
  9. data/stylesheets/flint/mixins/lib/_main.scss +0 -2
  10. data/tests/bootcamp/_bootcamp.scss +46 -0
  11. data/tests/bootcamp/core/functions/_actual.scss +3 -0
  12. data/tests/bootcamp/core/functions/_error.scss +29 -0
  13. data/tests/bootcamp/core/functions/_expect.scss +6 -0
  14. data/tests/bootcamp/core/functions/_not-to.scss +5 -0
  15. data/tests/bootcamp/core/functions/_should.scss +6 -0
  16. data/tests/bootcamp/core/functions/_to.scss +5 -0
  17. data/tests/bootcamp/core/mixins/_describe.scss +31 -0
  18. data/tests/bootcamp/core/mixins/_it.scss +31 -0
  19. data/tests/bootcamp/core/mixins/_runner.scss +28 -0
  20. data/tests/bootcamp/core/mixins/_should.scss +46 -0
  21. data/tests/bootcamp/core/mixins/_xdescribe.scss +9 -0
  22. data/tests/bootcamp/core/mixins/_xit.scss +9 -0
  23. data/tests/bootcamp/core/variables/_helpers.scss +5 -0
  24. data/tests/bootcamp/core/variables/_settings.scss +2 -0
  25. data/tests/bootcamp/core/variables/_should.scss +6 -0
  26. data/tests/bootcamp/core/variables/_trackers.scss +6 -0
  27. data/tests/bootcamp/lib/_sassyjson.scss +1075 -0
  28. data/tests/bootcamp/matchers/_be.scss +3 -0
  29. data/tests/bootcamp/matchers/_equal.scss +3 -0
  30. data/tests/bootcamp/matchers/lists/_be-empty.scss +3 -0
  31. data/tests/bootcamp/matchers/lists/_be-longer-than.scss +3 -0
  32. data/tests/bootcamp/matchers/lists/_be-shorter-than.scss +3 -0
  33. data/tests/bootcamp/matchers/lists/_contain.scss +3 -0
  34. data/tests/bootcamp/matchers/lists/_deep-contain.scss +3 -0
  35. data/tests/bootcamp/matchers/lists/_deep-equal.scss +47 -0
  36. data/tests/bootcamp/matchers/lists/_have-length-of.scss +3 -0
  37. data/tests/bootcamp/matchers/numbers/_be-close-to.scss +12 -0
  38. data/tests/bootcamp/matchers/numbers/_be-greater-than.scss +12 -0
  39. data/tests/bootcamp/matchers/numbers/_be-less-than.scss +12 -0
  40. data/tests/bootcamp/matchers/types/_be-falsy.scss +3 -0
  41. data/tests/bootcamp/matchers/types/_be-null.scss +3 -0
  42. data/tests/bootcamp/matchers/types/_be-truthy.scss +3 -0
  43. data/tests/bootcamp/matchers/types/_have-type-of.scss +3 -0
  44. data/tests/bootcamp/utils/_contain.scss +15 -0
  45. data/tests/bootcamp/utils/_equal.scss +23 -0
  46. data/tests/bootcamp/utils/_list-join.scss +35 -0
  47. data/tests/bootcamp/utils/_power.scss +15 -0
  48. data/tests/config.rb +52 -0
  49. data/tests/input/functions/_functions.scss +48 -0
  50. data/tests/input/functions/helpers/_helpers.scss +416 -0
  51. data/tests/input/functions/lib/_calc-breakpoint.scss +62 -0
  52. data/tests/input/functions/lib/_calc-width.scss +195 -0
  53. data/tests/input/functions/lib/_exists.scss +30 -0
  54. data/tests/input/functions/lib/_fluid-width.scss +32 -0
  55. data/tests/input/functions/lib/_get-index.scss +31 -0
  56. data/tests/input/functions/lib/_get-instance-value.scss +72 -0
  57. data/tests/input/functions/lib/_get-value.scss +28 -0
  58. data/tests/input/functions/lib/_has-family-instance.scss +35 -0
  59. data/tests/input/functions/lib/_instance.scss +187 -0
  60. data/tests/input/functions/lib/_last.scss +18 -0
  61. data/tests/input/functions/lib/_list-to-string.scss +28 -0
  62. data/tests/input/functions/lib/_map-fetch.scss +34 -0
  63. data/tests/input/functions/lib/_next-index.scss +24 -0
  64. data/tests/input/functions/lib/_purge.scss +14 -0
  65. data/tests/input/functions/lib/_remove.scss +14 -0
  66. data/tests/input/functions/lib/_replace-substring.scss +14 -0
  67. data/tests/input/functions/lib/_replace.scss +14 -0
  68. data/tests/input/functions/lib/_steal-key.scss +19 -0
  69. data/tests/input/functions/lib/_steal-values.scss +16 -0
  70. data/tests/input/functions/lib/_string-to-list.scss +28 -0
  71. data/tests/input/functions/lib/_support-syntax-bem.scss +14 -0
  72. data/tests/input/functions/lib/_support-syntax.scss +21 -0
  73. data/tests/input/functions/lib/_types-in-list.scss +50 -0
  74. data/tests/input/functions/lib/_use-syntax.scss +14 -0
  75. data/tests/input/output.scss +243 -0
  76. data/tests/output/output.css +1900 -0
  77. data/tests/tests.html +110 -0
  78. metadata +170 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d0d0539567fb162ecf38772974dbbc0cde72548
4
- data.tar.gz: 5094eb179d16d8b40ce55666c9cf11cd7a3244e1
3
+ metadata.gz: 972dad8929bdf7d5e6d125c9da7c2d4b2dd86d1b
4
+ data.tar.gz: 1b2a584bfc2a192ddde61af066822ef74cc9cb80
5
5
  SHA512:
6
- metadata.gz: f0286cbcee185f45947a5728bbe594e2841e738e4c613b18578118e41418d634bf415396ef7e6bd0abf2cc0e39225200e2b2f36f4de5c7ea657cd8982bd21296
7
- data.tar.gz: c82aa3383be1c1b424d6ed822a4294d19848da8492492f87856b3453a39ebe19fe4957a488916815a2c251173c077c131a41c582bec60252fad4a14fcfa246f9
6
+ metadata.gz: 29914803abf6c0e4dec89d76d1550776564fc6ef6a8219122d53e1e1d78a3464ea765894219636b7baeee207c1ff4d8ddc46b6d9602395ac2b0ee15ab62ec5ab
7
+ data.tar.gz: 9cc8360a92e548e24522bd5d382d2680f6b6b362070c6e7d85e0a0eca69fc3e12fd45f76096f87e26cd44e978187125f2c1a5c8658bc167420127dc3b7d06b3d
data/README.md CHANGED
@@ -53,36 +53,39 @@ function parses the selector string (for example, `.block__element__element`) li
53
53
  /**
54
54
  * Parser to support BEM syntax
55
55
  *
56
+ * @access private
57
+ *
56
58
  * @param {List} $selectors - string of selectors to parse
57
59
  *
58
60
  * @return {List} - parsed list of selectors according to syntax
61
+ *
62
+ * @group Internal Functions
59
63
  */
60
64
  @function flint-support-syntax-bem($selectors) {
61
- // Clean up selector, remove double underscores for spaces
62
- // add pseudo character to differentiate selectors
63
- $selectors: flint-replace-substring(inspect($selectors), "__", "/");
64
- // Parse string back to list without pseudo character
65
- $selectors: flint-string-to-list($selectors, "/");
66
- // Define top-most parent of selector
67
- $parent: nth($selectors, 1);
68
- // Create new list of parsed selectors
69
- $selector-list: ($parent);
70
-
71
- // Loop over each selector and build list of selectors
72
- @each $selector in $selectors {
73
- // Make sure current selector is not the parent
74
- @if $selector != $parent {
75
- // Save to selector list
76
- $selector-list: append($selector-list, ($parent + "__" + $selector), "comma");
77
- // Define new parent
78
- $parent: $parent + "__" + $selector;
79
- }
80
- }
81
-
82
- // Return the list of parsed selectors
83
- @return $selector-list;
65
+ // Clean up selector, remove double underscores for spaces
66
+ // add pseudo character to differentiate selectors
67
+ $selectors: flint-replace-substring(inspect(unquote($selectors)), "__", "/");
68
+ // Parse string back to list without pseudo character
69
+ $selectors: flint-string-to-list($selectors, "/");
70
+ // Define top-most parent of selector
71
+ $parent: nth($selectors, 1);
72
+ // Create new list of parsed selectors
73
+ $selector-list: ("#{$parent}",);
74
+
75
+ // Loop over each selector and build list of selectors
76
+ @each $selector in $selectors {
77
+ // Make sure current selector is not the parent
78
+ @if $selector != $parent {
79
+ // Save to selector list
80
+ $selector-list: append($selector-list, "#{$parent}__#{$selector}", "comma");
81
+ // Define new parent
82
+ $parent: "#{$parent}__#{$selector}";
83
+ }
84
+ }
85
+
86
+ // Return the list of parsed selectors
87
+ @return $selector-list;
84
88
  }
85
-
86
89
  ```
87
90
 
88
91
  This will be parsed into a list of selectors: `.block, .block__element, .block__element__element`. The list of selectors can then be used by the
@@ -1,4 +1,6 @@
1
- require 'sass'
1
+ require "sass"
2
+ require_relative "flint/version"
3
+ require_relative "flint/functions"
2
4
 
3
5
  base_directory = File.expand_path(File.join(File.dirname(__FILE__), '..'))
4
6
  flint_stylesheets_path = File.join(base_directory, 'stylesheets')
@@ -10,75 +12,5 @@ else
10
12
  end
11
13
 
12
14
  module Flint
13
- VERSION = "2.0.3"
14
- DATE = "2014-10-02"
15
- end
16
-
17
- module Sass::Script::Functions
18
-
19
- ###
20
- # Use ruby functions
21
- #
22
- # @return {Bool}
23
- ###
24
- def flint_use_ruby()
25
- Sass::Script::Bool.new(true)
26
- end
27
-
28
- ###
29
- # Fetch value from map
30
- #
31
- # @param {Map} map - map to fetch value from
32
- # @param {ArgList} keys - list of keys to traverse
33
- #
34
- # @return {*}
35
- ###
36
- def flint_ruby_map_fetch(map, *keys)
37
- assert_type map, :Map, :map
38
- result = map
39
- keys.each {|key| result != nil ? result = result.to_h.fetch(key, nil) : break}
40
- return result != nil ? result : Sass::Script::Bool.new(false)
41
- end
42
- declare :flint_ruby_map_fetch, :args => [:map, :keys], :var_args => true
43
-
44
- ###
45
- # Turn string into a flat list
46
- #
47
- # @param {String} string - string to operate on
48
- # @param {String} separator - item to find which separates substrings
49
- # @param {String} ignore - removes remaining string beyond item
50
- #
51
- # @return {List}
52
- ###
53
- def flint_ruby_string_to_list(string, separator, ignore)
54
- assert_type string, :String, :string
55
- assert_type separator, :String, :separator
56
- assert_type ignore, :String, :ignore
57
- # Remove everything after ignore, split with separator
58
- items = string.value[/[^#{ignore}]+/].split(separator.value)
59
- if items.count == 1
60
- Sass::Script::String.new(items[0], :comma)
61
- else
62
- Sass::Script::List.new(items.map { |i| Sass::Script::String.new(i) }, :comma)
63
- end
64
- end
65
- declare :flint_ruby_string_to_list, :args => [:string, :separator, :ignore]
66
-
67
- ###
68
- # Replace substring with string
69
- #
70
- # @param {String} string - string that contains substring
71
- # @param {String} find - substring to replace
72
- # @param {String} replace - new string to replace sub with
73
- #
74
- # @return {String}
75
- ###
76
- def flint_ruby_replace_substring(string, find, replace)
77
- assert_type string, :String, :string
78
- assert_type find, :String, :find
79
- assert_type replace, :String, :replace
80
- Sass::Script::String.new(string.value.gsub(find.value, replace.value))
81
- end
82
- declare :flint_ruby_replace_substring, :args => [:string, :find, :replace]
83
-
15
+ Sass::Script::Functions.send(:include, Flint)
84
16
  end
@@ -0,0 +1,97 @@
1
+ module Flint
2
+
3
+ def self.declare(*args)
4
+ Sass::Script::Functions.declare(*args)
5
+ end
6
+
7
+ def self.map(hash)
8
+ Sass::Script::Value::Map.new(hash)
9
+ end
10
+
11
+ ###
12
+ # Use ruby functions
13
+ #
14
+ # @return {Bool}
15
+ ###
16
+ def flint_use_ruby()
17
+ Sass::Script::Bool.new(true)
18
+ end
19
+
20
+ ###
21
+ # Fetch value from map
22
+ #
23
+ # @param {Map} map - map to fetch value from
24
+ # @param {ArgList} keys - list of keys to traverse
25
+ #
26
+ # @return {*}
27
+ ###
28
+ def flint_ruby_map_fetch(map, *keys)
29
+ assert_type map, :Map, :map
30
+ result = map
31
+ keys.each { |key| result.nil? ? break : result = result.to_h.fetch(key, nil) }
32
+ unless result.nil?
33
+ result
34
+ else
35
+ Sass::Script::Bool.new(false)
36
+ end
37
+ end
38
+ declare :flint_ruby_map_fetch, :args => [:map, :keys], :var_args => true
39
+
40
+ ###
41
+ # Joins all elements of list with passed glue
42
+ #
43
+ # @param {List} list
44
+ # @param {String} glue
45
+ #
46
+ # @return {String}
47
+ ###
48
+ def flint_ruby_list_to_string(list, glue)
49
+ assert_type list, :List, :list
50
+ assert_type glue, :String, :glue
51
+ arr = list.to_a.flatten.map { |item| item.value }
52
+ Sass::Script::String.new(arr.join(glue.value))
53
+ end
54
+ declare :flint_ruby_list_to_string, :args => [:list, :glue]
55
+
56
+ ###
57
+ # Turn string into a flat list
58
+ #
59
+ # @param {String} string - string to operate on
60
+ # @param {String} separator - item to find which separates substrings
61
+ # @param {String} ignore - removes remaining string beyond item
62
+ #
63
+ # @return {List}
64
+ ###
65
+ def flint_ruby_string_to_list(string, separator, ignore)
66
+ assert_type string, :String, :string
67
+ assert_type separator, :String, :separator
68
+ assert_type ignore, :String, :ignore
69
+ # Remove everything after ignore, split with separator
70
+ items = string.value[/[^#{ignore}]+/].split(separator.value)
71
+ if items.count == 1
72
+ Sass::Script::String.new(items[0], :comma)
73
+ else
74
+ Sass::Script::List.new(items.map { |i| Sass::Script::String.new(i) }, :comma)
75
+ end
76
+ end
77
+ declare :flint_ruby_string_to_list, :args => [:string, :separator, :ignore]
78
+
79
+ ###
80
+ # Replace substring with string
81
+ #
82
+ # @param {String} string - string that contains substring
83
+ # @param {String} find - substring to replace
84
+ # @param {String} replace - new string to replace sub with
85
+ #
86
+ # @return {String}
87
+ ###
88
+ def flint_ruby_replace_substring(string, find, replace)
89
+ assert_type string, :String, :string
90
+ assert_type find, :String, :find
91
+ assert_type replace, :String, :replace
92
+ Sass::Script::String.new(string.value.gsub(find.value, replace.value))
93
+ end
94
+ declare :flint_ruby_replace_substring, :args => [:string, :find, :replace]
95
+
96
+ Sass::Script::Functions.send(:include, Flint)
97
+ end
@@ -0,0 +1,4 @@
1
+ module Flint
2
+ VERSION = "2.0.4"
3
+ DATE = "2014-10-03"
4
+ end
@@ -14,18 +14,24 @@
14
14
  * @group Internal Functions
15
15
  */
16
16
  @function flint-list-to-string($list, $glue: "", $is-nested: false) {
17
- $result: null;
18
- $length: length($list);
19
17
 
20
- @for $i from 1 through $length {
21
- $n: nth($list, $i);
18
+ // Use Ruby function if available
19
+ @if $flint__use-ruby-functions {
20
+ @return flint_ruby_list_to_string($list, $glue);
21
+ } @else {
22
+ $result: null;
23
+ $length: length($list);
22
24
 
23
- @if flint-is-list($n) {
24
- $result: $result#{flint-list-to-string($n, $glue, true)};
25
- } @else {
26
- $result: if($i != length($list) or $is-nested, $result#{$n}#{$glue}, $result#{$n});
25
+ @for $i from 1 through $length {
26
+ $n: nth($list, $i);
27
+
28
+ @if flint-is-list($n) {
29
+ $result: $result#{flint-list-to-string($n, $glue, true)};
30
+ } @else {
31
+ $result: if($i != length($list) or $is-nested, $result#{$n}#{$glue}, $result#{$n});
32
+ }
27
33
  }
28
- }
29
34
 
30
- @return $result;
35
+ @return unquote($result);
36
+ }
31
37
  }
@@ -80,13 +80,13 @@
80
80
  $string-list: append($string-list, $matched-string, "comma");
81
81
 
82
82
  // Finally, return comma separated list of selectors
83
- @return $string-list;
83
+ @return flint-purge($string-list);
84
84
  } @else {
85
85
 
86
86
  // Else, just return the string as a single item list
87
87
  $string-list: append($string-list, $string);
88
88
 
89
- @return $string-list;
89
+ @return flint-purge($string-list);
90
90
  }
91
91
  }
92
92
  } @else {
@@ -12,22 +12,22 @@
12
12
  @function flint-support-syntax-bem($selectors) {
13
13
  // Clean up selector, remove double underscores for spaces
14
14
  // add pseudo character to differentiate selectors
15
- $selectors: flint-replace-substring(inspect($selectors), "__", "/");
15
+ $selectors: flint-replace-substring(inspect(unquote($selectors)), "__", "/");
16
16
  // Parse string back to list without pseudo character
17
17
  $selectors: flint-string-to-list($selectors, "/");
18
18
  // Define top-most parent of selector
19
19
  $parent: nth($selectors, 1);
20
20
  // Create new list of parsed selectors
21
- $selector-list: ($parent);
21
+ $selector-list: ("#{$parent}",);
22
22
 
23
23
  // Loop over each selector and build list of selectors
24
24
  @each $selector in $selectors {
25
25
  // Make sure current selector is not the parent
26
26
  @if $selector != $parent {
27
27
  // Save to selector list
28
- $selector-list: append($selector-list, ($parent + "__" + $selector), "comma");
28
+ $selector-list: append($selector-list, "#{$parent}__#{$selector}", "comma");
29
29
  // Define new parent
30
- $parent: $parent + "__" + $selector;
30
+ $parent: "#{$parent}__#{$selector}";
31
31
  }
32
32
  }
33
33
 
@@ -274,8 +274,6 @@
274
274
  * @param {String|Number} $context (null) - context value of span, or null for shorthand
275
275
  * @param {String|List} $gutter (null) - alias for gutter modifier
276
276
  *
277
- * @content all content passed will be placed _underneath_ output so that it takes precedence.
278
- *
279
277
  * @throws error if list lengths do not match number of breakpoints (when using variable shorthands).
280
278
  *
281
279
  * ----
@@ -0,0 +1,46 @@
1
+ @import "lib/sassyjson";
2
+
3
+ @import "core/variables/settings";
4
+
5
+ @import "core/variables/helpers";
6
+ @import "core/variables/should";
7
+ @import "core/variables/trackers";
8
+
9
+ @import "core/mixins/describe";
10
+ @import "core/mixins/it";
11
+ @import "core/mixins/runner";
12
+ @import "core/mixins/should";
13
+ @import "core/mixins/xdescribe";
14
+ @import "core/mixins/xit";
15
+
16
+ @import "core/functions/actual";
17
+ @import "core/functions/error";
18
+ @import "core/functions/expect";
19
+ @import "core/functions/not-to";
20
+ @import "core/functions/should";
21
+ @import "core/functions/to";
22
+
23
+ @import "utils/contain";
24
+ @import "utils/equal";
25
+ @import "utils/list-join";
26
+ @import "utils/power";
27
+
28
+ @import "matchers/be";
29
+ @import "matchers/equal";
30
+
31
+ @import "matchers/lists/be-empty";
32
+ @import "matchers/lists/be-longer-than";
33
+ @import "matchers/lists/be-shorter-than";
34
+ @import "matchers/lists/contain";
35
+ @import "matchers/lists/deep-contain";
36
+ @import "matchers/lists/deep-equal";
37
+ @import "matchers/lists/have-length-of";
38
+
39
+ @import "matchers/numbers/be-close-to";
40
+ @import "matchers/numbers/be-greater-than";
41
+ @import "matchers/numbers/be-less-than";
42
+
43
+ @import "matchers/types/be-falsy";
44
+ @import "matchers/types/be-null";
45
+ @import "matchers/types/be-truthy";
46
+ @import "matchers/types/have-type-of";
@@ -0,0 +1,3 @@
1
+ @function actual() {
2
+ @return $bc-actual;
3
+ }
@@ -0,0 +1,29 @@
1
+ @function error($type, $message) {
2
+ $title: null;
3
+
4
+ @if $type == "type" {
5
+ $title: "TYPE ERROR";
6
+ }
7
+
8
+ @else if $type == "warn" {
9
+ $title: "WARNING"
10
+ }
11
+
12
+ @else if $type == "dep" {
13
+ $title: "DEPRECATED"
14
+ }
15
+
16
+ @else if $type == "fatal" {
17
+ $bc-error: true !global;
18
+ $title: "FATAL ERROR";
19
+ }
20
+
21
+ @else {
22
+ $bc-error: true !global;
23
+ $title: "ERROR";
24
+ }
25
+
26
+ $bc-error-text: "!#{$title}! #{$message}." !global;
27
+
28
+ @return false;
29
+ }
@@ -0,0 +1,6 @@
1
+ @function expect($this) {
2
+ $bc-actual: $this !global;
3
+ $bc-actual-text: "Expected" !global;
4
+
5
+ @return null;
6
+ }
@@ -0,0 +1,5 @@
1
+ @function not-to($this) {
2
+ $bc-expect-text: "not to " + $bc-expect-text !global;
3
+
4
+ @return not $this;
5
+ }