activeadmin-magicfields 0.4.1 → 0.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1a2b1b0602c7707012b11d87316599b6b40aadb
4
- data.tar.gz: ee103224f51e24985c38f3b6537b440bc8fa53c2
3
+ metadata.gz: b48d7e0bf63ef822aeb651550b37344562e8f3be
4
+ data.tar.gz: 87135d72fc1f961eda506107f8327ef0dc7f9202
5
5
  SHA512:
6
- metadata.gz: 5faf7780d48487dce21219da8c9713c3b7c30ebb52829510703b9613ed94c3e6a1d2dd4cd018c5d22c5a219f7b408aa1861cb89197c6b13e424ba46256bbf997
7
- data.tar.gz: 7f225fc8b2176274066b84e3c74ab23c6fd20fbcf714ca90826f48f8bad71aec777f13537cc98f798c8af7eb2c23709755f04621ab733af5303e947821376e02
6
+ metadata.gz: de40ae1e30e31bf0ad6a1a2f463264171278c029e007b06d34f4cf6aa4fd00a11395b44b1fb7540600ed0b529c721970022fa6dcb3d9aed17653e9afb518da09
7
+ data.tar.gz: 8b2bf333c471c70ec8ae786bc500ec71e89f79f67e91997277d4a426a19f29cc8660a1b6fcf81f983c4a52ec378ef281d367826dffcd50c1aeba9ab83e4bc9d5
@@ -1,4 +1,4 @@
1
- Copyright 2015 Sergeev Peter
1
+ Copyright 2015 Silvain Toromanoff
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -46,23 +46,23 @@ Include assets in js and css manifests
46
46
 
47
47
  # Usage
48
48
 
49
- To use the gem, you need to enable parts on one of your models
49
+ To use the gem, you need to enable parts on one of your models (in the following example, we add parts to the Page model)
50
50
 
51
- ```
51
+ ``` ruby
52
52
  # db/migrate
53
- class CreateYourModelsParts < ActiveRecord::Migration
53
+ class CreatePagesParts < ActiveRecord::Migration
54
54
  def change
55
- create_table :your_models_parts do |t|
56
- t.integer :your_model_id
55
+ create_table :pages_parts do |t|
56
+ t.integer :page_id
57
57
  t.integer :part_id
58
58
  end
59
59
  end
60
60
  end
61
61
  ```
62
62
 
63
- ```
64
- # models/your_model.rb
65
- class YourModel < ActiveRecord::Base
63
+ ``` ruby
64
+ # models/page.rb
65
+ class Page < ActiveRecord::Base
66
66
  # ...
67
67
 
68
68
  has_many :part_objects, dependent: :destroy, inverse_of: :base_model, foreign_key: "base_model_id"
@@ -76,9 +76,9 @@ end
76
76
 
77
77
  The gem extends activeadmin's form builder, so to enable it you need to override the form builder using `builder` option:
78
78
 
79
- ```
80
- #admin/your_model.rb
81
- ActiveAdmin.register YourModel do
79
+ ``` ruby
80
+ #admin/page.rb
81
+ ActiveAdmin.register Page do
82
82
  # ...
83
83
 
84
84
  form builder: ActiveadminMagicfields::FormBuilder, html: { :enctype => "multipart/form-data" } do |f|
@@ -101,29 +101,32 @@ There are few parameters available, currently none of which can be changed:
101
101
 
102
102
  # Adding a custom field type
103
103
 
104
- To add a custom field type, just create a table called 'field_[your_field_type]s', a model in models/field/your_field_type.rb, and a form partial. This will enable you to use your_field_type as a part's custom field.
104
+ To add a custom field type, just create a table called 'field_[your_field_type]s', a model in models/field/your_field_type.rb, and a form partial. This will enable you to use your_field_type as a part's custom field. In the following example, we create the textarea field type.
105
+ (In `views/admin/field_inputs/_textarea.html.erb`, you can also find how to make this field a WYSIWYG field)
105
106
 
106
- ```
107
+ ``` ruby
107
108
  # db/migrate
108
- class CreateFieldYourFieldType < ActiveRecord::Migration
109
+ class CreateFieldTextarea < ActiveRecord::Migration
109
110
  def change
110
- create_table :field_your_field_types do |t|
111
+ create_table :field_textareas do |t|
111
112
  t.string :title #required for all field types
112
113
  t.integer :field_template_id #required for all field types
113
114
 
114
- t.[some_database_type] :your_field_type
115
+ t.text :textarea
115
116
 
116
117
  t.timestamps
117
118
  end
118
119
  end
119
120
  end
120
- ```
121
+
121
122
 
122
123
  ```
123
- # models/field/your_field_type.rb
124
+
125
+ ``` ruby
126
+ # models/field/textarea.rb
124
127
  module Field
125
128
  class YourFieldType < ActiveRecord::Base
126
- self.table_name = "field_your_field_types"
129
+ self.table_name = "field_textareas"
127
130
 
128
131
  has_one :part_object_field, as: :fieldable
129
132
  belongs_to :field_template
@@ -131,14 +134,14 @@ module Field
131
134
  delegate :title, to: :field_template, allow_nil: true
132
135
  delegate :is_required, to: :field_template, allow_nil: true
133
136
 
134
- validates :your_field_type, presence: { if: :is_required }
137
+ validates :textarea, presence: { if: :is_required }
135
138
 
136
139
  end
137
140
  end
138
141
  ```
139
142
 
140
143
  ```
141
- <%# views/admin/field_inputs/_your_field_type.html.erb %>
144
+ <%# views/admin/field_inputs/_textarea.html.erb %>
142
145
  <%= builder.input field_template.field_type, label: field_template.title, required: field_template.is_required, input_html: {name: form_prefix + builder.object_name.sub('part[', '[') + "[#{field_template.field_type}]" } %>
143
146
  ```
144
147
 
@@ -1,3 +1,3 @@
1
1
  module ActiveadminMagicfields
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeadmin-magicfields
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Silvain Toromanoff
@@ -88,14 +88,11 @@ files:
88
88
  - lib/app/models/repeater_part_object.rb
89
89
  - lib/app/views/admin/field_inputs/_checkbox.html.erb
90
90
  - lib/app/views/admin/field_inputs/_image.html.erb
91
- - lib/app/views/admin/field_inputs/_product.html.erb
92
91
  - lib/app/views/admin/field_inputs/_repeater.html.erb
93
- - lib/app/views/admin/field_inputs/_site_page.html.erb
94
92
  - lib/app/views/admin/field_inputs/_text.html.erb
95
93
  - lib/app/views/admin/field_inputs/_textarea.html.erb
96
94
  - lib/app/views/admin/part_objects/_part_object.html.erb
97
95
  - lib/app/views/admin/parts/_part.html.erb
98
- - lib/app/views/admin/parts/_part_old.arb
99
96
  - lib/generators/activeadmin-magicfields/install/install_generator.rb
100
97
  - lib/generators/activeadmin-magicfields/install/templates/create_field_checkbox.rb
101
98
  - lib/generators/activeadmin-magicfields/install/templates/create_field_image.rb
@@ -1 +0,0 @@
1
- <%= builder.input :product_id, as: :select, multiselect: false, collection: Spree::Product.all, label: field_template.title, required: field_template.is_required, input_html: {name: form_prefix + builder.object_name.sub('part[', '[') + "[product_id]" } %>
@@ -1 +0,0 @@
1
- <%= builder.input :site_page_id, as: :select, multiselect: false, collection: SitePage.all, label: field_template.title, required: field_template.is_required, input_html: {name: form_prefix + builder.object_name.sub('part[', '[') + "[site_page_id]" } %>
@@ -1,32 +0,0 @@
1
- # Define the Part Object
2
- part_objects = resource.part_objects.build
3
-
4
- # parents_array = params[:form_name].split("[").map{|n| n.chomp(']')}
5
-
6
- # raise
7
-
8
- # Build the form
9
- active_admin_form_for part, url: "to_be_stripped" do |f|
10
- f.semantic_fields_for :part_objects do |part_object|
11
-
12
- part_object.input :part_id, as: :hidden, input_html: {value: part.id}
13
-
14
- resource.field_templates.each_with_index do |field_template, ix|
15
- part_object.semantic_fields_for "part_object_fields_attributes[#{ix}]", part_objects.part_object_fields.build do |part_object_field|
16
-
17
-
18
- field_object = Field.const_get(field_template.field_type.classify).new
19
-
20
- part_object_field.semantic_fields_for "fieldable_attributes", field_object do |field|
21
- part_object.inputs do
22
- field.input field_template.field_type, label: field_template.title, required: field_template.is_required
23
- field.input :fieldable_type, as: :hidden, input_html: {value: field_template.field_type.classify}
24
- field.input :title, as: :hidden, input_html: {value: field_template.title}
25
- end
26
-
27
- end
28
- end
29
- end
30
- end
31
- end
32
-