view_component_scoped_css 0.1.2 → 0.2.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
  SHA256:
3
- metadata.gz: 23e8691887ae2ae3f85d8f23f4ad92bc47f5723c6db6ac4f0f0fcb2c886c36ec
4
- data.tar.gz: 25cc37a5ea2db946ea865e0a9bb4edfdc268c43ea44a7dad71396b698050ff4d
3
+ metadata.gz: 1efadcc6268b2ae05a59c932fa65ac87c1ef3fa4cac6ba663db21319448f47f9
4
+ data.tar.gz: c0d4498cb5db29c1b348721430a789e3058947bae9e6046558cd539b3f3a8cd3
5
5
  SHA512:
6
- metadata.gz: dbc31138ecca27da81a1b79ed256728d7dfe04599fe48d83fc502438bed81faf9a1cdef1f112b06a30336585d147f62863f3208e7a6c1eb3b109f66cc873956d
7
- data.tar.gz: 28a614c7a7c3aea992de5db12cb4053dc4560ec47c1929319817efc0b060f26814f2028004097a4c0fbe34354a262e9e807d90ef8a45cffb5e14cb104b8dbd83
6
+ metadata.gz: c5f8d15bad3c880d02eb0fb508e39ef50a6f60c8bf3a764a7cf2a21c11e22c67765e71e6e49579a498bfac063c5ae962970d6ecce4e609577c70415a1243ee46
7
+ data.tar.gz: e5432f3dc3dd08e6a6d6844b062ca22903a306a864351a997970c66bdace8040f7039f3a773642c170ab45a8cdda97755d90db38338df0b10abe8cf2037c434b
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ Gemfile.lock
data/Gemfile.lock CHANGED
@@ -1,38 +1,34 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- view_component_styled (0.1.0)
4
+ view_component_scoped_css (0.2.0)
5
5
  activesupport (>= 6.0.0)
6
- css_parser
6
+ sass-embedded
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (7.0.4)
11
+ activesupport (7.0.4.2)
12
12
  concurrent-ruby (~> 1.0, >= 1.0.2)
13
13
  i18n (>= 1.6, < 2)
14
14
  minitest (>= 5.1)
15
15
  tzinfo (~> 2.0)
16
- addressable (2.8.1)
17
- public_suffix (>= 2.0.2, < 6.0)
18
16
  ast (2.4.2)
19
17
  coderay (1.1.3)
20
- concurrent-ruby (1.1.10)
21
- css_parser (1.12.0)
22
- addressable
18
+ concurrent-ruby (1.2.2)
23
19
  diff-lcs (1.5.0)
20
+ google-protobuf (3.22.0-arm64-darwin)
24
21
  i18n (1.12.0)
25
22
  concurrent-ruby (~> 1.0)
26
23
  json (2.6.2)
27
24
  method_source (1.0.0)
28
- minitest (5.16.3)
25
+ minitest (5.18.0)
29
26
  parallel (1.22.1)
30
27
  parser (3.1.2.1)
31
28
  ast (~> 2.4.1)
32
29
  pry (0.14.1)
33
30
  coderay (~> 1.1)
34
31
  method_source (~> 1.0)
35
- public_suffix (5.0.0)
36
32
  rainbow (3.1.1)
37
33
  rake (13.0.6)
38
34
  regexp_parser (2.6.0)
@@ -63,19 +59,22 @@ GEM
63
59
  rubocop-ast (1.21.0)
64
60
  parser (>= 3.1.1.0)
65
61
  ruby-progressbar (1.11.0)
66
- tzinfo (2.0.5)
62
+ sass-embedded (1.58.3-arm64-darwin)
63
+ google-protobuf (~> 3.21)
64
+ tzinfo (2.0.6)
67
65
  concurrent-ruby (~> 1.0)
68
66
  unicode-display_width (2.3.0)
69
67
 
70
68
  PLATFORMS
71
69
  arm64-darwin-20
70
+ arm64-darwin-21
72
71
 
73
72
  DEPENDENCIES
74
73
  pry
75
74
  rake (~> 13.0)
76
75
  rspec (~> 3.0)
77
76
  rubocop (~> 1.7)
78
- view_component_styled!
77
+ view_component_scoped_css!
79
78
 
80
79
  BUNDLED WITH
81
80
  2.2.22
@@ -8,13 +8,9 @@ module ViewComponentScopedCss
8
8
  module Base
9
9
  extend ActiveSupport::Concern
10
10
 
11
- included do
12
- include ViewComponentScopedCss::Hook
13
- end
14
-
15
11
  class_methods do
16
12
  def component_css_tag
17
- ViewComponentScopedCss::CurrentContext.add(self)
13
+ ViewComponentScopedCss::CurrentContext.render_if_need(self)
18
14
  end
19
15
 
20
16
  def component_identifier
@@ -34,12 +30,16 @@ module ViewComponentScopedCss
34
30
  self.class.component_identifier_for_css
35
31
  end
36
32
 
37
- def component_tag(name = ViewComponentScopedCss.config.component_tag, &block)
38
- content_tag(
39
- name,
40
- class: [self.class.component_identifier_for_css, component_options[:class]].compact.join(" "),
41
- **component_options,
42
- &block
33
+ def component_tag(name = ViewComponentScopedCss.config.component_tag, **tag_options, &block)
34
+ safe_join(
35
+ [
36
+ self.class.component_css_tag,
37
+ content_tag(
38
+ name,
39
+ class: [self.class.component_identifier_for_css, tag_options[:class]].compact.join(" "),
40
+ **component_options, &block
41
+ )
42
+ ].compact
43
43
  )
44
44
  end
45
45
  end
@@ -2,23 +2,21 @@
2
2
 
3
3
  module ViewComponentScopedCss
4
4
  #
5
- # Class for holding the <style></style> of the component called on each request.
5
+ # Manage whether CSS has been Render
6
6
  #
7
7
  class CurrentContext < ActiveSupport::CurrentAttributes
8
- attribute :css
8
+ attribute :called
9
9
 
10
- def self.render
11
- return if css.empty?
12
-
13
- css.values.join("\n").html_safe
14
- end
15
-
16
- def self.add(view_component_class)
17
- self.css ||= {}
18
- self.css[view_component_class.name] ||= ViewComponentScopedCss::Tag.new(view_component_class).call
19
- self.css[view_component_class.name]
10
+ def self.render_if_need(view_component_class)
11
+ self.called ||= {}
12
+ if called[view_component_class.name]
13
+ nil
14
+ else
15
+ called[view_component_class.name] = true
16
+ ViewComponentScopedCss::Tag.new(view_component_class).call
17
+ end
20
18
  end
21
19
 
22
- resets { self.css = {} } if ViewComponentScopedCss.config.compile_cache
20
+ resets { self.called = {} }
23
21
  end
24
22
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ViewComponentScopedCss
4
- VERSION = "0.1.2"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -14,16 +14,11 @@ module ViewComponentScopedCss
14
14
  extend ActiveSupport::Autoload
15
15
  autoload :Loader
16
16
  autoload :CurrentContext
17
- autoload :Hook
18
17
  autoload :Base
19
18
  autoload :Config
20
19
  autoload :Tag
21
20
  autoload :Compiler
22
21
 
23
- def self.tags
24
- CurrentContext.render
25
- end
26
-
27
22
  def self.configure
28
23
  yield config
29
24
  end
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
13
13
  Inspired by the css in js component, it provides functionality to allow the same
14
14
  component-by-component implementation of styles in rails' standard component, view_components.
15
15
  "
16
- spec.homepage = "https://github.com/aileron-inc/view_component_in_css"
16
+ spec.homepage = "https://github.com/aileron-inc/view_component_scoped_css"
17
17
  spec.license = "MIT"
18
18
  spec.required_ruby_version = ">= 3.0"
19
19
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: view_component_scoped_css
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masa (Aileron inc)
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-12 00:00:00.000000000 Z
11
+ date: 2023-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -65,17 +65,16 @@ files:
65
65
  - lib/view_component_scoped_css/compiler.rb
66
66
  - lib/view_component_scoped_css/config.rb
67
67
  - lib/view_component_scoped_css/current_context.rb
68
- - lib/view_component_scoped_css/hook.rb
69
68
  - lib/view_component_scoped_css/loader.rb
70
69
  - lib/view_component_scoped_css/railtie.rb
71
70
  - lib/view_component_scoped_css/tag.rb
72
71
  - lib/view_component_scoped_css/version.rb
73
72
  - view_component_scoped_css.gemspec
74
- homepage: https://github.com/aileron-inc/view_component_in_css
73
+ homepage: https://github.com/aileron-inc/view_component_scoped_css
75
74
  licenses:
76
75
  - MIT
77
76
  metadata:
78
- homepage_uri: https://github.com/aileron-inc/view_component_in_css
77
+ homepage_uri: https://github.com/aileron-inc/view_component_scoped_css
79
78
  source_code_uri: https://github.com/aileron-inc/view_component_scoped_css
80
79
  changelog_uri: https://github.com/aileron-inc/view_component_scoped_css/blob/master/CHANGELOG.md
81
80
  rubygems_mfa_required: 'true'
@@ -94,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
93
  - !ruby/object:Gem::Version
95
94
  version: '0'
96
95
  requirements: []
97
- rubygems_version: 3.2.22
96
+ rubygems_version: 3.4.3
98
97
  signing_key:
99
98
  specification_version: 4
100
99
  summary: Provides view_component with scss in the form of css modules
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ViewComponentScopedCss
4
- #
5
- # Hook before_render to view component to provide inline css
6
- #
7
- module Hook
8
- extend ActiveSupport::Concern
9
- included do
10
- include ActiveSupport::Callbacks
11
- define_callbacks :render
12
- end
13
-
14
- def before_render
15
- run_callbacks :render do
16
- ViewComponentScopedCss::CurrentContext.add(self.class)
17
- end
18
- end
19
-
20
- class_methods do
21
- def before_render(&block)
22
- set_callback(:render, :before, &block)
23
- end
24
- end
25
- end
26
- end