inline_forms 0.5.0 → 0.5.1
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/VERSION +1 -1
- data/app/helpers/form_elements/associated.rb +1 -0
- data/app/helpers/form_elements/check_box.rb +1 -0
- data/app/helpers/form_elements/checklist.rb +1 -0
- data/app/helpers/form_elements/date.rb +2 -0
- data/app/helpers/form_elements/dropdown.rb +1 -0
- data/app/helpers/form_elements/dropdown_with_values.rb +1 -0
- data/app/helpers/form_elements/geo_code_curacao.rb +1 -0
- data/app/helpers/form_elements/range.rb +1 -0
- data/app/helpers/form_elements/text_area.rb +1 -0
- data/app/helpers/form_elements/text_field.rb +2 -1
- data/inline_forms.gemspec +2 -2
- data/lib/generators/inline_forms/USAGE +49 -4
- data/lib/generators/inline_forms/inline_forms_generator.rb +14 -19
- data/lib/generators/inline_forms/templates/migration.rb +0 -1
- data/lib/generators/inline_forms/templates/model.rb +1 -1
- data/lib/inline_forms.rb +16 -0
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.1
|
data/inline_forms.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{inline_forms}
|
8
|
-
s.version = "0.5.
|
8
|
+
s.version = "0.5.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ace Suares"]
|
12
|
-
s.date = %q{2011-02-
|
12
|
+
s.date = %q{2011-02-04}
|
13
13
|
s.description = %q{Inline Forms aims to ease the setup of forms that provide inline editing. The field list can be specified in the model.}
|
14
14
|
s.email = %q{ace@suares.an}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -1,8 +1,53 @@
|
|
1
1
|
Description:
|
2
|
-
|
2
|
+
The first argument must be a Model. Next comes a list of name:form_element pairs that describe the model and it's database.
|
3
|
+
We will generate a model, a migration, a controller and a route. Please do check the migration and the model because they will likely need tweaking.
|
3
4
|
|
4
5
|
Example:
|
5
|
-
rails generate inline_forms Thing
|
6
|
+
rails generate inline_forms Thing name:text_field description:text_area yesno:check_box gender:boolean_with_values
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
This will create:
|
9
|
+
create app/models/thing.rb
|
10
|
+
create app/controllers/things_controller.rb
|
11
|
+
route resources :things
|
12
|
+
create db/migrate/20110204074707_inline_forms_create_things.rb
|
13
|
+
|
14
|
+
app/models/thing.rb:
|
15
|
+
class Thing < ActiveRecord::Base
|
16
|
+
def presentation
|
17
|
+
#define your presentation here
|
18
|
+
end
|
19
|
+
def inline_forms_field_list
|
20
|
+
[
|
21
|
+
[ :string, 'name', :text_field ],
|
22
|
+
[ :text, 'description', :text_area ],
|
23
|
+
[ :boolean, 'yesno', :check_box ],
|
24
|
+
[ :boolean, 'gender', :boolean_with_values ],
|
25
|
+
]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
app/controllers/things_controller.rb
|
30
|
+
class ThingsController < InlineFormsController
|
31
|
+
end
|
32
|
+
|
33
|
+
config/routes.rb:
|
34
|
+
...
|
35
|
+
resources :things
|
36
|
+
...
|
37
|
+
|
38
|
+
db/migrate/20111015234500_inline_forms_create_things.rb
|
39
|
+
class InlineFormsCreateThings < ActiveRecord::Migration
|
40
|
+
def self.up
|
41
|
+
create_table :things do |t|
|
42
|
+
t.string :name
|
43
|
+
t.text :description
|
44
|
+
t.boolean :yesno
|
45
|
+
t.boolean :gender
|
46
|
+
t.timestamps
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.down
|
51
|
+
drop_table :things
|
52
|
+
end
|
53
|
+
end
|
@@ -4,37 +4,32 @@ module InlineForms
|
|
4
4
|
Rails::Generators::GeneratedAttribute.class_eval do
|
5
5
|
def migration_type
|
6
6
|
# convert our form_elements to real types for migration
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
# our types get converted
|
11
|
-
when :dropdown, :dropdown_with_values then :integer
|
12
|
-
when :check_box, :boolean_with_values then :boolean
|
13
|
-
when :date then :date
|
14
|
-
when :text_area then :text
|
15
|
-
else
|
16
|
-
:unknown # migration will fail, probably.
|
17
|
-
end
|
18
|
-
|
7
|
+
# each helper adds to this list
|
8
|
+
# be aware that the standard list overwrites the customized list if we merge like this!
|
9
|
+
MIGRATION_TYPE_CONVERSION_LIST.merge(STANDARD_MIGRATION_COLUMN_TYPES)[type] || :unknown
|
19
10
|
end
|
11
|
+
|
20
12
|
def field_type
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
13
|
+
# convert standard types to one of ours
|
14
|
+
if MIGRATION_TYPE_CONVERSION_LIST.has_key?(type)
|
15
|
+
then type
|
16
|
+
else
|
17
|
+
case type
|
18
|
+
when :integer, :float, :decimal then :text_field
|
25
19
|
when :time then :time_select
|
26
20
|
when :datetime, :timestamp then :datetime_select
|
27
21
|
when :date then :date_select
|
28
22
|
when :text then :text_area
|
29
23
|
when :boolean then :check_box
|
30
24
|
else
|
31
|
-
:
|
25
|
+
:unknown
|
26
|
+
end
|
32
27
|
end
|
33
28
|
end
|
34
29
|
|
35
|
-
|
30
|
+
end
|
36
31
|
|
37
|
-
argument :attributes, :type => :array, :banner => "
|
32
|
+
argument :attributes, :type => :array, :banner => "[name:form_element]..."
|
38
33
|
|
39
34
|
source_root File.expand_path('../templates', __FILE__)
|
40
35
|
|
data/lib/inline_forms.rb
CHANGED
@@ -1,6 +1,22 @@
|
|
1
1
|
puts 'loading inline_forms...'
|
2
2
|
|
3
3
|
module InlineForms
|
4
|
+
# put the standard types in the list. new form_elements in app/helpers/form_elelemnts add to this.
|
5
|
+
STANDARD_MIGRATION_COLUMN_TYPES = {
|
6
|
+
:string => :string,
|
7
|
+
:text => :text,
|
8
|
+
:integer => :integer,
|
9
|
+
:float => :float,
|
10
|
+
:decimal => :decimal,
|
11
|
+
:datetime => :datetime,
|
12
|
+
:timestamp => :timestamp,
|
13
|
+
:time => :time,
|
14
|
+
:date => :date,
|
15
|
+
:binary => :binary,
|
16
|
+
:boolean => :boolean,
|
17
|
+
}
|
18
|
+
MIGRATION_TYPE_CONVERSION_LIST = {}
|
19
|
+
|
4
20
|
class InlineFormsEngine < Rails::Engine
|
5
21
|
initializer 'inline_forms.helper' do |app|
|
6
22
|
ActionView::Base.send :include, InlineFormsHelper
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inline_forms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 1
|
10
|
+
version: 0.5.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ace Suares
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-02-
|
18
|
+
date: 2011-02-04 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|