Skip to content

Commit

Permalink
Refactor so both modules can be used together
Browse files Browse the repository at this point in the history
  • Loading branch information
pedantic-git committed Jul 11, 2024
1 parent 91e876e commit 6452319
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 25 deletions.
24 changes: 24 additions & 0 deletions lib/phlexible/rails/action_controller/base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

module Phlexible
module Rails
module ActionController
module Base

protected

def phlex_view(options)
phlex_view_path(options)&.camelize&.safe_constantize
end

def phlex_view_path(options)
if options[:action]
"/#{controller_path}/#{options[:action]}_view"
elsif options[:template]
"/#{options[:template]}_view"
end
end
end
end
end
end
17 changes: 6 additions & 11 deletions lib/phlexible/rails/action_controller/implicit_render.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@
# include Phlexible::Rails::ActionController::ImplicitRender
# end
#

require_relative "base"

module Phlexible
module Rails
module ActionController
module ImplicitRender
include Base

def default_render
render_plex_view({ action: action_name }) || super
end
Expand All @@ -40,20 +45,10 @@ def default_phlex_render
def render_plex_view(options)
options[:action] ||= action_name

return unless (view = phlex_view(options[:action]))
return unless (view = phlex_view({action: options[:action]}))

render view.new, options
end

private

def phlex_view(action_name = @_action_name)
phlex_view_path(action_name).camelize.safe_constantize
end

def phlex_view_path(action_name)
"#{controller_path}/#{action_name}_view"
end
end
end
end
Expand Down
20 changes: 6 additions & 14 deletions lib/phlexible/rails/action_controller/render_action.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# frozen_string_literal: true


require_relative "base"

module Phlexible
module Rails
module ActionController
module RenderAction
include Base

def render_to_body(options = {})
if view = phlex_view(options)
Expand All @@ -10,20 +16,6 @@ def render_to_body(options = {})
super
end
end

private

def phlex_view(options)
phlex_view_path(options)&.camelize&.safe_constantize
end

def phlex_view_path(options)
if options[:action]
"/#{controller_path}/#{options[:action]}_view"
elsif options[:template]
"/#{options[:template]}_view"
end
end
end
end
end
Expand Down

0 comments on commit 6452319

Please sign in to comment.