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 CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.5.1
@@ -1,4 +1,5 @@
1
1
  module InlineFormsHelper
2
+ InlineForms::MIGRATION_TYPE_CONVERSION_LIST[:associated]=:references
2
3
  # associated
3
4
  def associated_show(object, attribute, values)
4
5
  #show a list of records
@@ -1,4 +1,5 @@
1
1
  module InlineFormsHelper
2
+ InlineForms::MIGRATION_TYPE_CONVERSION_LIST[:check_box]=:boolean
2
3
  # boolean, bit unaptly named check_box
3
4
  def check_box_show(object, attribute, values)
4
5
  values ||= { 'false' => 'no', 'true' => 'yes' }
@@ -1,4 +1,5 @@
1
1
  module InlineFormsHelper
2
+ InlineForms::MIGRATION_TYPE_CONVERSION_LIST[:checklist]=:references
2
3
  # checklist
3
4
  def checklist_show(object, attribute, values)
4
5
  out = '<ul class="checklist">'
@@ -1,4 +1,6 @@
1
1
  module InlineFormsHelper
2
+ InlineForms::MIGRATION_TYPE_CONVERSION_LIST[:date_select]=:date
3
+
2
4
  # date
3
5
  def date_show(object, attribute, values)
4
6
  link_to_inline_edit object, attribute, object.send(attribute), nil
@@ -1,4 +1,5 @@
1
1
  module InlineFormsHelper
2
+ InlineForms::MIGRATION_TYPE_CONVERSION_LIST[:dropdown]=:integer
2
3
  # dropdown
3
4
  def dropdown_show(object, attribute, values)
4
5
  attribute_value = object.send(attribute).presentation rescue nil
@@ -1,4 +1,5 @@
1
1
  module InlineFormsHelper
2
+ InlineForms::MIGRATION_TYPE_CONVERSION_LIST[:dropdown_with_values]=:integer
2
3
  # dropdown_with_values
3
4
  def dropdown_with_values_show(object, attribute, values)
4
5
  link_to_inline_edit object, attribute, values[object.send(attribute)], values
@@ -1,4 +1,5 @@
1
1
  module InlineFormsHelper
2
+ InlineForms::MIGRATION_TYPE_CONVERSION_LIST[:geo_code_curacao]=:string
2
3
  # geo_code_curacao
3
4
  def geo_code_curacao_show(object, attribute, values)
4
5
  attribute_value = object.send(attribute).presentation rescue nil
@@ -1,4 +1,5 @@
1
1
  module InlineFormsHelper
2
+ InlineForms::MIGRATION_TYPE_CONVERSION_LIST[:range]=:integer
2
3
  # range
3
4
  def range_show(object, attribute, values)
4
5
  link_to_inline_edit object, attribute, object.send(attribute), nil
@@ -1,4 +1,5 @@
1
1
  module InlineFormsHelper
2
+ InlineForms::MIGRATION_TYPE_CONVERSION_LIST[:text_area]=:text
2
3
  # text_area
3
4
  def text_area_show(object, attribute, values)
4
5
  link_to_inline_edit object, attribute, object.send(attribute), nil
@@ -1,5 +1,6 @@
1
1
  module InlineFormsHelper
2
- # text_field
2
+ InlineForms::MIGRATION_TYPE_CONVERSION_LIST[:text_field]=:string
3
+ # text
3
4
  def text_field_show(object, attribute, values)
4
5
  link_to_inline_edit object, attribute, object.send(attribute), nil
5
6
  end
@@ -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.0"
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-03}
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
- Explain the generator
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
- This will create:
8
- what/will/it/create
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
- case type
8
- # normal types don't get converted
9
- when :string, :text, :integer, :float, :decimal, :datetime, :timestamp, :time, :date, :binary, :boolean then type
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
- case type
22
- # out types don't get converted
23
- when :dropdown, :dropdown_with_values, :check_box, :boolean_with_values then type
24
- when :integer, :float, :decimal then :text_field # who knows if they wanted a dropdown?
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
- :unkown # form will fail to generatie, probably
25
+ :unknown
26
+ end
32
27
  end
33
28
  end
34
29
 
35
- end
30
+ end
36
31
 
37
- argument :attributes, :type => :array, :banner => "field:type field:type"
32
+ argument :attributes, :type => :array, :banner => "[name:form_element]..."
38
33
 
39
34
  source_root File.expand_path('../templates', __FILE__)
40
35
 
@@ -12,4 +12,3 @@ def self.down
12
12
  drop_table :<%= table_name %>
13
13
  end
14
14
  end
15
- #The types supported by Active Record are :primary_key, :string, :text, :integer, :float, :decimal, :datetime, :timestamp, :time, :date, :binary, :boolean
@@ -11,4 +11,4 @@ class <%= name %> < ActiveRecord::Base
11
11
  <% end %>
12
12
  ]
13
13
  end
14
- end
14
+ end
@@ -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: 11
4
+ hash: 9
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 0
10
- version: 0.5.0
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-03 00:00:00 -04:00
18
+ date: 2011-02-04 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency