hierarchical_menu 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Changelog CHANGED
@@ -1,3 +1,12 @@
1
+ 0.1.1
2
+
3
+ * more documentation
4
+
5
+ 0.1.0
6
+
7
+ * general improvements
8
+ * #to_html_ul accepts code blocks
9
+
1
10
  0.0.1
2
11
 
3
12
  * "release earlier, release often"
@@ -1,8 +1,13 @@
1
1
  = Hierarchical Menu
2
2
 
3
- Hierarchical menu, based on <tt>rubytree gem</tt>. Outputs html (other formats
3
+ Hierarchical menu, based on <tt>rubytree</tt> gem. Outputs html (other formats
4
4
  planned) with optional JavaScript show/hide.
5
5
 
6
+ == Example client code.
7
+
8
+ See +examples/example.rb+ and +examples/example.css+ in the distribution
9
+ directory.
10
+
6
11
  == Synopsis
7
12
 
8
13
  require 'hmenu'
@@ -12,30 +17,47 @@ planned) with optional JavaScript show/hide.
12
17
  Simple example:
13
18
 
14
19
  root.add_path('/aaa/bbb/ccc/eee', {
15
- :name => 'test2',
16
- :href => '/xxx/yyy/2.html',
20
+ # all keys are optional
21
+ :name => 'test2',
22
+ :href => '/xxx/yyy/2.html',
23
+ :n => 10
24
+ :extra_class => 'my-css-class hmenu-selected'
17
25
  })
18
26
 
19
- With HTML list generator:
27
+ CSS class +hmenu-selected+ is special: it will be "opened" on startup
28
+ by the "embedded" JavaScript code (see below).
29
+
30
+ The +:n+ key will be used to sort list items.
31
+
32
+ === HTML list generator:
20
33
 
21
34
  html_ul_simple = root.to_html_ul
22
35
 
36
+ === Customize behavior
37
+
23
38
  You can add any extra/custom information:
24
39
 
25
40
  root.add_path('/aaa/bbb/ccc/ddd', {
26
41
  :name => 'test1',
27
42
  :href => '/xxx/yyy/zzz.html',
28
- :extra_info => Object.new
43
+ :custom_info => Object.new
29
44
  })
30
45
 
31
46
  And then match within a code block to ``mangle'' the output:
32
47
 
33
- html_ul = root.to_html_ul do |node, output|
34
- output[:name] += ' (extra_info is just an Object)' if
48
+ html_ul = root.to_html_ul do |node, output| # code block is optional!
49
+ if
35
50
  node.content.respond_to? :[] and
36
- node.content[:extra_info].class == Object
51
+ node.content[:custom_info].class == Object
52
+
53
+ output[:name] += ' (extra_info is just an Object)' # edit text
54
+ output[:extra_class] = 'hmenu-selected' # add a CSS class
55
+ output[:href] = nil # turn off hyperref
56
+ end
37
57
  end
38
58
 
59
+ === Style and JavaScript to show/hide: complete HTML output
60
+
39
61
  Some Style (HMenu::CSS), and some JavaScript code (HMenu::JS) to show/hide
40
62
  submenus:
41
63
 
@@ -46,7 +68,7 @@ submenus:
46
68
  </script>
47
69
  <style type="text/css">
48
70
  #{HMenu::CSS.out}
49
- #{File.read File.join HMenu::ROOTDIR, 'css/hmenu.more.example.css'}
71
+ #{File.read File.join HMenu::ROOTDIR, 'examples/example.css'}
50
72
  </style>
51
73
  </head>
52
74
  <body onload="reset_menus();">
@@ -1,4 +1,4 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/lib'
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '../lib'
2
2
 
3
3
  require 'hmenu'
4
4
 
@@ -21,9 +21,14 @@ root.add_path('/aaa/fff/ccc/eee', {
21
21
  })
22
22
 
23
23
  html_ul = root.to_html_ul do |node, output| # code block is optional!
24
- output[:name] += ' (extra_info is just an Object)' if
24
+ if
25
25
  node.content.respond_to? :[] and
26
26
  node.content[:extra_info].class == Object
27
+
28
+ output[:name] += ' (extra_info is just an Object)'
29
+ output[:extra_class] = 'hmenu-selected'
30
+ output[:href] = nil
31
+ end
27
32
  end
28
33
 
29
34
  puts <<END # you may use a template system like ERB if you wish...
@@ -33,7 +38,7 @@ puts <<END # you may use a template system like ERB if you wish...
33
38
  </script>
34
39
  <style type="text/css">
35
40
  #{HMenu::CSS.out}
36
- #{File.read File.join HMenu::ROOTDIR, 'css/hmenu.more.example.css'}
41
+ #{File.read File.join HMenu::ROOTDIR, 'examples/hmenu.more.example.css'}
37
42
  </style>
38
43
  </head>
39
44
  <body onload="reset_menus();">
@@ -17,7 +17,7 @@ a:hover {
17
17
  background: blue;
18
18
  }
19
19
 
20
- .hmenu-bullet:hover {
20
+ span.hmenu-bullet:hover, div.hmenu-bullet:hover {
21
21
  color: green;
22
22
  }
23
23
 
@@ -49,6 +49,7 @@ ul.hmenu li.hmenu-selected, ul.hmenu-submenu li.hmenu-selected {
49
49
  }
50
50
  ul.hmenu li, ul.hmenu-submenu li {
51
51
  padding: 0 5px; /* 4px + 1px = 5px */
52
+ line-height: 1.7em;
52
53
  }
53
54
 
54
55
  span.hmenu-root, div.hmenu-root {
@@ -56,4 +57,8 @@ span.hmenu-root, div.hmenu-root {
56
57
  border: none;
57
58
  }
58
59
 
60
+ ul {
61
+ padding-left: 1em;
62
+ }
63
+
59
64
 
@@ -7,7 +7,7 @@ module HMenu
7
7
  end
8
8
 
9
9
 
10
- VERSION = '0.1.0'
10
+ VERSION = '0.1.1'
11
11
  # TODO: manage symlinks...
12
12
  ROOTDIR = self.rootdir_pathname.to_s
13
13
 
@@ -2,6 +2,7 @@ require 'hmenu/constants'
2
2
 
3
3
  module HMenu
4
4
  module CSS
5
+ # Return a minimal CSS to make the menu work.
5
6
  def self.out
6
7
  File.read "#{::HMenu::ROOTDIR}/css/hmenu.css"
7
8
  end
@@ -6,14 +6,18 @@ require 'tree'
6
6
 
7
7
  module Tree
8
8
  class TreeNode
9
+ # Has the same effect of using Tree::TreeNode#<< multiple time
10
+ # but with a filepath-like syntax:
11
+ #
12
+ # node.add_recursive '/path/to/a/deep/node', "MyContent"
13
+ #
14
+ # A leading slash in the path means that it is absolute (i.e. refers
15
+ # to the tree root)
16
+ #
17
+ # path may be an Array (instead of String), but this is intended for
18
+ # "private" use only (i.e. recursive calls)
19
+ #
9
20
  def add_recursive(path, content)
10
- #
11
- # A leading slash in the path means that it is absolute (i.e. refers
12
- # to the tree root)
13
- #
14
- # path may be an Array (instead of String), but this is intended for
15
- # "private" use only (i.e. recursive calls)
16
- #
17
21
  if path.respond_to? :split
18
22
  path = path.split('/')
19
23
  end
@@ -2,6 +2,8 @@ require 'hmenu/constants'
2
2
 
3
3
  module HMenu
4
4
  module JS
5
+ # Return JavaScript code to show/hide submenus by clicking
6
+ # on list bullets.
5
7
  def self.out
6
8
  File.read "#{::HMenu::ROOTDIR}/js/hmenu.js"
7
9
  end
@@ -6,9 +6,45 @@ require 'hmenu/extensions/tree'
6
6
  module HMenu
7
7
  class Node < Tree::TreeNode
8
8
 
9
+ # See #Tree::TreeNode#add_recursive .
10
+ #
11
+ # +content_hash+ has the following pre-defined keys:
12
+ #
13
+ # +:n+:: Integer, for sorting (default +0+)
14
+ #
15
+ # +:name+:: String, displayed name (if different from node name takem from the path)
16
+ #
17
+ # +:description+:: String, will be rendered as a +title+ HTML attribute
18
+ #
19
+ # +:extra_class+:: String, add extra HTML/CSS class; you may also provide a space-separeted list of classes; NOTE: class +hmenu-selected+ is special: the JavaScript code from HMenu::JS.out (function +reset_menus()+) will expand items with such class instead of collasing them.
20
+ #
21
+ # You can add any custom keys and use them later for any customization.
22
+ #
23
+ def add_path(path, content_hash) # just for docs
24
+ super(node, content_hash)
25
+ end
26
+
27
+ # Retuns the HTML code for the menu as an unnumbered list.
28
+ #
29
+ # A block may optionally be provided to modify the output:
30
+ #
31
+ # html_ul = root.to_html_ul do |node, output|
32
+ # if
33
+ # node.content.respond_to? :[] and
34
+ # node.content[:extra_info].class == Object
35
+ #
36
+ # output[:name] += ' (extra_info is just an Object)'
37
+ # # modify the dsplayed name
38
+ # output[:extra_class] = 'hmenu-selected'
39
+ # # expanded/hghlightd by JS/CSS
40
+ # output[:href] = nil
41
+ # # turn off hyperlink
42
+ # end
43
+ # end
44
+ #
9
45
  def to_html_ul(&block)
10
- ctag = 'div'
11
- btag = 'div'
46
+ ctag = 'div' # HTML tag for content
47
+ btag = 'div' # HTML tag for bullets
12
48
 
13
49
  o = content ? content.clone : nil
14
50
  if block.respond_to? :call
@@ -71,6 +107,8 @@ module HMenu
71
107
  return s
72
108
  end
73
109
 
110
+ protected
111
+
74
112
  def <=>(other) # for sorting
75
113
  n <=> other.n
76
114
  end
@@ -83,16 +121,5 @@ module HMenu
83
121
  end
84
122
  end
85
123
 
86
- def mangle_output(o, &block)
87
- unless o
88
- if block.respond_to? :call
89
- o = {}
90
- block.call(self, o)
91
- else
92
- o = content.dup
93
- end
94
- end
95
- end
96
-
97
124
  end
98
125
  end
metadata CHANGED
@@ -1,12 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hierarchical_menu
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 0
9
- version: 0.1.0
4
+ version: 0.1.1
10
5
  platform: ruby
11
6
  authors:
12
7
  - Guido De Rosa
@@ -14,22 +9,19 @@ autorequire:
14
9
  bindir: bin
15
10
  cert_chain: []
16
11
 
17
- date: 2010-09-27 00:00:00 +02:00
12
+ date: 2010-09-28 00:00:00 +00:00
18
13
  default_executable:
19
14
  dependencies:
20
15
  - !ruby/object:Gem::Dependency
21
16
  name: rubytree
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
25
20
  requirements:
26
21
  - - ">="
27
22
  - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
23
  version: "0"
31
- type: :runtime
32
- version_requirements: *id001
24
+ version:
33
25
  description: Ruby Tree based hierarchical menus with HTML output and JavaScript show/hide
34
26
  email: guido.derosa@vemarsas.it
35
27
  executables: []
@@ -40,10 +32,10 @@ extra_rdoc_files:
40
32
  - README.rdoc
41
33
  files:
42
34
  - README.rdoc
43
- - example.rb
35
+ - examples/example.rb
44
36
  - Changelog
45
37
  - css/hmenu.css
46
- - css/hmenu.more.example.css
38
+ - examples/hmenu.more.example.css
47
39
  - js/hmenu.js
48
40
  - lib/hmenu.rb
49
41
  - lib/hmenu/extensions/tree.rb
@@ -53,8 +45,6 @@ files:
53
45
  - lib/hmenu/node.rb
54
46
  has_rdoc: true
55
47
  homepage: http://github.com/gderosa/hierarchical_menu
56
- licenses: []
57
-
58
48
  post_install_message:
59
49
  rdoc_options:
60
50
  - --main
@@ -62,27 +52,23 @@ rdoc_options:
62
52
  require_paths:
63
53
  - lib
64
54
  required_ruby_version: !ruby/object:Gem::Requirement
65
- none: false
66
55
  requirements:
67
56
  - - ">="
68
57
  - !ruby/object:Gem::Version
69
- segments:
70
- - 0
71
58
  version: "0"
59
+ version:
72
60
  required_rubygems_version: !ruby/object:Gem::Requirement
73
- none: false
74
61
  requirements:
75
62
  - - ">="
76
63
  - !ruby/object:Gem::Version
77
- segments:
78
- - 0
79
64
  version: "0"
65
+ version:
80
66
  requirements: []
81
67
 
82
68
  rubyforge_project:
83
- rubygems_version: 1.3.7
69
+ rubygems_version: 1.3.1
84
70
  signing_key:
85
- specification_version: 3
71
+ specification_version: 2
86
72
  summary: Hierarchical menus with html output
87
73
  test_files: []
88
74