File: bootstrap-navi.rb

package info (click to toggle)
tdiary-contrib 5.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,772 kB
  • sloc: ruby: 17,305; javascript: 8,263; lisp: 562; xml: 451; php: 61; sql: 40; makefile: 18
file content (54 lines) | stat: -rw-r--r-- 1,401 bytes parent folder | download | duplicates (6)
1
2
3
4
5
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Show navi for twitter-bootstrap theme
#
# Copyright (c) KAOD Masanori <kdmsnr at gmail.com>
# You can redistribute it and/or modify it under GPL.

def bootstrap_navi(options = {})
  default_options = {
    :navbar_class => nil,
    :site_name? => true,
    :search_form? => true
  }
  options = default_options.merge(options)

  body = ""
  if options[:site_name?]
    body += <<-EOS
      <a class="brand" href="#{@conf.index}">#{h @conf.html_title}</a>
    EOS
  end

  body += <<-EOS
      <ul class="nav">
        #{navi_user.gsub(/span/, "li")}
        #{navi_admin.gsub(/span/, "li")}
      </ul>
  EOS

  if options[:search_form?]
    body += <<-EOS
      <form class="navbar-search pull-left"
        method="get" action="http://www.google.co.jp/search"
        onsubmit="$('#sitesearch').val($(location).attr('host')+$(location).attr('pathname'))">
        <input type="hidden" name="ie" value="UTF8">
        <input type="hidden" name="oe" value="UTF8">
        <input type="hidden" name="sitesearch" id="sitesearch">
        <input type="text" class="search-query" placeholder="Search" name="q">
      </form>
    EOS
  end

  <<-EOS
<div class="navbar #{options[:navbar_class]}">
  <div class="navbar-inner">
    <div class="container">
      #{body}
    </div>
  </div>
</div>
EOS
end

add_header_proc do
  %Q|<meta name="viewport" content="width=device-width, initial-scale=1.0">|
end