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, #hint_of, #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


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

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



14
15
16
# File 'lib/helpers/wallaby/resources_helper.rb', line 14

def 
  Wallaby.configuration.
end

#extract(resource) ⇒ Object

Get the origin resource object

Parameters:

Returns:

  • (Object)


32
33
34
35
# File 'lib/helpers/wallaby/resources_helper.rb', line 32

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

#model_decorator(model_class) ⇒ Wallaby::ModelDecorator



9
10
11
# File 'lib/helpers/wallaby/resources_helper.rb', line 9

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)


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

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



38
39
40
# File 'lib/helpers/wallaby/resources_helper.rb', line 38

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