app/helpers/pagelets_helper.rb in pagelet_rails-0.1.1 vs app/helpers/pagelets_helper.rb in pagelet_rails-0.1.2
- old
+ new
@@ -1,7 +1,27 @@
module PageletsHelper
+ def html_container_attributes
+ html_opts = pagelet_options.html || {}
+ classes = html_opts.fetch(:class, '').split(' ')
+ classes << "pagelet-#{controller_name}"
+ classes << "pagelet-#{controller_name}-#{action_name}"
+
+ html_opts[:id] ||= pagelet_default_id
+ html_opts[:class] = classes.join(' ')
+
+ html_opts['data-pagelet-container'] = true
+
+ encode_data = pagelet_options.original_options.to_h.except('remote')
+ html_opts['data-pagelet-options'] = PageletRails::Encryptor.encode(encode_data)
+
+ if pagelet_options.ajax_group
+ html_opts['data-pagelet-group'] = pagelet_options.ajax_group
+ end
+ html_opts
+ end
+
def pagelet_stream
return nil if pagelet_stream_objects.empty?
pagelet_stream_objects.each do |key, block|
concat content_tag('script', raw("PageletRails.pageletArrived('#{key}', '#{j capture(&block)}');\n"), type: 'text/javascript')
end
@@ -22,11 +42,11 @@
def pagelet_stream_objects
request.instance_variable_get(:@pagelet_stream_objects) || {}
end
def pagelet path, p_options = {}
- puts "Rendering pagelet #{path}".blue
+ Rails.logger.info "Rendering pagelet #{path}"
p_params = p_options.delete(:params) { {} }.with_indifferent_access
if path.is_a? Symbol
path = self.send("#{path}_path", p_params)
@@ -70,11 +90,15 @@
p_request = ActionDispatch::Request.new(env)
p_request.parameters.clear
p_request.parameters.merge! p_params
- p_response = controller_class.make_response! p_request
- c.dispatch(action, p_request, p_response)
+ if c.method(:dispatch).arity == 3
+ p_response = controller_class.make_response! p_request
+ c.dispatch(action, p_request, p_response)
+ else
+ c.dispatch(action, p_request)
+ end
body = c.response.body
body.html_safe
end