very_simple_menu 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 654ee1bc2965cf8d9bc48b0c5302969c2523bcb6
4
+ data.tar.gz: 900244f6dd3700c1397ef865699aee6ef85b0821
5
+ SHA512:
6
+ metadata.gz: 14cfd182057b8cb239579e1dda32d308f0f396a1d42784a1c19629a66942617419be06da61afa93558977b4221784f92489d97316ba774574862ebfaadeda57d
7
+ data.tar.gz: 326b45b8d70e5e3d9efd56b003d91df8a11bec005b60445844db0c2a4a7230d47c7851441ff69c7d74cef1303f11305c10cb6cea9a8bc1fdf8f6dc7ec73e5920
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 Marcelo Guilherme Jacobus Jr
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # SimpleMenu
2
+
3
+ A simple menu builder
4
+
5
+ [![Build Status](https://travis-ci.org/mjacobus/very_simple_menu.png?branch=master)](https://travis-ci.org/mjacobus/very_simple_menu)
6
+ [![Coverage Status](https://coveralls.io/repos/mjacobus/very_simple_menu/badge.png)](https://coveralls.io/r/mjacobus/very_simple_menu)
7
+ [![Code Climate](https://codeclimate.com/github/mjacobus/very_simple_menu.png)](https://codeclimate.com/github/mjacobus/very_simple_menu)
8
+ [![Dependency Status](https://gemnasium.com/mjacobus/very_simple_menu.png)](https://gemnasium.com/mjacobus/very_simple_menu)
9
+ [![Gem Version](https://badge.fury.io/rb/very_simple_menu.png)](http://badge.fury.io/rb/very_simple_menu)
10
+
11
+ ## Instalation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'very_simple_menu'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+
24
+ Run bundle install
25
+
26
+ ## Usage
27
+
28
+ ## Layout (or even view)
29
+ ```erb
30
+ <%= simple_menu.add({
31
+ :products => ["Products", "/products"],
32
+ :services => ["Services", "/services"],
33
+ }) %>
34
+ ```
35
+
36
+ ## View
37
+
38
+ ```erb
39
+ # app/views/products/show.html.erb
40
+ <% simple_menu.active = :products %>
41
+ ```
42
+
43
+
44
+ renders
45
+
46
+ ```erb
47
+ <ul>
48
+ <li><a href="/products">Products</a></li>
49
+ <li><a href="/services">Services</a></li>
50
+ </ul>
51
+ ```
52
+
53
+ ## Aditional Menus
54
+
55
+ ```erb
56
+ <% simple_menu('sidebar').active = :all %>
57
+
58
+ <%= simple_menu('sidebar').add({
59
+ :all => ["All", "/products"],
60
+ :most_viewed => ["Most Viewed", "/products/most-viewed"],
61
+ }) %>
62
+ ```
63
+
64
+ ## Author
65
+
66
+ - [Marcelo Jacobus](https://github.com/mjacobus)
67
+
68
+
69
+ ## Contributing
70
+
71
+ 1. Fork it
72
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
73
+ **Do not forget to write tests**
74
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
75
+ 4. Push to the branch (`git push origin my-new-feature`)
76
+ 5. Create new Pull Request
77
+
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'SimpleMenu'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
@@ -0,0 +1,73 @@
1
+ module SimpleMenu
2
+ class Helper
3
+
4
+ # can be initialized with the items passed through params
5
+ def initialize(params = {})
6
+ clear
7
+ params.each do |key, options|
8
+ add(key, options[0], options[1], options[2])
9
+ end
10
+ end
11
+
12
+ def clear
13
+ @items = ActiveSupport::OrderedHash.new
14
+ self
15
+ end
16
+
17
+ def add(key, label = nil, url = nil, params = {})
18
+ if key.kind_of? Hash
19
+ key.each do |key, options|
20
+ add(key, options[0], options[1], options[2])
21
+ end
22
+ else
23
+ key = key.to_sym
24
+ if items.has_key? key
25
+ raise("key #{key} has already been taken")
26
+ end
27
+
28
+ items[key] = [label, url, params]
29
+ end
30
+
31
+ self
32
+ end
33
+
34
+ def items
35
+ @items
36
+ end
37
+
38
+ def active=(key)
39
+ if key
40
+ @active = key.to_sym
41
+ else
42
+ @active = nil
43
+ end
44
+
45
+ self
46
+ end
47
+
48
+ def active
49
+ @active
50
+ end
51
+
52
+ def to_s
53
+ html = []
54
+
55
+ items.each do |key, options|
56
+ if key == active
57
+ html << '<li class="active">'
58
+ else
59
+ html << '<li>'
60
+ end
61
+
62
+ html << "<a href=\"#{options[1]}\">#{options[0]}</a>"
63
+ html << '</li>'
64
+ end
65
+
66
+ if html.length > 0
67
+ "<ul>#{html.join('')}</ul>"
68
+ else
69
+ ""
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleMenu
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,11 @@
1
+ require "simple_menu/helper"
2
+
3
+ module SimpleMenu
4
+ def simple_menu(name = :default)
5
+ name = name.to_sym
6
+ @simple_menus ||= {}
7
+ @simple_menus[name] ||= SimpleMenu::Helper.new
8
+ end
9
+ end
10
+
11
+ ActionView::Base.send :include, SimpleMenu
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :simple_menu do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: very_simple_menu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Marcelo Jacobus
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard-rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Menu Helper
84
+ email:
85
+ - marcelo.jacobus@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - lib/simple_menu.rb
91
+ - lib/simple_menu/helper.rb
92
+ - lib/simple_menu/version.rb
93
+ - lib/tasks/simple_menu_tasks.rake
94
+ - MIT-LICENSE
95
+ - Rakefile
96
+ - README.md
97
+ homepage: http://github.com/mjacobus/very_simple_menu
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.0.3
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Menu Helper
121
+ test_files: []