rbexy 0.3.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +2 -0
- data/lib/rbexy.rb +0 -1
- data/lib/rbexy/component.rb +11 -1
- data/lib/rbexy/component/backtrace_cleaner.rb +59 -0
- data/lib/rbexy/configuration.rb +1 -0
- data/lib/rbexy/lexer.rb +0 -1
- data/lib/rbexy/nodes.rb +16 -22
- data/lib/rbexy/runtime.rb +1 -0
- data/lib/rbexy/version.rb +1 -1
- data/lib/rbexy/view_context_helper.rb +8 -0
- data/rbexy.gemspec +1 -1
- metadata +5 -5
- data/lib/rbexy/output_buffer.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20306c3d1c288a652a8a9d4d455c9378a22165ef7c07240e234159794cd02d18
|
4
|
+
data.tar.gz: 4c8e6b19cd8f47744aba8e2850fbc73425678252628a7c6c46e31abf66937e97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70920c8f7a9da04edccbe8de30b6b12ad10e9bfe3d6a4657d412e74cad1f23c705c3bd213c81d15859b18457917f4dd5672030fd4d0072dd06bbf894c2d8eb15
|
7
|
+
data.tar.gz: 0aa89cce16b4011a91b2ffeb89472ec687b40bcd9f97f061dd85e7f01507fe034e4b3388fb14da066921c98846187f3c77b154b3d1d03b145716a7e50e9a4657
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rbexy (0.
|
4
|
+
rbexy (1.0.0)
|
5
5
|
actionview (>= 5.0, < 7.0)
|
6
6
|
activesupport (>= 5.0, < 7.0)
|
7
7
|
railties (>= 5.0, < 7.0)
|
@@ -201,7 +201,7 @@ PLATFORMS
|
|
201
201
|
DEPENDENCIES
|
202
202
|
guard-rspec (~> 4.7, >= 4.7.3)
|
203
203
|
pry-byebug
|
204
|
-
rails (>=
|
204
|
+
rails (>= 6.0, < 7.0)
|
205
205
|
rake
|
206
206
|
rbexy!
|
207
207
|
rspec (~> 3.9)
|
data/README.md
CHANGED
data/lib/rbexy.rb
CHANGED
@@ -6,7 +6,6 @@ module Rbexy
|
|
6
6
|
autoload :Nodes, "rbexy/nodes"
|
7
7
|
autoload :Runtime, "rbexy/runtime"
|
8
8
|
autoload :HashMash, "rbexy/hash_mash"
|
9
|
-
autoload :OutputBuffer, "rbexy/output_buffer"
|
10
9
|
autoload :ComponentTagBuilder, "rbexy/component_tag_builder"
|
11
10
|
autoload :ViewContextHelper, "rbexy/view_context_helper"
|
12
11
|
autoload :Configuration, "rbexy/configuration"
|
data/lib/rbexy/component.rb
CHANGED
@@ -3,6 +3,8 @@ require "active_support/core_ext/class/attribute"
|
|
3
3
|
|
4
4
|
module Rbexy
|
5
5
|
class Component < ActionView::Base
|
6
|
+
autoload :BacktraceCleaner, "rbexy/component/backtrace_cleaner"
|
7
|
+
|
6
8
|
class TemplatePath < String
|
7
9
|
def to_s
|
8
10
|
self
|
@@ -43,10 +45,13 @@ module Rbexy
|
|
43
45
|
path = TemplatePath.new(component_name)
|
44
46
|
template = view_context.lookup_context.find(path)
|
45
47
|
template.render(self, {})
|
48
|
+
rescue ActionView::Template::Error => error
|
49
|
+
error.set_backtrace clean_template_backtrace(error.backtrace)
|
50
|
+
raise error
|
46
51
|
end
|
47
52
|
|
48
53
|
def content
|
49
|
-
content_block ?
|
54
|
+
content_block ? content_block.call : ""
|
50
55
|
end
|
51
56
|
|
52
57
|
def create_context(name, value)
|
@@ -75,5 +80,10 @@ module Rbexy
|
|
75
80
|
super
|
76
81
|
end
|
77
82
|
end
|
83
|
+
|
84
|
+
def clean_template_backtrace(backtrace)
|
85
|
+
return backtrace if Rbexy.configuration.debug
|
86
|
+
BacktraceCleaner.new(backtrace).call
|
87
|
+
end
|
78
88
|
end
|
79
89
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Rbexy
|
2
|
+
class Component
|
3
|
+
class BacktraceCleaner
|
4
|
+
attr_reader :backtrace
|
5
|
+
|
6
|
+
def initialize(backtrace)
|
7
|
+
@backtrace = backtrace
|
8
|
+
@found_templates = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
backtrace
|
13
|
+
.reject(&method(:internal_implementation_detail?))
|
14
|
+
.map(&method(:strip_rbx_internals_block_mention))
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
attr_reader :found_templates
|
20
|
+
|
21
|
+
def internal_implementation_detail?(line)
|
22
|
+
if template = template_name_if_rbx_internals(line)
|
23
|
+
redundant_internal_block?(line, template)
|
24
|
+
else
|
25
|
+
internal_method_call?(line)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def internal_method_call?(line)
|
30
|
+
line =~ /lib\/rbexy\/.*\.rb/ ||
|
31
|
+
line =~ /lib\/action_view\/.*\.rb/ ||
|
32
|
+
line =~ /lib\/active_support\/notifications\.rb/
|
33
|
+
end
|
34
|
+
|
35
|
+
def redundant_internal_block?(line, template)
|
36
|
+
if found_templates[template]
|
37
|
+
true
|
38
|
+
else
|
39
|
+
found_templates[template] = true
|
40
|
+
false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def strip_rbx_internals_block_mention(line)
|
45
|
+
if template_name_if_rbx_internals(line)
|
46
|
+
line.gsub(/block (\(\d+ levels\))? ?in /, "")
|
47
|
+
else
|
48
|
+
line
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def template_name_if_rbx_internals(line)
|
53
|
+
if /\/(?<template>[^\/]*)\.rbx:\d+:in `(block |_)/ =~ line
|
54
|
+
template
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/rbexy/configuration.rb
CHANGED
data/lib/rbexy/lexer.rb
CHANGED
data/lib/rbexy/nodes.rb
CHANGED
@@ -18,11 +18,7 @@ module Rbexy
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def compile
|
21
|
-
|
22
|
-
"Rbexy::OutputBuffer.new.tap { |output|",
|
23
|
-
children.map(&:compile).map { |c| "output << (#{c})"}.join(";"),
|
24
|
-
"}.html_safe"
|
25
|
-
].join(" ")
|
21
|
+
"#{children.map(&:compile).map { |c| "@output_buffer << rbexy_prep_output(#{c})"}.join(";")};@output_buffer"
|
26
22
|
end
|
27
23
|
end
|
28
24
|
|
@@ -75,26 +71,24 @@ module Rbexy
|
|
75
71
|
base_tag = "rbexy_tag.#{Util.safe_tag_name(name)}(#{compile_members})"
|
76
72
|
tag = if children.length > 0
|
77
73
|
[
|
78
|
-
"#{base_tag} {",
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
"}"
|
83
|
-
].join(" ")
|
74
|
+
"#{base_tag} { capture {",
|
75
|
+
children.map(&:compile).map { |c| "@output_buffer << rbexy_prep_output(#{c})" }.join(";"),
|
76
|
+
"} }"
|
77
|
+
].join
|
84
78
|
else
|
85
79
|
base_tag
|
86
|
-
end
|
87
|
-
|
88
|
-
context_open = Rbexy.configuration.enable_context ? "rbexy_context.push({});" : nil
|
89
|
-
context_close = Rbexy.configuration.enable_context ? "rbexy_context.pop;" : nil
|
80
|
+
end + ".html_safe"
|
90
81
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
82
|
+
if Rbexy.configuration.enable_context
|
83
|
+
[
|
84
|
+
"(",
|
85
|
+
"rbexy_context.push({});",
|
86
|
+
"#{tag}.tap { rbexy_context.pop }",
|
87
|
+
")"
|
88
|
+
].join
|
89
|
+
else
|
90
|
+
tag
|
91
|
+
end
|
98
92
|
end
|
99
93
|
|
100
94
|
def compile_members
|
data/lib/rbexy/runtime.rb
CHANGED
data/lib/rbexy/version.rb
CHANGED
@@ -7,5 +7,13 @@ module Rbexy
|
|
7
7
|
def rbexy_context
|
8
8
|
@rbexy_context ||= [{}]
|
9
9
|
end
|
10
|
+
|
11
|
+
def rbexy_prep_output(*content)
|
12
|
+
return if content.length == 0
|
13
|
+
content = content.first
|
14
|
+
|
15
|
+
value = content.is_a?(Array) ? content.join.html_safe : content
|
16
|
+
[nil, false].include?(value) ? "" : value.to_s
|
17
|
+
end
|
10
18
|
end
|
11
19
|
end
|
data/rbexy.gemspec
CHANGED
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.add_dependency "actionview", ">= 5.0", "< 7.0"
|
30
30
|
spec.add_dependency "railties", ">= 5.0", "< 7.0"
|
31
31
|
|
32
|
-
spec.add_development_dependency "rails", ">=
|
32
|
+
spec.add_development_dependency "rails", ">= 6.0", "< 7.0"
|
33
33
|
spec.add_development_dependency "rspec", "~> 3.9"
|
34
34
|
spec.add_development_dependency "guard-rspec", "~> 4.7", ">= 4.7.3"
|
35
35
|
spec.add_development_dependency "rspec-rails", "~> 4.0", ">= 4.0.1"
|
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: 1.0.0
|
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-
|
11
|
+
date: 2020-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
requirements:
|
77
77
|
- - ">="
|
78
78
|
- !ruby/object:Gem::Version
|
79
|
-
version: '
|
79
|
+
version: '6.0'
|
80
80
|
- - "<"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '7.0'
|
@@ -86,7 +86,7 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '6.0'
|
90
90
|
- - "<"
|
91
91
|
- !ruby/object:Gem::Version
|
92
92
|
version: '7.0'
|
@@ -224,6 +224,7 @@ files:
|
|
224
224
|
- example.rb
|
225
225
|
- lib/rbexy.rb
|
226
226
|
- lib/rbexy/component.rb
|
227
|
+
- lib/rbexy/component/backtrace_cleaner.rb
|
227
228
|
- lib/rbexy/component_providers/namespaced_rbexy_provider.rb
|
228
229
|
- lib/rbexy/component_providers/rbexy_provider.rb
|
229
230
|
- lib/rbexy/component_providers/view_component_provider.rb
|
@@ -232,7 +233,6 @@ files:
|
|
232
233
|
- lib/rbexy/hash_mash.rb
|
233
234
|
- lib/rbexy/lexer.rb
|
234
235
|
- lib/rbexy/nodes.rb
|
235
|
-
- lib/rbexy/output_buffer.rb
|
236
236
|
- lib/rbexy/parser.rb
|
237
237
|
- lib/rbexy/rails.rb
|
238
238
|
- lib/rbexy/rails/component_template_resolver.rb
|
data/lib/rbexy/output_buffer.rb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
require "active_support/core_ext/string/output_safety"
|
2
|
-
|
3
|
-
module Rbexy
|
4
|
-
class OutputBuffer < ActiveSupport::SafeBuffer
|
5
|
-
def <<(content)
|
6
|
-
value = content.is_a?(Array) ? content.join.html_safe : content
|
7
|
-
super([nil, false].include?(value) ? "" : value.to_s)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|