add engine link option
This commit is contained in:
@@ -23,6 +23,8 @@
|
|||||||
li[ class=(controller_name == child_item.controller_name ? 'active' : '') ] = link_to child_item.title, child_item.path
|
li[ class=(controller_name == child_item.controller_name ? 'active' : '') ] = link_to child_item.title, child_item.path
|
||||||
- elsif menu_item.resource_link?
|
- elsif menu_item.resource_link?
|
||||||
li[ class=(menu_item.controller_name == controller_name ? 'active' : '')]= link_to menu_item.title, menu_item.path
|
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
|
.btn-group.pull-right
|
||||||
a.btn.dropdown-toggle[data-toggle="dropdown" href="#"]
|
a.btn.dropdown-toggle[data-toggle="dropdown" href="#"]
|
||||||
i.icon-user
|
i.icon-user
|
||||||
|
|||||||
@@ -48,6 +48,15 @@ module Cmtool
|
|||||||
return false if args.first.to_s.last == '?'
|
return false if args.first.to_s.last == '?'
|
||||||
@register.send(*args)
|
@register.send(*args)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def engine_link?
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
def resource_link?
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
@@ -79,6 +88,33 @@ module Cmtool
|
|||||||
end
|
end
|
||||||
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
|
# Resource link, indicates a link to standard resource. The first argument should
|
||||||
##
|
##
|
||||||
@@ -143,6 +179,11 @@ module Cmtool
|
|||||||
def resource_link(resource, options = {})
|
def resource_link(resource, options = {})
|
||||||
@items << ResourceLink.new(resource, options)
|
@items << ResourceLink.new(resource, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def engine_link(engine, options = {})
|
||||||
|
@items << EngineLink.new(resource, options)
|
||||||
|
end
|
||||||
|
|
||||||
def resource_links
|
def resource_links
|
||||||
@items.select{|i| i.is_a?(ResourceLink)}
|
@items.select{|i| i.is_a?(ResourceLink)}
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -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
|
||||||
Reference in New Issue
Block a user