css_modules 0.7.0 → 1.0.0

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: 7c9871bc394fa4fc5d7f43d7481929f7d8873f06
4
- data.tar.gz: 0ad7ecb1028b027b456e371762258dd132a67605
3
+ metadata.gz: 21b9fabe952b1363c961b54679fc160c266a4015
4
+ data.tar.gz: 055009fe0234af3921b944ef78971844ca5f5076
5
5
  SHA512:
6
- metadata.gz: 6f1af91b7bc4de1258ac9e4a4eebb0e15609a07327755077463c42c455197be1c2c896acb83b455a2afd68e496dba50b60ca6b0cae649f0496bd456f700536e9
7
- data.tar.gz: ad3d5ce2e82397097f242b97f9f9ed55e364031ce86ccf43de73e6b32cf6c78ea498cce3f68e22ba4761e7c79a55996534d345d0075cb5ef14e8b543d938f74d
6
+ metadata.gz: d2bacefe1455169e48a20efe29caa16ed6ce85cc56f8dee9dd0535062f6245a19e3d2a66c558ce6a0988c0cf8153f840875e0400e7f434464d3b527ec67c53f7
7
+ data.tar.gz: 7bc30bd4c1c1a1c97b262aedd2f98616d89c4214fd4d63bc660c66e3fb91605b8f3ff1e6950319c4334bd7ed2ede9795c8121b6a29fc5fbd5d151f827ab7defd
data/README.md CHANGED
@@ -159,8 +159,9 @@ $ gem install css_modules
159
159
  - Sprockets require CSS to JS? `require_styles` ?
160
160
  - Support plain `.css`
161
161
  - Support Sprockets 3+
162
+ - Test on different Sass versions
162
163
  - Check for hash collisions in development
163
- - Fix bundle cache
164
+ - Fix sprockets cache: a new version of this gem should expire an old cache
164
165
 
165
166
  ## License
166
167
 
@@ -6,11 +6,26 @@ module CSSModules
6
6
  # Make css_module.js accessible to Sprockets
7
7
  app.config.assets.paths << File.expand_path("../assets", __FILE__)
8
8
 
9
- # This is Sprockets 2 only :S
10
9
  app.config.assets.configure do |env|
11
- env.register_postprocessor('text/css', :css_modules) do |context, data|
12
- CSSModules::Rewrite.rewrite_css(data)
13
- end
10
+ env.register_postprocessor('text/css', RewritePostprocessor)
11
+ end
12
+ end
13
+
14
+ # Sprockets 2 & Sprockets 3-compatible postprocessor
15
+ # https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md#supporting-all-versions-of-sprockets-in-processors
16
+ class RewritePostprocessor
17
+ # Sprockets 2
18
+ def initialize(filename)
19
+ @source = yield
20
+ end
21
+
22
+ def render(variable, empty_hash)
23
+ self.class.call(data: @source)
24
+ end
25
+
26
+ # Sprockets 3+
27
+ def self.call(input)
28
+ CSSModules::Rewrite.rewrite_css(input[:data])
14
29
  end
15
30
  end
16
31
  end
@@ -43,8 +43,8 @@ module CSSModules
43
43
 
44
44
  def rebuild_parsed_rules(parsed_rules)
45
45
  new_members = parsed_rules.members.map do |member_seq|
46
- leading_rule = first_selector(member_seq).to_s
47
- matches = Rewrite::RE_MODULE.match(leading_rule)
46
+ leading_rule = first_pseudo_selector(member_seq).to_s
47
+ matches = leading_rule && Rewrite::RE_MODULE.match(leading_rule)
48
48
  if matches
49
49
  module_name = matches[:module_name]
50
50
  deeply_transform(module_name, member_seq)
@@ -55,13 +55,15 @@ module CSSModules
55
55
  Sass::Selector::CommaSequence.new(new_members)
56
56
  end
57
57
 
58
- # Get the first non-sequence member of `seq`
59
- def first_selector(seq)
58
+ # Get the first Sass::Selector::Pseudo member of `seq`, or nil
59
+ def first_pseudo_selector(seq)
60
60
  case seq
61
61
  when Sass::Selector::AbstractSequence
62
- first_selector(seq.members.first)
63
- else
62
+ seq.members.find { |m| first_pseudo_selector(m) }
63
+ when Sass::Selector::Pseudo
64
64
  seq
65
+ else # eg, String
66
+ nil
65
67
  end
66
68
  end
67
69
 
@@ -74,7 +76,9 @@ module CSSModules
74
76
  new_members.compact! # maybe a module selector returned nil
75
77
  clone_sequence(seq, new_members)
76
78
  when Sass::Selector::Id, Sass::Selector::Class
77
- modulized_name = Rewrite.modulize_selector(module_name, seq.name)
79
+ # Sass 3.2 has an array here, Sass 3.4 has a string:
80
+ selector_name = seq.name.is_a?(Array) ? seq.name.first : seq.name
81
+ modulized_name = Rewrite.modulize_selector(module_name, selector_name)
78
82
  seq.class.new(modulized_name)
79
83
  when Sass::Selector::Pseudo
80
84
  if seq.to_s =~ /:module/
@@ -1,3 +1,3 @@
1
1
  module CSSModules
2
- VERSION = "0.7.0"
2
+ VERSION = "1.0.0"
3
3
  end
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.7.0
4
+ version: 1.0.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-17 00:00:00.000000000 Z
11
+ date: 2016-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.2'
41
41
  - !ruby/object:Gem::Dependency
42
- name: sqlite3
42
+ name: appraisal
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: Provides a css-module-like experience to Sass/SCSS, Rails views and JavaScript
70
84
  email:
71
85
  - rdmosolgo@gmail.com