Module: Wallaby::ResourcesHelper

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

Instance Method Summary collapse

Methods included from PaginatableHelper

#custom_pagination_stats, #paginatable?

Methods included from SortingHelper

#next_sort_param, #sort_class, #sort_hash, #sort_link

Methods included from FormHelper

#form_type_partial_render, #model_choices

Instance Method Details

#decorate(resource) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/helpers/wallaby/resources_helper.rb', line 6

def decorate(resource)
  if resource.respond_to? :map # collection
    decorator = Wallaby::DecoratorFinder.find_resource resource.first.class
    resource.map do |item|
      decorator.decorate item
    end
  else
    decorator = Wallaby::DecoratorFinder.find_resource resource.class
    decorator.decorate resource
  end
end

#extract(resource) ⇒ Object



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

def extract(resource)
  if resource.is_a? Wallaby::ResourceDecorator
    resource.resource
  else
    resource
  end
end

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



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

def index_type_partial_render(options = {}, locals = {}, &block)
  type_partial_render options, locals, :index_metadata_of
end

#model_decorator(model_class) ⇒ Object



26
27
28
# File 'lib/helpers/wallaby/resources_helper.rb', line 26

def model_decorator(model_class)
  Wallaby::DecoratorFinder.find_model model_class
end

#model_servicer(model_decorator) ⇒ Object



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

def model_servicer(model_decorator)
  model_class = model_decorator.model_class
  Wallaby::ServicerFinder.find(model_class).new model_class, model_decorator
end

#show_title(decorated) ⇒ Object



51
52
53
54
# File 'lib/helpers/wallaby/resources_helper.rb', line 51

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

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



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/helpers/wallaby/resources_helper.rb', line 35

def type_partial_render(options = {}, locals = {},  = :show_metadata_of, &block)
  decorated   = locals[:object]
  field_name  = locals[:field_name].to_s

  fail ArgumentError unless field_name.present? && decorated.is_a?(Wallaby::ResourceDecorator)

  locals[:metadata] = decorated.send , field_name
  locals[:value]    = decorated.public_send field_name

  render(options, locals, &block) or render('string', locals, &block)
end