rbexy 0.1.0 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/lib/rbexy/component.rb +24 -17
- data/lib/rbexy/configuration.rb +0 -5
- data/lib/rbexy/lexer.rb +14 -2
- data/lib/rbexy/rails/engine.rb +6 -2
- data/lib/rbexy/version.rb +1 -1
- metadata +2 -3
- data/lib/rbexy/rails/template_handler.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2c4fd57eed2a80ab3e953e5ea7ca577723dad29e5af7d2fb1bc231171c359e6
|
4
|
+
data.tar.gz: 3f578fae5f23cab09d4b25744a933adcab8a119c72d3a937496298db9b235583
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7330738b406e5944b8b4c9d379f1527ec78745026e2505902149d32164ed8b074cbe8f485a2dcbdeae8e75e11339142e94d804bf1b0470d840313082fc73ce53
|
7
|
+
data.tar.gz: a900f8c4991796ef6719d4ed29bc6e7e60a7d04fdbee3fd29cc3ee38e50baa04597030dcac33c7e4c30f2af6b228e3e7cc863d348780732c77e0a4d80a5b9ba4
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/lib/rbexy/component.rb
CHANGED
@@ -43,11 +43,10 @@ module Rbexy
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def call
|
46
|
-
|
47
|
-
view_renderer.lookup_context = build_lookup_context(old_lookup_context)
|
46
|
+
replace_lookup_context
|
48
47
|
view_renderer.render(self, partial: component_name, &nil)
|
49
48
|
ensure
|
50
|
-
|
49
|
+
restore_lookup_context
|
51
50
|
end
|
52
51
|
|
53
52
|
def content
|
@@ -65,28 +64,36 @@ module Rbexy
|
|
65
64
|
raise(ContextNotFound, "no parent context `#{name}`")
|
66
65
|
end
|
67
66
|
|
67
|
+
def view_renderer
|
68
|
+
view_context.view_renderer
|
69
|
+
end
|
70
|
+
|
71
|
+
def component_name
|
72
|
+
self.class.name.underscore
|
73
|
+
end
|
74
|
+
|
68
75
|
private
|
69
76
|
|
70
|
-
attr_reader :view_context, :content_block
|
77
|
+
attr_reader :view_context, :content_block, :old_lookup_context
|
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
|
71
90
|
|
72
91
|
def build_lookup_context(existing_context)
|
73
92
|
paths = existing_context.view_paths.dup.unshift(
|
74
93
|
*Rbexy.configuration.template_paths.map { |p| ActionView::OptimizedFileSystemResolver.new(p) }
|
75
94
|
)
|
76
95
|
|
77
|
-
LookupContext.new(
|
78
|
-
paths,
|
79
|
-
LookupContext.details_hash(existing_context),
|
80
|
-
Rbexy.configuration.template_prefixes
|
81
|
-
)
|
82
|
-
end
|
83
|
-
|
84
|
-
def view_renderer
|
85
|
-
view_context.view_renderer
|
86
|
-
end
|
87
|
-
|
88
|
-
def component_name
|
89
|
-
self.class.name.underscore
|
96
|
+
LookupContext.new(paths, LookupContext.details_hash(existing_context))
|
90
97
|
end
|
91
98
|
|
92
99
|
def method_missing(meth, *args, &block)
|
data/lib/rbexy/configuration.rb
CHANGED
@@ -2,14 +2,9 @@ module Rbexy
|
|
2
2
|
class Configuration
|
3
3
|
attr_accessor :component_provider
|
4
4
|
attr_accessor :template_paths
|
5
|
-
attr_accessor :template_prefixes
|
6
5
|
|
7
6
|
def template_paths
|
8
7
|
@template_paths ||= []
|
9
8
|
end
|
10
|
-
|
11
|
-
def template_prefixes
|
12
|
-
@template_prefixes ||= []
|
13
|
-
end
|
14
9
|
end
|
15
10
|
end
|
data/lib/rbexy/lexer.rb
CHANGED
@@ -115,7 +115,7 @@ module Rbexy
|
|
115
115
|
expression_inner_single_quote
|
116
116
|
elsif scanner.scan(Patterns.open_tag_def)
|
117
117
|
potential_expression_inner_tag
|
118
|
-
elsif
|
118
|
+
elsif expression_content?
|
119
119
|
self.curr_expr += scanner.matched
|
120
120
|
else
|
121
121
|
raise SyntaxError, self
|
@@ -132,7 +132,7 @@ module Rbexy
|
|
132
132
|
expression_inner_single_quote
|
133
133
|
elsif scanner.scan(Patterns.open_tag_def)
|
134
134
|
potential_expression_inner_tag
|
135
|
-
elsif
|
135
|
+
elsif expression_content?
|
136
136
|
self.curr_expr += scanner.matched
|
137
137
|
else
|
138
138
|
raise SyntaxError, self
|
@@ -237,6 +237,7 @@ module Rbexy
|
|
237
237
|
end
|
238
238
|
|
239
239
|
def potential_expression_inner_tag
|
240
|
+
# binding.pry
|
240
241
|
if self.curr_expr =~ Patterns.expression_internal_tag_prefixes
|
241
242
|
tokens << [:EXPRESSION_BODY, curr_expr]
|
242
243
|
self.curr_expr = ""
|
@@ -275,5 +276,16 @@ module Rbexy
|
|
275
276
|
self.curr_expr += scanner.getch
|
276
277
|
stack.pop unless curr_expr.end_with?('\\')
|
277
278
|
end
|
279
|
+
|
280
|
+
def expression_content?
|
281
|
+
# Patterns.expression_content ends at `<` characters, because we need to
|
282
|
+
# separately scan for allowed open_tag_defs within expressions. We should
|
283
|
+
# support any found open_tag_ends as expression content, as that means the
|
284
|
+
# open_tag_def was not considered allowed (or stack would be inside
|
285
|
+
# :tag_def instead of :expression) so we should thus also consider the
|
286
|
+
# open_tag_end to just be a part of the expression (maybe its in a string,
|
287
|
+
# etc).
|
288
|
+
scanner.scan(Patterns.expression_content) || scanner.scan(Patterns.open_tag_end)
|
289
|
+
end
|
278
290
|
end
|
279
291
|
end
|
data/lib/rbexy/rails/engine.rb
CHANGED
@@ -4,9 +4,13 @@ module Rbexy
|
|
4
4
|
module Rails
|
5
5
|
class Engine < ::Rails::Engine
|
6
6
|
initializer "rbexy" do |app|
|
7
|
-
|
7
|
+
template_handler = ::Rails.version.to_f >= 6.0 ?
|
8
|
+
proc { |template, source| Rbexy.compile(source) } :
|
9
|
+
proc { |template| Rbexy.compile(template.source) }
|
8
10
|
|
9
|
-
|
11
|
+
ActionView::Template.register_template_handler(:rbx, template_handler)
|
12
|
+
|
13
|
+
ActiveSupport.on_load :action_controller_base do
|
10
14
|
helper Rbexy::ViewContextHelper
|
11
15
|
end
|
12
16
|
|
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.1.
|
4
|
+
version: 0.1.5
|
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-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -235,7 +235,6 @@ files:
|
|
235
235
|
- lib/rbexy/parser.rb
|
236
236
|
- lib/rbexy/rails.rb
|
237
237
|
- lib/rbexy/rails/engine.rb
|
238
|
-
- lib/rbexy/rails/template_handler.rb
|
239
238
|
- lib/rbexy/runtime.rb
|
240
239
|
- lib/rbexy/version.rb
|
241
240
|
- lib/rbexy/view_context_helper.rb
|