Module: SemanticNavigation::Core::MixIn::DslMethods
- Included in:
- Navigation, Node
- Defined in:
- lib/semantic_navigation/core/mix_in/dsl_methods.rb
Instance Method Summary collapse
- #divider(options = {}) ⇒ Object
- #header(id, options = {}) ⇒ Object
- #item(id, url = nil, options = {}, &block) ⇒ Object
- #method_missing(m, *args, &block) ⇒ Object
- #scope(options = {}, &block) ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/semantic_navigation/core/mix_in/dsl_methods.rb', line 58 def method_missing(m,*args,&block) if m.to_s.match(/^[_]+$/).to_a.size > 0 divider else super(m,args,&block) end end |
Instance Method Details
#divider(options = {}) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/semantic_navigation/core/mix_in/dsl_methods.rb', line 49 def divider( = {}) [:id] = :divider [:render_if] ||= [[:render_if], *@scope_render_if].compact [:url] = nil [:i18n_name] = nil [:name] = nil @sub_elements.push Leaf.new(, @level+1) end |
#header(id, options = {}) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/semantic_navigation/core/mix_in/dsl_methods.rb', line 41 def header(id, ={}) [:id] = id.to_sym [:render_if] = [[:render_if], *@scope_render_if].compact [:url] = nil [:i18n_name] = @i18n_name @sub_elements.push Leaf.new(, @level+1) end |
#item(id, url = nil, options = {}, &block) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/semantic_navigation/core/mix_in/dsl_methods.rb', line 6 def item(id, url=nil, ={}, &block) [:id] = id.to_sym [:render_if] = [*@render_if, [:render_if], *@scope_render_if].compact if url.is_a?(Array) [:url] = [url].flatten(1).map{|url| scope_url_params(decode_url(url))} else [:url] = scope_url_params(decode_url(url)) end [:i18n_name] = @i18n_name if block_given? element = Node.new(, @level+1) element.instance_eval &block else element = Leaf.new(, @level+1) #Deprecation warning message #TODO:Should be deleted after moving the header and divider definition via item if element.url.nil? && !element.name.empty? SemanticNavigation.(:method, 'item', 'header', 'header definition') elsif element.url.nil? && element.name.empty? SemanticNavigation.(:method, 'item', 'header', 'divider definition') end end @sub_elements.push element end |
#scope(options = {}, &block) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/semantic_navigation/core/mix_in/dsl_methods.rb', line 66 def scope( = {}, &block) @scope_url ||= [:url] (@scope_render_if ||= []).push [:render_if] self.instance_eval &block @scope_render_if.pop @scope_url = {} end |