mbleigh-uberkit 0.0.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/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Michael Bleigh and Intridea, Inc.
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 ADDED
@@ -0,0 +1,77 @@
1
+ Uberkit
2
+ =======
3
+
4
+ The Uberkit is a set of helpers to ease the development of common UI
5
+ practices.
6
+
7
+ Installation
8
+ ------------
9
+
10
+ Uberkit is available both as a gem and as a traditional plugin. To use
11
+ it as a gem, add this to your environment.rb:
12
+
13
+ config.gem 'mbleigh-uberkit', :lib => 'uberkit', :source => 'http://gems.github.com/'
14
+
15
+ To install it as a plugin (Rails 2.1 or later):
16
+
17
+ script/plugin install git://github.com/mbleigh/uberkit.git
18
+
19
+ UberMenu
20
+ --------
21
+
22
+ UberMenu is the simplest way to generate the markup for CSS menus,
23
+ including state representation and special hooks for cross-browser
24
+ advanced CSS needs.
25
+
26
+ === Basic Example
27
+
28
+ <% ubermenu do |m| %>
29
+ <% m.action 'Home', '/' %>
30
+ <% m.action 'Users', users_path %>
31
+ <% m.action 'Log Out', logout_path, :class => "special" %>
32
+ <% end %>
33
+
34
+ Becomes...
35
+
36
+ <ul>
37
+ <li class="first current first_current"><a href="/">Home</a></li>
38
+ <li><a href="/users">Users</a></li>
39
+ <li class="special last"><a href="/logout">Log Out</a></li>
40
+ </ul>
41
+
42
+ === Submenus
43
+
44
+ You can nest ubermenus for subnavigation using the 'submenu' method.
45
+ If you pass :delegate instead of a url to the submenu option, it will
46
+ automatically pick up the url of the first action in the submenu instead.
47
+
48
+ <% ubermenu 'nav' do |m| %>
49
+ <% m.action 'Home', home_path %>
50
+ <% m.submenu 'Services', services_home_path do |s| %>
51
+ <% s.action 'Service A', service_path('a') %>
52
+ <% s.action 'Service B', service_path('b') %>
53
+ <% end %>
54
+ <% end %>
55
+
56
+ === State
57
+
58
+ UberMenus automatically retain state using the current_page? helper.
59
+ You can specify further by passing a :current boolean expression to
60
+ evaluate whether or not the menu item is selected:
61
+
62
+ <% ubermenu 'nav' do |m| %>
63
+ <% m.action 'Users', users_path, :current => controller.controller_name == 'users' %>
64
+ <% end %>
65
+
66
+ === Method Listing
67
+
68
+ * action - like link_to with additional options (see below)
69
+ :current - a boolean expression to determine whether this menu option is selected,
70
+ works with current_page? (if current_page? is true this will be true regardless)
71
+ :force_current - boolean expression that ignores the current_page?
72
+ :disabled - adds 'disabled' to class and forces non-current
73
+ * remote_action - like link_to_remote
74
+ * custom_action - only builds the outer <li>, accepts block for contents
75
+ * submenu - accepts a block yielding a new menu object
76
+
77
+ Copyright (c) 2008 Michael Bleigh and Intridea, Inc., released under the MIT license
@@ -0,0 +1,15 @@
1
+ module Uberkit
2
+ class Displayer
3
+ include ActionView::Helpers::CaptureHelper
4
+ include ActionView::Helpers::TextHelper
5
+ include ActionView::Helpers::TagHelper
6
+
7
+ def initialize(template)
8
+ @template = template
9
+ end
10
+
11
+ def is_haml?
12
+ false
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,82 @@
1
+ module Uberkit
2
+ module Menu
3
+ def ubermenu(options = {}, &block)
4
+ nav = NavigationMenu.new(self,options)
5
+ yield nav
6
+ concat(nav.to_html, block.binding) if nav.actions.any?
7
+ end
8
+
9
+ class NavigationMenu < Uberkit::Displayer
10
+ def initialize(template,options = {})
11
+ super(template)
12
+ @actions = []
13
+ @subnavs = []
14
+ @id = options.delete(:id)
15
+ @class_name = options.delete(:class)
16
+ end
17
+
18
+ def action_wrapper(contents, options = {}, url_for_options = {})
19
+ classes = Array.new
20
+ classes << "first" if @actions.first == [contents, options, url_for_options]
21
+ classes << "last" if @actions.last == [contents, options, url_for_options]
22
+ classes << "current" if merits_current?(contents,options,url_for_options)
23
+ classes << "disabled" if options.delete(:disabled)
24
+ classes << classes.join("_") if classes.size > 1
25
+ content_tag(:li, contents, :class => classes.join(" "))
26
+ end
27
+
28
+ def merits_current?(contents,options={},url_for_options={})
29
+ if options[:force_current]
30
+ return true if options.delete(:current) == true && !options[:disabled]
31
+ else
32
+ return true if (options.delete(:current) == true || (!url_for_options.is_a?(Symbol) && (@template.current_page?(url_for_options)) && url_for_options != {}) and !options[:disabled])
33
+ end
34
+ false
35
+ end
36
+
37
+ def action(name, options = {}, html_options = {})
38
+ wrapper_options = { :current => html_options.delete(:current), :disabled => html_options.delete(:disabled), :force_current => html_options.delete(:force_current), :url => options }
39
+ @actions << [@template.link_to(name,options,html_options), wrapper_options, options]
40
+ end
41
+
42
+ def actions
43
+ @actions
44
+ end
45
+
46
+ def remote_action(name, options = {}, html_options = {})
47
+ wrapper_options = { :current => options.delete(:current), :disabled => options.delete(:disabled), :force_current => options.delete(:force_current), :url => options[:url] }
48
+ @actions << [@template.link_to_remote(name,options,html_options), wrapper_options, options[:url]]
49
+ end
50
+
51
+ def custom_action(options = {}, &block)
52
+ options[:force_current] = true
53
+ @actions << [capture(&block), options, {}]
54
+ end
55
+
56
+ def submenu(name, options = {}, html_options = {}, &block)
57
+ subnav = NavigationMenu.new(@template,html_options)
58
+ @subnavs << subnav
59
+ yield subnav
60
+
61
+ if subnav.actions.any?
62
+ if options == :delegate
63
+ @actions << [@template.link_to(name, subnav.actions.first[1][:url]) + subnav.to_html, {:current => subnav.any_current?, :url => subnav.actions.first[1][:url]}, options]
64
+ else
65
+ @actions << [@template.link_to(name,options,html_options) + subnav.to_html, {:current => subnav.any_current?, :url => options}, options] if subnav.actions.any?
66
+ end
67
+ end
68
+ end
69
+
70
+ def any_current?
71
+ @actions.select{|a| merits_current?(*a)}.any?
72
+ end
73
+
74
+ def build
75
+ content_tag :ul, @actions.collect{|a| action_wrapper(*a)}.join("\n"),
76
+ :id => @id,
77
+ :class => @class_name
78
+ end
79
+ alias :to_html :build
80
+ end
81
+ end
82
+ end
data/lib/uberkit.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'uberkit/displayer'
2
+ require 'uberkit/menu'
data/rails/init.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'uberkit'
2
+
3
+ ActionView::Base.send :include, Uberkit::Menu
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mbleigh-uberkit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michael Bleigh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-07-07 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: UberKit is a set of tools for common UI problems in Rails including menus.
17
+ email: michael@intridea.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - MIT-LICENSE
26
+ - README
27
+ - lib/uberkit/displayer.rb
28
+ - lib/uberkit/menu.rb
29
+ - lib/uberkit.rb
30
+ - rails/init.rb
31
+ has_rdoc: false
32
+ homepage: http://www.actsascommunity.com/projects/uberkit
33
+ post_install_message:
34
+ rdoc_options: []
35
+
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: "0"
43
+ version:
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ requirements: []
51
+
52
+ rubyforge_project:
53
+ rubygems_version: 1.2.0
54
+ signing_key:
55
+ specification_version: 2
56
+ summary: A Rails plugin for a common set of UI tools and helpers for building interfaces.
57
+ test_files: []
58
+