@@ -2,9 +2,9 @@ module Matestack::Ui::Core::Render
2
2
3
3
# Matestack allows you to use `render` to render matestack pages.
4
4
#
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 '
8
8
#
9
9
def render ( *args )
10
10
if ( matestack_class = args . first ) . is_a? ( Class ) && ( matestack_class < Matestack ::Ui ::Page )
@@ -37,8 +37,8 @@ def render(*args)
37
37
# end
38
38
# end
39
39
#
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 `.
42
42
#
43
43
# Custom action names translate also into page names.
44
44
#
@@ -51,20 +51,38 @@ def render(*args)
51
51
# `Pages::Clients::Bookings::Step1`.
52
52
#
53
53
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
65
56
else
66
57
super
67
58
end
68
59
end
69
60
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
+
70
88
end
0 commit comments