proscenium-view_component 0.1.0.beta1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a456f5347c34b3cc3493a5fad3ebe4d040c94a38aab761b1a66a7f69d4ee69e2
4
+ data.tar.gz: 9b78f7e2ab948e3045c38390551e6b1e971e9671536613ac034b92ae2a1af988
5
+ SHA512:
6
+ metadata.gz: e936e9332f9d83e13247564744e834b792386a24d1cfacfda735b749186f0aa5044d2734416872b202418a188216570e2ea98dead25ea4a20fc444f98e270543
7
+ data.tar.gz: f3b61b88680a7f4591a568c5f3b25f71bb823472993c8a1a2a79f0775ce689d4ad3d9d8ae3843c62668d6afc7246ed53344cd52633bbb2bc096bb2b309169bdd
data/.rubocop.yml ADDED
@@ -0,0 +1,47 @@
1
+ plugins:
2
+ - rubocop-rails
3
+ - rubocop-minitest
4
+ - rubocop-disable_syntax
5
+ - rubocop-capybara
6
+ - rubocop-packaging
7
+ - rubocop-rake
8
+ - rubocop-performance
9
+
10
+ AllCops:
11
+ TargetRubyVersion: 3.3
12
+ NewCops: enable
13
+ SuggestExtensions: false
14
+ Exclude:
15
+ - "gemfiles/**/*"
16
+
17
+ Layout/LineLength:
18
+ Max: 100
19
+ Layout/IndentationConsistency:
20
+ EnforcedStyle: indented_internal_methods
21
+
22
+ Lint/ConstantDefinitionInBlock:
23
+ Exclude:
24
+ - "test/**/*"
25
+
26
+ Metrics:
27
+ Enabled: false
28
+
29
+ Style/DisableSyntax:
30
+ DisableSyntax:
31
+ - unless
32
+ - and_or_not
33
+ - numbered_parameters
34
+
35
+ Style/CaseEquality:
36
+ Enabled: false
37
+ Style/Documentation:
38
+ Enabled: false
39
+ Style/ClassAndModuleChildren:
40
+ Enabled: false
41
+ Style/NegatedIf:
42
+ Enabled: false
43
+
44
+ Minitest/EmptyLineBeforeAssertionMethods:
45
+ Enabled: false
46
+ Minitest/MultipleAssertions:
47
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.4.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Joel Moss
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # Proscenium::ViewComponent
2
+
3
+ Enhances [ViewComponent](https://viewcomponent.org/) by integrating it with the [Proscenium](https://proscenium.rocks/) framework. It supports automatic side-loading of assets, and CSS Modules for scoped styling.
4
+
5
+ ## Installation
6
+
7
+ Install the gem and add to the application's Gemfile by executing:
8
+
9
+ ```bash
10
+ bundle add proscenium-view_component
11
+ ```
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ ```bash
16
+ gem install proscenium-view_component
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ Simply write your ViewComponent classes and inherit from `Proscenium::ViewComponent::Base`.
22
+
23
+ ```ruby
24
+ class MyView < Proscenium::ViewComponent::Base
25
+ def call
26
+ tag.h1 'Hello World'
27
+ end
28
+ end
29
+ ```
30
+
31
+ ### Side-loading
32
+
33
+ Any ViewComponent class that inherits `Proscenium::ViewComponent::Base` will automatically be [side-loaded](https://github.com/joelmoss/proscenium?tab=readme-ov-file#side-loading).
34
+
35
+ ### CSS Modules
36
+
37
+ [CSS Modules](https://github.com/joelmoss/proscenium?tab=readme-ov-file#css-modules) are fully supported in ViewComponent classes, with access to the [`css_module` helper](https://github.com/joelmoss/proscenium?tab=readme-ov-file#in-your-views) if you need it.
38
+
39
+ ```ruby
40
+ # /app/components/user_component.rb
41
+ class UserComponent < Proscenium::ViewComponent::Base
42
+ def view_template
43
+ div.h1 @user.name, class: css_module(:user_name)
44
+ end
45
+ end
46
+ ```
47
+
48
+ ```css
49
+ /* # /app/components/user_component.module.css */
50
+ .userName {
51
+ color: red;
52
+ font-size: 50px;
53
+ }
54
+ ```
55
+
56
+ The view above will be rendered something like this:
57
+
58
+ ```html
59
+ <h1 class="user_name-ABCD1234">Joel Moss</h1>
60
+ ```
61
+
62
+ ## Development
63
+
64
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
65
+
66
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
67
+
68
+ ## Contributing
69
+
70
+ Bug reports and pull requests are welcome on GitHub at https://github.com/joelmoss/proscenium-view_component.
71
+
72
+ ## License
73
+
74
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/setup'
4
+
5
+ APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
6
+ load 'rails/tasks/engine.rake'
7
+
8
+ load 'rails/tasks/statistics.rake'
9
+
10
+ require 'bundler/gem_tasks'
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Proscenium::ViewComponent
4
+ class Base < ::ViewComponent::Base
5
+ include Proscenium::SourcePath
6
+ include CssModules
7
+
8
+ class_attribute :sideload_assets_options
9
+
10
+ class << self
11
+ attr_accessor :abstract_class
12
+
13
+ def inherited(child)
14
+ child.prepend Sideload
15
+
16
+ super
17
+ end
18
+
19
+ def sideload_assets(value)
20
+ self.sideload_assets_options = value
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Proscenium
4
+ module ViewComponent::CssModules
5
+ include Proscenium::CssModule
6
+
7
+ def self.included(base)
8
+ base.extend Proscenium::CssModule::Path
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Proscenium
4
+ module ViewComponent
5
+ class Engine < ::Rails::Engine
6
+ isolate_namespace Proscenium::ViewComponent
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Proscenium::ViewComponent
4
+ # Renders a <div> for use with React components, with data attributes specifying the component
5
+ # path and props.
6
+ #
7
+ # If a content block is given, that content will be rendered inside the component, allowing for a
8
+ # "loading" UI. If no block is given, then a "loading..." text will be rendered. It is intended
9
+ # that the component is mounted to this div, and the loading UI will then be replaced with the
10
+ # component's rendered output.
11
+ class ReactComponent < Base
12
+ self.abstract_class = true
13
+
14
+ include Proscenium::ReactComponentable
15
+
16
+ def call
17
+ tag.send root_tag, data: data_attributes do
18
+ tag.div content || 'loading...'
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Proscenium::ViewComponent
4
+ module Sideload
5
+ def before_render
6
+ Proscenium::SideLoad.sideload_inheritance_chain self, controller.sideload_assets_options
7
+
8
+ super
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Proscenium
4
+ module ViewComponent
5
+ VERSION = '0.1.0.beta1'
6
+ end
7
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support'
4
+ require 'proscenium'
5
+ require 'view_component'
6
+
7
+ module Proscenium
8
+ module ViewComponent
9
+ class Error < StandardError; end
10
+
11
+ extend ActiveSupport::Autoload
12
+
13
+ autoload :Base
14
+ autoload :Sideload
15
+ autoload :ReactComponent
16
+ autoload :CssModules
17
+ end
18
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: proscenium-view_component
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.beta1
5
+ platform: ruby
6
+ authors:
7
+ - Joel Moss
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: proscenium
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: 0.19.0.beta17
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: 0.19.0.beta17
26
+ - !ruby/object:Gem::Dependency
27
+ name: rails
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 7.1.0
33
+ - - "<"
34
+ - !ruby/object:Gem::Version
35
+ version: '9.0'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 7.1.0
43
+ - - "<"
44
+ - !ruby/object:Gem::Version
45
+ version: '9.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: view_component
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: 3.22.0
53
+ type: :runtime
54
+ prerelease: false
55
+ version_requirements: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: 3.22.0
60
+ description: Proscenium integration for ViewComponent
61
+ email:
62
+ - joel@developwithstyle.com
63
+ executables: []
64
+ extensions: []
65
+ extra_rdoc_files: []
66
+ files:
67
+ - ".rubocop.yml"
68
+ - ".ruby-version"
69
+ - LICENSE.txt
70
+ - README.md
71
+ - Rakefile
72
+ - lib/proscenium/view_component.rb
73
+ - lib/proscenium/view_component/base.rb
74
+ - lib/proscenium/view_component/css_modules.rb
75
+ - lib/proscenium/view_component/engine.rb
76
+ - lib/proscenium/view_component/react_component.rb
77
+ - lib/proscenium/view_component/sideload.rb
78
+ - lib/proscenium/view_component/version.rb
79
+ homepage: https://github.com/joelmoss/proscenium-view_component
80
+ licenses:
81
+ - MIT
82
+ metadata:
83
+ homepage_uri: https://github.com/joelmoss/proscenium-view_component
84
+ source_code_uri: https://github.com/joelmoss/proscenium-view_component
85
+ changelog_uri: https://github.com/joelmoss/proscenium-view_component/releases
86
+ rubygems_mfa_required: 'true'
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 3.3.0
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubygems_version: 3.6.7
102
+ specification_version: 4
103
+ summary: Proscenium integration for ViewComponent
104
+ test_files: []