@@ -2,9 +2,9 @@ module Matestack::Ui::Core::Render
22
33 # Matestack allows you to use `render` to render matestack pages.
44 #
5- # render Pages::Member::Bookings
6- # render matestack: Pages::Member::Bookings
7- # render matestack: 'member/bookings'
5+ # render Pages::Member::Bookings::Index
6+ # render matestack: Pages::Member::Bookings::Index
7+ # render matestack: 'member/bookings/index '
88 #
99 def render ( *args )
1010 if ( matestack_class = args . first ) . is_a? ( Class ) && ( matestack_class < Matestack ::Ui ::Page )
@@ -37,8 +37,8 @@ def render(*args)
3737 # end
3838 # end
3939 #
40- # In this example, `clients/bookings#index` will render `Pages::Clients::Bookings`,
41- # `clients/bookings#show` will render `Pages::Clients::Booking `.
40+ # In this example, `clients/bookings#index` will render `Pages::Clients::Bookings::Index `,
41+ # `clients/bookings#show` will render `Pages::Clients::Bookings::Show `.
4242 #
4343 # Custom action names translate also into page names.
4444 #
@@ -51,20 +51,38 @@ def render(*args)
5151 # `Pages::Clients::Bookings::Step1`.
5252 #
5353 def default_render ( *args )
54- matestack_page_path = "pages/#{ controller_path } "
55- matestack_page_path = "#{ matestack_page_path } /#{ action_name } " unless action_name . in? %w( index show )
56- matestack_class_name_parts = matestack_page_path . split ( "/" ) . collect { |str | str . camelcase }
57- matestack_class_name_parts [ -1 ] = matestack_class_name_parts [ -1 ] . singularize if action_name == "show"
58- matestack_class_name = matestack_class_name_parts . join ( "::" )
59- begin
60- matestack_class = matestack_class_name . constantize
61- rescue NameError
62- end
63- if matestack_class
64- render matestack : matestack_class
54+ if matestack_page_class = default_render_matestack_page_class
55+ render matestack : matestack_page_class
6556 else
6657 super
6758 end
6859 end
6960
61+ def possible_default_render_matestack_page_paths
62+ paths = [ ]
63+ paths << "pages/#{ controller_path } /#{ action_name } "
64+ paths << "pages/#{ controller_path } " if action_name == "index"
65+ paths << "pages/#{ controller_path . singularize } " if action_name == "show"
66+ paths << "#{ controller_path } /#{ action_name } _page"
67+ paths << "#{ controller_path } _page" if action_name == "index"
68+ paths << "#{ controller_path . singularize } _page" if action_name == "show"
69+ paths
70+ end
71+
72+ def possible_default_render_matestack_page_class_names
73+ possible_default_render_matestack_page_paths . collect { |page_path |
74+ page_path . split ( "/" ) . collect { |str | str . camelcase } . join ( "::" )
75+ }
76+ end
77+
78+ def default_render_matestack_page_class
79+ possible_default_render_matestack_page_class_names . each do |class_name |
80+ begin
81+ return matestack_class = class_name . constantize
82+ rescue NameError
83+ end
84+ end
85+ return nil
86+ end
87+
7088end
0 commit comments