rack-backend-api 0.2.1 → 0.2.2
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/README.md +1 -0
- data/lib/backend_api.rb +1 -1
- data/lib/sequel_rack_backend_api_adapter.rb +7 -2
- data/rack-backend-api.gemspec +1 -1
- data/test/spec_sequel_adapter.rb +6 -0
- metadata +4 -4
data/README.md
CHANGED
@@ -293,6 +293,7 @@ CHANGE LOG
|
|
293
293
|
0.1.0 Introduce sorting functionality
|
294
294
|
0.2.0 Control what you send on 201 responses
|
295
295
|
0.2.1 Have a title in forms + Only use `_method` if not POST
|
296
|
+
0.2.2 Backend form should accept a block for populating the fields
|
296
297
|
|
297
298
|
COPYRIGHT
|
298
299
|
=========
|
data/lib/backend_api.rb
CHANGED
@@ -25,9 +25,14 @@ module ::Sequel::Plugins::RackBackendApiAdapter
|
|
25
25
|
|
26
26
|
def backend_form(url, cols=nil, opts={})
|
27
27
|
cols ||= default_backend_columns
|
28
|
-
|
28
|
+
if block_given?
|
29
|
+
fields_list = ''
|
30
|
+
yield(fields_list)
|
31
|
+
else
|
32
|
+
fields_list = respond_to?(:crushyform) ? crushyform(cols) : backend_fields(cols)
|
33
|
+
end
|
29
34
|
o = "<form action='#{url}' method='POST' #{"enctype='multipart/form-data'" if fields_list.match(/type='file'/)} class='backend-form'>\n"
|
30
|
-
o << backend_form_title
|
35
|
+
o << backend_form_title unless block_given?
|
31
36
|
o << fields_list
|
32
37
|
opts[:method] = 'PUT' if (opts[:method].nil? && !self.new?)
|
33
38
|
o << "<input type='hidden' name='_method' value='#{opts[:method]}' />\n" unless opts[:method].nil?
|
data/rack-backend-api.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'rack-backend-api'
|
3
|
-
s.version = "0.2.
|
3
|
+
s.version = "0.2.2"
|
4
4
|
s.platform = Gem::Platform::RUBY
|
5
5
|
s.summary = "A Rack middleware that provides a simple API for your Admin section"
|
6
6
|
s.description = "The purpose of this Rack Middleware is to provide an API that interfaces with database actions in order to build a CMS."
|
data/test/spec_sequel_adapter.rb
CHANGED
@@ -110,4 +110,10 @@ describe 'Sequel Adapter' do
|
|
110
110
|
Author[1].backend_form('/url').should.match(/#{Regexp.escape(Author[1].backend_form_title)}/)
|
111
111
|
end
|
112
112
|
|
113
|
+
should 'Yield the given block to populate the form fields' do
|
114
|
+
Author[1].backend_form('/url'){|out| out << '<!-- YIELDED -->'}.should.match(/<!-- YIELDED -->/)
|
115
|
+
Author[1].backend_form('/url', [:name]){|out|}.should.not.match(/#{Regexp.escape Author[1].crushyfield(:name)}/)
|
116
|
+
Author[1].backend_form('/url'){|out| out << '<!-- YIELDED -->'}.should.not.match(/#{Regexp.escape(Author[1].backend_form_title)}/)
|
117
|
+
end
|
118
|
+
|
113
119
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-backend-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 2
|
10
|
+
version: 0.2.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Mickael Riga
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-08-
|
18
|
+
date: 2011-08-08 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|