slotify 0.0.1.alpha.0 → 0.0.2

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.
@@ -1,30 +0,0 @@
1
- module Slotify
2
- class Helpers
3
- include Utils
4
-
5
- def initialize(view_context)
6
- @view_context = view_context
7
- end
8
-
9
- def respond_to_missing?(name, include_private = false)
10
- @view_context.respond_to?(name) || @view_context.tag.respond_to?(name)
11
- end
12
-
13
- def method_missing(name, *args, **options, &block)
14
- results = with_resolved_args(args, options, block) do |rargs, roptions, rblock|
15
- call_helper(name, *rargs, **roptions.to_h, &rblock)
16
- end
17
- results.reduce(ActiveSupport::SafeBuffer.new) { _1 << _2 }
18
- end
19
-
20
- private
21
-
22
- def call_helper(name, ...)
23
- if @view_context.respond_to?(name)
24
- @view_context.public_send(name, ...)
25
- else
26
- @view_context.tag.public_send(name, ...)
27
- end
28
- end
29
- end
30
- end
@@ -1,18 +0,0 @@
1
- module Slotify
2
- module SlotifyHelpers
3
- def slotify_helpers(*method_names)
4
- proxy = Module.new
5
- method_names.each do |name|
6
- proxy.define_method(name) do |*args, **kwargs, &block|
7
- return super(*args, **kwargs, &block) if args.none?
8
- results = Utils.with_resolved_args(args, kwargs, block) do
9
- super(*_1, **_2.to_h, &_3 || block)
10
- end
11
-
12
- results.reduce(ActiveSupport::SafeBuffer.new) { _1 << _2 }
13
- end
14
- end
15
- prepend proxy
16
- end
17
- end
18
- end
data/lib/slotify/utils.rb DELETED
@@ -1,50 +0,0 @@
1
- module Slotify
2
- module Utils
3
- extend ActiveSupport::Concern
4
-
5
- def singular?(str)
6
- str = str.to_s
7
- str.singularize == str && str.pluralize != str
8
- end
9
-
10
- def singularize(sym)
11
- sym.to_s.singularize.to_sym
12
- end
13
-
14
- def plural?(str)
15
- !singular?(str)
16
- end
17
-
18
- def to_array(input)
19
- input.is_a?(Array) ? input : [input]
20
- end
21
-
22
- def merge_tag_options(...)
23
- TagOptionsMerger.call(...)
24
- end
25
-
26
- def with_resolved_args(args = [], options = {}, block = nil)
27
- args = args.is_a?(Array) ? args.clone : [args]
28
- entry_index = args.index { _1.is_a?(EntryCollection) || _1.is_a?(Entry) }
29
- if entry_index.nil?
30
- [yield(args, options, block)]
31
- else
32
- target = args[entry_index]
33
- entries = target.is_a?(EntryCollection) ? target : [target]
34
- entries.map do |entry|
35
- cloned_args = args.clone
36
- cloned_args[entry_index, 1] = entry.args.clone
37
-
38
- yield(
39
- cloned_args,
40
- merge_tag_options(options, entry.options),
41
- entry.block || block
42
- )
43
- end
44
- end
45
- end
46
-
47
- module_function :merge_tag_options
48
- module_function :with_resolved_args
49
- end
50
- end