inline_forms 0.8.2 → 0.8.3

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 CHANGED
@@ -1 +1 @@
1
- 0.8.2
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.2"
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-13}
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 ( relation? ||
55
- column_type == :no_migration ||
56
- name == "_presentation" ||
57
- name == "_order" )
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
- @belongs_to = "\n"
78
- @has_many = "\n"
79
- @has_one = "\n"
80
- @habtm = "\n"
81
- @has_attached_files = "\n"
82
- @presentation = "\n"
83
- @order = "\n"
84
- @inline_forms_attribute_list = String.new
85
-
86
- for attribute in attributes
87
- if attribute.column_type == :belongs_to # :drop_down, :references and :belongs_to all end up with the column_type :belongs_to
88
- @belongs_to << ' belongs_to :' + attribute.name + "\n"
89
- end
90
- if attribute.type == :has_many ||
91
- attribute.type == :has_many_destroy
92
- @has_many << ' has_many :' + attribute.name
93
- @has_many << ', :dependent => :destroy' if attribute.type == :has_many_destroy
94
- @has_many << "\n"
95
- end
96
- if attribute.type == :has_one
97
- @has_one << ' has_one :' + attribute.name + "\n"
98
- end
99
- if attribute.type == :habtm ||
100
- attribute.type == :has_and_belongs_to_many ||
101
- attribute.type == :check_list
102
- @habtm << ' has_and_belongs_to_many :' + attribute.name + "\n"
103
- end
104
- if attribute.type == :image
105
- @has_attached_files << " has_attached_file :#{attribute.name},
106
- :styles => { :medium => \"300x300>\", :thumb => \"100x100>\" }\n"
107
- end
108
- if attribute.name == '_presentation'
109
- @presentation << " def _presentation\n" +
110
- " \"#{attribute.type.to_s}\"\n" +
111
- " end\n" +
112
- "\n"
113
- end
114
- if attribute.name == '_order'
115
- @order << " def <=>(other)\n" +
116
- " self.#{attribute.type} <=> other.#{attribute.type}\n" +
117
- " end\n" +
118
- "\n"
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
- if attribute.attribute?
121
- attribute.attribute_type == :unknown ? commenter = '#' : commenter = ' '
122
- @inline_forms_attribute_list << commenter +
123
- ' [ :' +
124
- attribute.name +
125
- ' , "' + attribute.name +
126
- '", :' + attribute.attribute_type.to_s +
127
- " ], \n"
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 generate_route
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
- @columns = String.new
152
-
153
- for attribute in attributes
154
- if attribute.column_type == :image
155
- @columns << ' t.string :' + attribute.name + "_file_name\n"
156
- @columns << ' t.string :' + attribute.name + "_content_type\n"
157
- @columns << ' t.integer :' + attribute.name + "_file_size\n"
158
- @columns << ' t.datetime :' + attribute.name + "_updated_at\n"
159
- else
160
- if attribute.migration?
161
- attribute.attribute_type == :unknown ? commenter = '#' : commenter = ' '
162
- @columns << commenter +
163
- ' t.' +
164
- attribute.column_type.to_s +
165
- " :" +
166
- attribute.name +
167
- " \n"
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
- copy_file "_inline_forms_tabs.html.erb", "app/views/_inline_forms_tabs.html.erb" unless File.exists?('app/views/_inline_forms_tabs.html.erb')
176
- inject_into_file "app/views/_inline_forms_tabs.html.erb",
177
- " <%= tab.#{name.underscore} '#{name}', #{name.pluralize.underscore + '_path'} %>\n",
178
- :after => "<% tabs_tag :open_tabs => { :id => \"tabs\" } do |tab| %>\n"
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
@@ -1,3 +1,3 @@
1
1
  class <%= controller_name -%> < InlineFormsController
2
- set_tab :<%= name.underscore %>
2
+ <%= " set_tab :" + name.underscore + "\n" unless @flag_not_accessible_through_html -%>
3
3
  end
@@ -1,7 +1,7 @@
1
1
  class InlineFormsCreate<%= table_name.camelize %> < ActiveRecord::Migration
2
2
 
3
3
  def self.up
4
- create_table :<%= table_name %> do |t|
4
+ create_table :<%= table_name + ", :id => " + @create_id.to_s %> do |t|
5
5
  <%= @columns -%>
6
6
  t.timestamps
7
7
  end
@@ -11,4 +11,8 @@ class <%= name %> < ActiveRecord::Base
11
11
  <%= @inline_forms_attribute_list -%>
12
12
  <%= @order if @order.length > 1 -%>
13
13
 
14
+ def self.not_accessible_through_html?
15
+ <%= @flag_not_accessible_through_html %>
16
+ end
17
+
14
18
  end
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: 59
4
+ hash: 57
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 2
10
- version: 0.8.2
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-13 00:00:00 -04:00
18
+ date: 2011-03-16 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency