Module: Wallaby::ResourcesHelper

Includes:
ApplicationHelper, Authorizable, BaseHelper, Decoratable, FormHelper, IndexHelper, Paginatable, Resourcable, SecureHelper, Servicable
Defined in:
lib/helpers/wallaby/resources_helper.rb

Overview

Resources helper

Constant Summary

Constants included from StylingHelper

StylingHelper::FONT_AWESOME_MAPPING

Instance Method Summary collapse

Methods included from Servicable

#current_servicer

Methods included from Resourcable

#collection, #create_params, #current_model_class, #current_resources_name, #new_resource, #resource, #resource_id, #resource_params, #update_params

Methods included from Paginatable

#current_paginator, #paginate, #pagination_params_for

Methods included from Decoratable

#current_decorator, #current_fields, #current_model_decorator, #decorate, #decorator_of, #extract

Methods included from Authorizable

#authorized?, #current_authorizer, #unauthorized?

Methods included from IndexHelper

#all_label, #export_link, #filter_label, #filter_link, #filter_name_by, #json_fields_of, #sort_link_builder

Methods included from FormHelper

#hint_of, #polymorphic_options, #remote_url

Methods included from BaseHelper

#body_class, #model_classes, #model_tree, #to_model_label, #to_resources_name

Methods included from LinksHelper

#cancel_link, #delete_link, #edit_link, #index_link, #new_link, #show_link

Methods included from StylingHelper

#fa_icon, #fa_map, #html_classes, #imodal, #itooltip, #muted, #na, #null

Methods included from SecureHelper

#logout_method, #logout_path, #user_portrait

Methods included from ApplicationHelper

#form_for, #wt

Methods included from Urlable

#edit_path, #index_path, #new_path, #show_path, #url_for

Methods included from Engineable

#current_engine, #current_engine_name, #current_engine_route, #script_name

Methods included from Configurable

#wallaby_controller

Methods included from ConfigurationHelper

#configuration, #default_metadata, #features, #mapping, #models, #pagination, #security, #sorting

Instance Method Details

#first_field_by(*conditions) ⇒ String, ...

To find the first field that meets given conditions.

Examples:

To find summary field whose name contains summary and type is string:

first_field_by({ name: /summary/, type: 'string' })

Parameters:

  • conditions (Array<Hash>)

Returns:

  • (String, Symbol)

    field name when found

  • (nil)

    when not found



75
76
77
78
# File 'lib/helpers/wallaby/resources_helper.rb', line 75

def first_field_by(*conditions)
  fields = block_given? ? yield : current_fields
  FieldUtils.first_field_by(*conditions, fields)
end

#show_title(decorated) ⇒ String

Title for show page of given resource

Parameters:

Returns:

  • (String)


59
60
61
62
63
64
65
66
67
# File 'lib/helpers/wallaby/resources_helper.rb', line 59

def show_title(decorated)
  unless decorated.is_a? ResourceDecorator
    raise ::ArgumentError, 'Please provide a resource wrapped by a decorator.'
  end

  [
    to_model_label(decorated.model_class), decorated.to_label
  ].compact.join ': '
end

#type_render(_partial_name = '', _locals = {}) ⇒ Object

Deprecated.


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/helpers/wallaby/resources_helper.rb', line 20

def type_render(_partial_name = '', _locals = {})
  Deprecator.alert method(__callee__), from: '0.3.0', alternative: <<~INSTRUCTION
    If it's for index type partils, please follow below example:

      render(
        field_name,
        object: decorated,
        field_name: field_name,
        value: decorated.try(field_name),
        metadata: decorated.index_metadata_of(field_name)
      )

    If it's for show type partils, please follow below example:

      render(
        field_name,
        object: decorated,
        field_name: field_name,
        value: decorated.try(field_name),
        metadata: decorated.show_metadata_of(field_name)
      )

    If it's for new/create/edit/update/destroy type partils, please follow below example:

      render(
        field_name,
        form: form,
        object: decorated,
        field_name: field_name,
        value: decorated.try(field_name),
        metadata: decorated.form_metadata_of(field_name)
      )

  INSTRUCTION
end