inline_forms 0.8.2 → 0.8.3
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/inline_forms_helper.rb +3 -1
- data/inline_forms.gemspec +2 -2
- data/lib/generators/inline_forms/inline_forms_generator.rb +122 -95
- data/lib/generators/inline_forms/templates/controller.erb +1 -1
- data/lib/generators/inline_forms/templates/migration.erb +1 -1
- data/lib/generators/inline_forms/templates/model.erb +4 -0
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.8.
|
1
|
+
0.8.3
|
@@ -33,7 +33,7 @@ class InlineFormsController < ApplicationController
|
|
33
33
|
update_span = params[:update]
|
34
34
|
respond_to do |format|
|
35
35
|
# found this here: http://www.ruby-forum.com/topic/211467
|
36
|
-
format.html { render 'inline_forms/index', :layout => 'inline_forms' }
|
36
|
+
format.html { render 'inline_forms/index', :layout => 'inline_forms' } unless @Klass.not_accessible_through_html?
|
37
37
|
format.js { render(:update) {|page| page.replace_html update_span, :partial => 'inline_forms/index' } }
|
38
38
|
end
|
39
39
|
end
|
@@ -42,7 +42,8 @@ module InlineFormsHelper
|
|
42
42
|
#
|
43
43
|
def inline_forms_new_record(object, attributes=nil)
|
44
44
|
attributes ||= object.inline_forms_attribute_list
|
45
|
-
out = String.new
|
45
|
+
out = String.new
|
46
|
+
logger.info attributes.inspect
|
46
47
|
attributes.each do | attribute, name, form_element |
|
47
48
|
if not form_element.to_sym == :associated
|
48
49
|
css_class_id = "attribute_#{attribute}_#{object.id}"
|
@@ -61,6 +62,7 @@ module InlineFormsHelper
|
|
61
62
|
out += content_tag :tr, name_cell + value_cell
|
62
63
|
end
|
63
64
|
end
|
65
|
+
logger.info "return"
|
64
66
|
return content_tag :table, raw(out), :cellspacing => 0, :cellpadding => 0
|
65
67
|
end
|
66
68
|
|
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.
|
8
|
+
s.version = "0.8.3"
|
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-03-
|
12
|
+
s.date = %q{2011-03-16}
|
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 = [
|
@@ -51,15 +51,19 @@ module InlineForms
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def migration?
|
54
|
-
not (
|
55
|
-
|
56
|
-
name == "
|
57
|
-
name == "
|
54
|
+
not ( column_type == :no_migration ||
|
55
|
+
name == "_presentation" ||
|
56
|
+
name == "_order" ||
|
57
|
+
name == "_enabled" ||
|
58
|
+
name == "_id" ||
|
59
|
+
relation? )
|
58
60
|
end
|
59
61
|
|
60
62
|
def attribute?
|
61
|
-
not ( name == '_presentation'
|
62
|
-
name == '_order'
|
63
|
+
not ( name == '_presentation' ||
|
64
|
+
name == '_order' ||
|
65
|
+
name == '_enabled' ||
|
66
|
+
name == "_id" ||
|
63
67
|
relation? )
|
64
68
|
end
|
65
69
|
|
@@ -72,112 +76,135 @@ module InlineForms
|
|
72
76
|
def copy_stylesheet
|
73
77
|
copy_file File.expand_path('../../../../public/stylesheets', __FILE__) + "/inline_forms.css", "public/stylesheets/inline_forms.css" unless File.exists?('public/stylesheets/inline_forms.css')
|
74
78
|
end
|
79
|
+
|
80
|
+
# using flags.
|
81
|
+
def set_some_flags
|
82
|
+
@flag_not_accessible_through_html = true
|
83
|
+
@flag_create_migration = true
|
84
|
+
@flag_create_model = true
|
85
|
+
@create_id = true
|
86
|
+
for attribute in attributes
|
87
|
+
@flag_not_accessible_through_html = false if attribute.name == '_enabled'
|
88
|
+
@flag_create_migration = false if attribute.name == '_no_migration'
|
89
|
+
@flag_create_model = false if attribute.name == '_no_model'
|
90
|
+
@create_id = false if attribute.name == "_id" && attribute.type == :false
|
91
|
+
end
|
92
|
+
@flag_create_controller = @flag_create_model
|
93
|
+
@flag_create_resource_route = @flag_create_model
|
94
|
+
end
|
75
95
|
|
76
96
|
def generate_model
|
77
|
-
@
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
97
|
+
if @flag_create_model
|
98
|
+
@belongs_to = "\n"
|
99
|
+
@has_many = "\n"
|
100
|
+
@has_one = "\n"
|
101
|
+
@habtm = "\n"
|
102
|
+
@has_attached_files = "\n"
|
103
|
+
@presentation = "\n"
|
104
|
+
@order = "\n"
|
105
|
+
@inline_forms_attribute_list = String.new
|
106
|
+
|
107
|
+
for attribute in attributes
|
108
|
+
if attribute.column_type == :belongs_to # :drop_down, :references and :belongs_to all end up with the column_type :belongs_to
|
109
|
+
@belongs_to << ' belongs_to :' + attribute.name + "\n"
|
110
|
+
end
|
111
|
+
if attribute.type == :has_many ||
|
112
|
+
attribute.type == :has_many_destroy
|
113
|
+
@has_many << ' has_many :' + attribute.name
|
114
|
+
@has_many << ', :dependent => :destroy' if attribute.type == :has_many_destroy
|
115
|
+
@has_many << "\n"
|
116
|
+
end
|
117
|
+
if attribute.type == :has_one
|
118
|
+
@has_one << ' has_one :' + attribute.name + "\n"
|
119
|
+
end
|
120
|
+
if attribute.type == :habtm ||
|
121
|
+
attribute.type == :has_and_belongs_to_many ||
|
122
|
+
attribute.type == :check_list
|
123
|
+
@habtm << ' has_and_belongs_to_many :' + attribute.name + "\n"
|
124
|
+
end
|
125
|
+
if attribute.type == :image
|
126
|
+
@has_attached_files << " has_attached_file :#{attribute.name},
|
127
|
+
:styles => { :medium => \"300x300>\", :thumb => \"100x100>\" }\n"
|
128
|
+
end
|
129
|
+
if attribute.name == '_presentation'
|
130
|
+
@presentation << " def _presentation\n" +
|
131
|
+
" \"#{attribute.type.to_s}\"\n" +
|
132
|
+
" end\n" +
|
133
|
+
"\n"
|
134
|
+
end
|
135
|
+
if attribute.name == '_order'
|
136
|
+
@order << " def <=>(other)\n" +
|
137
|
+
" self.#{attribute.type} <=> other.#{attribute.type}\n" +
|
138
|
+
" end\n" +
|
139
|
+
"\n"
|
140
|
+
end
|
141
|
+
if attribute.attribute?
|
142
|
+
attribute.attribute_type == :unknown ? commenter = '#' : commenter = ' '
|
143
|
+
@inline_forms_attribute_list << commenter +
|
144
|
+
' [ :' +
|
145
|
+
attribute.name +
|
146
|
+
' , "' + attribute.name +
|
147
|
+
'", :' + attribute.attribute_type.to_s +
|
148
|
+
" ], \n"
|
149
|
+
end
|
119
150
|
end
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
"
|
151
|
+
unless @inline_forms_attribute_list.empty?
|
152
|
+
@inline_forms_attribute_list = "\n" +
|
153
|
+
" def inline_forms_attribute_list\n" +
|
154
|
+
" [\n" +
|
155
|
+
@inline_forms_attribute_list +
|
156
|
+
" ]\n" +
|
157
|
+
" end\n" +
|
158
|
+
"\n"
|
128
159
|
end
|
160
|
+
template "model.erb", "app/models/#{model_file_name}.rb"
|
129
161
|
end
|
130
|
-
unless @inline_forms_attribute_list.empty?
|
131
|
-
@inline_forms_attribute_list = "\n" +
|
132
|
-
" def inline_forms_attribute_list\n" +
|
133
|
-
" [\n" +
|
134
|
-
@inline_forms_attribute_list +
|
135
|
-
" ]\n" +
|
136
|
-
" end\n" +
|
137
|
-
"\n"
|
138
|
-
end
|
139
|
-
template "model.erb", "app/models/#{model_file_name}.rb"
|
140
|
-
end
|
141
|
-
|
142
|
-
def generate_controller
|
143
|
-
template "controller.erb", "app/controllers/#{controller_file_name}.rb"
|
144
162
|
end
|
145
163
|
|
146
|
-
def
|
147
|
-
route "resources :#{resource_name}"
|
148
|
-
end
|
164
|
+
def generate_resource_route
|
165
|
+
route "resources :#{resource_name}" if @flag_create_resource_route
|
166
|
+
end
|
149
167
|
|
150
168
|
def generate_migration
|
151
|
-
@
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
attribute.
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
169
|
+
if @flag_create_migration
|
170
|
+
@columns = String.new
|
171
|
+
|
172
|
+
for attribute in attributes
|
173
|
+
if attribute.column_type == :image
|
174
|
+
@columns << ' t.string :' + attribute.name + "_file_name\n"
|
175
|
+
@columns << ' t.string :' + attribute.name + "_content_type\n"
|
176
|
+
@columns << ' t.integer :' + attribute.name + "_file_size\n"
|
177
|
+
@columns << ' t.datetime :' + attribute.name + "_updated_at\n"
|
178
|
+
else
|
179
|
+
if attribute.migration?
|
180
|
+
attribute.attribute_type == :unknown ? commenter = '#' : commenter = ' '
|
181
|
+
@columns << commenter +
|
182
|
+
' t.' +
|
183
|
+
attribute.column_type.to_s +
|
184
|
+
" :" +
|
185
|
+
attribute.name +
|
186
|
+
" \n"
|
187
|
+
end
|
168
188
|
end
|
169
189
|
end
|
190
|
+
template "migration.erb", "db/migrate/#{time_stamp}_inline_forms_create_#{table_name}.rb"
|
170
191
|
end
|
171
|
-
template "migration.erb", "db/migrate/#{time_stamp}_inline_forms_create_#{table_name}.rb"
|
172
192
|
end
|
173
193
|
|
174
194
|
def add_tab
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
195
|
+
unless @flag_not_accessible_through_html
|
196
|
+
copy_file "_inline_forms_tabs.html.erb", "app/views/_inline_forms_tabs.html.erb" unless File.exists?('app/views/_inline_forms_tabs.html.erb')
|
197
|
+
inject_into_file "app/views/_inline_forms_tabs.html.erb",
|
198
|
+
" <%= tab.#{name.underscore} '#{name}', #{name.pluralize.underscore + '_path'} %>\n",
|
199
|
+
:after => "<% tabs_tag :open_tabs => { :id => \"tabs\" } do |tab| %>\n"
|
200
|
+
end
|
179
201
|
end
|
180
202
|
|
203
|
+
def generate_controller
|
204
|
+
template "controller.erb", "app/controllers/#{controller_file_name}.rb" if @flag_create_controller
|
205
|
+
end
|
206
|
+
|
207
|
+
|
181
208
|
private
|
182
209
|
def model_file_name
|
183
210
|
name.underscore
|
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: 57
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 8
|
9
|
-
-
|
10
|
-
version: 0.8.
|
9
|
+
- 3
|
10
|
+
version: 0.8.3
|
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-03-
|
18
|
+
date: 2011-03-16 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|