bjornblomqvist-AppFormBuilder 0.0.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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
@@ -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.0.0"
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-03}
13
+ s.description = %q{TODO: 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{TODO: 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.
data/README.rdoc ADDED
@@ -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.
data/Rakefile ADDED
@@ -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{TODO: one-line summary of your gem}
9
+ gem.description = %Q{TODO: 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.0.0
@@ -0,0 +1,87 @@
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
+ def boolean_filter(field, options = {})
80
+ collection_select field, [['Ja/Nej', ''], ['Ja', 'true'], ['Nej', 'false']], :last, :first, options
81
+ end
82
+
83
+ def language_select(field, options = {})
84
+ collection_select field, ['sv', 'en'], :to_s, :to_s, options
85
+ end
86
+
87
+ 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,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bjornblomqvist-AppFormBuilder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Darwin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-03 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: "TODO: longer description of your gem"
26
+ email: darwin.git@marianna.se
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - AppFormBuilder.gemspec
38
+ - LICENSE
39
+ - README.rdoc
40
+ - Rakefile
41
+ - VERSION
42
+ - lib/AppFormBuilder.rb
43
+ - spec/AppFormBuilder_spec.rb
44
+ - spec/spec_helper.rb
45
+ has_rdoc: true
46
+ homepage: http://github.com/bjornblomqvist/AppFormBuilder
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --charset=UTF-8
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.2.0
68
+ signing_key:
69
+ specification_version: 2
70
+ summary: "TODO: one-line summary of your gem"
71
+ test_files:
72
+ - spec/AppFormBuilder_spec.rb
73
+ - spec/spec_helper.rb