Skip to content

Commit 42d24fa

Browse files
committed
extend render to support matestack pages
1 parent b322a69 commit 42d24fa

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

app/helpers/matestack/ui/core/application_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module Matestack
22
module Ui
33
module Core
44
module ApplicationHelper
5+
include Matestack::Ui::Core::Render
56

67
def render_page(page_class, only_page=false)
78
page_class.new(nil, context: {

app/lib/matestack/ui/core/render.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module Matestack::Ui::Core::Render
2+
3+
# Matestack allows you to use `render` to render matestack pages.
4+
#
5+
# render Pages::Member::Bookings
6+
# render matestack: Pages::Member::Bookings
7+
# render matestack: 'member/bookings'
8+
#
9+
def render(*args)
10+
if (matestack_class = args.first).is_a?(Class) && (matestack_class < Matestack::Ui::Page)
11+
responder_for matestack_class
12+
elsif (options = args.first).kind_of?(Hash) && (matestack_arg = options[:matestack]).present?
13+
if (matestack_path = matestack_arg).kind_of? String
14+
matestack_path = "pages/#{matestack_path}" unless matestack_path.start_with?("pages/") or matestack_path.start_with?("components/")
15+
matestack_class = matestack_path.split("/").collect { |str| str.camelcase }.join("::").constantize
16+
elsif matestack_arg.is_a?(Class) && (matestack_arg < Matestack::Ui::Page)
17+
matestack_class = matestack_arg
18+
end
19+
responder_for matestack_class
20+
else
21+
super
22+
end
23+
end
24+
25+
end

0 commit comments

Comments
 (0)