Module: BreezyTemplate::PartialExtension
- Included in:
- BreezyTemplate
- Defined in:
- lib/breezy_template/partial_extension.rb
Instance Method Summary collapse
- #_extended_options?(value) ⇒ Boolean
- #_normalize_options_for_partial(options) ⇒ Object
- #_partial_digest(partial) ⇒ Object
- #_partial_options?(options) ⇒ Boolean
- #_render_partial(options) ⇒ Object
- #_render_partial_with_collection(collection, options) ⇒ Object
- #_set_inline_partial(name, object, options) ⇒ Object
- #array!(collection = [], *attributes) ⇒ Object
- #set!(key, value = BLANK, *args) ⇒ Object
Instance Method Details
#_extended_options?(value) ⇒ Boolean
26 27 28 |
# File 'lib/breezy_template/partial_extension.rb', line 26 def (value) (value) || super end |
#_normalize_options_for_partial(options) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/breezy_template/partial_extension.rb', line 34 def () if !() return end = [*[:partial]] partial, rest = if partial && !rest .dup.merge(partial: [partial, rest || {}]) else end end |
#_partial_digest(partial) ⇒ Object
48 49 50 51 52 |
# File 'lib/breezy_template/partial_extension.rb', line 48 def _partial_digest(partial) lookup_context = @context.lookup_context name = lookup_context.find(partial, [], true).virtual_path _partial_digestor({name: name, finder: lookup_context}) end |
#_partial_options?(options) ⇒ Boolean
30 31 32 |
# File 'lib/breezy_template/partial_extension.rb', line 30 def () ::Hash === && .key?(:partial) end |
#_render_partial(options) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/breezy_template/partial_extension.rb', line 73 def _render_partial() partial, = [:partial] fragment_name = [:fragment_name] if fragment_name fragment_name = fragment_name.to_sym path = @path.dup.join('.') @js.push "fragments['#{fragment_name}'] = fragments['#{fragment_name}'] || []; fragments['#{fragment_name}'].push('#{path}'); lastFragmentName='#{fragment_name}'; lastFragmentPath='#{path}';" @fragments[fragment_name] end [:locals].merge! json: self @context.render .merge(partial: partial) end |
#_render_partial_with_collection(collection, options) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/breezy_template/partial_extension.rb', line 87 def _render_partial_with_collection(collection, ) = () partial, partial_opts = [:partial] array_opts = .dup partial_opts.reverse_merge! locals: {} partial_opts.reverse_merge! ::BreezyTemplate. as = partial_opts[:as] extract_fragment_name = partial_opts.delete(:fragment_name) locals = partial_opts.delete(:locals) array_opts.delete(:partial) array! collection, array_opts do |member| member_locals = locals.clone member_locals.merge! collection: collection member_locals.merge! as.to_sym => member if as partial_opts.merge!(locals: member_locals) if extract_fragment_name.respond_to?(:call) partial_opts.merge!(fragment_name: extract_fragment_name.call(member)) end _render_partial end end |
#_set_inline_partial(name, object, options) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/breezy_template/partial_extension.rb', line 54 def _set_inline_partial(name, object, ) = () partial, partial_opts = [:partial] value = if object.nil? && partial.empty? [] else locals = {} locals[partial_opts[:as]] = object if !_blank?(partial_opts) && partial_opts.key?(:as) locals.merge!(partial_opts[:locals]) if partial_opts.key? :locals partial_opts.merge!(locals: locals) _result(BLANK, ){ _render_partial() } end set! name, value end |
#array!(collection = [], *attributes) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/breezy_template/partial_extension.rb', line 15 def array!(collection = [], *attributes) = attributes.last || {} = () if attributes.one? && () _render_partial_with_collection(collection, ) else super end end |
#set!(key, value = BLANK, *args) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/breezy_template/partial_extension.rb', line 5 def set!(key, value = BLANK, *args) = args.last || {} if args.one? && () _set_inline_partial key, value, else super end end |