campo 0.3.4 → 0.9.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.
@@ -0,0 +1,174 @@
1
+
2
+ # encoding: UTF-8
3
+
4
+ require_relative "./spec_helper.rb"
5
+ require_relative "../lib/campo/campo.rb"
6
+ require_relative "../lib/campo/plugins/partial.rb"
7
+ require_relative "../lib/campo/plugins/aria.rb"
8
+ require_relative "../lib/campo/plugins/jqueryvalidation.rb"
9
+
10
+ describe :"Campo::Plugins::JQueryValidation" do
11
+ before(:all) do
12
+ Campo.plugins.clear
13
+ end
14
+ describe :"Campo::Plugins::JQueryValidation::Klass" do
15
+ context "Initialisation" do
16
+ subject { Campo::Plugins::JQueryValidation::Klass.new }
17
+ it { should_not be_nil }
18
+ it { should be_a_kind_of Campo::Plugins::JQueryValidation::Klass }
19
+ end
20
+
21
+ context "After initialisation" do
22
+ subject { Campo::Plugins::JQueryValidation::Klass.new }
23
+ it { should respond_to(:befores, :afters, :before_output, :after_output, :on_plugin, :extras, :plugged_in) }
24
+ end
25
+ end
26
+
27
+ describe :"Campo::Plugins::JQueryValidation.new" do
28
+ subject { Campo::Plugins::JQueryValidation.new }
29
+ it { should_not be_nil }
30
+ it { should be_a_kind_of Campo::Plugins::JQueryValidation::Klass }
31
+ end
32
+
33
+ context "Plugging in the JQueryValidation plugin" do
34
+ before(:each) {
35
+ Campo.plugins.clear
36
+ Campo.plugin :partial
37
+ Campo.plugin :JQueryValidation
38
+ }
39
+ after(:each) { Campo.plugins.clear }
40
+ context "ancestors" do
41
+ subject { Campo::Base.ancestors }
42
+ it { should include( Campo::Plugins::JQueryValidation::InstanceMethods::Convenience ) }
43
+ end
44
+ context "included methods" do
45
+ context "Convenience" do
46
+ subject { Campo::Input.new "name"}
47
+ it { should respond_to( :validate ) }
48
+ end
49
+ context "Outputter" do
50
+ subject { Campo::Outputter.new }
51
+ it { should respond_to( :jquery_script_declaration ) }
52
+ it { should respond_to( :jqv_form_names ) }
53
+ end
54
+ end
55
+ end
56
+
57
+
58
+ describe "output" do
59
+ context "Given a partial" do
60
+ before {
61
+ Campo.plugins.clear
62
+ Campo.plugin :partial
63
+ Campo.plugin :Aria
64
+ Campo.plugin :JQueryValidation, form: "wrapper_form" }
65
+ let(:form) {
66
+ Campo.literal ".form" do
67
+ text("a").validate
68
+ text "c"
69
+ text( "g", size: 3 ).validate( :digits, :maxlength, :required )
70
+ end
71
+ }
72
+ let(:expected) {
73
+ <<'STR'
74
+ :javascript
75
+ $().ready(function(){
76
+ $("#wrapper_form").validate({
77
+ rules: {
78
+ a: { required: true },
79
+ g: { required: true, maxlength: 3, digits: true }
80
+ }
81
+ });
82
+ });
83
+ .form
84
+ %label{ for: "a", class: "required", }
85
+ A
86
+ %input{ atts[:a], tabindex: "#{@campo_tabindex += 1}", id: "a", type: "text", name: "a", class: "required", }
87
+ %label{ for: "c", }
88
+ C
89
+ %input{ atts[:c], tabindex: "#{@campo_tabindex += 1}", id: "c", type: "text", name: "c", }
90
+ %label{ for: "g", class: "required", }
91
+ G
92
+ %input{ atts[:g], tabindex: "#{@campo_tabindex += 1}", id: "g", type: "text", size: "3", name: "g", class: "required", }
93
+ STR
94
+ }
95
+
96
+
97
+ subject { Campo.output(form, :partial => true) }
98
+ it { should_not be_nil }
99
+ it { should be_a_kind_of String }
100
+ it { should == expected }
101
+ it { should include(%Q!class: "required"!) }
102
+ end
103
+
104
+
105
+
106
+ context "Given a whole form" do
107
+ before {
108
+ Campo.plugins.clear
109
+ Campo.plugin :partial
110
+ Campo.plugin :Aria
111
+ Campo.plugin :JQueryValidation}
112
+ let(:form) {
113
+ Campo.form "exampleForm" do
114
+ text("a").validate
115
+ text( "b" ).validate
116
+ text "c"
117
+ text( "d", size: 2 ).validate( :maxlength )
118
+ text( "e", size: 5 ).validate( :maxlength, :required )
119
+ text( "f" ).validate( :digits )
120
+ text( "g", size: 3 ).validate( :digits, :maxlength, :required )
121
+ end
122
+ }
123
+ let(:expected) { <<'STR'
124
+ :javascript
125
+ $().ready(function(){
126
+ $("#exampleForm").validate({
127
+ rules: {
128
+ a: { required: true },
129
+ b: { required: true },
130
+ d: { maxlength: 2 },
131
+ e: { required: true, maxlength: 5 },
132
+ f: { digits: true },
133
+ g: { required: true, maxlength: 3, digits: true }
134
+ }
135
+ });
136
+ });
137
+ - atts = {} if atts.nil?
138
+ - atts.default_proc = proc {|hash, key| hash[key] = {} } if atts.default_proc.nil?
139
+ - inners = {} if inners.nil?
140
+ - inners.default = "" if inners.default.nil?
141
+ - @campo_tabindex ||= 0 # for tabindex
142
+ %form{ atts[:exampleform], id: "exampleForm", method: "POST", name: "exampleForm", role: "form", }
143
+ %label{ for: "a", class: "required", }
144
+ A
145
+ %input{ atts[:a], tabindex: "#{@campo_tabindex += 1}", id: "a", type: "text", name: "a", class: "required", }
146
+ %label{ for: "b", class: "required", }
147
+ B
148
+ %input{ atts[:b], tabindex: "#{@campo_tabindex += 1}", id: "b", type: "text", name: "b", class: "required", }
149
+ %label{ for: "c", }
150
+ C
151
+ %input{ atts[:c], tabindex: "#{@campo_tabindex += 1}", id: "c", type: "text", name: "c", }
152
+ %label{ for: "d", }
153
+ D
154
+ %input{ atts[:d], tabindex: "#{@campo_tabindex += 1}", id: "d", type: "text", size: "2", name: "d", }
155
+ %label{ for: "e", class: "required", }
156
+ E
157
+ %input{ atts[:e], tabindex: "#{@campo_tabindex += 1}", id: "e", type: "text", size: "5", name: "e", class: "required", }
158
+ %label{ for: "f", }
159
+ F
160
+ %input{ atts[:f], tabindex: "#{@campo_tabindex += 1}", id: "f", type: "text", name: "f", }
161
+ %label{ for: "g", class: "required", }
162
+ G
163
+ %input{ atts[:g], tabindex: "#{@campo_tabindex += 1}", id: "g", type: "text", size: "3", name: "g", class: "required", }
164
+ STR
165
+ }
166
+ subject { Campo.output(form) }
167
+ it { should_not be_nil }
168
+ it { should be_a_kind_of String }
169
+ it { should == expected }
170
+ it { should include(%Q!class: "required"!) }
171
+ end
172
+ end
173
+
174
+ end
@@ -0,0 +1,77 @@
1
+ # encoding: UTF-8
2
+
3
+ require_relative "./spec_helper.rb"
4
+ require_relative "../lib/campo/campo.rb"
5
+ require_relative "../lib/campo/plugins/partial.rb"
6
+
7
+
8
+ describe :"Campo::Plugins::Partial" do
9
+ before(:all) do
10
+ Campo.plugins.clear
11
+ Campo.plugin :partial # this is normally done by lib/campo.rb
12
+ end
13
+ describe :"Campo::Plugins::Partial::Klass" do
14
+ context "Initialisation" do
15
+ subject { Campo::Plugins::Partial::Klass.new }
16
+ it { should_not be_nil }
17
+ it { should be_a_kind_of Campo::Plugins::Partial::Klass }
18
+ end
19
+
20
+ context "After initialisation" do
21
+ subject { Campo::Plugins::Partial::Klass.new }
22
+ it { should respond_to(:befores, :afters, :before_output, :after_output, :on_plugin, :extras, :plugged_in) }
23
+ end
24
+ end
25
+
26
+ describe :"Campo::Plugins::Partial.new" do
27
+ subject { Campo::Plugins::Partial.new }
28
+ it { should_not be_nil }
29
+ it { should be_a_kind_of Campo::Plugins::Partial::Klass }
30
+ end
31
+
32
+ context "Plugging in the Partial plugin" do
33
+ before(:each) { Campo.plugin :partial }
34
+ after(:each) { Campo.plugins.clear }
35
+ context "ancestors" do
36
+ subject { Campo::Outputter.ancestors }
37
+ it { should include( Campo::Plugins::Partial::InstanceMethods ) }
38
+ end
39
+ context "included methods" do
40
+ subject { Campo::Outputter.new }
41
+ it { should respond_to( :partial, :declarations, :options, :befores ) }
42
+ describe :partial do
43
+ subject { Campo::Outputter.new.partial }
44
+ it { should be_nil }
45
+ end
46
+ describe :declarations do
47
+ subject { Campo::Outputter.new.declarations }
48
+ it { should_not be_nil }
49
+ it { should be_a_kind_of String }
50
+ it { should include("- atts = {} if atts.nil?") }
51
+ it { should include("# for tabindex\n").should be_true }
52
+ end
53
+ describe :options do
54
+ subject { Campo::Outputter.new.options }
55
+ it { should_not be_nil }
56
+ it { should be_a_kind_of Hash }
57
+ it { should include(n: 0, tab: 2, partial: false) }
58
+ end
59
+ describe :befores do
60
+ subject { Campo::Outputter.new.befores }
61
+ it { should_not be_nil }
62
+ it { should be_a_kind_of Array }
63
+ it { should be_empty }
64
+ describe "What befores is holding" do
65
+ subject { Campo::Outputter.new.befores.first }
66
+ it { should be_nil }
67
+ end
68
+ end
69
+ describe :afters do
70
+ subject { Campo::Outputter.new.afters }
71
+ it { should_not be_nil }
72
+ it { should be_a_kind_of Array }
73
+ it { should have(1).items }
74
+ end
75
+ end
76
+ end
77
+ end # partial
@@ -0,0 +1,66 @@
1
+ # encoding: UTF-8
2
+
3
+ require_relative "./spec_helper.rb"
4
+ require_relative "../lib/campo/campo.rb"
5
+ require_relative "../lib/campo/plugins.rb"
6
+ require_relative "../lib/campo/plugins/partial.rb"
7
+
8
+ describe :"Campo::plugins" do
9
+ before(:all) do
10
+ Campo.plugins.clear
11
+ end
12
+ context "before plugging anything in" do
13
+ subject { Campo.plugins }
14
+ it { should be_a_kind_of Hash }
15
+ it { should be_empty }
16
+ context "Outputter" do
17
+ # subject { Campo::Outputter.new }
18
+ describe "befores" do
19
+ subject { Campo::Outputter.new.befores }
20
+ it { should_not be_nil }
21
+ it { should be_a_kind_of Array }
22
+ it { should be_empty }
23
+ end
24
+ describe "afters" do
25
+ subject { Campo::Outputter.new.afters }
26
+ it { should_not be_nil }
27
+ it { should be_a_kind_of Array }
28
+ it { should be_empty }
29
+ end
30
+ context "check_for_plugins" do
31
+ context "Given type of 'befores'" do
32
+ subject { Campo::Outputter.new.check_for_plugins :befores }
33
+ it { should_not be_nil }
34
+ it { should be_a_kind_of Array }
35
+ it { should be_empty }
36
+ end
37
+ context "Given type of 'afters'" do
38
+ subject { Campo::Outputter.new.check_for_plugins :afters }
39
+ it { should_not be_nil }
40
+ it { should be_a_kind_of Array }
41
+ it { should be_empty }
42
+ end
43
+ end
44
+
45
+ end
46
+ end
47
+ context "after plugging something in" do
48
+ before(:each) { Campo.plugin :partial }
49
+
50
+ subject { Campo.plugins }
51
+ it { should be_a_kind_of Hash }
52
+ it { should_not be_empty }
53
+ it { should include( :partial ) }
54
+
55
+ describe "the value" do
56
+ subject { Campo.plugins[:partial] }
57
+ it { should_not be_nil }
58
+ it { be_a_kind_of Campo::Plugins::Partial::Klass }
59
+ end
60
+
61
+ context "and then clearing the plugins" do
62
+ subject { Campo.plugins.clear }
63
+ it { should be_empty }
64
+ end
65
+ end
66
+ end
@@ -4,4 +4,12 @@ RSpec::Matchers.define :be_full_of do |klass|
4
4
  match do |items|
5
5
  items.all?{|x| x.kind_of? klass }
6
6
  end
7
+ end
8
+
9
+ # encoding: UTF-8
10
+
11
+ RSpec::Matchers.define :contain_a_kind_of do |klass|
12
+ match do |items|
13
+ items.any?{|x| x.kind_of? klass }
14
+ end
7
15
  end
metadata CHANGED
@@ -1,89 +1,95 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: campo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Iain Barnett
9
9
  autorequire:
10
10
  bindir: bin
11
- cert_chain:
12
- - ! '-----BEGIN CERTIFICATE-----
13
-
14
- MIIDNDCCAhygAwIBAgIBADANBgkqhkiG9w0BAQUFADBAMRIwEAYDVQQDDAlpYWlu
15
-
16
- c3BlZWQxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
17
-
18
- bTAeFw0xMDA4MTkyMTQwMDlaFw0xMTA4MTkyMTQwMDlaMEAxEjAQBgNVBAMMCWlh
19
-
20
- aW5zcGVlZDEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYD
21
-
22
- Y29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApraebFPxvJVrayuZ
23
-
24
- xJkFZLAId7j0G3QG4oyJcRaJVhaJ36zcCUeg6/6f9LC78nZSmL2zA2ZG9H3Lzda0
25
-
26
- 0j+McpynbK/eSq0XpruQbuuhcOBow1KgDfjdhz3qXylHJ/iIzBosQzoEIk5eVY84
27
-
28
- R0qD+vNHwZQoDE+k4PB8LWIfbJPi+dmnL16C0qireO3nZASwTSGm1JdUtgESP0Hn
29
-
30
- f1KAe/ox00S8cSQNGUZ/fAsrnhAOApL9V38TwxiL0eMVcY+TbUspI26MB8oNwsgV
31
-
32
- zkBNt2lI45/SguV5wWMOWbWZ2v//w3PrBCUenkk+vwZmpOQUlk/8Ebrk+UeoAN1F
33
-
34
- NqE2DQIDAQABozkwNzAJBgNVHRMEAjAAMB0GA1UdDgQWBBTMWVuCrozPKTpMRYkm
35
-
36
- RUAqQFsGdDALBgNVHQ8EBAMCBLAwDQYJKoZIhvcNAQEFBQADggEBAFqZW23axU5A
37
-
38
- Hf/p5iBfRlJLIZqFmVbGb1A+mxaPFUkhERH7FfY4ay4p2Ci1DNhSYQLy5dsB1ik0
39
-
40
- J0tlNaXxkJ0uq6up65yoj4/XBJArm9oiO7PcwrzC52bmiEv4Ir67/AGRyfmgIU0A
41
-
42
- 5jv3cSFcnbrwCvClZOoVhNkvaxer3/DgLecpjgXfSwY++JHU0L/5HplidHzjE3PZ
43
-
44
- 1YGYQYJGIy5Hap8Lpn1x9/Q2C8pMX33JRItrIVie6UIsrGXVtGS5lZS/pri9Budd
45
-
46
- +ikjZ+dLa/HjsXQ5HcI6WdySxyKElXr2Ecs8ipmnxCk6+KH9/2OnXrpBzeIXJoMS
47
-
48
- YK13fiGcldY=
49
-
50
- -----END CERTIFICATE-----
51
-
52
- '
53
- date: 2011-12-17 00:00:00.000000000 +00:00
54
- default_executable:
11
+ cert_chain: []
12
+ date: 2012-06-16 00:00:00.000000000 Z
55
13
  dependencies:
56
14
  - !ruby/object:Gem::Dependency
57
15
  name: haml
58
- requirement: &2157040780 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
59
17
  none: false
60
18
  requirements:
61
19
  - - ~>
62
20
  - !ruby/object:Gem::Version
63
21
  version: 3.1.1
64
- type: :runtime
22
+ type: :development
65
23
  prerelease: false
66
- version_requirements: *2157040780
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.1.1
30
+ - !ruby/object:Gem::Dependency
31
+ name: yard
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
67
62
  description: ! ' Form builder for Haml
68
63
 
69
64
  '
70
- email:
71
- - iainspeed @nospam@ gmail.com
65
+ email: iainspeed @nospam@ gmail.com
72
66
  executables: []
73
67
  extensions: []
74
68
  extra_rdoc_files: []
75
69
  files:
76
70
  - .gitignore
77
- - CHANGES
71
+ - .rspec
72
+ - .travis.yml
73
+ - CHANGES.markdown
74
+ - Gemfile
78
75
  - README.markdown
76
+ - Rakefile
79
77
  - campo.gemspec
80
78
  - lib/campo.rb
79
+ - lib/campo/campo.rb
80
+ - lib/campo/plugins.rb
81
+ - lib/campo/plugins/aria.rb
82
+ - lib/campo/plugins/jqueryvalidation.rb
83
+ - lib/campo/plugins/partial.rb
81
84
  - lib/campo/version.rb
85
+ - spec/aria_spec.rb
82
86
  - spec/campo_spec.rb
87
+ - spec/jqueryvalidation_spec.rb
88
+ - spec/partial_spec.rb
89
+ - spec/plugins_spec.rb
83
90
  - spec/spec_helper.rb
84
91
  - spec/support/matchers/items.rb
85
- has_rdoc: true
86
- homepage:
92
+ homepage: https://github.com/yb66/Campo
87
93
  licenses: []
88
94
  post_install_message:
89
95
  rdoc_options: []
@@ -103,11 +109,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
109
  version: '0'
104
110
  requirements: []
105
111
  rubyforge_project:
106
- rubygems_version: 1.6.2
112
+ rubygems_version: 1.8.23
107
113
  signing_key:
108
114
  specification_version: 3
109
115
  summary: Form builder for Haml
110
116
  test_files:
117
+ - spec/aria_spec.rb
111
118
  - spec/campo_spec.rb
119
+ - spec/jqueryvalidation_spec.rb
120
+ - spec/partial_spec.rb
121
+ - spec/plugins_spec.rb
112
122
  - spec/spec_helper.rb
113
123
  - spec/support/matchers/items.rb