reform 1.2.3 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 777f16f9f2f9f029ad3d3b9ee1cdd2b12ec31bb7
4
- data.tar.gz: a1dc7b0e61b13090a6a67bda43520104c58e502d
3
+ metadata.gz: 9de1e1d5688d37d56c180a7b0c622a5319bd7347
4
+ data.tar.gz: b68d927a7b7a2dc8beb287ce8692c4527866a731
5
5
  SHA512:
6
- metadata.gz: 9ca591099b12b4b519311e74d1bb89c7251473b2f827115d7c56c9880886a8a9f76f4326d48d386dc4d36f42c753ccf74bedb088d714524764022a5a7b316dea
7
- data.tar.gz: efb2ea5be6e19226fbe2ad6f9741380e9ab5a2b1630fcd96dabb146c0c26cb8478a7668ef7ff378170d1a7e66842a2c9b646ffb120d971bb37eaa438c9018116
6
+ metadata.gz: 56c84d82a9e5981796d199a045d6e014e7f3dc1d69051e997b07c5b213c905a7f92c21d20b618907212f0a3544711b142f3fbd2d790bcc498ecfcaa5d290244c
7
+ data.tar.gz: cce2349a4ff6c075a23bb28d9f536997f3f49c869b4f08469cedb2978e9d0784b858b0c0649b4ab770e8d12d340224c2472860668c05fd2eba97ca23e459ef13
data/CHANGES.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## 1.2.4
2
+
3
+ * Added `Form#readonly?` to find out whether a field is set to writeable. This is helpful for simple_form to display a disabled input field.
4
+
5
+ ```ruby
6
+ property :title, writeable: false
7
+ ```
8
+
9
+ In the view, you can then use something along the following code.
10
+
11
+ ```ruby
12
+ f.input :title, readonly: @form.readonly?(:title)
13
+ ```
14
+
1
15
  ## 1.2.3
2
16
 
3
17
  * Make `ModelReflections` work with simple_form 3.1.0. (#176). It also provides `defined_enums` and `::reflect_on_association` now.
data/README.md CHANGED
@@ -310,7 +310,7 @@ When rendering this form you could use the form's accessors manually.
310
310
  Or use something like `#fields_for` in a Rails environment.
311
311
 
312
312
  ```haml
313
- = form_for @form |f|
313
+ = form_for @form do |f|
314
314
  = f.text_field :title
315
315
  = f.text_field :length
316
316
 
@@ -378,7 +378,7 @@ Reform will expose the collection using the `#songs` method.
378
378
  However, `#fields_for` works just fine, again.
379
379
 
380
380
  ```haml
381
- = form_for @form |f|
381
+ = form_for @form do |f|
382
382
  = f.text_field :title
383
383
 
384
384
  = f.fields_for :songs do |s|
Binary file
@@ -191,6 +191,13 @@ module Reform
191
191
 
192
192
  alias_method :aliased_model, :model
193
193
 
194
+ module Readonly
195
+ def readonly?(name)
196
+ self.class.representer_class.representable_attrs.get(name)[:writeable] == false
197
+ end
198
+ end
199
+ include Readonly
200
+
194
201
  # TODO: remove me in 2.0.
195
202
  module Reform20Switch
196
203
  def self.included(base)
@@ -1,3 +1,3 @@
1
1
  module Reform
2
- VERSION = "1.2.3"
2
+ VERSION = "1.2.4"
3
3
  end
@@ -0,0 +1,14 @@
1
+ require "test_helper"
2
+
3
+ class ReadonlyTest < MiniTest::Spec
4
+ class SongForm < Reform::Form
5
+ property :artist
6
+ property :title, writeable: false
7
+ # TODO: what to do with virtual values?
8
+ end
9
+
10
+ let (:form) { SongForm.new(OpenStruct.new) }
11
+
12
+ it { form.readonly?(:artist).must_equal false }
13
+ it { form.readonly?(:title).must_equal true }
14
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reform
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-12-10 00:00:00.000000000 Z
12
+ date: 2014-12-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: representable
@@ -276,6 +276,7 @@ files:
276
276
  - test/rails/integration_test.rb
277
277
  - test/read_only_test.rb
278
278
  - test/readable_test.rb
279
+ - test/readonly_test.rb
279
280
  - test/reform_test.rb
280
281
  - test/representer_test.rb
281
282
  - test/save_test.rb
@@ -363,6 +364,7 @@ test_files:
363
364
  - test/rails/integration_test.rb
364
365
  - test/read_only_test.rb
365
366
  - test/readable_test.rb
367
+ - test/readonly_test.rb
366
368
  - test/reform_test.rb
367
369
  - test/representer_test.rb
368
370
  - test/save_test.rb