From be58b377e16c2b2138865171a1a01416b3e8a8db Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Fri, 27 Jun 2014 16:58:18 +0800 Subject: [PATCH] breadcrumbs for orbit 4.5 --- .../breadcrumb_widgets_controller.rb | 21 +++++++++++++++++++ lib/breadcrumb_widget/engine.rb | 6 ++++++ 2 files changed, 27 insertions(+) create mode 100644 app/controllers/breadcrumb_widgets_controller.rb diff --git a/app/controllers/breadcrumb_widgets_controller.rb b/app/controllers/breadcrumb_widgets_controller.rb new file mode 100644 index 0000000..1c8f11e --- /dev/null +++ b/app/controllers/breadcrumb_widgets_controller.rb @@ -0,0 +1,21 @@ +class BreadcrumbWidgetsController < ApplicationController + def widget + params = OrbitHelper.params + url = params["url"] + crumbs = url.split("/") + data = [] + crumbs.each do |crumb| + if crumb == "" + p = Page.root + data << {"page_name" => p.name, "url" => "/#{locale.to_s}" + p.url} + else + p = Page.where(:page_id => crumb).first + data << {"page_name" => p.name, "url" => "/#{locale.to_s}" + p.url} + end + end + { + "crumbs" => data + } + + end +end \ No newline at end of file diff --git a/lib/breadcrumb_widget/engine.rb b/lib/breadcrumb_widget/engine.rb index a7419e4..785f272 100644 --- a/lib/breadcrumb_widget/engine.rb +++ b/lib/breadcrumb_widget/engine.rb @@ -1,4 +1,10 @@ module BreadcrumbWidget class Engine < ::Rails::Engine + initializer "breadcrumb_widget" do + OrbitApp.registration "BreadcrumbWidget", :type => "OrbitWidget" do + widget_label "Breadcrumb" + widget_methods ["widget"] + end + end end end