visionmedia-dm-forms 0.0.2 → 0.0.3

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.
@@ -1,10 +1,8 @@
1
1
 
2
+ require 'rubygems'
2
3
  require 'dm-forms'
3
4
  require 'rspec_hpricot_matchers'
4
- include RspecHpricotMatchers
5
-
6
- class String
7
- def deindent spaces = 6
8
- gsub /^ {0,#{spaces}}/, ''
9
- end
10
- end
5
+
6
+ Spec::Runner.configure do |config|
7
+ config.include RspecHpricotMatchers
8
+ end
@@ -22,4 +22,9 @@ namespace :spec do
22
22
  t.spec_opts = ["--color", "--format", "specdoc", "--require", "spec/spec_helper.rb"]
23
23
  end
24
24
 
25
+ desc 'Bind specs'
26
+ task :bind do
27
+ sh %(rbind to spec/**/*.rb lib/**/*.rb -i 1 -e 'system "clear && rake spec"')
28
+ end
29
+
25
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: visionmedia-dm-forms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - TJ Holowaychuk
@@ -9,11 +9,22 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-15 00:00:00 -08:00
12
+ date: 2009-03-23 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: dm-core
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: visionmedia-rext
27
+ type: :runtime
17
28
  version_requirement:
18
29
  version_requirements: !ruby/object:Gem::Requirement
19
30
  requirements:
@@ -23,6 +34,7 @@ dependencies:
23
34
  version:
24
35
  - !ruby/object:Gem::Dependency
25
36
  name: rspec_hpricot_matchers
37
+ type: :development
26
38
  version_requirement:
27
39
  version_requirements: !ruby/object:Gem::Requirement
28
40
  requirements:
@@ -37,45 +49,53 @@ executables: []
37
49
  extensions: []
38
50
 
39
51
  extra_rdoc_files:
40
- - README.rdoc
41
- - lib/dm-forms.rb
52
+ - lib/dm-forms/base.rb
42
53
  - lib/dm-forms/core_ext.rb
43
- - lib/dm-forms/elements.rb
44
- - lib/dm-forms/model_elements.rb
54
+ - lib/dm-forms/helpers.rb
55
+ - lib/dm-forms/mixins/descriptions.rb
56
+ - lib/dm-forms/mixins/errors.rb
57
+ - lib/dm-forms/mixins/labels.rb
58
+ - lib/dm-forms/mixins/wrappers.rb
59
+ - lib/dm-forms/mixins.rb
45
60
  - lib/dm-forms/tag.rb
46
61
  - lib/dm-forms/version.rb
62
+ - lib/dm-forms.rb
63
+ - README.rdoc
47
64
  - tasks/benchmarks.rake
48
65
  - tasks/docs.rake
49
66
  - tasks/gemspec.rake
50
67
  - tasks/spec.rake
51
68
  files:
52
- - History.rdoc
53
- - Manifest
54
- - README.rdoc
55
- - Rakefile
56
- - Todo.rdoc
69
+ - dm-forms.gemspec
57
70
  - examples/benchmarks.rb
58
- - examples/datamapper.rb
59
- - examples/elements.rb
60
- - examples/haml.rb
61
- - examples/login.haml
62
- - lib/dm-forms.rb
71
+ - examples/login.rb
72
+ - History.rdoc
73
+ - lib/dm-forms/base.rb
63
74
  - lib/dm-forms/core_ext.rb
64
- - lib/dm-forms/elements.rb
65
- - lib/dm-forms/model_elements.rb
75
+ - lib/dm-forms/helpers.rb
76
+ - lib/dm-forms/mixins/descriptions.rb
77
+ - lib/dm-forms/mixins/errors.rb
78
+ - lib/dm-forms/mixins/labels.rb
79
+ - lib/dm-forms/mixins/wrappers.rb
80
+ - lib/dm-forms/mixins.rb
66
81
  - lib/dm-forms/tag.rb
67
82
  - lib/dm-forms/version.rb
68
- - spec/functional/core_ext_spec.rb
69
- - spec/functional/elements_spec.rb
83
+ - lib/dm-forms.rb
84
+ - Manifest
85
+ - Rakefile
86
+ - README.rdoc
87
+ - spec/functional/helpers_spec.rb
88
+ - spec/functional/mixins/descriptions_spec.rb
89
+ - spec/functional/mixins/labels_spec.rb
90
+ - spec/functional/mixins/wrappers_spec.rb
70
91
  - spec/functional/tag_spec.rb
71
92
  - spec/integration/datamapper_spec.rb
72
- - spec/integration/haml_spec.rb
73
93
  - spec/spec_helper.rb
74
94
  - tasks/benchmarks.rake
75
95
  - tasks/docs.rake
76
96
  - tasks/gemspec.rake
77
97
  - tasks/spec.rake
78
- - dm-forms.gemspec
98
+ - Todo.rdoc
79
99
  has_rdoc: true
80
100
  homepage: http://github.com/visionmedia/dm-forms
81
101
  post_install_message:
@@ -1,37 +0,0 @@
1
-
2
- $:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
3
- require 'dm-forms'
4
- require 'dm-core'
5
- require 'dm-validations'
6
-
7
- include DataMapper::Form::ModelElements
8
- DataMapper.setup :default, 'sqlite3::memory:'
9
-
10
- class User
11
- include DataMapper::Resource
12
- property :id, Serial
13
- property :name, String, :format => /^[\w]+$/
14
- property :email, String, :format => :email_address
15
- end
16
-
17
- DataMapper.auto_migrate!
18
- user = User.new :name => 'tj', :email => 'invalid email@lame.com'
19
-
20
- s = errors_for(user)
21
- s << form_for(user, :action => '/user') do |f|
22
- f.textarea :name
23
- f.textarea :email
24
- f.submit :op, :value => 'Add'
25
- end
26
- puts s
27
-
28
- user.email = 'tj@vision-media.ca'
29
- user.save
30
-
31
- s = errors_for(user)
32
- s << form_for(user, :action => '/user') do |f|
33
- f.textarea :name, :label => 'Name'
34
- f.textarea :email, :label => 'Email'
35
- f.submit :op, :value => 'Update'
36
- end
37
- puts s
@@ -1,31 +0,0 @@
1
-
2
- $:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
3
- require 'dm-forms'
4
-
5
- include DataMapper::Form::Elements
6
-
7
- def example before, &block
8
- puts before << "\n\n"
9
- puts yield.gsub!(/^/, ' ')
10
- puts
11
- end
12
-
13
- example %(textarea :comments) do
14
- textarea :comments
15
- end
16
-
17
- example %(textarea :comments, :label => 'Comments', :description => 'Tell us what you think') do
18
- textarea :comments, :label => 'Comments', :description => 'Tell us what you think'
19
- end
20
-
21
- example %(textfield :email, :label => 'Email', :required => true) do
22
- textfield :email, :label => 'Email', :required => true
23
- end
24
-
25
- example 'Login' do
26
- form :login do |f|
27
- f.textfield :name, :label => 'Username'
28
- f.textfield :pass, :label => 'Password'
29
- f.submit :op, :value => 'Login'
30
- end
31
- end
@@ -1,21 +0,0 @@
1
-
2
- $:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
3
- require 'rubygems'
4
- require 'haml'
5
- require 'dm-forms'
6
-
7
- include DataMapper::Form::ModelElements
8
-
9
- # Haml does not play very nice with nested Ruby, but then again
10
- # there is relatively nothing that cannot be altered via styling
11
- # so placing forms directly within a Haml view is not entirely
12
- # necessary.
13
- def login_form
14
- form :login, :action => '/user' do |f|
15
- f.textarea :name, :label => 'Name'
16
- f.textarea :email, :label => 'Email'
17
- f.submit :op, :value => 'Login'
18
- end
19
- end
20
-
21
- puts Haml::Engine.new(File.read(File.dirname(__FILE__) + '/login.haml')).render
@@ -1,4 +0,0 @@
1
- #primary
2
- .content
3
- %h1 Login
4
- = login_form
@@ -1,210 +0,0 @@
1
-
2
- module DataMapper
3
- module Form
4
- module Elements
5
-
6
- ##
7
- # Proxy object for capturing elements. See Elements#capture_elements.
8
-
9
- class Proxy
10
- def initialize model = nil
11
- @model = model
12
- end
13
-
14
- def method_missing meth, *args, &block
15
- add_error_class_to args if has_a_model_with_errors_on? args.first
16
- (@elements ||= []) << Elements.send(meth, *args, &block)
17
- end
18
-
19
- def add_error_class_to args
20
- ((args[1] ||= {})[:class] ||= '') << ' error'
21
- end
22
-
23
- def has_a_model_with_errors_on? meth
24
- @model and !@model.valid? and @model.errors.on meth
25
- end
26
- end
27
-
28
- module_function
29
-
30
- ##
31
- # Generates a generic HTML +name+ tag. Although this method is
32
- # generally used internally by dm-forms, you may utilize it directly
33
- # passing any of the following +options+.
34
- #
35
- # === Options:
36
- #
37
- # :self_closing Wither or not the element should self-close (<br />)
38
- # :attributes Hash of attributes such as :type => :textfield
39
- #
40
-
41
- def tag name, options = {}, &block
42
- Tag.new(name, options, &block).render
43
- end
44
-
45
- ##
46
- # Generates a label.
47
-
48
- def label value, options = {}
49
- value << ':'
50
- value << '<em>*</em>' if options.delete :required
51
- %(<label for="#{options[:for]}">#{value}</label>\n)
52
- end
53
-
54
- ##
55
- # Generates a legend.
56
-
57
- def legend value
58
- %(<legend>#{value}</legend>)
59
- end
60
-
61
- ##
62
- # Generates a description.
63
-
64
- def desc text
65
- %(\n<p class="description">#{text}</p>) unless text.blank?
66
- end
67
-
68
- ##
69
- # Generates an option.
70
-
71
- def option value, title
72
- %(<option value="#{value}">#{title}</option>\n)
73
- end
74
-
75
- ##
76
- # Generates a form.
77
-
78
- def form name, options = {}, &block
79
- options = { :method => :post, :id => "form-#{name}" }.merge options
80
- unless valid_http_verb? options
81
- old_value = options[:value] || ''
82
- options[:value] = hidden_method(options[:method]) << old_value
83
- options[:method] = :post
84
- end
85
- tag :form, :attributes => options, &block
86
- end
87
-
88
- ##
89
- # Generates a fieldset.
90
-
91
- def fieldset name, options = {}, &block
92
- legend_value = options.has_key?(:legend) ? options.delete(:legend) : name.humanize.capitalize
93
- options = { :class => "fieldset-#{name}" }.merge options
94
- options[:value] = "\n" << legend(legend_value) << (options.delete(:value) || '')
95
- tag :fieldset, :attributes => options, &block
96
- end
97
-
98
- ##
99
- # Generates a textfield.
100
-
101
- def textfield name, options = {}
102
- options = { :type => :textfield, :name => name }.merge options
103
- tag :input, :self_closing => true, :attributes => options
104
- end
105
-
106
- ##
107
- # Generates a password field.
108
-
109
- def password name, options = {}
110
- options = { :type => :password, :name => name }.merge options
111
- tag :input, :self_closing => true, :attributes => options
112
- end
113
-
114
- ##
115
- # Generates a checkbox.
116
-
117
- def checkbox name, options = {}
118
- options = { :type => :checkbox, :name => name }.merge options
119
- tag :input, :self_closing => true, :attributes => options
120
- end
121
-
122
- ##
123
- # Generates a hidden field.
124
-
125
- def hidden name, options = {}
126
- options = { :type => :hidden, :name => name }.merge options
127
- tag :input, :self_closing => true, :attributes => options
128
- end
129
-
130
- ##
131
- # Creates hidden _method, with value of +method+.
132
-
133
- def hidden_method method
134
- hidden :_method, :value => method
135
- end
136
-
137
- ##
138
- # Generates a radio button.
139
-
140
- def radio name, options = {}
141
- options = { :type => :radio, :name => name }.merge options
142
- tag :input, :self_closing => true, :attributes => options
143
- end
144
-
145
- ##
146
- # Generates a file field.
147
-
148
- def file name, options = {}
149
- options = { :type => :file, :name => name }.merge options
150
- tag :input, :self_closing => true, :attributes => options
151
- end
152
-
153
- ##
154
- # Generates a select field.
155
-
156
- def select name, options = {}, &block
157
- options = { :name => name, :value => "\n" }.merge options
158
- options[:value] << capture_elements(&block) if block_given?
159
- options[:value] << select_options(options) if options.include? :options
160
- tag :select, :attributes => options
161
- end
162
-
163
- ##
164
- # Generates a textarea.
165
-
166
- def textarea name, options = {}, &block
167
- options = { :name => name }.merge options
168
- tag :textarea, :attributes => options, &block
169
- end
170
-
171
- ##
172
- # Generates a submit button.
173
-
174
- def submit name, options = {}
175
- options = { :type => :submit, :name => name }.merge options
176
- tag :input, :self_closing => true, :attributes => options
177
- end
178
-
179
- ##
180
- # Generates a button.
181
-
182
- def button name, options = {}
183
- type = options.has_key?(:src) ? :image : :button
184
- options = { :type => type, :name => name }.merge options
185
- tag :input, :self_closing => true, :attributes => options
186
- end
187
-
188
- ##
189
- # Capture results of elements called within +block+. Optionally
190
- # a DataMapper model may be passed, at which point error classes
191
- # will be applied to invalid elements.
192
-
193
- def capture_elements model = nil, &block
194
- elements = yield Proxy.new(model)
195
- elements.join
196
- end
197
-
198
- private
199
-
200
- def select_options options #:nodoc:
201
- options.delete(:options).collect { |value, title| option(value, title) }.join
202
- end
203
-
204
- def valid_http_verb? options #:nodoc:
205
- [:get, :post].include? options[:method]
206
- end
207
-
208
- end
209
- end
210
- end