css_modules 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/css_modules/rewrite.rb +56 -31
- data/lib/css_modules/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac4a3d14787aa438918ff5b6686f7dc162a2f7fd
|
4
|
+
data.tar.gz: 18c62d5cb744d9efb95ba0c9ce60b9e6e1c5937a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ea78e745fc2ff7435ea8bfcc0a83fa5c978a233f133c2c7535d2844bc848eef4b935506d52409e757fc034f361edda430214f57fd58260213dc935c636fdaa1
|
7
|
+
data.tar.gz: 11efd91084b1872e522972223d1afcc5c26501270345e1ea517c55ef8187db4447b2da5887b9dd290019056d6496adf151dda9a473e51f692d259d7ffc02a839
|
data/lib/css_modules/rewrite.rb
CHANGED
@@ -5,7 +5,7 @@ module CSSModules
|
|
5
5
|
module Rewrite
|
6
6
|
# Module Scopes
|
7
7
|
# :module(login) { .button {color: red;} }
|
8
|
-
RE_MODULE = /^\:module\((?<module_name>.*?)\)
|
8
|
+
RE_MODULE = /^\:module\((?<module_name>.*?)\)/
|
9
9
|
|
10
10
|
module_function
|
11
11
|
# Take css module code as input, and rewrite it as
|
@@ -36,7 +36,6 @@ module CSSModules
|
|
36
36
|
# No need to `yield` here since we run _after_ Sass -- it's already flattened.
|
37
37
|
# @return [void]
|
38
38
|
def visit_rule(node)
|
39
|
-
node.rule = node.rule.map { |r| transform_selector(r) }
|
40
39
|
node.parsed_rules = rebuild_parsed_rules(node.parsed_rules)
|
41
40
|
end
|
42
41
|
|
@@ -44,46 +43,72 @@ module CSSModules
|
|
44
43
|
|
45
44
|
def rebuild_parsed_rules(parsed_rules)
|
46
45
|
new_members = parsed_rules.members.map do |member_seq|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
46
|
+
leading_rule = first_selector(member_seq).to_s
|
47
|
+
matches = Rewrite::RE_MODULE.match(leading_rule)
|
48
|
+
if matches
|
49
|
+
module_name = matches[:module_name]
|
50
|
+
deeply_transform(module_name, member_seq)
|
51
|
+
else
|
52
|
+
member_seq
|
53
|
+
end
|
54
54
|
end
|
55
55
|
Sass::Selector::CommaSequence.new(new_members)
|
56
56
|
end
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
58
|
+
# Get the first non-sequence member of `seq`
|
59
|
+
def first_selector(seq)
|
60
|
+
case seq
|
61
|
+
when Sass::Selector::AbstractSequence
|
62
|
+
first_selector(seq.members.first)
|
63
|
+
else
|
64
|
+
seq
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# We know this is a modulized rule
|
69
|
+
# now we should transform its ID and classes to modulized
|
70
|
+
def deeply_transform(module_name, seq)
|
71
|
+
case seq
|
72
|
+
when Sass::Selector::AbstractSequence
|
73
|
+
new_members = seq.members.map { |m| deeply_transform(module_name, m) }
|
74
|
+
new_members.compact! # maybe a module selector returned nil
|
75
|
+
clone_sequence(seq, new_members)
|
76
|
+
when Sass::Selector::Id, Sass::Selector::Class
|
77
|
+
modulized_name = Rewrite.modulize_selector(module_name, seq.name)
|
78
|
+
seq.class.new(modulized_name)
|
79
|
+
when Sass::Selector::Pseudo
|
80
|
+
if seq.to_s =~ /:module/
|
81
|
+
nil
|
82
|
+
else
|
83
|
+
seq
|
84
|
+
end
|
85
|
+
else
|
86
|
+
seq
|
87
|
+
end
|
61
88
|
end
|
62
89
|
|
63
|
-
#
|
64
|
-
def
|
65
|
-
|
66
|
-
|
67
|
-
|
90
|
+
# Make a new kind of `seq`, containing `new_members`
|
91
|
+
def clone_sequence(seq, new_members)
|
92
|
+
case seq
|
93
|
+
when Sass::Selector::Sequence
|
94
|
+
seq.class.new(new_members)
|
95
|
+
when Sass::Selector::CommaSequence
|
96
|
+
seq.class.new(new_members)
|
97
|
+
when Sass::Selector::SimpleSequence
|
98
|
+
seq.class.new(new_members, seq.subject?, seq.source_range)
|
68
99
|
else
|
69
|
-
|
70
|
-
declaration_parts = matches[:declarations].split(" ")
|
71
|
-
declaration_parts
|
72
|
-
.map { |declaration_or_operator| rebuild_selector(module_name, declaration_or_operator) }
|
73
|
-
.join(" ")
|
100
|
+
raise("Unknown sequence to clone: #{seq.class}")
|
74
101
|
end
|
75
102
|
end
|
76
103
|
|
77
|
-
#
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
when "."
|
84
|
-
".#{Rewrite.modulize_selector(module_name, selector[1..-1])}"
|
104
|
+
# Debug print-out of a sequence:
|
105
|
+
def deep_print(seq, indent = "")
|
106
|
+
case seq
|
107
|
+
when Sass::Selector::AbstractSequence
|
108
|
+
puts indent + seq.class.name + " => "
|
109
|
+
seq.members.map { |m| deep_print(m, indent + " ") }
|
85
110
|
else
|
86
|
-
|
111
|
+
puts indent + seq.class.name + " (#{seq})"
|
87
112
|
end
|
88
113
|
end
|
89
114
|
end
|
data/lib/css_modules/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: css_modules
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Mosolgo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|