Skip to content

Commit

Permalink
add: working poc
Browse files Browse the repository at this point in the history
  • Loading branch information
reeganviljoen committed Aug 18, 2024
1 parent e364805 commit 16a542d
Show file tree
Hide file tree
Showing 44 changed files with 808 additions and 38 deletions.
49 changes: 44 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,47 @@
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
*.gem
*.rbc
.ruby-version
/.config
/coverage/assets
/coverage/index.html
/coverage/*.json
/coverage/*.json.lock
/InstalledFiles
/pkg/
/spec/reports/
/spec/examples.txt
/test/tmp/
/test/version_tmp/
/tmp/
/test/log/*
/test/sandbox/tmp/*
/test/sandbox/log/*
/test/tmp/*
/.yardoc

## Specific to RubyMotion:
.dat*
.repl_history
build/
*.bridgesupport
build-iPhoneOS/
build-iPhoneSimulator/

## Documentation cache and generated files:
/doc/
/rdoc/

## Environment normalization:
/.bundle/
/vendor/bundle
/lib/bundler/man/

# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
.rvmrc

# Sample bug replication repo
/replicate-bug

# Appraisal
/gemfiles/*.gemfile.lock
/gemfiles/.bundle/
14 changes: 14 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
appraise "rails-7.0" do
gem "rails", "~> 7.0"
gem "view_component", "~> 3.13.0"
end

appraise "rails-7.1" do
gem "rails", "~> 7.1"
gem "view_component", "~> 3.13.0"
end

appraise "rails-7.2" do
gem "rails", "~> 7.2"
gem "view_component", "~> 3.13.0"
end
83 changes: 83 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
PATH
remote: .
specs:
render_kit (0.1.0)

GEM
remote: https://rubygems.org/
specs:
appraisal (2.5.0)
bundler
rake
thor (>= 0.14.0)
ast (2.4.2)
json (2.7.2)
language_server-protocol (3.17.0.3)
lint_roller (1.1.0)
minitest (5.25.0)
nio4r (2.7.3)
parallel (1.26.2)
parser (3.3.4.2)
ast (~> 2.4.1)
racc
puma (6.4.2)
nio4r (~> 2.0)
racc (1.8.1)
rainbow (3.1.1)
rake (13.2.1)
regexp_parser (2.9.2)
rexml (3.3.5)
strscan
rubocop (1.65.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.4, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.32.0)
parser (>= 3.3.1.0)
rubocop-performance (1.21.1)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (1.13.0)
standard (1.34.0)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.60)
standard-custom (~> 1.0.0)
standard-performance (~> 1.3)
standard-custom (1.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.50)
standard-performance (1.4.0)
lint_roller (~> 1.1)
rubocop-performance (~> 1.21.0)
strscan (3.1.0)
thor (1.3.1)
unicode-display_width (2.5.0)

PLATFORMS
aarch64-linux
arm-linux
arm64-darwin
x86-linux
x86_64-darwin
x86_64-linux

DEPENDENCIES
appraisal
bundler (~> 2)
minitest (~> 5.16)
puma (~> 6)
rake (~> 13.0)
render_kit!
rubocop (~> 1.21)
standard (~> 1)

BUNDLED WITH
2.5.13
10 changes: 7 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# frozen_string_literal: true

require "bundler/gem_tasks"
require "minitest/test_task"
require "rake/testtask"

Minitest::TestTask.create
Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"]
end

require "rubocop/rake_task"

RuboCop::RakeTask.new

task default: %i[test rubocop]
task default: %i[test]
11 changes: 11 additions & 0 deletions gemfiles/rails_7.0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rake", "~> 13.0"
gem "minitest", "~> 5.16"
gem "rubocop", "~> 1.21"
gem "rails", "~> 7.0"
gem "view_component", "~> 3.13.0"

gemspec path: "../"
11 changes: 11 additions & 0 deletions gemfiles/rails_7.1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rake", "~> 13.0"
gem "minitest", "~> 5.16"
gem "rubocop", "~> 1.21"
gem "rails", "~> 7.1"
gem "view_component", "~> 3.13.0"

gemspec path: "../"
11 changes: 11 additions & 0 deletions gemfiles/rails_7.2.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rake", "~> 13.0"
gem "minitest", "~> 5.16"
gem "rubocop", "~> 1.21"
gem "rails", "~> 7.2"
gem "view_component", "~> 3.13.0"

gemspec path: "../"
10 changes: 6 additions & 4 deletions lib/render_kit.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# frozen_string_literal: true

require_relative "render_kit/version"

require "render_kit/version"
require "active_support/dependencies/autoload"
require "render_kit/engine"
module RenderKit
class Error < StandardError; end
# Your code goes here...
extend ActiveSupport::Autoload

autoload :RenderableRegistry
end
18 changes: 18 additions & 0 deletions lib/render_kit/engine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

require "rails"

require "render_kit/view_paths_monkey_patch"
require "render_kit/rendering_helper_monkey_patch"

module RenderKit
class Engine < ::Rails::Engine # :nodoc:
initializer "render_kit.action_view" do |app|
ActiveSupport.on_load(:action_view) do
ActionView::LookupContext.include RenderKit::ViewPathsMonkeyPatch
ActionView::Base.include RenderKit::ViewPathsMonkeyPatch
ActionView::Base.prepend RenderKit::RenderingHelperMonkeyPatch
end
end
end
end
15 changes: 15 additions & 0 deletions lib/render_kit/renderable_registry.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module RenderKit
module RenderableRegistry # :nodoc:
@renderables = Hash.new {}

def self.get_renderables(path)
@renderables[path]
end

def self.set_renderable(path, renderable_klass)
@renderables[path] = renderable_klass
end
end
end
15 changes: 15 additions & 0 deletions lib/render_kit/rendering_helper_monkey_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen string literal: true

require "active_support/concern"

module RenderKit
module RenderingHelperMonkeyPatch
def render(options = {}, locals = {}, &)
if renderable = RenderKit::RenderableRegistry.get_renderables(options)
renderable.new(locals).render_in(self, &)
else
super
end
end
end
end
15 changes: 15 additions & 0 deletions lib/render_kit/view_paths_monkey_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen string literal: true

require "active_support/concern"

module RenderKit
module ViewPathsMonkeyPatch
extend ActiveSupport::Concern

module ClassMethods
def register_renderable(path, renderable_klass)
RenderKit::RenderableRegistry.set_renderable(path, renderable_klass)
end
end
end
end
22 changes: 11 additions & 11 deletions render_kit.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ Gem::Specification.new do |spec|
spec.authors = ["Reegan Viljoen"]
spec.email = ["[email protected]"]

spec.summary = "TODO: Write a short summary, because RubyGems requires one."
spec.description = "TODO: Write a longer description or delete this line."
spec.homepage = "TODO: Put your gem's website or public repo URL here."
spec.summary = "A small library to allow claases to be rendered oike partials in Rails"
spec.description = "A small library to allow claases to be rendered oike partials in Rails"
# spec.homepage = "TODO: Put your gem's website or public repo URL here."
spec.required_ruby_version = ">= 3.0.0"

spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"

spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
# spec.metadata["homepage_uri"] = spec.homepage
# spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."

# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
Expand All @@ -32,9 +32,9 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

# Uncomment to register a new dependency of your gem
# spec.add_dependency "example-gem", "~> 1.0"

# For more information and examples about making a new gem, check out our
# guide at: https://bundler.io/guides/creating_gem.html
spec.add_development_dependency "appraisal"
spec.add_development_dependency "bundler", "~> 2"
spec.add_development_dependency "minitest", "~> 5.18"
spec.add_development_dependency "puma", "~> 6"
spec.add_development_dependency "standard", "~> 1"
end
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div> I have been implicity rendered </div>
5 changes: 5 additions & 0 deletions test/sandbox/app/components/implicit_render_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class ImplicitRenderComponent < ViewComponent::Base
ActionView::Base.register_renderable("implicit_render_component", ImplicitRenderComponent)
end
4 changes: 4 additions & 0 deletions test/sandbox/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class ApplicationController < ActionController::Base
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
allow_browser versions: :modern
end
Empty file.
6 changes: 6 additions & 0 deletions test/sandbox/app/controllers/test_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class TestController < ActionController::Base
protect_from_forgery

def component_implicit_render
end
end
2 changes: 2 additions & 0 deletions test/sandbox/app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ApplicationHelper
end
23 changes: 23 additions & 0 deletions test/sandbox/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<title><%= content_for(:title) || "Sandbox" %></title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>

<%= yield :head %>

<link rel="manifest" href="/manifest.json">
<link rel="icon" href="/icon.png" type="image/png">
<link rel="icon" href="/icon.svg" type="image/svg+xml">
<link rel="apple-touch-icon" href="/icon.png">
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
<%= javascript_importmap_tags %>
</head>

<body>
<%= yield %>
</body>
</html>
13 changes: 13 additions & 0 deletions test/sandbox/app/views/layouts/mailer.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
/* Email styles need to be inline */
</style>
</head>

<body>
<%= yield %>
</body>
</html>
1 change: 1 addition & 0 deletions test/sandbox/app/views/layouts/mailer.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= yield %>
Loading

0 comments on commit 16a542d

Please sign in to comment.