Module: Ramaze::Helper::Sidebar

Defined in:
lib/cortex_reaver/helper/sidebar.rb

Overview

Provides programmatic sidebar boxes

Instance Method Summary collapse

Instance Method Details

#path_matches?(path) ⇒ Boolean

True if the given glob matches our request path.

Returns:

  • (Boolean)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/cortex_reaver/helper/sidebar.rb', line 17

def path_matches?(path)
  case path
  when String
    # Convert string to regex.
    pattern = path.gsub(/\*(\*)?/) do |match|
      if match[1]
        '.*'
      else
        '[^\/]*'
      end
    end

    if Regexp.new("^#{pattern}$").match request.path
      true
    else
      false
    end
  when Regexp
    if path.match request.path
      true
    else
      false
    end
  end
end

Renders the sidebar



6
7
8
9
10
11
12
13
14
# File 'lib/cortex_reaver/helper/sidebar.rb', line 6

def sidebar
  sidebar = ''
  CortexReaver.config.view.sidebar.each do |path, view|
    if path_matches? path
      sidebar << CortexReaver::MainController.render_view('sidebar/' + view)
    end
  end
  sidebar
end