dynamic_menu 0.2.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest CHANGED
@@ -1,5 +1,4 @@
1
1
  README.rdoc
2
2
  Rakefile
3
- dynamic_menu.gemspec
4
3
  lib/dynamic_menu.rb
5
4
  Manifest
data/README.rdoc CHANGED
@@ -1,70 +1,30 @@
1
- =Dynamic Menu
2
- ==Introduction
3
- Dynamic Menu is a gem to make it easy to add a custom menu to your application via a controller.
4
- == Install
5
- You need to add:
1
+ =DYNAMIC MENU
6
2
 
7
- gem "dynamic_menu"
3
+ Dynamic Menu is a Gem that provides a way to make it easy to create a menu that changes according
4
+ to the controller action. The controller passes in information into an array which is accessed by
5
+ the view.
8
6
 
9
- to your gemfile if you would like the latest stable version
7
+ ==Installation
8
+ While pre-1.0 releases exits we recommend not using them as the code in them is not the best
9
+ and will not auto-load into your controller, they will not be commented on here.
10
10
 
11
- if you would like the latest version (could be broke at download) you can add
12
- this line to your gemfile:
11
+ In your Gemfile make sure you have
13
12
 
14
- gem "dynamic_menu",:git=>"git://github.com/plowdawg/dynamic_menu.git"
13
+ gem 'dynamic_menu','~>1.0.0'
15
14
 
16
- == How to use
15
+ then run bundle install
17
16
 
18
- ===Option1
19
- You can create an array in a controller like so:
17
+ ==How to use
18
+ To use DynamicMenu you need to create an array such as @MenuItems and store items in it.
19
+ So in your controller in each method you can do something like:
20
20
 
21
- @actionMenuItem = Array.new
21
+ @MenuItems = Array.new
22
22
 
23
- option1 = DynamicMenu::ActionMenuItem.new("Name",link_to_path)
23
+ @MenuItems << newmenuitem("name","link")
24
24
 
25
- @actionMenuItem[0] = option1
25
+ newmenuitem() is the method you need to use to add a menu-item.
26
26
 
27
- then you can refrence it by using a loop such as
28
-
29
- @actionMenuItem.each do |menu|
30
-
31
- menu.link_tag #this generates the entire link
32
-
33
- end
34
-
35
- if you need a delete and confirmation method then you can declare it like so:
36
-
37
- option1 = DynamicMenu::ActionMenuItem.new("Link Name", link_to_path, :delete, "Are you sure?")
38
-
39
- the first is what the link will look like on the view, second is the view, third is the method (only works
40
- for delete) and the fourth is the confirmation method (which also only works on delete)
41
-
42
- ===Option2
43
- Like Option1 except in your controller you can declare include DynamicForm right underneath the class
44
-
45
- like so:
46
-
47
- class SomeController < ApplicationController
48
-
49
- include DynamicMenu
50
-
51
- then instead of using DynamicMenu::ActionMenuItem.new you can use ActionMenuItem.new
52
-
53
-
54
- ==Tips
55
- To prevent long code you can no arrays like so:
56
-
57
- @actionMenuItems = Array.new
58
-
59
- @actionMenuItems << ActionMenuItem.new("Link",link_path)
60
-
61
- ==Updates
62
- As of 0.2.0 you can now make a custom submit link via the Dynamic Menu. It is buggy in 0.2.0 so we recommend that you use 0.2.1 if you would like to do this. This option requires you to be using JQuery or somehow reference it, as the code to detect the enter key runs with its syntax.
63
-
64
- To make a link that acts like a submit button simply use :submit as a link.
65
-
66
- As of 0.2.2 you can use :back as link because it will load a javascript to get you back
67
-
68
- For example:
69
-
70
- @actionMenuItems << ActionMenuItem.new("Submit Form",:submit)
27
+ newmenuitem has the arguments of name, link, method, and confirm. Method and confirm only
28
+ need to be specified if you are using anything other than get. Link may use :submit which
29
+ will submit a form when clicked and add a JavaScript method to listen for the enter key to
30
+ submit the form. Name and Link are the only required fields and are both Strings...
data/Rakefile CHANGED
@@ -2,13 +2,16 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('dynamic_menu', '0.2.3') do |p|
5
+ Echoe.new('dynamic_menu', '1.0.0') do |p|
6
6
  p.description = "Allow the creation of Menus"
7
7
  p.url = "http://pessetto.com"
8
8
  p.author = "Travis Pessettto"
9
9
  p.email = "travis@pessetto.com"
10
10
  p.ignore_pattern = ["tmp/*", "script/*"]
11
11
  p.development_dependencies = []
12
+
12
13
  end
13
14
 
15
+
16
+
14
17
  Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
data/dynamic_menu.gemspec CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{dynamic_menu}
5
- s.version = "0.2.3"
5
+ s.version = "1.0.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = [%q{Travis Pessettto}]
9
- s.date = %q{2011-08-08}
9
+ s.date = %q{2011-08-12}
10
10
  s.description = %q{Allow the creation of Menus}
11
11
  s.email = %q{travis@pessetto.com}
12
12
  s.extra_rdoc_files = [%q{README.rdoc}, %q{lib/dynamic_menu.rb}]
13
- s.files = [%q{README.rdoc}, %q{Rakefile}, %q{dynamic_menu.gemspec}, %q{lib/dynamic_menu.rb}, %q{Manifest}]
13
+ s.files = [%q{README.rdoc}, %q{Rakefile}, %q{lib/dynamic_menu.rb},%q{lib/engine.rb}, %q{Manifest}, %q{dynamic_menu.gemspec}]
14
14
  s.homepage = %q{http://pessetto.com}
15
15
  s.rdoc_options = [%q{--line-numbers}, %q{--inline-source}, %q{--title}, %q{Dynamic_menu}, %q{--main}, %q{README.rdoc}]
16
16
  s.require_paths = [%q{lib}]
data/lib/dynamic_menu.rb CHANGED
@@ -1,49 +1,43 @@
1
1
  module DynamicMenu
2
-
3
- class ActionMenuItem
4
- include ActionView::Helpers::UrlHelper
5
- include ActionView::Helpers::JavaScriptHelper
6
-
7
- attr_accessor :name, :link, :method, :link_tag
8
-
9
- def initialize(name, link , method = :get, confirm="Are You Sure?")
10
- @name = name
11
- @link = link
12
- @method = method
13
- @link_tag = ""
2
+ require 'engine' if defined?(Rails)
3
+
4
+ module MenuItems
5
+ def newmenuitem(name,link,method=:get,confirm="Are you sure?")
6
+ genlink = ""
14
7
 
15
-
16
- if method == :delete
17
- @link_tag = link_to name, link, :method=>method, :confirm=>confirm
18
- else
19
- if link == :submit
20
- #make it easy to include a submit button via link...for enter support...requires
21
- #JQUERY!!!
22
- @link_tag = link_to_function name, "$('form').submit()"
8
+ if method==:delete
9
+ genlink += "<a href=\"#{link}\" data-confirm=\"#{confirm}\" data-method=\"delete\" rel=\"nofollow\">
10
+ #{name}</a>".html_safe
11
+ elsif link==:submit
12
+ genlink += "<a href=\"#\" onclick=\"$('form').submit(); return false;\">#{name}</a>".html_safe
23
13
  @link_tag += "<script type=\"text/javascript\">
24
14
  $(document).ready(function(){
25
15
  $('html').keypress(function(e){
26
- if(e.which == 13){
16
+ if(e.which == 13){
27
17
  $('form').submit();
28
- return false;
29
- }
18
+ return false;
19
+ }
30
20
  });
31
21
  });</script>".html_safe
32
- elsif link == :back
33
- @link_tag = "<a href=\"#\" id=\"jcheats-back\">#{name}</a>".html_safe
34
- @link_tag += "<script type=\"text/javascript\">
35
- $(\"#jcheats-back\").live(\"click\",
22
+ elsif link == :back
23
+ genlink = "<a href=\"#\" id=\"jcheats-back\">#{name}</a>".html_safe
24
+ genlink += "<script type=\"text/javascript\">
25
+ $(\"#jcheats-back\").live(\"click\",
36
26
  function(){
37
- var ref = document.referrer;
38
- document.location=ref;
27
+ var ref = document.referrer;
28
+ document.location=ref;
39
29
  });
40
- </script>".html_safe
41
- else
42
- @link_tag = link_to name, link
43
- end #end if submit
44
- end #end if delete
45
- end #end initalize
30
+ </script>".html_safe
31
+ else
32
+ genlink = "<a href=\"#{link}\">#{name}<a>".html_safe
33
+ end
34
+ return genlink
35
+ end
36
+
46
37
 
47
- end #end actionmenu Item
38
+ def foo
39
+ "bar"
40
+ end
48
41
 
49
- end #end Modlue
42
+ end
43
+ end
data/lib/engine.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'dynamic_menu'
2
+
3
+ module DynamicMenu
4
+ class Engine < Rails::Engine
5
+ initializer "dynamic_menu.menu_items" do |app|
6
+ ActionController::Base.send :include, DynamicMenu::MenuItems
7
+ end
8
+ end
9
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamic_menu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-08 00:00:00.000000000Z
12
+ date: 2011-08-12 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: Allow the creation of Menus
15
15
  email: travis@pessetto.com
@@ -21,9 +21,10 @@ extra_rdoc_files:
21
21
  files:
22
22
  - README.rdoc
23
23
  - Rakefile
24
- - dynamic_menu.gemspec
25
24
  - lib/dynamic_menu.rb
25
+ - lib/engine.rb
26
26
  - Manifest
27
+ - dynamic_menu.gemspec
27
28
  homepage: http://pessetto.com
28
29
  licenses: []
29
30
  post_install_message: