rbexy 0.1.0 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f380f26df4a04d8cc73a9a65b5abaad571a32670013eabb3465eaa7f08ab1de4
4
- data.tar.gz: e729b87a8e1ec2918dce115b240bfbea991a11203d73f003a42cccb972544c93
3
+ metadata.gz: f2c4fd57eed2a80ab3e953e5ea7ca577723dad29e5af7d2fb1bc231171c359e6
4
+ data.tar.gz: 3f578fae5f23cab09d4b25744a933adcab8a119c72d3a937496298db9b235583
5
5
  SHA512:
6
- metadata.gz: 795cead4247e37aed6d803f430318e8cb5f080ee431fc0f2f6820684b211a0a45d58ea9205b2cbd3c9e94dcf2021fe972596bd48109276334a2b32661813c9ef
7
- data.tar.gz: 6ec46d0e829a2d2fb387b45c372cdd2fa5dcb9f04d5e872c8dea637ee9867af964d76eabd1f2b3f83b437db3c4da823359dba0a24bb149d0fae0f3bdfcc15204
6
+ metadata.gz: 7330738b406e5944b8b4c9d379f1527ec78745026e2505902149d32164ed8b074cbe8f485a2dcbdeae8e75e11339142e94d804bf1b0470d840313082fc73ce53
7
+ data.tar.gz: a900f8c4991796ef6719d4ed29bc6e7e60a7d04fdbee3fd29cc3ee38e50baa04597030dcac33c7e4c30f2af6b228e3e7cc863d348780732c77e0a4d80a5b9ba4
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  spec/dummy/log/
2
+ pkg/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbexy (0.1.0)
4
+ rbexy (0.1.5)
5
5
  actionview (>= 5.0, < 7.0)
6
6
  activesupport (>= 5.0, < 7.0)
7
7
  railties (>= 5.0, < 7.0)
@@ -43,11 +43,10 @@ module Rbexy
43
43
  end
44
44
 
45
45
  def call
46
- old_lookup_context = view_renderer.lookup_context
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
- view_renderer.lookup_context = old_lookup_context
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)
@@ -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
@@ -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 scanner.scan(Patterns.expression_content)
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 scanner.scan(Patterns.expression_content)
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
@@ -4,9 +4,13 @@ module Rbexy
4
4
  module Rails
5
5
  class Engine < ::Rails::Engine
6
6
  initializer "rbexy" do |app|
7
- ActionView::Template.register_template_handler(:rbx, Rbexy::Rails::TemplateHandler)
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
- ActiveSupport.on_load :action_controller do
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
 
@@ -1,3 +1,3 @@
1
1
  module Rbexy
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.5"
3
3
  end
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.0
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-05 00:00:00.000000000 Z
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
@@ -1,9 +0,0 @@
1
- module Rbexy
2
- module Rails
3
- class TemplateHandler
4
- def self.call(template, source)
5
- Rbexy.compile(source)
6
- end
7
- end
8
- end
9
- end