AppFormBuilder 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,54 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{AppFormBuilder}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Darwin"]
12
+ s.date = %q{2009-09-17}
13
+ s.description = %q{longer description of your gem}
14
+ s.email = %q{darwin.git@marianna.se}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "AppFormBuilder.gemspec",
23
+ "LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/AppFormBuilder.rb",
28
+ "spec/AppFormBuilder_spec.rb",
29
+ "spec/spec_helper.rb"
30
+ ]
31
+ s.has_rdoc = true
32
+ s.homepage = %q{http://github.com/bjornblomqvist/AppFormBuilder}
33
+ s.rdoc_options = ["--charset=UTF-8"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.1}
36
+ s.summary = %q{one-line summary of your gem}
37
+ s.test_files = [
38
+ "spec/AppFormBuilder_spec.rb",
39
+ "spec/spec_helper.rb"
40
+ ]
41
+
42
+ if s.respond_to? :specification_version then
43
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
+ s.specification_version = 2
45
+
46
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
47
+ s.add_development_dependency(%q<rspec>, [">= 0"])
48
+ else
49
+ s.add_dependency(%q<rspec>, [">= 0"])
50
+ end
51
+ else
52
+ s.add_dependency(%q<rspec>, [">= 0"])
53
+ end
54
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Darwin
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.
@@ -0,0 +1,18 @@
1
+ = AppFormBuilder
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but
13
+ bump version in a commit by itself I can ignore when I pull)
14
+ * Send me a pull request. Bonus points for topic branches.
15
+
16
+ == Copyright
17
+
18
+ Copyright (c) 2009 Darwin. See LICENSE for details.
@@ -0,0 +1,48 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "AppFormBuilder"
8
+ gem.summary = %Q{: one-line summary of your gem}
9
+ gem.description = %Q{longer description of your gem}
10
+ gem.email = "darwin.git@marianna.se"
11
+ gem.homepage = "http://github.com/bjornblomqvist/AppFormBuilder"
12
+ gem.authors = ["Darwin"]
13
+ gem.add_development_dependency "rspec"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ require 'spec/rake/spectask'
21
+ Spec::Rake::SpecTask.new(:spec) do |spec|
22
+ spec.libs << 'lib' << 'spec'
23
+ spec.spec_files = FileList['spec/**/*_spec.rb']
24
+ end
25
+
26
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
27
+ spec.libs << 'lib' << 'spec'
28
+ spec.pattern = 'spec/**/*_spec.rb'
29
+ spec.rcov = true
30
+ end
31
+
32
+ task :spec => :check_dependencies
33
+
34
+ task :default => :spec
35
+
36
+ require 'rake/rdoctask'
37
+ Rake::RDocTask.new do |rdoc|
38
+ if File.exist?('VERSION')
39
+ version = File.read('VERSION')
40
+ else
41
+ version = ""
42
+ end
43
+
44
+ rdoc.rdoc_dir = 'rdoc'
45
+ rdoc.title = "AppFormBuilder #{version}"
46
+ rdoc.rdoc_files.include('README*')
47
+ rdoc.rdoc_files.include('lib/**/*.rb')
48
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,97 @@
1
+ # encoding: utf-8
2
+
3
+ class AppFormBuilder < ActionView::Helpers::FormBuilder
4
+
5
+ %w[text_field collection_select password_field text_area file_field].each do |method_name|
6
+ define_method method_name do |field, *args|
7
+ options = args.extract_options!
8
+ label_text = options.delete :label
9
+ error_text = options.delete :error
10
+ label_text += "<span class=\"error_text\">"+ (error_text ? error_text : getError(field)) +"</span>" if getError(field)
11
+ @template.content_tag('div', label(field, label_text) + super(field, *args, options), :class => 'field')
12
+ end
13
+ end
14
+
15
+ define_method :check_box do |field, *args|
16
+ options = args.extract_options!
17
+ label_text = options.delete :label
18
+ @template.content_tag('div', %Q[
19
+ #{super(field, options)}
20
+ #{label(field, label_text)}
21
+ ], :class => 'field checkbox')
22
+ end
23
+
24
+ define_method :radio_button do |field, value, *args|
25
+ options = args.extract_options!
26
+ label_text = options.delete :label
27
+ @template.content_tag('div', %Q[
28
+ #{super(field, value, options)}
29
+ #{label(field, label_text)}
30
+ ], :class => 'field checkbox')
31
+ end
32
+
33
+ def submit(text, options = {})
34
+ @template.content_tag('button', text,
35
+ options.merge(:type => 'submit')
36
+ )
37
+ end
38
+
39
+ def label(field, text)
40
+ super(field, text, label_options(field))
41
+ end
42
+
43
+ def label_options(field)
44
+ getError(field) ? { :class => 'error' } : {}
45
+ end
46
+
47
+ def getError(field)
48
+ return nil if object.nil? || !object.respond_to?(:errors)
49
+ object.errors[field]
50
+ end
51
+
52
+ def checkbox_set(field, values, options = {})
53
+ current = object.send(field)
54
+ ix = 0;
55
+ values.map do |value|
56
+ attrs = {
57
+ :type => 'checkbox',
58
+ :name => "#{@object_name}[#{field}][]",
59
+ :id => "#{@object_name}_#{field}_#{ix += 1}",
60
+ :value => value
61
+ }
62
+ attrs[:checked] = 'checked' if current.nil? || current.include?(value)
63
+
64
+ %Q{
65
+ <div class="checkbox field">
66
+ <input #{format_attrs attrs} />
67
+ <label for="#{@object_name}_#{field}_#{ix}">#{value}</label>
68
+ </div>
69
+ }
70
+ end.join("\n")
71
+ end
72
+
73
+ def format_attrs(attrs)
74
+ attrs.map do |key, value|
75
+ "#{key}=\"#{value}\""
76
+ end.join " "
77
+ end
78
+
79
+ end
80
+
81
+
82
+ # Monkey-patch to force all input elements to include a value attribute,
83
+ # even when the model value is nil. Ugly but effective (I think). Use at
84
+ # your own risk.
85
+ raise 'Ouch' unless ActionView && ActionView::Helpers && ActionView::Helpers::InstanceTag
86
+
87
+ module ActionView
88
+ module Helpers
89
+ class InstanceTag #:nodoc:
90
+
91
+ def value_before_type_cast(object)
92
+ self.class.value_before_type_cast(object, @method_name) || ''
93
+ end
94
+
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Appformbuilder" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'AppFormBuilder'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: AppFormBuilder
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.1
6
+ platform: ruby
7
+ authors:
8
+ - Darwin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-05-02 00:00:00 +02:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rspec
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ type: :development
26
+ version_requirements: *id001
27
+ description: longer description of your gem
28
+ email: darwin.git@marianna.se
29
+ executables: []
30
+
31
+ extensions: []
32
+
33
+ extra_rdoc_files:
34
+ - LICENSE
35
+ - README.rdoc
36
+ files:
37
+ - .document
38
+ - AppFormBuilder.gemspec
39
+ - LICENSE
40
+ - README.rdoc
41
+ - Rakefile
42
+ - VERSION
43
+ - lib/AppFormBuilder.rb
44
+ - spec/AppFormBuilder_spec.rb
45
+ - spec/spec_helper.rb
46
+ has_rdoc: true
47
+ homepage: http://github.com/bjornblomqvist/AppFormBuilder
48
+ licenses: []
49
+
50
+ post_install_message:
51
+ rdoc_options: []
52
+
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ requirements: []
68
+
69
+ rubyforge_project:
70
+ rubygems_version: 1.6.2
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: ": one-line summary of your gem"
74
+ test_files:
75
+ - spec/AppFormBuilder_spec.rb
76
+ - spec/spec_helper.rb