Sha256: fcd995500cc01e7a6f9ee113b41f684acef8ede8618e54e1e9968f498215294e
Contents?: true
Size: 1.9 KB
Versions: 6
Compression:
Stored size: 1.9 KB
Contents
require 'polyblock' module Polyblock module SimpleFormHelper # def self.simple_fields_for_polyblock(fb, title, *args, &block) # ( '<div class="polyblock-fields">' << # fb.simple_fields_for(title, *args, &block) << '</div>' ).html_safe # end # def simple_fields_for_polyblock(fb, title, *args, &block) # if title.is_a? FormBuilder # return retrofit_simple_fields_for_polyblock(fb, title, *args, &block) # end # pb = pb_from_name(name, fb) # new_block = block_given? ? block : ->(fb2) { # render partial: 'polyblock/simple_fields_for', # locals: { f: fb2 } } # Polyblock::SimpleFormHelper.simple_fields_for_polyblock( # fb, title, *args, &new_block) # end # Retrofit method # def retrofit_simple_fields_for_polyblock(name, f, options={}, &block) def simple_fields_for_polyblock(name, f, options={}, &block) pb = pb_from_name(name, f) settings = { :field => { :as => :ckeditor, :label => name.to_s.titleize, :input_html => { :value => pb.present? ? pb.content : nil } }, :use_input_field => false }.deep_merge(options) # Merge in legacy fields [:label, :input_html].each{|o| settings[:field][o] = settings[o] if settings[o].present? } new_block = block_given? ? block : ->(fb2) { render partial: 'polyblock/simple_fields_for', locals: { f: fb2, pb: pb, name: name, options: settings } } new_block.call(f) end protected def pb_from_name(name, fb) if name.is_a?(Symbol) if fb.object.is_a?(Block) then fb.object else fb.object.send(name) end else foi_block = Block.fetch_or_initialize name return foi_block if foi_block.present? raise 'Invalid name passed to pb_from_name helper!' end end end end
Version data entries
6 entries across 6 versions & 1 rubygems