Module: SemanticNavigation::Core::MixIn::DslMethods

Included in:
Navigation, Node
Defined in:
lib/semantic_navigation/core/mix_in/dsl_methods.rb

Instance Method Summary collapse

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(options = {})
  options[:id] = :divider
  options[:render_if] ||= [options[:render_if], *@scope_render_if].compact
  options[:url] = nil
  options[:i18n_name] = nil
  options[:name] = nil
  @sub_elements.push Leaf.new(options, @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, options={})
  options[:id] = id.to_sym
  options[:render_if] = [options[:render_if], *@scope_render_if].compact
  options[:url] = nil
  options[:i18n_name] = @i18n_name
  @sub_elements.push Leaf.new(options, @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, options={}, &block)
  options[:id] = id.to_sym
  options[:render_if] = [*@render_if, options[:render_if], *@scope_render_if].compact

  if url.is_a?(Array)
    options[:url] = [url].flatten(1).map{|url| scope_url_params(decode_url(url))}
  else
    options[:url] = scope_url_params(decode_url(url))
  end

  options[:i18n_name] = @i18n_name

  if block_given?
    element = Node.new(options, @level+1)
    element.instance_eval &block
  else
    element = Leaf.new(options, @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.deprecation_message(:method,
                                             'item',
                                             'header',
                                             'header definition')
    elsif element.url.nil? && element.name.empty?
      SemanticNavigation.deprecation_message(: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(options = {}, &block)
  @scope_url ||= options[:url]
  (@scope_render_if ||= []).push options[:render_if]

  self.instance_eval &block

  @scope_render_if.pop
  @scope_url = {}
end