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
+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