add engine link option

This commit is contained in:
2012-12-26 20:45:22 +01:00
parent 55efff20a8
commit bf83d33527
3 changed files with 67 additions and 0 deletions
@@ -23,6 +23,8 @@
li[ class=(controller_name == child_item.controller_name ? 'active' : '') ] = link_to child_item.title, child_item.path
- elsif menu_item.resource_link?
li[ class=(menu_item.controller_name == controller_name ? 'active' : '')]= link_to menu_item.title, menu_item.path
- elsif menu_item.engine_link?
li= link_to menu_item.title, menu_item.path
.btn-group.pull-right
a.btn.dropdown-toggle[data-toggle="dropdown" href="#"]
i.icon-user
+41
View File
@@ -48,6 +48,15 @@ module Cmtool
return false if args.first.to_s.last == '?'
@register.send(*args)
end
def engine_link?
false
end
def resource_link?
false
end
end
##
@@ -79,6 +88,33 @@ module Cmtool
end
end
##
# Engine link, links to an engine. Root by default
##
class EngineLink < ElementBase
attr_reader :engine
def initialize(engine, options = {})
@engine, @options = engine, options
end
def engine_link?
true
end
def title
options[:title] || engine.name.split('::').first
end
def path
case options[:path]
when Symbol then engine.routes.url_helpers.send(:"#{options[:path]}_path")
when String then options[:path]
else engine.routes.url_helpers.root_path
end
end
end
##
# Resource link, indicates a link to standard resource. The first argument should
##
@@ -143,6 +179,11 @@ module Cmtool
def resource_link(resource, options = {})
@items << ResourceLink.new(resource, options)
end
def engine_link(engine, options = {})
@items << EngineLink.new(resource, options)
end
def resource_links
@items.select{|i| i.is_a?(ResourceLink)}
end
+24
View File
@@ -0,0 +1,24 @@
require 'spec_helper'
describe Cmtool::Menu::EngineLink do
let(:options) { Hash.new }
let(:link){ Cmtool::Menu::EngineLink.new(Cmtool::Engine, options)}
subject{ link }
its(:title) { should == 'Cmtool' }
it 'Should change title when given as option' do
options[:title] = 'Engine Title'
link.title.should == 'Engine Title'
end
it "should change the path to internal path when given as symbol option" do
options[:path] = :faqs
link.path.should == '/cmtool/faqs'
end
it "should directly return a path specified as a string in the options" do
options[:path] = 'http://www.google.com/'
link.path.should == 'http://www.google.com/'
end
end