45 lines
1.1 KiB
Ruby
45 lines
1.1 KiB
Ruby
class SiteMenuWidgetsController < ApplicationController
|
|
|
|
def widget
|
|
pages = Page.root.child_pages_enabled_for_sitemap
|
|
def create_json(pages)
|
|
items = []
|
|
pages.each do |page|
|
|
item = {}
|
|
if page.child_page.size > 0
|
|
if page.page_type == "page"
|
|
item["page_name"] = page.name
|
|
item["url"] = "/#{locale.to_s}" + page.url
|
|
item["children"] = create_json(page.sorted_published_child_pages)
|
|
item["target"] = "_self"
|
|
else
|
|
item["page_name"] = page.name
|
|
item["url"] = "/#{locale.to_s}" + page.url
|
|
item["children"] = create_json(page.sorted_published_child_pages)
|
|
item["target"] = "_blank"
|
|
end
|
|
else
|
|
if page.page_type == "page"
|
|
item["page_name"] = page.name
|
|
item["url"] = "/#{locale.to_s}" + page.url
|
|
item["target"] = "_self"
|
|
item["children"] = []
|
|
else
|
|
item["page_name"] = page.name
|
|
item["url"] = page.external_url
|
|
item["target"] = "_blank"
|
|
item["children"] = []
|
|
end
|
|
end
|
|
items << item
|
|
end
|
|
items
|
|
end
|
|
items = create_json(pages)
|
|
{
|
|
"pages" => items,
|
|
"extras" => {"widget_title" => "Sub Menu"}
|
|
}
|
|
|
|
end
|
|
end |