module Granite::Projector::Helpers

Public Instance Methods

action_path(action, **options) click to toggle source
# File lib/granite/projector/helpers.rb, line 30
def action_path(action, **options)
  action_url(action, **options, only_path: true)
end
action_url(action, **options) click to toggle source
# File lib/granite/projector/helpers.rb, line 20
def action_url(action, **options)
  action_path = controller_actions[action.to_sym].fetch(:as, action)
  params = required_params.merge(projector_action: action_path)

  Rails.application.routes.url_for(
    options.reverse_merge(url_options).merge!(params),
    corresponding_route.name
  )
end
h()
Alias for: view_context
view_context() click to toggle source
# File lib/granite/projector/helpers.rb, line 15
def view_context
  Granite.view_context
end
Also aliased as: h

Private Instance Methods

corresponding_route() click to toggle source
# File lib/granite/projector/helpers.rb, line 42
def corresponding_route
  @corresponding_route ||= fetch_corresponding_route
end
fetch_corresponding_route() click to toggle source
# File lib/granite/projector/helpers.rb, line 54
def fetch_corresponding_route
  Rails.application.routes.routes.granite_cache[*route_id] || fail(ActionNotMountedError, self)
end
required_params() click to toggle source
# File lib/granite/projector/helpers.rb, line 36
def required_params
  corresponding_route.required_parts
    .map { |name| [name, action.public_send(name)] }
    .to_h
end
route_id() click to toggle source
# File lib/granite/projector/helpers.rb, line 46
def route_id
  [action_class.name.underscore, projector_name]
end
url_options() click to toggle source
# File lib/granite/projector/helpers.rb, line 50
def url_options
  h&.url_options || {}
end