merrymenu 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2011 YOURNAME
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.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = Merrymenu
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,16 @@
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
+
8
+ Bundler::GemHelper.install_tasks
9
+
10
+ require 'rspec/core'
11
+ require 'rspec/core/rake_task'
12
+ RSpec::Core::RakeTask.new(:spec) do |spec|
13
+ spec.pattern = FileList['spec/**/*_spec.rb']
14
+ end
15
+
16
+ task :default => :spec
@@ -0,0 +1,18 @@
1
+ module Merrymenu
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
5
+
6
+ desc <<DESC
7
+ Description:
8
+ Copies merrymenu configuration file to your application's initializer directory and merrymenu.css.scss
9
+ default stylesheet to the assets/stylesheets directory
10
+ DESC
11
+
12
+ def copy_config_file
13
+ template 'merrymenu_config.rb', 'config/initializers/merrymenu_config.rb'
14
+ template 'merrymenu.css.scss', 'app/assets/stylesheets/merrymenu.css.scss'
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ .menu {
2
+ .tab { float:left; }
3
+ }
@@ -0,0 +1,8 @@
1
+ # Example
2
+ # --------------------------------------------------
3
+ # Merrymenu::Builder.configure do |config|
4
+ # config.menu do |m|
5
+ # m.tab 'tab 1', '/tab1'
6
+ # m.tab 'tab 2', '/tab2'
7
+ # end
8
+ # end
@@ -0,0 +1,68 @@
1
+ module Merrymenu
2
+
3
+ class Configure
4
+ attr_accessor :menus
5
+
6
+ def initialize
7
+ @menus = {}
8
+ end
9
+
10
+ def configure
11
+ menu = Menu.new
12
+ yield menu
13
+ @menus[menu.name] = menu.build
14
+ end
15
+
16
+ end
17
+
18
+ class Menu
19
+ include ActiveSupport::Configurable
20
+ attr_accessor :name, :tabs, :use_I18n_translation
21
+
22
+ def initialize
23
+ self.use_I18n_translation = false
24
+ end
25
+
26
+ def menu(name="menu")
27
+ @name = name
28
+ tabs = Tabs.new
29
+ yield tabs
30
+ @tabs = tabs.build
31
+ end
32
+
33
+ def build
34
+ tabs
35
+ end
36
+ end
37
+
38
+ class Tabs
39
+ attr_accessor :tabs
40
+
41
+ def initialize
42
+ @tabs = []
43
+ end
44
+
45
+ def tab(name, url, options={})
46
+ @tabs << Tab.new(name, url, options)
47
+ end
48
+
49
+ def build
50
+ tabs
51
+ end
52
+
53
+ end
54
+
55
+ class Tab
56
+ attr_accessor :name, :url, :roles
57
+
58
+ def initialize(name, url, options={})
59
+ options = options.symbolize_keys.reverse_merge!(:roles => nil)
60
+ @name = name
61
+ @url = url
62
+ @roles = options[:roles]
63
+ end
64
+
65
+ end
66
+
67
+ Builder = Configure.new
68
+ end
@@ -0,0 +1,24 @@
1
+ require 'active_support/configurable'
2
+
3
+ module Merrymenu
4
+ # Configures global settings for Kaminari
5
+ # Merrymenu.configure do |config|
6
+ # config.use_I18n_translation = false
7
+ # end
8
+ def self.configure(&block)
9
+ yield @config ||= Merrymenu::Configuration.new
10
+ end
11
+
12
+ def self.config
13
+ @config
14
+ end
15
+
16
+ class Configuration #:nodoc:
17
+ include ActiveSupport::Configurable
18
+ config_accessor :use_I18n_translation
19
+ end
20
+
21
+ configure do |config|
22
+ config.use_I18n_translation = false
23
+ end
24
+ end
@@ -0,0 +1,13 @@
1
+ require 'merrymenu/config'
2
+ require 'merrymenu/view_helper'
3
+ require 'merrymenu/builder'
4
+
5
+ module Merrymenu
6
+ class Railtie < ::Rails::Railtie #:nodoc:
7
+ initializer 'merrymenu' do |app|
8
+ ActiveSupport.on_load(:action_view) do
9
+ ::ActionView::Base.send :include, Merrymenu::Helper
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Merrymenu
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,57 @@
1
+ module Merrymenu
2
+ module Helper
3
+
4
+ def render_menu(name="menu")
5
+
6
+ menu = Merrymenu::Builder.menus[name]
7
+ return "" if menu.nil?
8
+
9
+ tabs_html = ""
10
+
11
+ menu.each do |tab|
12
+ tabs_html << content_tag(:div, render_tab(tab), :class => tab_classes(tab)) if permit?(tab)
13
+ end
14
+
15
+ menu_html = content_tag(:div, tabs_html.html_safe, :class => name)
16
+ menu_html
17
+ end
18
+
19
+ def render_tab(tab)
20
+ # puts "CONFIG : #{config.inspect}"
21
+ # puts "Merrymenu CONFIG : #{Merrymenu.config.inspect}"
22
+ # puts "Merrymenu CONFIG use_I18n_translation : #{Merrymenu.config.use_I18n_translation}"
23
+ if Merrymenu.config.use_I18n_translation
24
+ content_tag(:a, I18n.t(tab.name), :href => tab.url)
25
+ else
26
+ content_tag(:a, tab.name, :href => tab.url)
27
+ end
28
+ end
29
+
30
+ protected
31
+
32
+ def tab_classes(tab)
33
+ classes = ['tab']
34
+ classes << 'current' if current_controller?(tab.url)
35
+ classes.join(' ')
36
+ end
37
+
38
+ def current_controller?(url)
39
+ pattern = url.gsub(/^\//, '')
40
+ result = controller.controller_path =~ /^#{pattern}/
41
+ return true unless result.nil?
42
+ end
43
+
44
+ def permit?(tab)
45
+ if tab.roles.nil?
46
+ return true
47
+ else
48
+ if @current_user
49
+ return @current_user.has_roles? tab.roles
50
+ else
51
+ false
52
+ end
53
+ end
54
+ end
55
+
56
+ end # end of helper
57
+ end # end of merrymenu
data/lib/merrymenu.rb ADDED
@@ -0,0 +1 @@
1
+ require 'merrymenu/railtie'
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :merrymenu do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: merrymenu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Franck D'agostini
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-15 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &70103282563900 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.1.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70103282563900
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec-rails
27
+ requirement: &70103282563220 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '2.5'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70103282563220
36
+ - !ruby/object:Gem::Dependency
37
+ name: sqlite3
38
+ requirement: &70103282562400 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70103282562400
47
+ - !ruby/object:Gem::Dependency
48
+ name: factory_girl_rails
49
+ requirement: &70103282561580 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.2'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70103282561580
58
+ description: Rails plugin to build a configurable html menu
59
+ email:
60
+ - franck.dagostini@gmail.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - lib/generators/merrymenu/install_generator.rb
66
+ - lib/generators/merrymenu/templates/merrymenu.css.scss
67
+ - lib/generators/merrymenu/templates/merrymenu_config.rb
68
+ - lib/merrymenu/builder.rb
69
+ - lib/merrymenu/config.rb
70
+ - lib/merrymenu/railtie.rb
71
+ - lib/merrymenu/version.rb
72
+ - lib/merrymenu/view_helper.rb
73
+ - lib/merrymenu.rb
74
+ - lib/tasks/merrymenu_tasks.rake
75
+ - MIT-LICENSE
76
+ - Rakefile
77
+ - README.rdoc
78
+ homepage: https://github.com/franck/merrymenu
79
+ licenses: []
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ segments:
91
+ - 0
92
+ hash: -241198786473309492
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ segments:
100
+ - 0
101
+ hash: -241198786473309492
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 1.8.11
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: Rails plugin to build a configurable html menu
108
+ test_files: []