render_kit 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0d9238ff2f0924852214bf0e648ce4a91ee8836163445a40597af6fa4d9f1eaf
4
+ data.tar.gz: d02a60c9604844aa656adb43fa31cade45ce4c734dacf05c8f92ec61806a64ed
5
+ SHA512:
6
+ metadata.gz: d2e3259a14ac106df5246fcc62fc01f85c12c0e8b2aa347cd658eeb3137f85232bc8631704e13cdeada0feec0477f5d533354be9ecbe0f80d41f4bdbf9f2f172
7
+ data.tar.gz: 7e3c4d01f46ca67d620d8452e9f6d9ab1a5bea3545e954cf5297cd8e75aab9ad714057ed33162907af0e8cece9184d99e4492a63a317d847d02fe74106e93e30
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.0
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
data/Appraisals ADDED
@@ -0,0 +1,14 @@
1
+ appraise "rails-7.0" do
2
+ gem "rails", "~> 7.0"
3
+ gem "view_component", "~> 3.13.0"
4
+ end
5
+
6
+ appraise "rails-7.1" do
7
+ gem "rails", "~> 7.1"
8
+ gem "view_component", "~> 3.13.0"
9
+ end
10
+
11
+ appraise "rails-7.2" do
12
+ gem "rails", "~> 7.2"
13
+ gem "view_component", "~> 3.13.0"
14
+ end
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-08-20
4
+
5
+ - Add controller implicit rendering
6
+ - Add view implicit rendering
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # RenderKit
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/render_kit`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ 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.
26
+
27
+ 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).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/render_kit. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/render_kit/blob/main/CODE_OF_CONDUCT.md).
32
+
33
+ ## Code of Conduct
34
+
35
+ Everyone interacting in the RenderKit project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/render_kit/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ require "rubocop/rake_task"
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[test]
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rake", "~> 13.0"
6
+ gem "minitest", "~> 5.16"
7
+ gem "rubocop", "~> 1.21"
8
+ gem "rails", "~> 7.0"
9
+ gem "view_component", "~> 3.13.0"
10
+
11
+ gemspec path: "../"
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rake", "~> 13.0"
6
+ gem "minitest", "~> 5.16"
7
+ gem "rubocop", "~> 1.21"
8
+ gem "rails", "~> 7.1"
9
+ gem "view_component", "~> 3.13.0"
10
+
11
+ gemspec path: "../"
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rake", "~> 13.0"
6
+ gem "minitest", "~> 5.16"
7
+ gem "rubocop", "~> 1.21"
8
+ gem "rails", "~> 7.2"
9
+ gem "view_component", "~> 3.13.0"
10
+
11
+ gemspec path: "../"
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails"
4
+
5
+ require "render_kit/view_paths_monkey_patch"
6
+ require "render_kit/rendering_helper_monkey_patch"
7
+ require "render_kit/implicit_render_monkey_patch"
8
+
9
+ module RenderKit
10
+ class Engine < ::Rails::Engine # :nodoc:
11
+ initializer "render_kit.action_view" do |app|
12
+ ActiveSupport.on_load(:action_view) do
13
+ ActionView::LookupContext.include RenderKit::ViewPathsMonkeyPatch
14
+ ActionView::Base.include RenderKit::ViewPathsMonkeyPatch
15
+ ActionView::Base.prepend RenderKit::RenderingHelperMonkeyPatch
16
+ end
17
+ end
18
+
19
+ initializer "render_kit.action_controller" do |app|
20
+ ActiveSupport.on_load(:action_controller) do
21
+ ActionController::Base.prepend RenderKit::RenderingHelperMonkeyPatch
22
+ ActionController::Base.prepend RenderKit::ImplicitRenderMonkeyPatch
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,19 @@
1
+ # frozen string literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module RenderKit
6
+ module ImplicitRenderMonkeyPatch
7
+ def default_render
8
+ if renderable = find_renderable(action_name.to_s, _prefixes)
9
+ render(renderable.new)
10
+ else
11
+ super
12
+ end
13
+ end
14
+
15
+ def find_renderable(action_name, prefixes)
16
+ RenderKit::RenderableRegistry.get_renderables([prefixes, action_name].join("_"), controller=true)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RenderKit
4
+ module RenderableRegistry # :nodoc:
5
+ @renderables = Hash.new { |h, k| h[k] = {} }
6
+
7
+ def self.get_renderables(path, controller=false)
8
+ if controller
9
+ renderable = @renderables[path]
10
+ renderable[:renderable_klass] if renderable&.[](:controller_render)
11
+ else
12
+ @renderables[path][:renderable_klass]
13
+ end
14
+ end
15
+
16
+ def self.set_renderable(path, renderable_klass, controller_render=false)
17
+ @renderables[path] = {
18
+ renderable_klass: renderable_klass,
19
+ controller_render: controller_render
20
+ }
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ # frozen string literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module RenderKit
6
+ module RenderingHelperMonkeyPatch
7
+ def render(options = {}, locals = {}, &)
8
+ if renderable = RenderKit::RenderableRegistry.get_renderables(options)
9
+ renderable.new(locals).render_in(self, &)
10
+ else
11
+ super
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RenderKit
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,15 @@
1
+ # frozen string literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module RenderKit
6
+ module ViewPathsMonkeyPatch
7
+ extend ActiveSupport::Concern
8
+
9
+ module ClassMethods
10
+ def register_renderable(path, renderable_klass, controller_render=false)
11
+ RenderKit::RenderableRegistry.set_renderable(path, renderable_klass, controller_render)
12
+ end
13
+ end
14
+ end
15
+ end
data/lib/render_kit.rb ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "render_kit/version"
4
+ require "active_support/dependencies/autoload"
5
+ require "render_kit/engine"
6
+ module RenderKit
7
+ extend ActiveSupport::Autoload
8
+
9
+ autoload :RenderableRegistry
10
+ end
@@ -0,0 +1,4 @@
1
+ module RenderKit
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: render_kit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Reegan Viljoen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-08-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: appraisal
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.18'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.18'
55
+ - !ruby/object:Gem::Dependency
56
+ name: puma
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: standard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1'
83
+ description: A small library to allow claases to be rendered oike partials in Rails
84
+ email:
85
+ - reeganviljoen@outlook.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".rubocop.yml"
91
+ - Appraisals
92
+ - CHANGELOG.md
93
+ - CODE_OF_CONDUCT.md
94
+ - README.md
95
+ - Rakefile
96
+ - gemfiles/rails_7.0.gemfile
97
+ - gemfiles/rails_7.1.gemfile
98
+ - gemfiles/rails_7.2.gemfile
99
+ - lib/render_kit.rb
100
+ - lib/render_kit/engine.rb
101
+ - lib/render_kit/implicit_render_monkey_patch.rb
102
+ - lib/render_kit/renderable_registry.rb
103
+ - lib/render_kit/rendering_helper_monkey_patch.rb
104
+ - lib/render_kit/version.rb
105
+ - lib/render_kit/view_paths_monkey_patch.rb
106
+ - sig/render_kit.rbs
107
+ homepage: https://github.com/reeganviljoen/render_kit
108
+ licenses: []
109
+ metadata:
110
+ homepage_uri: https://github.com/reeganviljoen/render_kit
111
+ source_code_uri: https://github.com/reeganviljoen/render_kit
112
+ changelog_uri: https://github.com/reeganviljoen/render_kit/blob/main/CHANGELOG.md
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: 3.0.0
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubygems_version: 3.5.13
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: A small library to allow claases to be rendered oike partials in Rails
132
+ test_files: []