inline_forms 0.5.3 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/app/controllers/inline_forms_controller.rb +1 -1
- data/app/helpers/form_elements/associated.rb +13 -13
- data/app/helpers/form_elements/check_box.rb +1 -1
- data/app/helpers/form_elements/checklist.rb +1 -1
- data/app/helpers/form_elements/date.rb +1 -1
- data/app/helpers/form_elements/dropdown.rb +1 -1
- data/app/helpers/form_elements/dropdown_with_values.rb +1 -1
- data/app/helpers/form_elements/geo_code_curacao.rb +1 -1
- data/app/helpers/form_elements/range.rb +1 -1
- data/app/helpers/form_elements/text_area.rb +1 -1
- data/app/helpers/form_elements/text_field.rb +1 -1
- data/app/helpers/inline_forms_helper.rb +1 -1
- data/app/views/inline_forms/_edit.html.erb +1 -1
- data/inline_forms.gemspec +5 -5
- data/lib/generators/inline_forms/inline_forms_generator.rb +32 -20
- data/lib/generators/inline_forms/templates/{controller.rb → controller.erb} +0 -0
- data/lib/generators/inline_forms/templates/{migration.rb → migration.erb} +2 -1
- data/lib/generators/inline_forms/templates/model.erb +22 -0
- data/lib/inline_forms.rb +26 -3
- metadata +8 -8
- data/lib/generators/inline_forms/templates/model.rb +0 -14
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.6.0
|
@@ -117,7 +117,7 @@ class InlineFormsController < ApplicationController
|
|
117
117
|
if @form_element == "associated"
|
118
118
|
@sub_id = params[:sub_id]
|
119
119
|
if @sub_id.to_i > 0
|
120
|
-
@associated_record_id = @object.send(@field.singularize + "_ids").index(@sub_id.to_i)
|
120
|
+
@associated_record_id = @object.send(@field.to_s.singularize + "_ids").index(@sub_id.to_i)
|
121
121
|
@associated_record = @object.send(@field)[@associated_record_id]
|
122
122
|
end
|
123
123
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module InlineFormsHelper
|
2
|
-
InlineForms::
|
2
|
+
InlineForms::SPECIAL_MIGRATION_TYPES[:associated]=:references
|
3
3
|
# associated
|
4
4
|
def associated_show(object, attribute, values)
|
5
5
|
#show a list of records
|
@@ -7,31 +7,31 @@ module InlineFormsHelper
|
|
7
7
|
if @sub_id && @sub_id.to_i > 0
|
8
8
|
# if it's not a new record (sub_id > 0) then just update the list-element
|
9
9
|
out << '<li>'
|
10
|
-
out << link_to( @associated_record.
|
10
|
+
out << link_to( @associated_record.presentation,
|
11
11
|
send('edit_' + @Klass.to_s.underscore + '_path', object,
|
12
12
|
:field => attribute,
|
13
13
|
:sub_id => @sub_id,
|
14
14
|
:form_element => this_method.reverse.sub(/.*_/,'').reverse,
|
15
15
|
:values => values,
|
16
|
-
:update => "field_#{attribute.singularize}_#{@sub_id.to_s}" ),
|
16
|
+
:update => "field_#{attribute.to_s.singularize}_#{@sub_id.to_s}" ),
|
17
17
|
:method => :get,
|
18
18
|
:remote => true )
|
19
19
|
out << '</li>'
|
20
20
|
else
|
21
21
|
# if it's a new record (sub_id == 0) then update the whole <ul> and redraw all list-elements
|
22
22
|
out << "<ul class='associated #{attribute}' id='list_#{attribute}_#{object.id.to_s}'>" if @sub_id.nil?
|
23
|
-
if not object.send(attribute.pluralize).empty?
|
23
|
+
if not object.send(attribute.to_s.pluralize).empty?
|
24
24
|
# if there are things to show, show them
|
25
|
-
object.send(attribute.pluralize).each do |m|
|
26
|
-
out << "<span id='field_#{attribute.singularize}_#{m.id.to_s}'>"
|
25
|
+
object.send(attribute.to_s.pluralize).each do |m|
|
26
|
+
out << "<span id='field_#{attribute.to_s.singularize}_#{m.id.to_s}'>"
|
27
27
|
out << '<li>'
|
28
|
-
out << link_to( m.
|
28
|
+
out << link_to( m.presentation, send('edit_' + @Klass.to_s.underscore + '_path',
|
29
29
|
object,
|
30
30
|
:field => attribute,
|
31
31
|
:sub_id => m.id,
|
32
32
|
:form_element => this_method.sub(/_[a-z]+$/,''),
|
33
33
|
:values => values,
|
34
|
-
:update => "field_#{attribute.singularize}_#{m.id.to_s}" ),
|
34
|
+
:update => "field_#{attribute.to_s.singularize}_#{m.id.to_s}" ),
|
35
35
|
:method => :get,
|
36
36
|
:remote => true )
|
37
37
|
out << '</li>'
|
@@ -58,13 +58,13 @@ module InlineFormsHelper
|
|
58
58
|
# @sub_id is the id of the associated record
|
59
59
|
if @sub_id.to_i > 0
|
60
60
|
# only if @sub_id > 0, means we have a associated record
|
61
|
-
@associated_record_id = object.send(attribute.singularize + "_ids").index(@sub_id.to_i)
|
61
|
+
@associated_record_id = object.send(attribute.to_s.singularize + "_ids").index(@sub_id.to_i)
|
62
62
|
@associated_record = object.send(attribute)[@associated_record_id]
|
63
|
-
@update_span = "field_#{attribute.singularize}_#{@sub_id.to_s}"
|
63
|
+
@update_span = "field_#{attribute.to_s.singularize}_#{@sub_id.to_s}"
|
64
64
|
else
|
65
65
|
# but if @sub_id = 0, then we are dealing with a new associated record
|
66
66
|
# in that case, we .new a record, and the update_span is the whole <ul>
|
67
|
-
@associated_record = attribute.singularize.capitalize.constantize.new
|
67
|
+
@associated_record = attribute.to_s.singularize.capitalize.constantize.new
|
68
68
|
@update_span = 'list_' + attribute.to_s + '_' + object.id.to_s
|
69
69
|
end
|
70
70
|
render :partial => "inline_forms/subform"
|
@@ -73,9 +73,9 @@ module InlineFormsHelper
|
|
73
73
|
return if object.id.nil?
|
74
74
|
if @sub_id.to_i > 0
|
75
75
|
# get the existing associated record
|
76
|
-
@associated_record_id = object.send(attribute.singularize + "_ids").index(@sub_id.to_i)
|
76
|
+
@associated_record_id = object.send(attribute.to_s.singularize + "_ids").index(@sub_id.to_i)
|
77
77
|
@associated_record = object.send(attribute)[@associated_record_id]
|
78
|
-
@update_span = "field_" + attribute.singularize + '_' + @sub_id.to_s
|
78
|
+
@update_span = "field_" + attribute.to_s.singularize + '_' + @sub_id.to_s
|
79
79
|
else
|
80
80
|
# create a new associated record
|
81
81
|
@associated_record = object.send(attribute.to_sym).new
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module InlineFormsHelper
|
2
|
-
InlineForms::
|
2
|
+
InlineForms::SPECIAL_MIGRATION_TYPES[:check_box]=:boolean
|
3
3
|
# boolean, bit unaptly named check_box
|
4
4
|
def check_box_show(object, attribute, values)
|
5
5
|
values ||= { 'false' => 'no', 'true' => 'yes' }
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module InlineFormsHelper
|
2
|
-
InlineForms::
|
2
|
+
InlineForms::SPECIAL_MIGRATION_TYPES[:dropdown]=:integer
|
3
3
|
# dropdown
|
4
4
|
def dropdown_show(object, attribute, values)
|
5
5
|
attribute_value = object.send(attribute).presentation rescue nil
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module InlineFormsHelper
|
2
|
-
InlineForms::
|
2
|
+
InlineForms::SPECIAL_MIGRATION_TYPES[:dropdown_with_values]=:integer
|
3
3
|
# dropdown_with_values
|
4
4
|
def dropdown_with_values_show(object, attribute, values)
|
5
5
|
link_to_inline_edit object, attribute, values[object.send(attribute)], values
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module InlineFormsHelper
|
2
|
-
InlineForms::
|
2
|
+
InlineForms::SPECIAL_MIGRATION_TYPES[:geo_code_curacao]=:string
|
3
3
|
# geo_code_curacao
|
4
4
|
def geo_code_curacao_show(object, attribute, values)
|
5
5
|
attribute_value = object.send(attribute).presentation rescue nil
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module InlineFormsHelper
|
2
|
-
InlineForms::
|
2
|
+
InlineForms::SPECIAL_MIGRATION_TYPES[:text_area]=:text
|
3
3
|
# text_area
|
4
4
|
def text_area_show(object, attribute, values)
|
5
5
|
link_to_inline_edit object, attribute, object.send(attribute), nil
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module InlineFormsHelper
|
2
|
-
InlineForms::
|
2
|
+
InlineForms::SPECIAL_MIGRATION_TYPES[:text_field]=:string
|
3
3
|
# text
|
4
4
|
def text_field_show(object, attribute, values)
|
5
5
|
link_to_inline_edit object, attribute, object.send(attribute), nil
|
@@ -74,7 +74,7 @@ module InlineFormsHelper
|
|
74
74
|
t = ''
|
75
75
|
objects.each do |object|
|
76
76
|
t += content_tag tag do
|
77
|
-
inline_form object, object.respond_to?(:inline_forms_field_list) ? object.inline_forms_field_list : [ :name, 'name', '
|
77
|
+
inline_form object, object.respond_to?(:inline_forms_field_list) ? object.inline_forms_field_list : [ :name, 'name', 'text_field' ]
|
78
78
|
end
|
79
79
|
end
|
80
80
|
return raw(t)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<% form_tag send(@Klass.to_s.underscore + '_path', :update => @update_span ,
|
2
|
-
#|| @form_element == "associated" ? @sub_id && @sub_id.to_i > 0 ? "field_#{@field.singularize}_#{@sub_id}" : "list_#{@field}_#{@object.id.to_s}" : "field_#{@field}_#{@object.id.to_s}",
|
2
|
+
#|| @form_element == "associated" ? @sub_id && @sub_id.to_i > 0 ? "field_#{@field.to_s.singularize}_#{@sub_id}" : "list_#{@field}_#{@object.id.to_s}" : "field_#{@field}_#{@object.id.to_s}",
|
3
3
|
:field => @field,
|
4
4
|
:form_element => @form_element,
|
5
5
|
:values => @values,
|
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.
|
8
|
+
s.version = "0.6.0"
|
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-10}
|
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 = [
|
@@ -47,9 +47,9 @@ Gem::Specification.new do |s|
|
|
47
47
|
"inline_forms.gemspec",
|
48
48
|
"lib/generators/inline_forms/USAGE",
|
49
49
|
"lib/generators/inline_forms/inline_forms_generator.rb",
|
50
|
-
"lib/generators/inline_forms/templates/controller.
|
51
|
-
"lib/generators/inline_forms/templates/migration.
|
52
|
-
"lib/generators/inline_forms/templates/model.
|
50
|
+
"lib/generators/inline_forms/templates/controller.erb",
|
51
|
+
"lib/generators/inline_forms/templates/migration.erb",
|
52
|
+
"lib/generators/inline_forms/templates/model.erb",
|
53
53
|
"lib/inline_forms.rb",
|
54
54
|
"test/helper.rb",
|
55
55
|
"test/test_inline_forms.rb"
|
@@ -2,44 +2,56 @@ module InlineForms
|
|
2
2
|
class InlineFormsGenerator < Rails::Generators::NamedBase
|
3
3
|
|
4
4
|
Rails::Generators::GeneratedAttribute.class_eval do
|
5
|
+
# attributes are in the form name:type (f.i. price:integer)
|
6
|
+
# we want to extend the types to our list of types
|
7
|
+
# but some of the old types are still needed
|
8
|
+
# f.i. price:integer turns into a text_field
|
9
|
+
#
|
5
10
|
def migration_type
|
6
|
-
# convert
|
11
|
+
# convert any type into a migration type
|
7
12
|
# each helper adds to this list
|
8
13
|
# be aware that the standard list overwrites the customized list if we merge like this!
|
9
|
-
|
14
|
+
SPECIAL_MIGRATION_TYPES.merge(DEFAULT_MIGRATION_TYPES).merge(RELATION_TYPES).merge(SPECIAL_RELATION_TYPES)[type] || :unknown
|
10
15
|
end
|
11
16
|
|
12
17
|
def field_type
|
13
18
|
# convert standard types to one of ours
|
14
|
-
|
15
|
-
then type
|
16
|
-
else
|
17
|
-
case type
|
18
|
-
when :integer, :float, :decimal then :text_field
|
19
|
-
when :time then :time_select
|
20
|
-
when :datetime, :timestamp then :datetime_select
|
21
|
-
when :date then :date_select
|
22
|
-
when :text then :text_area
|
23
|
-
when :boolean then :check_box
|
24
|
-
else
|
25
|
-
:unknown
|
26
|
-
end
|
27
|
-
end
|
19
|
+
SPECIAL_MIGRATION_TYPES.merge(RELATION_TYPES).merge(SPECIAL_RELATION_TYPES).has_key?(type) ? type : DEFAULT_FIELD_TYPES[type] || :unknown
|
28
20
|
end
|
29
21
|
|
30
|
-
|
22
|
+
def migration_name
|
23
|
+
# convert some to _id
|
24
|
+
( relation? || field_type == :dropdown) ? name + '_id' : name
|
25
|
+
end
|
26
|
+
|
27
|
+
def belongs_to?
|
28
|
+
relation? || field_type == :dropdown
|
29
|
+
end
|
30
|
+
|
31
|
+
def has_many?
|
32
|
+
field_type == :associated
|
33
|
+
end
|
31
34
|
|
35
|
+
def relation?
|
36
|
+
RELATION_TYPES.has_key?(field_type)
|
37
|
+
end
|
38
|
+
|
39
|
+
def special_relation?
|
40
|
+
SPECIAL_RELATION_TYPES.has_key?(field_type)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
32
44
|
argument :attributes, :type => :array, :banner => "[name:form_element]..."
|
33
45
|
|
34
46
|
source_root File.expand_path('../templates', __FILE__)
|
35
47
|
|
36
48
|
def generate_model
|
37
49
|
#copy_file "stylesheet.css", "public/stylesheets/#{file_name}.css"
|
38
|
-
template "model.
|
50
|
+
template "model.erb", "app/models/#{model_file_name}.rb"
|
39
51
|
end
|
40
52
|
|
41
53
|
def generate_controller
|
42
|
-
template "controller.
|
54
|
+
template "controller.erb", "app/controllers/#{controller_file_name}.rb"
|
43
55
|
end
|
44
56
|
|
45
57
|
def generate_route
|
@@ -47,7 +59,7 @@ module InlineForms
|
|
47
59
|
end
|
48
60
|
|
49
61
|
def generate_migration
|
50
|
-
template "migration.
|
62
|
+
template "migration.erb", "db/migrate/#{time_stamp}_inline_forms_create_#{table_name}.rb"
|
51
63
|
end
|
52
64
|
|
53
65
|
private
|
File without changes
|
@@ -2,7 +2,8 @@ class InlineFormsCreate<%= table_name.camelize %> < ActiveRecord::Migration
|
|
2
2
|
def self.up
|
3
3
|
create_table :<%= table_name %> do |t|
|
4
4
|
<% for attribute in attributes -%>
|
5
|
-
|
5
|
+
<%= '#' if attribute.migration_type == :unknown || attribute.special_relation? -%>
|
6
|
+
t.<%= attribute.migration_type %> :<%= attribute.migration_name %>
|
6
7
|
<% end -%>
|
7
8
|
t.timestamps
|
8
9
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class <%= name %> < ActiveRecord::Base
|
2
|
+
|
3
|
+
<% for attribute in attributes -%>
|
4
|
+
<%= 'belongs_to :' + attribute.name if attribute.belongs_to? %>
|
5
|
+
<% end %>
|
6
|
+
<% for attribute in attributes -%>
|
7
|
+
<%= 'has_many :' + attribute.name if attribute.has_many? %>
|
8
|
+
<% end %>
|
9
|
+
|
10
|
+
def presentation
|
11
|
+
'please define presentation!'
|
12
|
+
end
|
13
|
+
|
14
|
+
def inline_forms_field_list
|
15
|
+
[
|
16
|
+
<% for attribute in attributes -%>
|
17
|
+
<%= '#' if attribute.relation? -%>
|
18
|
+
<%= '[ :' + attribute.name + ', "' + attribute.name + '", :' + attribute.field_type.to_s + ' ], ' %>
|
19
|
+
<% end -%>
|
20
|
+
]
|
21
|
+
end
|
22
|
+
end
|
data/lib/inline_forms.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
puts 'loading inline_forms...'
|
2
2
|
|
3
3
|
module InlineForms
|
4
|
-
#
|
5
|
-
|
4
|
+
# convert type to migration_type
|
5
|
+
DEFAULT_MIGRATION_TYPES = {
|
6
6
|
:string => :string,
|
7
7
|
:text => :text,
|
8
8
|
:integer => :integer,
|
@@ -15,7 +15,30 @@ module InlineForms
|
|
15
15
|
:binary => :binary,
|
16
16
|
:boolean => :boolean,
|
17
17
|
}
|
18
|
-
|
18
|
+
# convert type to field_type
|
19
|
+
DEFAULT_FIELD_TYPES = {
|
20
|
+
:string => :text_field,
|
21
|
+
:text => :text_area,
|
22
|
+
:integer => :text_field,
|
23
|
+
:float => :text_field,
|
24
|
+
:decimal => :text_field,
|
25
|
+
:datetime => :datetime_select,
|
26
|
+
:timestamp => :datetime_select,
|
27
|
+
:time => :time_select,
|
28
|
+
:date => :date_select,
|
29
|
+
:binary => :text_field,
|
30
|
+
:boolean => :check_box,
|
31
|
+
|
32
|
+
}
|
33
|
+
# define this so the helpers can add to it
|
34
|
+
SPECIAL_MIGRATION_TYPES = {}
|
35
|
+
# experimental
|
36
|
+
RELATION_TYPES = {
|
37
|
+
:belongs_to => :integer,
|
38
|
+
}
|
39
|
+
SPECIAL_RELATION_TYPES = {
|
40
|
+
:associated => :associated,
|
41
|
+
}
|
19
42
|
|
20
43
|
class InlineFormsEngine < Rails::Engine
|
21
44
|
initializer 'inline_forms.helper' do |app|
|
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: 7
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 6
|
9
|
+
- 0
|
10
|
+
version: 0.6.0
|
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-10 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -118,9 +118,9 @@ files:
|
|
118
118
|
- inline_forms.gemspec
|
119
119
|
- lib/generators/inline_forms/USAGE
|
120
120
|
- lib/generators/inline_forms/inline_forms_generator.rb
|
121
|
-
- lib/generators/inline_forms/templates/controller.
|
122
|
-
- lib/generators/inline_forms/templates/migration.
|
123
|
-
- lib/generators/inline_forms/templates/model.
|
121
|
+
- lib/generators/inline_forms/templates/controller.erb
|
122
|
+
- lib/generators/inline_forms/templates/migration.erb
|
123
|
+
- lib/generators/inline_forms/templates/model.erb
|
124
124
|
- lib/inline_forms.rb
|
125
125
|
- test/helper.rb
|
126
126
|
- test/test_inline_forms.rb
|
@@ -1,14 +0,0 @@
|
|
1
|
-
class <%= name %> < ActiveRecord::Base
|
2
|
-
|
3
|
-
def presentation
|
4
|
-
#define your presentation here
|
5
|
-
end
|
6
|
-
|
7
|
-
def inline_forms_field_list
|
8
|
-
[
|
9
|
-
<% for attribute in attributes %>
|
10
|
-
[ :<%= attribute.migration_type %>, '<%= attribute.name %>', :<%= attribute.field_type %> ],
|
11
|
-
<% end %>
|
12
|
-
]
|
13
|
-
end
|
14
|
-
end
|