ioquatix-html_helpers 0.1.0

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/README ADDED
@@ -0,0 +1,93 @@
1
+ Copyright (c) 2008 Samuel Williams.
2
+ Development proudly sponsored by Orion Transfer Ltd.
3
+ http://www.oriontransfer.co.nz/
4
+
5
+ ===== HTML Helpers ====
6
+
7
+ As the name implies, HTML Helpers is a library of helper methods for producing nice HTML.
8
+
9
+ It is still very basic, but provides three things:
10
+
11
+ ==== Tabular Form Builder ====
12
+
13
+ The tabular form builder creates a <table> for forms. It's fairly easy to use.
14
+
15
+ Typically, one creates a form partial
16
+
17
+ * users/_form.rhtml
18
+ <code>
19
+ <% f.fieldset do %>
20
+ <%= f.error_messages %>
21
+ <%= f.text_field :login %>
22
+ <%= f.text_field :email %>
23
+
24
+ <%= f.text_field :password %>
25
+
26
+ <%= f.check_box :verified %>
27
+ <%= f.check_box :deleted %>
28
+
29
+ <%= f.submit %>
30
+ <% end %>
31
+ </code>
32
+
33
+ * users/new.rhtml
34
+ <code>
35
+ <h1>New User</h1>
36
+
37
+ <% table_form_for :user, :url => {:action => :create} do |f| %>
38
+ <%= f.render_form %>
39
+ <% end %>
40
+ </code>
41
+
42
+ ==== Icon Tag ====
43
+
44
+ This helper basically is a substitute for image_tag with a very specific purpose: putting icons on the page.
45
+
46
+ Most people should be familiar with icon sets such as http://www.famfamfam.com/. It is often useful to specify icons
47
+ in a generic way, especially when there are a lot of them.
48
+
49
+ Icon tag helps to minimize the amount of typing needed to put icons on the page. It also integrates with engines.
50
+
51
+ For example:
52
+
53
+ <code>
54
+ <%= link_if_authorized icon_tag(:edit), edit_user_path(user) %>
55
+ </code>
56
+
57
+ This searches through a number of different locations. In this case, #{controller} means "users" and #{icon} means :edit. For plugins, it searches:
58
+
59
+ - /public/images/#{controller}/#{icon}
60
+ - /public/plugin_assets/:plugin_name/images/#{controller}/#{icon}
61
+ - /public/images/default/#{icon}
62
+ - /public/plugin_assets/:plugin_name/images/default/#{icon}
63
+
64
+ Icons must be PNG at this time, but this may change in the future.
65
+
66
+ ==== Inside Layout ====
67
+
68
+ This helper basically allows you to render one layout inside another. For example:
69
+
70
+ * layouts/admin.rhtml
71
+ <code>
72
+ <% inside_layout 'application' do %>
73
+ <h1>Admin Interface</h1>
74
+ <%= yield %>
75
+ <% end %>
76
+ </code>
77
+
78
+ ===== License =====
79
+
80
+ This program is free software: you can redistribute it and/or modify
81
+ it under the terms of the GNU General Public License as published by
82
+ the Free Software Foundation, either version 3 of the License, or
83
+ (at your option) any later version.
84
+
85
+ This program is distributed in the hope that it will be useful,
86
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
87
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
88
+ GNU General Public License for more details.
89
+
90
+ You should have received a copy of the GNU General Public License
91
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
92
+
93
+
@@ -0,0 +1,5 @@
1
+
2
+ require 'html_helpers/tabular_form_builder'
3
+ require 'html_helpers/icons_helper'
4
+ require 'html_helpers/inside_layout'
5
+ require 'html_helpers/form_object'
@@ -0,0 +1,25 @@
1
+ module ApplicationHelper
2
+ def submit_button(value = "Save changes", url_for_options = {}, options = {}, *parameters_for_url)
3
+ options.stringify_keys!
4
+
5
+ options["action"] = url_for(url_for_options, *parameters_for_url) if url_for_options.size != 0
6
+
7
+ if disable_with = options.delete("disable_with")
8
+ options["onclick"] = "this.disabled=true;this.value='#{disable_with}';this.form.submit();#{options["onclick"]}"
9
+ end
10
+
11
+ if action = options.delete("action")
12
+ options["onclick"] = "this.form.action='#{escape_javascript(action)}';#{options['onclick']}"
13
+ end
14
+
15
+ if method = options.delete("method")
16
+ options["onclick"] = "this.form.method='#{escape_javascript(method)}';#{options['onclick']}"
17
+ end
18
+
19
+ if confirm = options.delete("confirm")
20
+ options["onclick"] = "if (!#{confirm_javascript_function(confirm)}){return false};#{options['onclick']}"
21
+ end
22
+
23
+ tag :input, { "type" => "submit", "name" => "commit", "value" => value }.update(options.stringify_keys)
24
+ end
25
+ end
@@ -0,0 +1,48 @@
1
+ module IconHelper
2
+ def self.current_plugin(c = caller)
3
+ current_file = File.expand_path c[0]
4
+ Engines.plugins.find do |plugin|
5
+ current_file.index(File.expand_path(plugin.directory)) == 0
6
+ end
7
+ end
8
+ end
9
+
10
+ module ApplicationHelper
11
+
12
+ DefaultIconCategory = "default"
13
+
14
+ def icon_path(category, icon, root = '')
15
+ File.join('', root, 'images', category.to_s, icon.to_s + '.png')
16
+ end
17
+
18
+ def icon_src(category, icon, root = '')
19
+ paths = []
20
+ paths << icon_path(category, icon)
21
+ paths << icon_path(category, icon, root)
22
+ paths << icon_path(DefaultIconCategory, icon, root)
23
+ paths << icon_path(DefaultIconCategory, icon)
24
+
25
+ paths.each { |p| $stderr.puts ("Icon Path: " + File.join(RAILS_ROOT, 'public', p)) }
26
+ return paths.find { |p| File.exist?(File.join(RAILS_ROOT, 'public', p)) }
27
+ end
28
+
29
+ def icon_tag(icon, options = {})
30
+ category = options.delete(:controller) || options.delete(:category) || controller.controller_name
31
+ root = options.delete('root') || ''
32
+
33
+ if defined? Engines.plugins
34
+ plugin = options.delete(:plugin) || IconHelper::current_plugin(caller)
35
+ root = File.join("plugin_assets", plugin.name) unless plugin.nil?
36
+ end
37
+
38
+ css_class = options.delete(:class) || 'icon'
39
+
40
+ src = icon_src(category, icon, root)
41
+
42
+ if src
43
+ return tag('img', {'class' => css_class, 'src' => src})
44
+ else
45
+ return options[:unavailable]
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,11 @@
1
+ module ApplicationHelper
2
+
3
+ def inside_layout(layout, &block)
4
+ @template.instance_variable_set("@content_for_layout", capture(&block))
5
+
6
+ layout = layout.include?("/") ? layout : "layouts/#{layout}" if layout
7
+ buffer = eval("_erbout", block.binding)
8
+ buffer.concat(@template.render_file(layout, true))
9
+ end
10
+
11
+ end
@@ -0,0 +1,123 @@
1
+ # Good
2
+
3
+ class ActionView::Helpers::FormBuilder
4
+ def render_form(partial = 'form', args = {})
5
+ ctr = eval("controller", @proc.binding)
6
+ ctr.send(:render, :partial => partial, :locals => {:f => self}.merge(args))
7
+ end
8
+
9
+ ButtonLabels = {'new' => 'Create', 'edit' => 'Update'}
10
+
11
+ def _button_label
12
+ ctr = eval("controller", @proc.binding)
13
+ action_name = ctr.action_name
14
+ return ButtonLabels[action_name] || action_name.camelcase
15
+ end
16
+ end
17
+
18
+ #module ApplicationHelper
19
+
20
+ class TabularFormBuilder < ActionView::Helpers::FormBuilder
21
+ ((field_helpers + ["select", "collection_select", "date_select", "time_select", "datetime_select"]) - %w(hidden_field)).each do |selector|
22
+ src = <<-END_SRC
23
+ def #{selector}(*args)
24
+ generic_form_field(#{selector.dump}, *args) { super(*args) }
25
+ end
26
+ END_SRC
27
+ class_eval src, __FILE__, __LINE__
28
+ end
29
+
30
+ def comments(text)
31
+ tr(td('') + td(text))
32
+ end
33
+
34
+ def submit(text = nil, options = {}, html_options = {})
35
+ text ||= _button_label
36
+ generic_field_html(nil, @template.submit_tag(text, html_options), options)
37
+ end
38
+
39
+ def file_column_field(field, options = {})
40
+ generic_field(field) { @template.file_column_field(@object_name, field, options) }
41
+ end
42
+
43
+ def fieldset(new_section_name = nil, &block)
44
+ s = ("<legend>#{new_section_name}</legend>" if new_section_name) || ""
45
+
46
+ @template.concat("<fieldset>#{s}<table>", block.binding)
47
+ yield
48
+ @template.concat("</table></fieldset>", block.binding)
49
+ end
50
+
51
+ def separator(new_section_name = nil)
52
+ s = ("<legend>#{new_section_name}</legend>" if new_section_name) || ""
53
+
54
+ @template.concat("</table></fieldset><fieldset>#{s}<table>", block.binding)
55
+ end
56
+
57
+ def generic_field(field_name, options = {}, &block)
58
+ field_text = @template.capture(&block)
59
+ @template.concat(generic_field_html(field_name, field_text, options), block.binding)
60
+ end
61
+
62
+ protected
63
+ def generic_field_html(field_name, field_text, options = {})
64
+ required = options.delete(:required) || false
65
+ required_text = required ? td('*', :class => 'required_field') : td('')
66
+
67
+ label_text = options.delete(:label) || field_name.to_s.humanize
68
+
69
+ unless label_text.blank?
70
+ if options[:label] == :after
71
+ tr(td('') + td(field_text + label(label_text, "#{@object_name}_#{field_name}", true)) + required_text)
72
+ else
73
+ tr(
74
+ td(label(label_text, "#{@object_name}_#{field_name}")) +
75
+ td(field_text) + required_text
76
+ )
77
+ end
78
+ else # No label
79
+ tr(td(field_text, :colspan => 2, :style => "text-align: right;") + required_text)
80
+ end
81
+ end
82
+
83
+ protected
84
+ def generic_form_field(selector, *args, &block)
85
+ field_name = args[0]
86
+ field_text = @template.capture(&block)
87
+
88
+ case selector
89
+ when "check_box": generic_field_html(field_name, field_text, args[1] || {})
90
+ when "collection_select": generic_field_html(field_name, field_text, args[4] || {})
91
+ when "country_select": generic_field_html(field_name, field_text, args[2] || {})
92
+ when "radio_button": generic_field_html(field_name, field_text, args[2] || {})
93
+ when "select": generic_field_html(field_name, field_text, args[2] || {})
94
+ when "time_zone_select": generic_field_html(field_name, field_text, args[2] || {})
95
+ else generic_field_html(field_name, field_text, args[1] || {})
96
+ end
97
+ end
98
+
99
+ def tr content, html_options = {}
100
+ @template.content_tag 'tr', content, html_options
101
+ end
102
+
103
+ def td content, html_options = {}
104
+ @template.content_tag 'td', content, html_options
105
+ end
106
+
107
+ def label text, for_field, after = false
108
+ @template.content_tag 'label', "#{text}#{after ? '' : ':'}", :for => for_field
109
+ end
110
+ end
111
+
112
+ def table_form_for(*args, &block)
113
+ if args.last.is_a? Hash
114
+ args.last[:builder] = TabularFormBuilder
115
+ else
116
+ options = {:builder => TabularFormBuilder}
117
+ args << options
118
+ end
119
+
120
+ form_for(*args, &block)
121
+ end
122
+
123
+ #end
@@ -0,0 +1,54 @@
1
+
2
+ /*Credits: Dynamic Drive CSS Library */
3
+ /*URL: http://www.dynamicdrive.com/style/ */
4
+
5
+ .pagination {
6
+ padding: 2px;
7
+ }
8
+
9
+ .pagination ul {
10
+ margin: 0;
11
+ padding: 0;
12
+ text-align: left; /*Set to "right" to right align pagination interface*/
13
+ font-size: 16px;
14
+ }
15
+
16
+ .pagination li {
17
+ list-style-type: none;
18
+ display: inline;
19
+ padding-bottom: 1px;
20
+ }
21
+
22
+ .pagination a, .pagination a:visited {
23
+ padding: 0 5px;
24
+ border: 1px solid #9aafe5;
25
+ text-decoration: none;
26
+ color: #2e6ab1;
27
+ }
28
+
29
+ .pagination a:hover, .pagination a:active {
30
+ border: 1px solid #2b66a5;
31
+ color: #000;
32
+ background-color: #ebebeb;
33
+ }
34
+
35
+ .pagination .currentpage {
36
+ padding: 0 5px;
37
+ border: 1px solid #2b66a5;
38
+ text-decoration: none;
39
+ background-color: #2e6ab1;
40
+ color: #FFF !important;
41
+ font-weight: bold;
42
+ }
43
+
44
+ .pagination .disablepage {
45
+ padding: 0 5px;
46
+ border: 1px solid #929292;
47
+ background-color: white;
48
+ color: #929292;
49
+ font-weight: ;
50
+ }
51
+
52
+ .pagination a.prevnext {
53
+ font-weight: bold;
54
+ }
data/rails/init.rb ADDED
File without changes
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ioquatix-html_helpers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Samuel Williams
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-10-24 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: ioquatix-engines
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
24
+ description:
25
+ email:
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files: []
31
+
32
+ files:
33
+ - lib/html_helpers
34
+ - lib/html_helpers/form_object.rb
35
+ - lib/html_helpers/icons_helper.rb
36
+ - lib/html_helpers/inside_layout.rb
37
+ - lib/html_helpers/tabular_form_builder.rb
38
+ - lib/html_helpers.rb
39
+ - rails/assets
40
+ - rails/assets/stylesheets
41
+ - rails/assets/stylesheets/pagination.css
42
+ - rails/init.rb
43
+ - README
44
+ has_rdoc: false
45
+ homepage: http://wiki.oriontransfer.org/?rails:html_helpers
46
+ post_install_message:
47
+ rdoc_options: []
48
+
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ requirements: []
64
+
65
+ rubyforge_project:
66
+ rubygems_version: 1.2.0
67
+ signing_key:
68
+ specification_version: 2
69
+ summary: HTML Helpers for Rails. Enhances support for HTML forms, images and layouts.
70
+ test_files: []
71
+