Module: Wallaby::View::ActionViewable

Extended by:
ActiveSupport::Concern
Included in:
Wallaby::View
Defined in:
lib/wallaby/view/action_viewable.rb

Overview

This module overrides Rails core methods #lookup_context and #_prefixes to provide better performance and more lookup prefixes.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#_prefixes(prefixes: nil, controller_path: nil, action_name: nil, themes: nil, options: nil, &block) ⇒ Array<String>

Override _prefixes to allow other (e.g. CustomPrefixes#action_name, CustomPrefixes#themes) to be added to the prefixes list.

Parameters:

  • prefixes (Array<String>) (defaults to: nil)

    the base prefixes

  • action_name (String) (defaults to: nil)

    the action name to add to the prefixes list

  • themes (String) (defaults to: nil)

    the theme name to add to the prefixes list

  • options (Hash) (defaults to: nil)

    the options that CustomPrefixes accepts

Returns:

  • (Array<String>)


# File 'lib/wallaby/view/action_viewable.rb', line 49

#lookup_contextCustomLookupContext

Override lookup_context to provide caching for template/partial lookup.

Returns:



# File 'lib/wallaby/view/action_viewable.rb', line 37

#original_lookup_contextActionView::LookupContext

Original method of #lookup_context

Returns:

  • (ActionView::LookupContext)


# File 'lib/wallaby/view/action_viewable.rb', line 29

#original_prefixesArray<String>

Original method of #_prefixes

Returns:

  • (Array<String>)


# File 'lib/wallaby/view/action_viewable.rb', line 33

#override_lookup_contextCustomLookupContext

Override lookup_context to provide caching for template/partial lookup.

Returns:



44
45
46
47
# File 'lib/wallaby/view/action_viewable.rb', line 44

def override_lookup_context
  @_lookup_context ||= # rubocop:disable Naming/MemoizedInstanceVariableName
    CustomLookupContext.convert(original_lookup_context, prefixes: _prefixes)
end

#override_prefixes(prefixes: nil, action_name: nil, themes: nil, options: nil, &block) ⇒ Array<String>

Override _prefixes to allow other (e.g. CustomPrefixes#action_name, CustomPrefixes#themes) to be added to the prefixes list.

Parameters:

  • prefixes (Array<String>) (defaults to: nil)

    the base prefixes

  • action_name (String) (defaults to: nil)

    the action name to add to the prefixes list

  • themes (String) (defaults to: nil)

    the theme name to add to the prefixes list

  • options (Hash) (defaults to: nil)

    the options that CustomPrefixes accepts

Returns:

  • (Array<String>)


60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/wallaby/view/action_viewable.rb', line 60

def override_prefixes(
  prefixes: nil,
  action_name: nil,
  themes: nil,
  options: nil, &block
)
  @_prefixes ||= # rubocop:disable Naming/MemoizedInstanceVariableName
    CustomPrefixes.execute(
      prefixes: prefixes || original_prefixes,
      action_name: action_name || params[:action],
      themes: themes || self.class.themes,
      options: self.class.prefix_options.merge(options || {}), &block
    )
end