inline_forms 0.8.0 → 0.8.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 CHANGED
@@ -1 +1 @@
1
- 0.8.0
1
+ 0.8.1
@@ -1,36 +1,38 @@
1
- InlineForms::SPECIAL_COLUMN_TYPES[:checklist]=:references
1
+ InlineForms::SPECIAL_COLUMN_TYPES[:check_list]=:no_migration
2
2
 
3
3
  # checklist
4
- def checklist_show(object, attribute)
4
+ def check_list_show(object, attribute)
5
5
  out = '<ul class="checklist">'
6
6
  out << link_to_inline_edit(object, attribute) if object.send(attribute).empty?
7
7
  object.send(attribute).sort.each do | item |
8
8
  out << '<li>'
9
- out << link_to_inline_edit(object, attribute, item.title)
9
+ out << link_to_inline_edit(object, attribute, item._presentation )
10
10
  out << '</li>'
11
11
  end
12
12
  out << '</ul>'
13
+ out.html_safe
13
14
  end
14
15
 
15
- def checklist_edit(object, attribute)
16
+ def check_list_edit(object, attribute)
16
17
  object.send(attribute).build if object.send(attribute).empty?
17
18
  values = object.send(attribute).first.class.name.constantize.find(:all) # TODO bring order
18
19
  out = '<div class="edit_form_checklist">'
19
20
  out << '<ul>'
20
21
  values.each do | item |
21
22
  out << '<li>'
22
- out << check_box_tag( attribute + '[' + item.id.to_s + ']', 'yes', object.send(attribute.singularize + "_ids").include?(item.id) )
23
+ out << check_box_tag( attribute + '[' + item.id.to_s + ']', 1, object.send(attribute.singularize + "_ids").include?(item.id) )
23
24
  out << '<div class="edit_form_checklist_text">'
24
- out << h(item.title)
25
+ out << h(item._presentation)
25
26
  out << '</div>'
26
27
  out << '<div style="clear: both;"></div>'
27
28
  out << '</li>'
28
29
  end
29
30
  out << '</ul>'
30
31
  out << '</div>'
32
+ out.html_safe
31
33
  end
32
34
 
33
- def checklist_update(object, attribute)
35
+ def check_list_update(object, attribute)
34
36
  params[attribute] ||= {}
35
37
  object.send(attribute.singularize + '_ids=', params[attribute].keys)
36
38
  end
@@ -88,11 +88,11 @@ module InlineFormsHelper
88
88
  private
89
89
 
90
90
  # link_to_inline_edit
91
- def link_to_inline_edit(object, attribute, attribute_value)
91
+ def link_to_inline_edit(object, attribute, attribute_value='')
92
92
  attribute_value = h(attribute_value)
93
93
  spaces = attribute_value.length > 40 ? 0 : 40 - attribute_value.length
94
94
  attribute_value << "&nbsp;".html_safe * spaces
95
- link_to raw(attribute_value),
95
+ link_to attribute_value,
96
96
  send( 'edit_' + @Klass.to_s.underscore + '_path',
97
97
  object,
98
98
  :attribute => attribute.to_s,
data/inline_forms.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{inline_forms}
8
- s.version = "0.8.0"
8
+ s.version = "0.8.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"]
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
27
27
  "app/controllers/inline_forms_controller.rb",
28
28
  "app/helpers/form_elements/associated.rb",
29
29
  "app/helpers/form_elements/check_box.rb",
30
- "app/helpers/form_elements/checklist.rb",
30
+ "app/helpers/form_elements/check_list.rb",
31
31
  "app/helpers/form_elements/date.rb",
32
32
  "app/helpers/form_elements/dropdown.rb",
33
33
  "app/helpers/form_elements/dropdown_with_integers.rb",
@@ -50,8 +50,17 @@ module InlineForms
50
50
  RELATIONS.has_key?(type) || special_relation?
51
51
  end
52
52
 
53
- def has_many?
54
- attribute_type == :associated
53
+ def migration?
54
+ not ( relation? ||
55
+ column_type == :no_migration ||
56
+ name == "_presentation" ||
57
+ name == "_order" )
58
+ end
59
+
60
+ def attribute?
61
+ not ( name == '_presentation' ||
62
+ name == '_order' ||
63
+ relation? )
55
64
  end
56
65
 
57
66
 
@@ -71,20 +80,25 @@ module InlineForms
71
80
  @habtm = "\n"
72
81
  @has_attached_files = "\n"
73
82
  @presentation = "\n"
83
+ @order = "\n"
74
84
  @inline_forms_attribute_list = String.new
75
85
 
76
86
  for attribute in attributes
77
87
  if attribute.column_type == :belongs_to # :drop_down, :references and :belongs_to all end up with the column_type :belongs_to
78
88
  @belongs_to << ' belongs_to :' + attribute.name + "\n"
79
89
  end
80
- if attribute.type == :has_many
81
- @has_many << ' has_many :' + attribute.name + "\n"
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"
82
95
  end
83
96
  if attribute.type == :has_one
84
97
  @has_one << ' has_one :' + attribute.name + "\n"
85
98
  end
86
99
  if attribute.type == :habtm ||
87
- attribute.type == :has_and_belongs_to_many
100
+ attribute.type == :has_and_belongs_to_many ||
101
+ attribute.type == :check_list
88
102
  @habtm << ' has_and_belongs_to_many :' + attribute.name + "\n"
89
103
  end
90
104
  if attribute.type == :image
@@ -97,7 +111,13 @@ module InlineForms
97
111
  " end\n" +
98
112
  "\n"
99
113
  end
100
- unless attribute.name == '_presentation' || attribute.relation?
114
+ if attribute.name == '_order'
115
+ @order << " def <=>(other)\n" +
116
+ " self.#{attribute.type} <=> other.#{attribute.type}\n" +
117
+ " end\n" +
118
+ "\n"
119
+ end
120
+ if attribute.attribute?
101
121
  attribute.attribute_type == :unknown ? commenter = '#' : commenter = ' '
102
122
  @inline_forms_attribute_list << commenter +
103
123
  ' [ :' +
@@ -137,7 +157,7 @@ module InlineForms
137
157
  @columns << ' t.integer :' + attribute.name + "_file_size\n"
138
158
  @columns << ' t.datetime :' + attribute.name + "_updated_at\n"
139
159
  else
140
- unless attribute.name == '_presentation' || attribute.special_relation?
160
+ if attribute.migration?
141
161
  attribute.attribute_type == :unknown ? commenter = '#' : commenter = ' '
142
162
  @columns << commenter +
143
163
  ' t.' +
@@ -9,5 +9,6 @@ class <%= name %> < ActiveRecord::Base
9
9
  <%= @has_attached_files if @has_attached_files.length > 1 -%>
10
10
  <%= @presentation if @presentation.length > 1 -%>
11
11
  <%= @inline_forms_attribute_list -%>
12
+ <%= @order if @order.length > 1 -%>
12
13
 
13
14
  end
data/lib/inline_forms.rb CHANGED
@@ -116,11 +116,11 @@ module InlineForms
116
116
 
117
117
  # The stuff in this hash will add a line to the model, but little else.
118
118
  SPECIAL_RELATIONS = {
119
- :has_many => :has_many,
120
- :has_one => :has_one,
121
- :has_and_belongs_to_many => :has_and_belongs_to_many,
122
- :habtm => :has_and_belongs_to_many,
123
- :associated => :associated,
119
+ :has_many => :no_migration,
120
+ :has_one => :no_migration,
121
+ :has_and_belongs_to_many => :no_migration,
122
+ :habtm => :no_migration,
123
+ :habtm_destroy => :no_migration,
124
124
  }
125
125
 
126
126
  # Declare as a Rails::Engine, see http://www.ruby-forum.com/topic/211017#927932
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: 63
4
+ hash: 61
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 0
10
- version: 0.8.0
9
+ - 1
10
+ version: 0.8.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ace Suares
@@ -98,7 +98,7 @@ files:
98
98
  - app/controllers/inline_forms_controller.rb
99
99
  - app/helpers/form_elements/associated.rb
100
100
  - app/helpers/form_elements/check_box.rb
101
- - app/helpers/form_elements/checklist.rb
101
+ - app/helpers/form_elements/check_list.rb
102
102
  - app/helpers/form_elements/date.rb
103
103
  - app/helpers/form_elements/dropdown.rb
104
104
  - app/helpers/form_elements/dropdown_with_integers.rb