rbexy 0.2.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -2
- data/Gemfile.lock +1 -1
- data/docker-compose.yml +12 -0
- data/lib/rbexy/component.rb +18 -46
- data/lib/rbexy/configuration.rb +1 -0
- data/lib/rbexy/lexer.rb +1 -1
- data/lib/rbexy/nodes.rb +6 -3
- data/lib/rbexy/output_buffer.rb +4 -2
- data/lib/rbexy/rails.rb +2 -0
- data/lib/rbexy/rails/component_template_resolver.rb +35 -0
- data/lib/rbexy/rails/controller_helper.rb +20 -0
- data/lib/rbexy/rails/engine.rb +2 -2
- data/lib/rbexy/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e21e51ccf4a683d3f4c26ef53af86382de7fd9b26e3db2a0790fdf6d7e3df800
|
4
|
+
data.tar.gz: f956dd52d3e20229df1290269f17fe28a7cd352cfa4b2c5649ede1f38f8bb9dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e792baa90cab354b588425c5a5851c5c23372c7cafcdb34e65d79bdd8a75b7271668dd02867a4987f6687ee704d4f8d63201e5192cb49a9fa27377610968fb07
|
7
|
+
data.tar.gz: 3d022540841d61746e14b909c70e3e7e769c78e6d03bbc5ca87dd6f611043a197309e83ab068a903089a201f88f7941edd5c1effc68497bb156ec203da2814bc
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/docker-compose.yml
CHANGED
@@ -6,6 +6,7 @@ volumes:
|
|
6
6
|
services:
|
7
7
|
rbexy:
|
8
8
|
build: .
|
9
|
+
image: rbexy
|
9
10
|
volumes:
|
10
11
|
- .:/app
|
11
12
|
- bundle:/usr/local/bundle
|
@@ -13,3 +14,14 @@ services:
|
|
13
14
|
- $HOME/.gitconfig:/root/.gitconfig:ro
|
14
15
|
- $HOME/.gem/credentials:/root/.gem/credentials
|
15
16
|
working_dir: /app
|
17
|
+
dummy:
|
18
|
+
image: rbexy
|
19
|
+
volumes:
|
20
|
+
- .:/app
|
21
|
+
- bundle:/usr/local/bundle
|
22
|
+
working_dir: /app/spec/dummy/
|
23
|
+
command: ./start.sh
|
24
|
+
ports:
|
25
|
+
- 3000:3000
|
26
|
+
environment:
|
27
|
+
- RAILS_LOG_STDOUT=1
|
data/lib/rbexy/component.rb
CHANGED
@@ -1,22 +1,20 @@
|
|
1
1
|
require "action_view"
|
2
|
+
require "active_support/core_ext/class/attribute"
|
2
3
|
|
3
4
|
module Rbexy
|
4
5
|
class Component < ActionView::Base
|
5
|
-
class
|
6
|
-
def
|
7
|
-
|
8
|
-
value = key == :locale ? [context.locale] : context.send(key)
|
9
|
-
details_hash[key] = value
|
10
|
-
end
|
6
|
+
class TemplatePath < String
|
7
|
+
def to_s
|
8
|
+
self
|
11
9
|
end
|
10
|
+
end
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
12
|
+
def self.component_name
|
13
|
+
name.underscore
|
14
|
+
end
|
15
|
+
|
16
|
+
def component_name
|
17
|
+
self.class.component_name
|
20
18
|
end
|
21
19
|
|
22
20
|
def initialize(view_context, **props)
|
@@ -37,20 +35,18 @@ module Rbexy
|
|
37
35
|
def setup(**props); end
|
38
36
|
|
39
37
|
def render(&block)
|
40
|
-
@content = nil
|
41
38
|
@content_block = block_given? ? block : nil
|
42
39
|
call
|
43
40
|
end
|
44
41
|
|
45
42
|
def call
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
restore_lookup_context
|
43
|
+
path = TemplatePath.new(component_name)
|
44
|
+
template = view_context.lookup_context.find(path)
|
45
|
+
template.render(self, {})
|
50
46
|
end
|
51
47
|
|
52
48
|
def content
|
53
|
-
|
49
|
+
content_block ? view_context.capture(self, &content_block) : ""
|
54
50
|
end
|
55
51
|
|
56
52
|
def create_context(name, value)
|
@@ -64,37 +60,13 @@ module Rbexy
|
|
64
60
|
raise(ContextNotFound, "no parent context `#{name}`")
|
65
61
|
end
|
66
62
|
|
67
|
-
def
|
68
|
-
|
69
|
-
end
|
70
|
-
|
71
|
-
def component_name
|
72
|
-
self.class.name.underscore
|
63
|
+
def compiled_method_container
|
64
|
+
Rbexy::Component
|
73
65
|
end
|
74
66
|
|
75
67
|
private
|
76
68
|
|
77
|
-
attr_reader :view_context, :content_block
|
78
|
-
|
79
|
-
def replace_lookup_context
|
80
|
-
return if view_renderer.lookup_context.is_a? Rbexy::Component::LookupContext
|
81
|
-
@old_lookup_context = view_renderer.lookup_context
|
82
|
-
view_renderer.lookup_context = build_lookup_context(old_lookup_context)
|
83
|
-
end
|
84
|
-
|
85
|
-
def restore_lookup_context
|
86
|
-
return unless old_lookup_context
|
87
|
-
view_renderer.lookup_context = old_lookup_context
|
88
|
-
@old_lookup_context = nil
|
89
|
-
end
|
90
|
-
|
91
|
-
def build_lookup_context(existing_context)
|
92
|
-
paths = existing_context.view_paths.dup.unshift(
|
93
|
-
*Rbexy.configuration.template_paths.map { |p| ActionView::OptimizedFileSystemResolver.new(p) }
|
94
|
-
)
|
95
|
-
|
96
|
-
LookupContext.new(paths, LookupContext.details_hash(existing_context))
|
97
|
-
end
|
69
|
+
attr_reader :view_context, :content_block
|
98
70
|
|
99
71
|
def method_missing(meth, *args, &block)
|
100
72
|
if view_context.respond_to?(meth)
|
data/lib/rbexy/configuration.rb
CHANGED
data/lib/rbexy/lexer.rb
CHANGED
data/lib/rbexy/nodes.rb
CHANGED
@@ -85,11 +85,14 @@ module Rbexy
|
|
85
85
|
base_tag
|
86
86
|
end
|
87
87
|
|
88
|
+
context_open = Rbexy.configuration.enable_context ? "rbexy_context.push({});" : nil
|
89
|
+
context_close = Rbexy.configuration.enable_context ? "rbexy_context.pop;" : nil
|
90
|
+
|
88
91
|
[
|
89
92
|
"Rbexy::OutputBuffer.new.tap { |output|",
|
90
|
-
|
91
|
-
"output << (#{tag});",
|
92
|
-
|
93
|
+
context_open,
|
94
|
+
"output << (#{tag}).html_safe;",
|
95
|
+
context_close,
|
93
96
|
"}.html_safe"
|
94
97
|
].join(" ")
|
95
98
|
end
|
data/lib/rbexy/output_buffer.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
+
require "active_support/core_ext/string/output_safety"
|
2
|
+
|
1
3
|
module Rbexy
|
2
|
-
class OutputBuffer <
|
4
|
+
class OutputBuffer < ActiveSupport::SafeBuffer
|
3
5
|
def <<(content)
|
4
|
-
value = content.is_a?(Array) ? content.join : content
|
6
|
+
value = content.is_a?(Array) ? content.join.html_safe : content
|
5
7
|
super([nil, false].include?(value) ? "" : value.to_s)
|
6
8
|
end
|
7
9
|
end
|
data/lib/rbexy/rails.rb
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
require "action_view"
|
2
|
+
|
3
|
+
module Rbexy
|
4
|
+
module Rails
|
5
|
+
class ComponentTemplateResolver < ActionView::FileSystemResolver
|
6
|
+
# Rails 6 requires us to override `_find_all` in order to hook
|
7
|
+
def _find_all(name, prefix, partial, details, key, locals)
|
8
|
+
find_templates(name, prefix, partial, details, locals)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Rails 5 only requires `find_templates` (which tbh is the proper way
|
12
|
+
# to implement subclasses of ActionView::Resolver)
|
13
|
+
def find_templates(name, prefix, partial, details, locals = [])
|
14
|
+
return [] unless name.is_a? Rbexy::Component::TemplatePath
|
15
|
+
|
16
|
+
templates_path = File.join(@path, prefix, name)
|
17
|
+
extensions = details[:handlers].join(",")
|
18
|
+
|
19
|
+
Dir["#{templates_path}.*{#{extensions}}"].map do |template_path|
|
20
|
+
source = File.binread(template_path)
|
21
|
+
handler = ActionView::Template.handler_for_extension(File.extname(template_path)[1..-1])
|
22
|
+
virtual_path = ["rbexy_component", prefix, name].join("/")
|
23
|
+
|
24
|
+
ActionView::Template.new(
|
25
|
+
source,
|
26
|
+
template_path,
|
27
|
+
handler,
|
28
|
+
locals: [],
|
29
|
+
virtual_path: virtual_path
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "active_support/concern"
|
2
|
+
|
3
|
+
module Rbexy
|
4
|
+
module Rails
|
5
|
+
module ControllerHelper
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
def rbexy_component_provider; end
|
9
|
+
|
10
|
+
class_methods do
|
11
|
+
def inherited(klass)
|
12
|
+
super
|
13
|
+
Rbexy.configuration.template_paths.each do |path|
|
14
|
+
prepend_view_path(Rbexy::Rails::ComponentTemplateResolver.new(path))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/rbexy/rails/engine.rb
CHANGED
@@ -13,8 +13,7 @@ module Rbexy
|
|
13
13
|
ActiveSupport.on_load :action_controller_base do
|
14
14
|
helper Rbexy::ViewContextHelper
|
15
15
|
helper_method :rbexy_component_provider
|
16
|
-
|
17
|
-
def rbexy_component_provider; end
|
16
|
+
include ControllerHelper
|
18
17
|
end
|
19
18
|
|
20
19
|
if defined?(ViewComponent)
|
@@ -25,6 +24,7 @@ module Rbexy
|
|
25
24
|
require "rbexy/component_providers/rbexy_provider"
|
26
25
|
config.component_provider = Rbexy::ComponentProviders::RbexyProvider.new
|
27
26
|
config.template_paths << ::Rails.root.join("app", "components")
|
27
|
+
config.enable_context = true
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
data/lib/rbexy/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbexy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Giancola
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -235,6 +235,8 @@ files:
|
|
235
235
|
- lib/rbexy/output_buffer.rb
|
236
236
|
- lib/rbexy/parser.rb
|
237
237
|
- lib/rbexy/rails.rb
|
238
|
+
- lib/rbexy/rails/component_template_resolver.rb
|
239
|
+
- lib/rbexy/rails/controller_helper.rb
|
238
240
|
- lib/rbexy/rails/engine.rb
|
239
241
|
- lib/rbexy/runtime.rb
|
240
242
|
- lib/rbexy/version.rb
|