Module: Wallaby::ResourcesHelper

Includes:
FormHelper, IndexHelper
Defined in:
lib/helpers/wallaby/resources_helper.rb

Overview

Resources helper

Instance Method Summary collapse

Methods included from IndexHelper

#all_label, #export_link, #filter_label, #filter_link, #paginate, #sort_link_builder

Methods included from FormHelper

#form_type_partial_render, #polymorphic_options, #remote_url

Instance Method Details

#decorate(resource) ⇒ Object

Wrap resource into a decorator

Parameters:

  • resource (Object, Enumerable)

Returns:

  • Wallaby::ResourceDecorator, Enumerable<Wallaby::ResourceDecorator


20
21
22
23
24
25
# File 'lib/helpers/wallaby/resources_helper.rb', line 20

def decorate(resource)
  return resource if resource.is_a? ResourceDecorator
  return resource.map { |item| decorate item } if resource.respond_to? :map
  decorator = Map.resource_decorator_map resource.class
  decorator ? decorator.new(resource) : resource
end

#default_metadataObject

Shortcut for ‘Wallaby.configuration.metadata



12
13
14
# File 'lib/helpers/wallaby/resources_helper.rb', line 12

def 
  Wallaby.configuration.
end

#extract(resource) ⇒ Object

Get the origin resource object

Parameters:

Returns:

  • (Object)


30
31
32
33
# File 'lib/helpers/wallaby/resources_helper.rb', line 30

def extract(resource)
  return resource.resource if resource.is_a? ResourceDecorator
  resource
end

#model_decorator(model_class) ⇒ Object



7
8
9
# File 'lib/helpers/wallaby/resources_helper.rb', line 7

def model_decorator(model_class)
  Map.model_decorator_map model_class
end

#show_title(decorated) ⇒ String

Title for show page of given resource

Parameters:

Returns:

  • (String)

Raises:

  • (::ArgumentError)


43
44
45
46
47
48
# File 'lib/helpers/wallaby/resources_helper.rb', line 43

def show_title(decorated)
  raise ::ArgumentError unless decorated.is_a? ResourceDecorator
  [
    to_model_label(decorated.model_class), decorated.to_label
  ].compact.join ': '
end

#type_partial_render(options = {}, locals = {}, &block) ⇒ Object

Render partial for index/show



36
37
38
# File 'lib/helpers/wallaby/resources_helper.rb', line 36

def type_partial_render(options = {}, locals = {}, &block)
  PartialRenderer.render self, options, locals, params[:action], &block
end