robinsp-robins_html_helpers 0.1.2 → 0.2.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.
Files changed (31) hide show
  1. data/Manifest +30 -0
  2. data/README.rdoc +17 -1
  3. data/Rakefile +2 -1
  4. data/lib/robins_html_helpers.rb +34 -6
  5. data/lib/robins_html_helpers/form_builder.rb +59 -0
  6. data/rails_generators/robins_html_helpers_resources/USAGE +0 -0
  7. data/rails_generators/robins_html_helpers_resources/robins_html_helpers_resources_generator.rb +14 -0
  8. data/rails_generators/robins_html_helpers_resources/templates/robins_html_helpers.css +6 -0
  9. data/rails_generators/robins_html_helpers_resources/templates/robins_html_helpers.js +50 -0
  10. data/robins_html_helpers.gemspec +6 -6
  11. data/spec/helpers/helpers_spec.rb +72 -0
  12. data/spec/models/form_builder_spec.rb +142 -0
  13. data/spec/railsenv/app/controllers/application_controller.rb +10 -0
  14. data/spec/railsenv/config/boot.rb +110 -0
  15. data/spec/railsenv/config/database.yml +22 -0
  16. data/spec/railsenv/config/environment.rb +41 -0
  17. data/spec/railsenv/config/environments/development.rb +17 -0
  18. data/spec/railsenv/config/environments/production.rb +28 -0
  19. data/spec/railsenv/config/environments/test.rb +28 -0
  20. data/spec/railsenv/config/initializers/backtrace_silencers.rb +7 -0
  21. data/spec/railsenv/config/initializers/inflections.rb +10 -0
  22. data/spec/railsenv/config/initializers/mime_types.rb +5 -0
  23. data/spec/railsenv/config/initializers/new_rails_defaults.rb +19 -0
  24. data/spec/railsenv/config/initializers/session_store.rb +15 -0
  25. data/spec/railsenv/config/locales/en.yml +5 -0
  26. data/spec/railsenv/config/routes.rb +43 -0
  27. data/spec/railsenv/db/test.sqlite3 +0 -0
  28. data/spec/spec.opts +4 -0
  29. data/spec/spec_helper.rb +21 -0
  30. data/tasks/rspec.rake +6 -0
  31. metadata +31 -4
data/Manifest ADDED
@@ -0,0 +1,30 @@
1
+ rails_generators/robins_html_helpers_resources/USAGE
2
+ rails_generators/robins_html_helpers_resources/templates/robins_html_helpers.css
3
+ rails_generators/robins_html_helpers_resources/templates/robins_html_helpers.js
4
+ rails_generators/robins_html_helpers_resources/robins_html_helpers_resources_generator.rb
5
+ spec/railsenv/config/routes.rb
6
+ spec/railsenv/config/environments/production.rb
7
+ spec/railsenv/config/environments/test.rb
8
+ spec/railsenv/config/environments/development.rb
9
+ spec/railsenv/config/environment.rb
10
+ spec/railsenv/config/initializers/new_rails_defaults.rb
11
+ spec/railsenv/config/initializers/backtrace_silencers.rb
12
+ spec/railsenv/config/initializers/session_store.rb
13
+ spec/railsenv/config/initializers/inflections.rb
14
+ spec/railsenv/config/initializers/mime_types.rb
15
+ spec/railsenv/config/database.yml
16
+ spec/railsenv/config/boot.rb
17
+ spec/railsenv/config/locales/en.yml
18
+ spec/railsenv/db/test.sqlite3
19
+ spec/railsenv/app/controllers/application_controller.rb
20
+ spec/models/form_builder_spec.rb
21
+ spec/spec.opts
22
+ spec/spec_helper.rb
23
+ spec/helpers/helpers_spec.rb
24
+ robins_html_helpers.gemspec
25
+ Rakefile
26
+ Manifest
27
+ tasks/rspec.rake
28
+ lib/robins_html_helpers/form_builder.rb
29
+ lib/robins_html_helpers.rb
30
+ README.rdoc
data/README.rdoc CHANGED
@@ -1 +1,17 @@
1
- # Helpers for HTML stuff I use frequently.
1
+ =Robin's HTML Helpers
2
+ Some of the helpers I use frequently when working on Rails views.
3
+
4
+ === Install
5
+
6
+ Add GitHub as a gem source repo if you haven't already done so:
7
+ $ gem sources -a http://gems.github.com
8
+
9
+ Install this gem:
10
+ $ sudo gem install robinsp-robins_html_helpers
11
+
12
+ === Rails
13
+ If you want to configure your Rails app to explicitly require this gem, add something
14
+ like this to the config block in environment.rb:
15
+ config.gem 'robinsp-robins_html_helpers',
16
+ :lib => 'robins_html_helpers',
17
+ :source => 'http://gems.github.com'
data/Rakefile CHANGED
@@ -7,13 +7,14 @@ require 'rubygems'
7
7
  require 'rake'
8
8
  require 'echoe'
9
9
 
10
- Echoe.new('robins_html_helpers', '0.1.2') do |p|
10
+ Echoe.new('robins_html_helpers', '0.2.0') do |p|
11
11
  p.description = "HTML stuff I use frequently."
12
12
  p.url = "http://github.com/robinsp/robins_html_helpers"
13
13
  p.author = "Robin Spainhour"
14
14
  p.email = "robin@robinspainhour.com"
15
15
  p.ignore_pattern = ["tmp/*", "script/*", ".project"]
16
16
  p.development_dependencies = []
17
+ p.runtime_dependencies = []
17
18
  end
18
19
 
19
20
  Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
@@ -1,12 +1,40 @@
1
1
  module RobinsHtmlHelpers
2
-
3
- # TODO: Document the options argument
2
+
3
+ # Wraps the content of its enclosed block in four divs that can hold corner images
4
+ # to create a rounded corner effect on a web page.
5
+ #
6
+ # ==== Example
7
+ #
8
+ # <% boxed_content do %>
9
+ # <p>Wrap me!</p>
10
+ # <% end %>
11
+ #
12
+ # Produces this HTML:
13
+ #
14
+ # <div class="box_bottom_left">
15
+ # <div class="box_bottom_right">
16
+ # <div class="box_top_left">
17
+ # <div class="box_top_right">
18
+ # <p>Wrap me!</p>
19
+ # </div>
20
+ # </div>
21
+ # </div>
22
+ # </div>
23
+ #
24
+ #
25
+ # The optional hash argument can be used to customize the classes and ids of the outermost
26
+ # and innermost divs:
27
+ #
28
+ # * <tt>:outer_class</tt> - CSS class of the outer div. Defaults to <tt>box_bottom_left</tt>
29
+ # * <tt>:inner_class</tt> - CSS class of the inner div. Defaults to <tt>box_top_right</tt>
30
+ # * <tt>:outer_id</tt> - HTML id of the outer div. (Not set by default)
31
+ # * <tt>:inner_id</tt> - HTML id of the inner div. (Not set by default)
4
32
  def boxed_content(options = {}, &block)
5
33
  # Default class names
6
- options[:bottom_left_class] ||= 'box_bottom_left'
7
- options[:bottom_right_class] ||= 'box_bottom_right'
8
- options[:top_left_class] ||= 'box_top_left'
9
- options[:top_right_class] ||= 'box_top_right'
34
+ options[:bottom_left_class] ||= 'box_bottom_left'
35
+ options[:bottom_right_class] ||= 'box_bottom_right'
36
+ options[:top_left_class] ||= 'box_top_left'
37
+ options[:top_right_class] ||= 'box_top_right'
10
38
 
11
39
  if options[:inner_class]
12
40
  options[:inner_class] = options[:inner_class] + " " + options[:top_right_class]
@@ -0,0 +1,59 @@
1
+ module RobinsHtmlHelpers
2
+ class FormBuilder < ActionView::Helpers::FormBuilder
3
+
4
+ def text_field(method, options = {})
5
+ label_text = options.delete(:label)
6
+ hint, hint_class = options.delete(:hint), options.delete(:hint_class)
7
+ the_dom_id = options[:id] || object_name + "_" + method.to_s
8
+ raise "No :hint supplied" if hint_class && hint.blank?
9
+
10
+ result = wrap_field(method, super(method, options), label_text )
11
+ result << hint_js_tag(the_dom_id, hint, (hint_class || "hinting")) unless hint.blank?
12
+ result
13
+ end
14
+
15
+ def text_area(method, options = {})
16
+ label_text = options.delete(:label)
17
+ hint, hint_class = options.delete(:hint), options.delete(:hint_class)
18
+ the_dom_id = options[:id] || object_name + "_" + method.to_s
19
+
20
+ raise "No :hint supplied" if hint_class && hint.blank?
21
+
22
+ result = wrap_field(method, super(method, options), label_text )
23
+ result << hint_js_tag(the_dom_id, hint, (hint_class || "hinting")) unless hint.blank?
24
+ result
25
+ end
26
+
27
+ def hint_js_tag(element_id, hint, hint_class)
28
+ raise "Missing arg" if element_id.blank? || hint.blank? || hint_class.blank?
29
+ script = "new RobinsHtmlHelpers.FormFieldHint('#{element_id}', '#{hint}', '#{hint_class}');"
30
+ @template.javascript_tag(script)
31
+ end
32
+
33
+ def password_field(method, options = {})
34
+ label_text = options.delete(:label)
35
+ wrap_field(method, super(method, options), label_text )
36
+ end
37
+
38
+ def date_select(method, options = {})
39
+ label_text = options.delete(:label)
40
+ wrap_field(method, super(method, options), label_text )
41
+ end
42
+
43
+ def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
44
+ label_text = options.delete(:label)
45
+ wrap_field(method, super(method, options, checked_value, unchecked_value), label_text )
46
+ end
47
+
48
+ def select(method, choices, options = {}, html_options = {})
49
+ label_text = html_options.delete(:label)
50
+ wrap_field(method, super(method, choices, options, html_options), label_text )
51
+ end
52
+
53
+ private
54
+ def wrap_field(method, form_field, label_text)
55
+ "<div class=\"custom_form_field\">#{label(method, label_text )} #{ form_field }</div>"
56
+ end
57
+ end
58
+
59
+ end
@@ -0,0 +1,14 @@
1
+ class RobinsHtmlHelpersResourcesGenerator < Rails::Generator::Base
2
+ def manifest
3
+ puts "Installing"
4
+ record do |m|
5
+ m.file 'robins_html_helpers.js',
6
+ 'public/javascripts/robins_html_helpers.js',
7
+ :collision => :ask
8
+
9
+ m.file 'robins_html_helpers.css',
10
+ 'public/stylesheets/robins_html_helpers.css',
11
+ :collision => :ask
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,6 @@
1
+
2
+ /* Example style for form field hints */
3
+ input.hinting,
4
+ textarea.hinting {
5
+ font-style: italic;
6
+ }
@@ -0,0 +1,50 @@
1
+ if ( Object.isUndefined(RobinsHtmlHelpers) ) {
2
+ var RobinsHtmlHelpers = { }
3
+ }
4
+
5
+ RobinsHtmlHelpers.FormFieldHint = Class.create ({
6
+ initialize: function(element, hint, hintClass) {
7
+ this.element = $(element);
8
+ this.hintText = hint;
9
+ this.hintClass = hintClass;
10
+ this.hintState = false;
11
+ this.showHintWhenBlank();
12
+ this.initEventHandlers();
13
+ },
14
+ initEventHandlers: function() {
15
+ this.onFocusHandler = this.onFocus.bind(this);
16
+ this.element.observe("focus", this.onFocusHandler);
17
+
18
+ this.onBlurHandler = this.onBlur.bind(this);
19
+ this.element.observe("blur", this.onBlurHandler);
20
+
21
+ this.onSubmitHandler = this.onSubmit.bind(this);
22
+ this.element.up('form').observe("submit", this.onSubmitHandler);
23
+ },
24
+ showHintWhenBlank: function() {
25
+ if ($F(this.element).empty() ) {
26
+ this.element.value = this.hintText;
27
+ }
28
+
29
+ this.hintState = ( $F(this.element) == this.hintText );
30
+
31
+ if (this.hintState) {
32
+ this.element.addClassName(this.hintClass);
33
+ }
34
+ else {
35
+ this.element.removeClassName(this.hintClass);
36
+ }
37
+ },
38
+ onFocus: function() {
39
+ this.element.removeClassName(this.hintClass);
40
+ if( this.hintState )
41
+ this.element.select();
42
+ },
43
+ onBlur: function() {
44
+ this.showHintWhenBlank();
45
+ },
46
+ onSubmit: function() {
47
+ if(this.hintState)
48
+ this.element.value = null;
49
+ }
50
+ });
@@ -2,26 +2,26 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{robins_html_helpers}
5
- s.version = "0.1.2"
5
+ s.version = "0.2.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 = ["Robin Spainhour"]
9
- s.date = %q{2008-12-11}
9
+ s.date = %q{2009-05-21}
10
10
  s.description = %q{HTML stuff I use frequently.}
11
11
  s.email = %q{robin@robinspainhour.com}
12
- s.extra_rdoc_files = ["lib/robins_html_helpers.rb", "README.rdoc"]
13
- s.files = ["Rakefile", "Manifest", "lib/robins_html_helpers.rb", "README.rdoc", "robins_html_helpers.gemspec"]
12
+ s.extra_rdoc_files = ["tasks/rspec.rake", "lib/robins_html_helpers/form_builder.rb", "lib/robins_html_helpers.rb", "README.rdoc"]
13
+ s.files = ["rails_generators/robins_html_helpers_resources/USAGE", "rails_generators/robins_html_helpers_resources/templates/robins_html_helpers.css", "rails_generators/robins_html_helpers_resources/templates/robins_html_helpers.js", "rails_generators/robins_html_helpers_resources/robins_html_helpers_resources_generator.rb", "spec/railsenv/config/routes.rb", "spec/railsenv/config/environments/production.rb", "spec/railsenv/config/environments/test.rb", "spec/railsenv/config/environments/development.rb", "spec/railsenv/config/environment.rb", "spec/railsenv/config/initializers/new_rails_defaults.rb", "spec/railsenv/config/initializers/backtrace_silencers.rb", "spec/railsenv/config/initializers/session_store.rb", "spec/railsenv/config/initializers/inflections.rb", "spec/railsenv/config/initializers/mime_types.rb", "spec/railsenv/config/database.yml", "spec/railsenv/config/boot.rb", "spec/railsenv/config/locales/en.yml", "spec/railsenv/db/test.sqlite3", "spec/railsenv/app/controllers/application_controller.rb", "spec/models/form_builder_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "spec/helpers/helpers_spec.rb", "robins_html_helpers.gemspec", "Rakefile", "Manifest", "tasks/rspec.rake", "lib/robins_html_helpers/form_builder.rb", "lib/robins_html_helpers.rb", "README.rdoc"]
14
14
  s.has_rdoc = true
15
15
  s.homepage = %q{http://github.com/robinsp/robins_html_helpers}
16
16
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Robins_html_helpers", "--main", "README.rdoc"]
17
17
  s.require_paths = ["lib"]
18
18
  s.rubyforge_project = %q{robins_html_helpers}
19
- s.rubygems_version = %q{1.3.1}
19
+ s.rubygems_version = %q{1.3.2}
20
20
  s.summary = %q{HTML stuff I use frequently.}
21
21
 
22
22
  if s.respond_to? :specification_version then
23
23
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
- s.specification_version = 2
24
+ s.specification_version = 3
25
25
 
26
26
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
27
  else
@@ -0,0 +1,72 @@
1
+ require File.expand_path(File.dirname(__FILE__) ) + "/../spec_helper"
2
+
3
+ describe "boxed_content", :type => :helper do
4
+ before do
5
+ @default_result = boxed_content
6
+ end
7
+
8
+ it "should be accessible to rails apps by default" do
9
+ ActionView::Base.new.methods.should include("boxed_content")
10
+ end
11
+
12
+ it "should be possible to set the html id of the outer div" do
13
+ @default_result.should_not have_tag("div#my_id")
14
+ boxed_content(:outer_id => "my_id").should have_tag("div#my_id")
15
+ end
16
+
17
+ it "should be possible to set the html id of the inner div" do
18
+ @default_result.should_not have_tag("div#my_id")
19
+ boxed_content(:inner_id => "my_id").should have_tag("div#my_id")
20
+ end
21
+
22
+ it "should be possible to override the default CSS class of the outer div" do
23
+ @default_result.should_not have_tag("div.my_class")
24
+ boxed_content(:outer_class => "my_class").should have_tag("div.my_class")
25
+ end
26
+
27
+ it "should be possible to override the default CSS class of the inner div" do
28
+ @default_result.should_not have_tag("div.my_class")
29
+ boxed_content(:inner_class => "my_class").should have_tag("div.my_class")
30
+ end
31
+
32
+ it "should set default CSS classes" do
33
+ boxed_content.should have_tag("div") do
34
+ with_tag("div.box_bottom_left") do
35
+ with_tag("div.box_bottom_right") do
36
+ with_tag("div.box_top_left") do
37
+ with_tag("div.box_top_right")
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ it "should be possible to use all params at the same time" do
45
+ params = {:outer_id => "my_outer_id",
46
+ :inner_id => "my_inner_id",
47
+ :outer_class => "my_outer_class",
48
+ :inner_class => "my_inner_class" }
49
+
50
+ boxed_content(params).should have_tag("div") do
51
+ with_tag("div.my_outer_class")
52
+ with_tag("div#my_outer_id") do
53
+ with_tag("div") do
54
+ with_tag("div") do
55
+ with_tag("div.my_inner_class")
56
+ with_tag("div#my_inner_id")
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ end
63
+
64
+ it "should wrap everything in a div to avoid margin problems in IE"
65
+
66
+ it "should be possible to omitt the div that fixes the IE margin problems"
67
+
68
+ def boxed_content(params = {})
69
+ eval_erb("<% boxed_content(#{params.inspect}) do %> <%end%>")
70
+ end
71
+
72
+ end
@@ -0,0 +1,142 @@
1
+ require File.expand_path(File.dirname(__FILE__) ) + "/../spec_helper"
2
+
3
+ describe RobinsHtmlHelpers::FormBuilder do
4
+
5
+ before do
6
+ @expected_attrib = :the_attrib
7
+
8
+ @mock_template = mock("the-template")
9
+ @mock_template.stubs(:javascript_tag).returns("")
10
+
11
+ @mock_object_name = 'object-name'
12
+ @mock_the_object = mock('the-object')
13
+
14
+ @builder = RobinsHtmlHelpers::FormBuilder.new(@mock_object_name,
15
+ @mock_the_object,
16
+ @mock_template,
17
+ nil, nil)
18
+
19
+ @mock_template.stubs(:label).returns("label-result")
20
+ @builder.stubs(:get_super).returns(@mock_template)
21
+
22
+ @expected_opts = {:object => @mock_the_object, :opt => "val" }
23
+ @opts_with_label = {:opt => "val", :label => "thelabel" }
24
+
25
+ end
26
+
27
+ [:text_field, :text_area, :password_field, :date_select, :check_box].each do |method|
28
+ describe "#{method.to_s}()" do
29
+ it "should wrap_field" do
30
+ @mock_template.expects(method)
31
+ @builder.expects(:wrap_field)
32
+ @builder.send(method, @expected_attrib)
33
+ end
34
+ end
35
+ end
36
+
37
+ describe "select()" do
38
+ it "should wrap_field" do
39
+ @mock_template.expects(:select)
40
+ @builder.expects(:wrap_field)
41
+ @builder.select(@expected_attrib, {} )
42
+ end
43
+ end
44
+
45
+ [:text_field, :text_area].each do |method|
46
+ describe "#{method.to_s}()" do
47
+ it "should remove :label param before delegating to super class" do
48
+ @mock_template.expects(method).with(@mock_object_name, @expected_attrib, @expected_opts)
49
+ @builder.send method, @expected_attrib, @opts_with_label
50
+ end
51
+
52
+
53
+ describe "with hints" do
54
+ before do
55
+ @mock_template.stubs(method)
56
+ @builder.stubs(:wrap_field).returns("field-result")
57
+ end
58
+
59
+ it "should remove :hint and :hint_class options before delegating to super class" do
60
+ @mock_template.expects(method).with(@mock_object_name, @expected_attrib, @expected_opts)
61
+ @builder.send method, @expected_attrib, {:opt => "val", :hint => "A hint", :hint_class => "CSS_class"}
62
+ end
63
+
64
+ it "should not allow :hint_class option without a :hint option" do
65
+ lambda { @builder.send(method, @expected_attrib, {:hint_class => "CSS_class"}) }.should raise_error("No :hint supplied")
66
+ end
67
+
68
+ it "should append hint JS" do
69
+ @builder.expects(:hint_js_tag).returns("hint-result")
70
+ @builder.send(method, @expected_attrib, {:hint => "A hint"}).should == "field-result" + "hint-result"
71
+ end
72
+
73
+ it "should default :hint_class to 'hinting' " do
74
+ @builder.expects(:hint_js_tag).with("dom_id", "A hint", "hinting").returns("hint-result")
75
+ @builder.send(method, @expected_attrib, {:id => "dom_id", :hint => "A hint"})
76
+ end
77
+
78
+ describe "with DOM id given by the developer" do
79
+ it "should create the hint JS by supplying an DOM element id, hint and hint_class" do
80
+ @builder.expects(:hint_js_tag).with("element_id", "A hint", "hint_class").returns("hint-result")
81
+ @builder.send method, @expected_attrib, {:id => "element_id", :hint => "A hint", :hint_class => "hint_class"}
82
+ end
83
+ end
84
+
85
+ describe "When the DOM id is set by default" do
86
+ it "should create the hint JS by supplying an DOM element id, hint and hint_class" do
87
+ @builder.expects(:hint_js_tag).with("#{@mock_object_name}_#{@expected_attrib.to_s}", "A hint", "hint_class").returns("hint-result")
88
+ @builder.send method, @expected_attrib, {:hint => "A hint", :hint_class => "hint_class"}
89
+ end
90
+ end
91
+
92
+ end
93
+ end
94
+ end
95
+
96
+ describe "password_field()" do
97
+ it "should remove :label option before delegating to super class" do
98
+ @mock_template.expects(:password_field).with(@mock_object_name, @expected_attrib, @expected_opts)
99
+ @builder.password_field(@expected_attrib, @opts_with_label)
100
+ end
101
+ end
102
+
103
+ describe "date_select()" do
104
+ it "should remove :label option before delegating to super class" do
105
+ @mock_template.expects(:date_select).with(@mock_object_name, @expected_attrib, @expected_opts, {})
106
+ @builder.date_select(@expected_attrib, @opts_with_label)
107
+ end
108
+ end
109
+
110
+ describe "select()" do
111
+ it "should remove :label option before delegating to super class" do
112
+ @mock_template.expects(:select).with(@mock_object_name, @expected_attrib, {}, {:object => @mock_the_object}, {:opt => "val" })
113
+ @builder.select( @expected_attrib, {}, {}, @opts_with_label )
114
+ end
115
+ end
116
+
117
+ describe "check_box()" do
118
+ it "should remove :label option before delegating to super class" do
119
+ @mock_template.expects(:check_box).with(@mock_object_name, @expected_attrib, @expected_opts, 1.to_s, 0.to_s)
120
+ @builder.check_box( @expected_attrib, @opts_with_label )
121
+ end
122
+ end
123
+
124
+ describe "hint_js_tag()" do
125
+ it "should call javascript_tag" do
126
+ element_id, hint, hint_class = "element_id", "hint", "hint_class"
127
+ js_script = "new RobinsHtmlHelpers.FormFieldHint('#{element_id}', '#{hint}', '#{hint_class}');"
128
+ @mock_template.expects(:javascript_tag).with(js_script)
129
+ @builder.hint_js_tag(element_id, hint, hint_class)
130
+ end
131
+
132
+ it "should fail is any argument is blank" do
133
+ element_id, hint, hint_class = "element_id", "hint", "hint_class"
134
+
135
+ lambda {@builder.hint_js_tag("", hint, hint_class)}.should raise_error("Missing arg")
136
+ lambda {@builder.hint_js_tag(element_id, "", hint_class)}.should raise_error("Missing arg")
137
+ lambda {@builder.hint_js_tag(element_id, hint, "")}.should raise_error("Missing arg")
138
+ end
139
+
140
+ end
141
+
142
+ end
@@ -0,0 +1,10 @@
1
+ # Filters added to this controller apply to all controllers in the application.
2
+ # Likewise, all the methods added will be available for all controllers.
3
+
4
+ class ApplicationController < ActionController::Base
5
+ helper :all # include all helpers, all the time
6
+ protect_from_forgery # See ActionController::RequestForgeryProtection for details
7
+
8
+ # Scrub sensitive parameters from your log
9
+ # filter_parameter_logging :password
10
+ end
@@ -0,0 +1,110 @@
1
+ # Don't change this file!
2
+ # Configure your app in config/environment.rb and config/environments/*.rb
3
+
4
+ RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
5
+
6
+ module Rails
7
+ class << self
8
+ def boot!
9
+ unless booted?
10
+ preinitialize
11
+ pick_boot.run
12
+ end
13
+ end
14
+
15
+ def booted?
16
+ defined? Rails::Initializer
17
+ end
18
+
19
+ def pick_boot
20
+ (vendor_rails? ? VendorBoot : GemBoot).new
21
+ end
22
+
23
+ def vendor_rails?
24
+ File.exist?("#{RAILS_ROOT}/vendor/rails")
25
+ end
26
+
27
+ def preinitialize
28
+ load(preinitializer_path) if File.exist?(preinitializer_path)
29
+ end
30
+
31
+ def preinitializer_path
32
+ "#{RAILS_ROOT}/config/preinitializer.rb"
33
+ end
34
+ end
35
+
36
+ class Boot
37
+ def run
38
+ load_initializer
39
+ Rails::Initializer.run(:set_load_path)
40
+ end
41
+ end
42
+
43
+ class VendorBoot < Boot
44
+ def load_initializer
45
+ require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
46
+ Rails::Initializer.run(:install_gem_spec_stubs)
47
+ Rails::GemDependency.add_frozen_gem_path
48
+ end
49
+ end
50
+
51
+ class GemBoot < Boot
52
+ def load_initializer
53
+ self.class.load_rubygems
54
+ load_rails_gem
55
+ require 'initializer'
56
+ end
57
+
58
+ def load_rails_gem
59
+ if version = self.class.gem_version
60
+ gem 'rails', version
61
+ else
62
+ gem 'rails'
63
+ end
64
+ rescue Gem::LoadError => load_error
65
+ $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
66
+ exit 1
67
+ end
68
+
69
+ class << self
70
+ def rubygems_version
71
+ Gem::RubyGemsVersion rescue nil
72
+ end
73
+
74
+ def gem_version
75
+ if defined? RAILS_GEM_VERSION
76
+ RAILS_GEM_VERSION
77
+ elsif ENV.include?('RAILS_GEM_VERSION')
78
+ ENV['RAILS_GEM_VERSION']
79
+ else
80
+ parse_gem_version(read_environment_rb)
81
+ end
82
+ end
83
+
84
+ def load_rubygems
85
+ require 'rubygems'
86
+ min_version = '1.3.1'
87
+ unless rubygems_version >= min_version
88
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
89
+ exit 1
90
+ end
91
+
92
+ rescue LoadError
93
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
94
+ exit 1
95
+ end
96
+
97
+ def parse_gem_version(text)
98
+ $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
99
+ end
100
+
101
+ private
102
+ def read_environment_rb
103
+ File.read("#{RAILS_ROOT}/config/environment.rb")
104
+ end
105
+ end
106
+ end
107
+ end
108
+
109
+ # All that for this:
110
+ Rails.boot!
@@ -0,0 +1,22 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3-ruby (not necessary on OS X Leopard)
3
+ development:
4
+ adapter: sqlite3
5
+ database: db/development.sqlite3
6
+ pool: 5
7
+ timeout: 5000
8
+
9
+ # Warning: The database defined as "test" will be erased and
10
+ # re-generated from your development database when you run "rake".
11
+ # Do not set this db to the same as development or production.
12
+ test:
13
+ adapter: sqlite3
14
+ database: db/test.sqlite3
15
+ pool: 5
16
+ timeout: 5000
17
+
18
+ production:
19
+ adapter: sqlite3
20
+ database: db/production.sqlite3
21
+ pool: 5
22
+ timeout: 5000
@@ -0,0 +1,41 @@
1
+ # Be sure to restart your server when you modify this file
2
+
3
+ # Specifies gem version of Rails to use when vendor/rails is not present
4
+ RAILS_GEM_VERSION = '2.3.2' unless defined? RAILS_GEM_VERSION
5
+
6
+ # Bootstrap the Rails environment, frameworks, and default configuration
7
+ require File.join(File.dirname(__FILE__), 'boot')
8
+
9
+ Rails::Initializer.run do |config|
10
+ # Settings in config/environments/* take precedence over those specified here.
11
+ # Application configuration should go into files in config/initializers
12
+ # -- all .rb files in that directory are automatically loaded.
13
+
14
+ # Add additional load paths for your own custom dirs
15
+ # config.load_paths += %W( #{RAILS_ROOT}/extras )
16
+
17
+ # Specify gems that this application depends on and have them installed with rake gems:install
18
+ # config.gem "bj"
19
+ # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
20
+ # config.gem "sqlite3-ruby", :lib => "sqlite3"
21
+ # config.gem "aws-s3", :lib => "aws/s3"
22
+
23
+ # Only load the plugins named here, in the order given (default is alphabetical).
24
+ # :all can be used as a placeholder for all plugins not explicitly named
25
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
26
+
27
+ # Skip frameworks you're not going to use. To use Rails without a database,
28
+ # you must remove the Active Record framework.
29
+ # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
30
+
31
+ # Activate observers that should always be running
32
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
33
+
34
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
35
+ # Run "rake -D time" for a list of tasks for finding time zone names.
36
+ config.time_zone = 'UTC'
37
+
38
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
39
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
40
+ # config.i18n.default_locale = :de
41
+ end
@@ -0,0 +1,17 @@
1
+ # Settings specified here will take precedence over those in config/environment.rb
2
+
3
+ # In the development environment your application's code is reloaded on
4
+ # every request. This slows down response time but is perfect for development
5
+ # since you don't have to restart the webserver when you make code changes.
6
+ config.cache_classes = false
7
+
8
+ # Log error messages when you accidentally call methods on nil.
9
+ config.whiny_nils = true
10
+
11
+ # Show full error reports and disable caching
12
+ config.action_controller.consider_all_requests_local = true
13
+ config.action_view.debug_rjs = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Don't care if the mailer can't send
17
+ config.action_mailer.raise_delivery_errors = false
@@ -0,0 +1,28 @@
1
+ # Settings specified here will take precedence over those in config/environment.rb
2
+
3
+ # The production environment is meant for finished, "live" apps.
4
+ # Code is not reloaded between requests
5
+ config.cache_classes = true
6
+
7
+ # Full error reports are disabled and caching is turned on
8
+ config.action_controller.consider_all_requests_local = false
9
+ config.action_controller.perform_caching = true
10
+ config.action_view.cache_template_loading = true
11
+
12
+ # See everything in the log (default is :info)
13
+ # config.log_level = :debug
14
+
15
+ # Use a different logger for distributed setups
16
+ # config.logger = SyslogLogger.new
17
+
18
+ # Use a different cache store in production
19
+ # config.cache_store = :mem_cache_store
20
+
21
+ # Enable serving of images, stylesheets, and javascripts from an asset server
22
+ # config.action_controller.asset_host = "http://assets.example.com"
23
+
24
+ # Disable delivery errors, bad email addresses will be ignored
25
+ # config.action_mailer.raise_delivery_errors = false
26
+
27
+ # Enable threaded mode
28
+ # config.threadsafe!
@@ -0,0 +1,28 @@
1
+ # Settings specified here will take precedence over those in config/environment.rb
2
+
3
+ # The test environment is used exclusively to run your application's
4
+ # test suite. You never need to work with it otherwise. Remember that
5
+ # your test database is "scratch space" for the test suite and is wiped
6
+ # and recreated between test runs. Don't rely on the data there!
7
+ config.cache_classes = true
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.action_controller.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+ config.action_view.cache_template_loading = true
16
+
17
+ # Disable request forgery protection in test environment
18
+ config.action_controller.allow_forgery_protection = false
19
+
20
+ # Tell Action Mailer not to deliver emails to the real world.
21
+ # The :test delivery method accumulates sent emails in the
22
+ # ActionMailer::Base.deliveries array.
23
+ config.action_mailer.delivery_method = :test
24
+
25
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
26
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
27
+ # like if you have constraints or database-specific column types
28
+ # config.active_record.schema_format = :sql
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying do debug a problem that might steem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,10 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format
4
+ # (all these examples are active by default):
5
+ # ActiveSupport::Inflector.inflections do |inflect|
6
+ # inflect.plural /^(ox)$/i, '\1en'
7
+ # inflect.singular /^(ox)en/i, '\1'
8
+ # inflect.irregular 'person', 'people'
9
+ # inflect.uncountable %w( fish sheep )
10
+ # end
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,19 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # These settings change the behavior of Rails 2 apps and will be defaults
4
+ # for Rails 3. You can remove this initializer when Rails 3 is released.
5
+
6
+ if defined?(ActiveRecord)
7
+ # Include Active Record class name as root for JSON serialized output.
8
+ ActiveRecord::Base.include_root_in_json = true
9
+
10
+ # Store the full class name (including module namespace) in STI type column.
11
+ ActiveRecord::Base.store_full_sti_class = true
12
+ end
13
+
14
+ # Use ISO 8601 format for JSON serialized times and dates.
15
+ ActiveSupport.use_standard_json_time_format = true
16
+
17
+ # Don't escape HTML entities in JSON, leave that for the #json_escape helper.
18
+ # if you're including raw json in an HTML page.
19
+ ActiveSupport.escape_html_entities_in_json = false
@@ -0,0 +1,15 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying cookie session data integrity.
4
+ # If you change this key, all old sessions will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ ActionController::Base.session = {
8
+ :key => '_railsenv_session',
9
+ :secret => '5b6ce90fd6469cb00f7486f06c61280817a3fde17955abe87a4ae1f02547c6f65d54a1a04e843e0bf4f1694935aa95bddf2f57ce886ffb395a89a3af01d07b4a'
10
+ }
11
+
12
+ # Use the database for sessions instead of the cookie-based default,
13
+ # which shouldn't be used to store highly confidential information
14
+ # (create the session table with "rake db:sessions:create")
15
+ # ActionController::Base.session_store = :active_record_store
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
@@ -0,0 +1,43 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+ # The priority is based upon order of creation: first created -> highest priority.
3
+
4
+ # Sample of regular route:
5
+ # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
6
+ # Keep in mind you can assign values other than :controller and :action
7
+
8
+ # Sample of named route:
9
+ # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
10
+ # This route can be invoked with purchase_url(:id => product.id)
11
+
12
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
13
+ # map.resources :products
14
+
15
+ # Sample resource route with options:
16
+ # map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }
17
+
18
+ # Sample resource route with sub-resources:
19
+ # map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller
20
+
21
+ # Sample resource route with more complex sub-resources
22
+ # map.resources :products do |products|
23
+ # products.resources :comments
24
+ # products.resources :sales, :collection => { :recent => :get }
25
+ # end
26
+
27
+ # Sample resource route within a namespace:
28
+ # map.namespace :admin do |admin|
29
+ # # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
30
+ # admin.resources :products
31
+ # end
32
+
33
+ # You can have the root of your site routed with map.root -- just remember to delete public/index.html.
34
+ # map.root :controller => "welcome"
35
+
36
+ # See how all your routes lay out with "rake routes"
37
+
38
+ # Install the default routes as the lowest priority.
39
+ # Note: These default routes make all actions in every controller accessible via GET requests. You should
40
+ # consider removing the them or commenting them out if you're using named routes and resources.
41
+ map.connect ':controller/:action/:id'
42
+ map.connect ':controller/:action/:id.:format'
43
+ end
File without changes
data/spec/spec.opts ADDED
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format progress
3
+ --loadby mtime
4
+ --reverse
@@ -0,0 +1,21 @@
1
+ # The minimal Rails project was created to run specs against using:
2
+ # rails -m http://github.com/robinsp/rails_templates/raw/master/minimal.rb railsenv
3
+
4
+
5
+ ENV["RAILS_ENV"] = "test"
6
+ require File.expand_path(File.dirname(__FILE__) + "/railsenv/config/environment")
7
+ require 'spec'
8
+ require 'spec/rails'
9
+
10
+ Spec::Runner.configure do |config|
11
+ config.use_transactional_fixtures = true
12
+ config.use_instantiated_fixtures = false
13
+ config.mock_with :mocha
14
+ end
15
+
16
+ plugin_spec_dir = File.dirname(__FILE__)
17
+ ActiveRecord::Base.logger = Logger.new(plugin_spec_dir + "/debug.log")
18
+
19
+ dir = File.expand_path(File.dirname(__FILE__))
20
+ require "#{dir}/../lib/robins_html_helpers"
21
+ require "#{dir}/../lib/robins_html_helpers/form_builder"
data/tasks/rspec.rake ADDED
@@ -0,0 +1,6 @@
1
+ require 'spec/rake/spectask'
2
+
3
+ desc "Run all specs in spec directory"
4
+ Spec::Rake::SpecTask.new(:spec) do |t|
5
+ t.spec_files = FileList['spec/**/*_spec.rb']
6
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: robinsp-robins_html_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robin Spainhour
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-11 00:00:00 -08:00
12
+ date: 2009-05-21 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -20,14 +20,41 @@ executables: []
20
20
  extensions: []
21
21
 
22
22
  extra_rdoc_files:
23
+ - tasks/rspec.rake
24
+ - lib/robins_html_helpers/form_builder.rb
23
25
  - lib/robins_html_helpers.rb
24
26
  - README.rdoc
25
27
  files:
28
+ - rails_generators/robins_html_helpers_resources/USAGE
29
+ - rails_generators/robins_html_helpers_resources/templates/robins_html_helpers.css
30
+ - rails_generators/robins_html_helpers_resources/templates/robins_html_helpers.js
31
+ - rails_generators/robins_html_helpers_resources/robins_html_helpers_resources_generator.rb
32
+ - spec/railsenv/config/routes.rb
33
+ - spec/railsenv/config/environments/production.rb
34
+ - spec/railsenv/config/environments/test.rb
35
+ - spec/railsenv/config/environments/development.rb
36
+ - spec/railsenv/config/environment.rb
37
+ - spec/railsenv/config/initializers/new_rails_defaults.rb
38
+ - spec/railsenv/config/initializers/backtrace_silencers.rb
39
+ - spec/railsenv/config/initializers/session_store.rb
40
+ - spec/railsenv/config/initializers/inflections.rb
41
+ - spec/railsenv/config/initializers/mime_types.rb
42
+ - spec/railsenv/config/database.yml
43
+ - spec/railsenv/config/boot.rb
44
+ - spec/railsenv/config/locales/en.yml
45
+ - spec/railsenv/db/test.sqlite3
46
+ - spec/railsenv/app/controllers/application_controller.rb
47
+ - spec/models/form_builder_spec.rb
48
+ - spec/spec.opts
49
+ - spec/spec_helper.rb
50
+ - spec/helpers/helpers_spec.rb
51
+ - robins_html_helpers.gemspec
26
52
  - Rakefile
27
53
  - Manifest
54
+ - tasks/rspec.rake
55
+ - lib/robins_html_helpers/form_builder.rb
28
56
  - lib/robins_html_helpers.rb
29
57
  - README.rdoc
30
- - robins_html_helpers.gemspec
31
58
  has_rdoc: true
32
59
  homepage: http://github.com/robinsp/robins_html_helpers
33
60
  post_install_message:
@@ -57,7 +84,7 @@ requirements: []
57
84
  rubyforge_project: robins_html_helpers
58
85
  rubygems_version: 1.2.0
59
86
  signing_key:
60
- specification_version: 2
87
+ specification_version: 3
61
88
  summary: HTML stuff I use frequently.
62
89
  test_files: []
63
90