uberkit 0.0.7
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 +20 -0
- data/README +149 -0
- data/Rakefile +15 -0
- data/VERSION.yml +5 -0
- data/lib/uberkit.rb +3 -0
- data/lib/uberkit/displayer.rb +15 -0
- data/lib/uberkit/form.rb +4 -0
- data/lib/uberkit/forms/builder.rb +97 -0
- data/lib/uberkit/forms/helper.rb +22 -0
- data/lib/uberkit/menu.rb +82 -0
- data/rails/init.rb +3 -0
- metadata +65 -0
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,149 @@
|
|
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
|
+
UberForms
|
20
|
+
---------
|
21
|
+
|
22
|
+
UberForms provide a simple context for building forms in a DRYer
|
23
|
+
manner by abstracting the markup into a simple, CSS-styleable
|
24
|
+
format. It is available as a form builder as Uberkit::Forms::Builder,
|
25
|
+
but is likely more useful when used in one of the helper forms:
|
26
|
+
uberform_for or remote_uberform_for.
|
27
|
+
|
28
|
+
=== Basic Example
|
29
|
+
|
30
|
+
<% uberform_for :user do |f| %>
|
31
|
+
<%= f.text_field :login %>
|
32
|
+
<%= f.password_field :password %>
|
33
|
+
<%= f.submit "Submit"%>
|
34
|
+
<% end %>
|
35
|
+
|
36
|
+
Becomes...
|
37
|
+
|
38
|
+
<form method="post" class="uberform" action="/users">
|
39
|
+
<div class="field_row">
|
40
|
+
<label for="user_login">Login:</label>
|
41
|
+
<input type="text" size="30" name="user[login]" id="user_login" class="text_field"/>
|
42
|
+
<br/>
|
43
|
+
</div>
|
44
|
+
<div class="field_row">
|
45
|
+
<label for="user_password">Password:</label>
|
46
|
+
<input type="password" size="30" name="user[password]" id="user_password" class="password_field"/>
|
47
|
+
<br/>
|
48
|
+
</div>
|
49
|
+
<button type="submit">Submit</button>
|
50
|
+
</form>
|
51
|
+
|
52
|
+
=== Labels, Help, and Descriptions
|
53
|
+
|
54
|
+
You can pass options into a given field to set a custom label,
|
55
|
+
some help text, or a description of the field.
|
56
|
+
|
57
|
+
<%= f.text_field :login, :label => "Username",
|
58
|
+
:help => "Only a-z and underscores.",
|
59
|
+
:description => "The name you will use to log in." %>
|
60
|
+
|
61
|
+
Becomes...
|
62
|
+
|
63
|
+
<div class="field_row">
|
64
|
+
<label for="user_login">Username:</label>
|
65
|
+
<input type="text" size="30" name="user[login]" label="Username" id="user_login" help="Only a-z and underscores." description="The name you will use to log in." class="text_field"/>
|
66
|
+
<span class="help">Only a-z and underscores.</span>
|
67
|
+
<span class="description">The name you will use to log in.</span>
|
68
|
+
<br/>
|
69
|
+
</div>
|
70
|
+
|
71
|
+
=== Custom Fields
|
72
|
+
|
73
|
+
Maybe the built-in form helpers won't do it for you. In that case, you
|
74
|
+
can use the custom helper to insert arbitrary HTML that still plays
|
75
|
+
nice with the rest of UberForms:
|
76
|
+
|
77
|
+
<% f.custom :label => "State", :for => "user_state" do |f| %>
|
78
|
+
<%= state_select :user, :state %>
|
79
|
+
<% end %>
|
80
|
+
|
81
|
+
Becomes...
|
82
|
+
|
83
|
+
<div class="field_row">
|
84
|
+
<label for="user_state">State:</label>
|
85
|
+
<div class="pseudo_field">
|
86
|
+
<select id="user_state">...</select>
|
87
|
+
</div>
|
88
|
+
<br/>
|
89
|
+
</div>
|
90
|
+
|
91
|
+
UberMenu
|
92
|
+
--------
|
93
|
+
|
94
|
+
UberMenu is the simplest way to generate the markup for CSS menus,
|
95
|
+
including state representation and special hooks for cross-browser
|
96
|
+
advanced CSS needs.
|
97
|
+
|
98
|
+
=== Basic Example
|
99
|
+
|
100
|
+
<% ubermenu do |m| %>
|
101
|
+
<% m.action 'Home', '/' %>
|
102
|
+
<% m.action 'Users', users_path %>
|
103
|
+
<% m.action 'Log Out', logout_path, :class => "special" %>
|
104
|
+
<% end %>
|
105
|
+
|
106
|
+
Becomes...
|
107
|
+
|
108
|
+
<ul>
|
109
|
+
<li class="first current first_current"><a href="/">Home</a></li>
|
110
|
+
<li><a href="/users">Users</a></li>
|
111
|
+
<li class="special last"><a href="/logout">Log Out</a></li>
|
112
|
+
</ul>
|
113
|
+
|
114
|
+
=== Submenus
|
115
|
+
|
116
|
+
You can nest ubermenus for subnavigation using the 'submenu' method.
|
117
|
+
If you pass :delegate instead of a url to the submenu option, it will
|
118
|
+
automatically pick up the url of the first action in the submenu instead.
|
119
|
+
|
120
|
+
<% ubermenu 'nav' do |m| %>
|
121
|
+
<% m.action 'Home', home_path %>
|
122
|
+
<% m.submenu 'Services', services_home_path do |s| %>
|
123
|
+
<% s.action 'Service A', service_path('a') %>
|
124
|
+
<% s.action 'Service B', service_path('b') %>
|
125
|
+
<% end %>
|
126
|
+
<% end %>
|
127
|
+
|
128
|
+
=== State
|
129
|
+
|
130
|
+
UberMenus automatically retain state using the current_page? helper.
|
131
|
+
You can specify further by passing a :current boolean expression to
|
132
|
+
evaluate whether or not the menu item is selected:
|
133
|
+
|
134
|
+
<% ubermenu 'nav' do |m| %>
|
135
|
+
<% m.action 'Users', users_path, :current => controller.controller_name == 'users' %>
|
136
|
+
<% end %>
|
137
|
+
|
138
|
+
=== Method Listing
|
139
|
+
|
140
|
+
* action - like link_to with additional options (see below)
|
141
|
+
:current - a boolean expression to determine whether this menu option is selected,
|
142
|
+
works with current_page? (if current_page? is true this will be true regardless)
|
143
|
+
:force_current - boolean expression that ignores the current_page?
|
144
|
+
:disabled - adds 'disabled' to class and forces non-current
|
145
|
+
* remote_action - like link_to_remote
|
146
|
+
* custom_action - only builds the outer <li>, accepts block for contents
|
147
|
+
* submenu - accepts a block yielding a new menu object
|
148
|
+
|
149
|
+
Copyright (c) 2008 Michael Bleigh and Intridea, Inc., released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |s|
|
4
|
+
s.name = "uberkit"
|
5
|
+
s.summary = "A Rails plugin for a common set of UI tools and helpers for building interfaces."
|
6
|
+
s.email = "michael@intridea.com"
|
7
|
+
s.homepage = "http://github.com/mbleigh/uberkit"
|
8
|
+
s.description = "UberKit is a set of tools for common UI problems in Rails including menus and forms."
|
9
|
+
s.authors = ["Michael Bleigh"]
|
10
|
+
s.files = FileList["[A-Z]*", "{lib,rails}/**/*"]
|
11
|
+
end
|
12
|
+
rescue LoadError
|
13
|
+
puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
14
|
+
end
|
15
|
+
|
data/VERSION.yml
ADDED
data/lib/uberkit.rb
ADDED
@@ -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
|
data/lib/uberkit/form.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
class Uberkit::Forms::Builder < ActionView::Helpers::FormBuilder
|
2
|
+
include ActionView::Helpers::CaptureHelper
|
3
|
+
include ActionView::Helpers::TextHelper
|
4
|
+
include ActionView::Helpers::UrlHelper
|
5
|
+
include ActionView::Helpers::TagHelper
|
6
|
+
|
7
|
+
helpers = field_helpers + %w(date_select datetime_select time_select select html_area state_select country_select check_box) - %w(hidden_field label fields_for)
|
8
|
+
|
9
|
+
helpers.each do |name|
|
10
|
+
define_method(name) do |field, *args|
|
11
|
+
options = args.extract_options!
|
12
|
+
class_names = array_from_classes(options[:class])
|
13
|
+
class_names << name
|
14
|
+
options[:class] = class_names.join(" ")
|
15
|
+
args << options
|
16
|
+
generic_field(options[:label],field,super(field,*args),{:description => options.delete(:description), :help => options.delete(:help), :required => options.delete(:required)})
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def generic_field(label_text,field,content,options = {})
|
21
|
+
required = options.delete(:required)
|
22
|
+
content_tag(:div, :class => "field_row#{' required' if required}#{' labelless' if label_text == ""}") do
|
23
|
+
ret = label(field, (label_text || field.to_s.titleize).to_s + ":") unless label_text == ""
|
24
|
+
ret << content
|
25
|
+
ret << content_tag(:span, options.delete(:help), :class => "help") if options[:help]
|
26
|
+
ret << content_tag(:span, options.delete(:description), :class => "description") if options[:description]
|
27
|
+
ret << "<br/>"
|
28
|
+
ret
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def reverse_field(label_text, field, content, options = {})
|
33
|
+
content_tag(:div, :class => "reverse_field#{' required' if options[:required]}#{' labelless' if options[:title].blank?}") do
|
34
|
+
result = ""
|
35
|
+
unless options[:title].blank?
|
36
|
+
result << content_tag(:span, options[:title], :class => "pseudo_label")
|
37
|
+
end
|
38
|
+
result << content_tag(:div, :class => "pseudo_field") do
|
39
|
+
ret = content
|
40
|
+
ret << label(field, label_text)
|
41
|
+
ret << content_tag(:span, options[:help], :class => 'help') unless options[:help].blank?
|
42
|
+
ret << content_tag(:span, options[:description], :class => 'description') unless options[:description].blank?
|
43
|
+
ret << "<br/>"
|
44
|
+
ret
|
45
|
+
end
|
46
|
+
result
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def check_box(field, options = {}, *args)
|
51
|
+
label_text = options.delete(:label) || field.to_s.titleize
|
52
|
+
help = options.delete(:help)
|
53
|
+
required = options.delete(:required)
|
54
|
+
description = options.delete(:description)
|
55
|
+
title = options.delete(:title)
|
56
|
+
reverse_field(label_text, field, super(field, options, *args), {:required => required, :help => help, :description => description, :title => title})
|
57
|
+
end
|
58
|
+
|
59
|
+
def radio_button(field, tag_value, options = {})
|
60
|
+
label_text = options.delete(:label) || tag_value.to_s.titleize
|
61
|
+
help = options.delete(:help)
|
62
|
+
required = options.delete(:required)
|
63
|
+
description = options.delete(:description)
|
64
|
+
title = options.delete(:title)
|
65
|
+
reverse_field(label_text, field, super(field, tag_value, options), {:required => required, :help => help, :description => description, :title => title} )
|
66
|
+
end
|
67
|
+
|
68
|
+
def submit(text)
|
69
|
+
content_tag(:button, text, :type => "submit")
|
70
|
+
end
|
71
|
+
|
72
|
+
def custom(options = {}, &block)
|
73
|
+
concat("<div class='field_row#{' labelless' unless options[:label]}'>#{"<label#{" for='#{options[:for]}'" if options[:for]}>#{options[:label] + ":" if options[:label]}</label>" if options[:label]}<div class='pseudo_field'>",block.binding)
|
74
|
+
yield
|
75
|
+
concat("</div> <br/></div>",block.binding)
|
76
|
+
end
|
77
|
+
|
78
|
+
def array_from_classes(html_classes)
|
79
|
+
html_classes ? html_classes.split(" ") : []
|
80
|
+
end
|
81
|
+
|
82
|
+
def fieldset(legend=nil,&block)
|
83
|
+
concat("<fieldset>#{"<legend>#{legend}</legend>" if legend}")
|
84
|
+
yield
|
85
|
+
concat("</fieldset>")
|
86
|
+
end
|
87
|
+
|
88
|
+
def output_buffer
|
89
|
+
@template.output_buffer
|
90
|
+
end
|
91
|
+
|
92
|
+
def output_buffer=(buf)
|
93
|
+
@template.output_buffer = buf
|
94
|
+
end
|
95
|
+
|
96
|
+
def is_haml?; false end
|
97
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Uberkit::Forms::Helper
|
2
|
+
def parse_options(*args)
|
3
|
+
options = args.extract_options!
|
4
|
+
options.merge!(:builder => Uberkit::Forms::Builder)
|
5
|
+
options[:html] ||= {}
|
6
|
+
class_names = options[:html][:class] ? options[:html][:class].split(" ") : []
|
7
|
+
class_names << "uberform"
|
8
|
+
class_names << options.delete(:kind).to_s
|
9
|
+
options[:html][:class] = class_names.join(" ")
|
10
|
+
args << options
|
11
|
+
end
|
12
|
+
|
13
|
+
def uberform_for(name_or_object_or_array, *args, &proc)
|
14
|
+
args = parse_options(*args)
|
15
|
+
form_for(name_or_object_or_array, *args, &proc)
|
16
|
+
end
|
17
|
+
|
18
|
+
def remote_uberform_for(name_or_object_or_array, *args, &proc)
|
19
|
+
args = parse_options(*args)
|
20
|
+
remote_form_for(name_or_object_or_array, *args, &proc)
|
21
|
+
end
|
22
|
+
end
|
data/lib/uberkit/menu.rb
ADDED
@@ -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]}, {:class => 'submenu'}]
|
64
|
+
else
|
65
|
+
@actions << [@template.link_to(name,options,html_options) + subnav.to_html, {:current => subnav.any_current?, :url => options}, {:class => 'submenu'}.merge(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/rails/init.rb
ADDED
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: uberkit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.7
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Bleigh
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-15 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: UberKit is a set of tools for common UI problems in Rails including menus and forms.
|
17
|
+
email: michael@intridea.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
files:
|
25
|
+
- MIT-LICENSE
|
26
|
+
- README
|
27
|
+
- Rakefile
|
28
|
+
- VERSION.yml
|
29
|
+
- lib/uberkit.rb
|
30
|
+
- lib/uberkit/displayer.rb
|
31
|
+
- lib/uberkit/form.rb
|
32
|
+
- lib/uberkit/forms/builder.rb
|
33
|
+
- lib/uberkit/forms/helper.rb
|
34
|
+
- lib/uberkit/menu.rb
|
35
|
+
- rails/init.rb
|
36
|
+
has_rdoc: true
|
37
|
+
homepage: http://github.com/mbleigh/uberkit
|
38
|
+
licenses: []
|
39
|
+
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options:
|
42
|
+
- --charset=UTF-8
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: "0"
|
50
|
+
version:
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
version:
|
57
|
+
requirements: []
|
58
|
+
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 1.3.5
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: A Rails plugin for a common set of UI tools and helpers for building interfaces.
|
64
|
+
test_files: []
|
65
|
+
|