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_options(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
28 29 30 |
# File 'lib/breezy_template/partial_extension.rb', line 28 def (value) (value) || super end |
#_normalize_options_for_partial(options) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/breezy_template/partial_extension.rb', line 36 def () if !() return end = [*[:partial]] partial, rest = if partial && !rest .dup.merge(partial: [partial, rest || {}]) else end end |
#_partial_digest(partial) ⇒ Object
50 51 52 53 54 |
# File 'lib/breezy_template/partial_extension.rb', line 50 def _partial_digest(partial) lookup_context = @context.lookup_context name = lookup_context.find(partial, lookup_context.prefixes, true).virtual_path _partial_digestor({name: name, finder: lookup_context}) end |
#_partial_options?(options) ⇒ Boolean
32 33 34 |
# File 'lib/breezy_template/partial_extension.rb', line 32 def () ::Hash === && .key?(:partial) end |
#_render_partial(options) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/breezy_template/partial_extension.rb', line 80 def _render_partial() partial, = [:partial] joint = [:joint] if joint joint = joint.to_sym path = @path.dup.join('.') @js.push "joints['#{joint}'] ||= []; joints['#{joint}'].push('#{path}');" @joints[joint] end [:locals].merge! json: self @context.render .merge(partial: partial) end |
#_render_partial_with_options(options) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/breezy_template/partial_extension.rb', line 94 def () = () partial, partial_opts = [:partial] ary_opts = .dup partial_opts.reverse_merge! locals: {} partial_opts.reverse_merge! ::BreezyTemplate. as = partial_opts[:as] if partial_opts.key?(:collection) collection = partial_opts.delete(:collection) extract_joint_name = partial_opts.delete(:joint) locals = partial_opts.delete(:locals) ary_opts.delete(:partial) array! collection, ary_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_joint_name.respond_to?(:call) partial_opts.merge!(joint: extract_joint_name.call(member)) end _render_partial end else _render_partial end end |
#_set_inline_partial(name, object, options) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/breezy_template/partial_extension.rb', line 56 def _set_inline_partial(name, object, ) = () partial, partial_opts = [:partial] if partial_opts[:joint] == true partial_opts[:joint] = name end 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) _scope{ _render_partial() } end = .dup .delete(:partial) set! name, value, end |
#array!(collection = [], *attributes) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/breezy_template/partial_extension.rb', line 15 def array!(collection = [], *attributes) = attributes.last || {} = () if attributes.one? && () _, opts = [:partial] opts.reverse_merge!(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 |