view_component_scoped_css 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ca24b914debb17569e059d451c0963f456c1431794e8f47d00267c2b2211f342
4
- data.tar.gz: 04b5d64c71a8843a3137bfb5df321f4ea0db95a5584eb7ed562b95653f30809f
3
+ metadata.gz: 1efadcc6268b2ae05a59c932fa65ac87c1ef3fa4cac6ba663db21319448f47f9
4
+ data.tar.gz: c0d4498cb5db29c1b348721430a789e3058947bae9e6046558cd539b3f3a8cd3
5
5
  SHA512:
6
- metadata.gz: 78144240a0d2f1a975015f5e3870b1a0b7c0807f2fe196d5bc7d23a408886549d8928864f9c6819c47f3c0d53f69d19b3295875f0f85d9cd1e8dca0eb211dca5
7
- data.tar.gz: a79a5ded14cbf384942bcaa215b5f20373bb61dd66094f4ea0197a157baee0ad4f36aa21ad130d9dfe1f347fdd57c4797113b7ea06c8d03b0754a5fffe014644
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,17 +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
- def reload_component_css_tag
17
- @component_css_tag = ViewComponentScopedCss::Tag.new(self).call
18
- end
19
-
20
12
  def component_css_tag
21
- @component_css_tag ||= ViewComponentScopedCss::Tag.new(self).call
13
+ ViewComponentScopedCss::CurrentContext.render_if_need(self)
22
14
  end
23
15
 
24
16
  def component_identifier
@@ -38,12 +30,16 @@ module ViewComponentScopedCss
38
30
  self.class.component_identifier_for_css
39
31
  end
40
32
 
41
- def component_tag(name = ViewComponentScopedCss.config.component_tag, &block)
42
- content_tag(
43
- name,
44
- class: [self.class.component_identifier_for_css, component_options[:class]].compact.join(" "),
45
- **component_options,
46
- &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
47
43
  )
48
44
  end
49
45
  end
@@ -2,22 +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)
17
- self.css ||= {}
18
- self.css[view_component.class.name] ||= view_component.class.component_css_tag
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
19
18
  end
20
19
 
21
- resets { self.css = {} }
20
+ resets { self.called = {} }
22
21
  end
23
22
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ViewComponentScopedCss
4
- VERSION = "0.1.1"
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.1
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-11-20 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,35 +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
- if ViewComponentScopedCss.config.compile_cache
15
- def before_render
16
- run_callbacks :render do
17
- ViewComponentScopedCss::CurrentContext.add(self)
18
- end
19
- end
20
- else
21
- def before_render
22
- run_callbacks :render do
23
- self.class.reload_component_css_tag
24
- ViewComponentScopedCss::CurrentContext.add(self)
25
- end
26
- end
27
- end
28
-
29
- class_methods do
30
- def before_render(&block)
31
- set_callback(:render, :before, &block)
32
- end
33
- end
34
- end
35
- end