rbexy 1.1.0 → 2.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -1
- data/README.md +18 -0
- data/lib/rbexy.rb +26 -9
- data/lib/rbexy/ast_transformer.rb +21 -0
- data/lib/rbexy/component.rb +1 -6
- data/lib/rbexy/component_resolver.rb +60 -0
- data/lib/rbexy/configuration.rb +18 -1
- data/lib/rbexy/lexer.rb +20 -13
- data/lib/rbexy/nodes.rb +15 -135
- data/lib/rbexy/nodes/abstract_attr.rb +12 -0
- data/lib/rbexy/nodes/abstract_element.rb +13 -0
- data/lib/rbexy/nodes/abstract_node.rb +58 -0
- data/lib/rbexy/nodes/component_element.rb +69 -0
- data/lib/rbexy/nodes/component_prop.rb +29 -0
- data/lib/rbexy/nodes/declaration.rb +15 -0
- data/lib/rbexy/nodes/expression.rb +15 -0
- data/lib/rbexy/nodes/expression_group.rb +55 -0
- data/lib/rbexy/nodes/html_attr.rb +13 -0
- data/lib/rbexy/nodes/html_element.rb +48 -0
- data/lib/rbexy/nodes/newline.rb +9 -0
- data/lib/rbexy/nodes/raw.rb +23 -0
- data/lib/rbexy/nodes/root.rb +19 -0
- data/lib/rbexy/nodes/text.rb +15 -0
- data/lib/rbexy/nodes/util.rb +9 -0
- data/lib/rbexy/parser.rb +22 -16
- data/lib/rbexy/rails/component_template_resolver.rb +3 -3
- data/lib/rbexy/rails/controller_helper.rb +0 -6
- data/lib/rbexy/rails/engine.rb +1 -7
- data/lib/rbexy/refinements.rb +5 -0
- data/lib/rbexy/refinements/array.rb +9 -0
- data/lib/rbexy/refinements/array/find_map.rb +13 -0
- data/lib/rbexy/refinements/array/insert_between_types.rb +26 -0
- data/lib/rbexy/refinements/array/map_type_when_neighboring_type.rb +26 -0
- data/lib/rbexy/runtime.rb +15 -23
- data/lib/rbexy/template.rb +12 -0
- data/lib/rbexy/version.rb +1 -1
- data/rbexy.gemspec +1 -0
- metadata +41 -11
- data/example.rb +0 -113
- data/lib/rbexy/component_providers/namespaced_rbexy_provider.rb +0 -20
- data/lib/rbexy/component_providers/rbexy_provider.rb +0 -21
- data/lib/rbexy/component_providers/view_component_provider.rb +0 -21
- data/lib/rbexy/component_tag_builder.rb +0 -19
- data/lib/rbexy/hash_mash.rb +0 -15
- data/lib/rbexy/view_context_helper.rb +0 -19
@@ -1,21 +0,0 @@
|
|
1
|
-
module Rbexy
|
2
|
-
module ComponentProviders
|
3
|
-
class RbexyProvider
|
4
|
-
def match?(name)
|
5
|
-
name =~ /^[A-Z]/ && find(name) != nil
|
6
|
-
end
|
7
|
-
|
8
|
-
def render(context, name, **attrs, &block)
|
9
|
-
props = attrs.transform_keys { |k| ActiveSupport::Inflector.underscore(k.to_s).to_sym }
|
10
|
-
find(name).new(context, **props).render(&block)
|
11
|
-
end
|
12
|
-
|
13
|
-
def find(name)
|
14
|
-
ActiveSupport::Inflector.constantize("#{name}Component")
|
15
|
-
rescue NameError => e
|
16
|
-
raise e unless e.message =~ /wrong constant name/ || e.message =~ /uninitialized constant/
|
17
|
-
nil
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module Rbexy
|
2
|
-
module ComponentProviders
|
3
|
-
class ViewComponentProvider
|
4
|
-
def match?(name)
|
5
|
-
name =~ /^[A-Z]/ && find(name) != nil
|
6
|
-
end
|
7
|
-
|
8
|
-
def render(context, name, **attrs, &block)
|
9
|
-
props = attrs.transform_keys { |k| ActiveSupport::Inflector.underscore(k.to_s).to_sym }
|
10
|
-
find(name).new(**props).render_in(context, &block)
|
11
|
-
end
|
12
|
-
|
13
|
-
def find(name)
|
14
|
-
ActiveSupport::Inflector.constantize("#{name}Component")
|
15
|
-
rescue NameError => e
|
16
|
-
raise e unless e.message =~ /wrong constant name/ || e.message =~ /uninitialized constant/
|
17
|
-
nil
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Rbexy
|
2
|
-
class ComponentTagBuilder < ActionView::Helpers::TagHelper::TagBuilder
|
3
|
-
attr_reader :component_provider
|
4
|
-
|
5
|
-
def initialize(context, component_provider)
|
6
|
-
super(context)
|
7
|
-
@component_provider = component_provider
|
8
|
-
end
|
9
|
-
|
10
|
-
def method_missing(called, *args, **attrs, &block)
|
11
|
-
component_name = called.to_s.gsub("__", "::")
|
12
|
-
if component_provider.match?(component_name)
|
13
|
-
component_provider.render(@view_context, component_name, **attrs, &block)
|
14
|
-
else
|
15
|
-
super
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
data/lib/rbexy/hash_mash.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
module Rbexy
|
2
|
-
module ViewContextHelper
|
3
|
-
def rbexy_tag
|
4
|
-
@rbexy_tag ||= Runtime.create_tag_builder(self)
|
5
|
-
end
|
6
|
-
|
7
|
-
def rbexy_prep_output(*value)
|
8
|
-
return if value.length == 0
|
9
|
-
value = value.first
|
10
|
-
|
11
|
-
value = rbexy_is_html_safe_array?(value) ? value.join.html_safe : value
|
12
|
-
[nil, false].include?(value) ? "" : value.to_s
|
13
|
-
end
|
14
|
-
|
15
|
-
def rbexy_is_html_safe_array?(value)
|
16
|
-
value.is_a?(Array) && value.all? { |v| v.respond_to?(:html_safe?) && v.html_safe? }
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|