combo_box 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -34,7 +34,6 @@
34
34
  };
35
35
  // Bind elements with the method
36
36
  // $('input[data-combo-box]').ready($.initializeComboBoxes);
37
- // $('input[data-combo-box]').ready($.initializeComboBoxes);
38
37
  $(document).ready(function(event) {
39
38
  $('input[data-combo-box]').each($.initializeComboBoxes);
40
39
  });
@@ -11,7 +11,7 @@ module ComboBox
11
11
  # Generates a default action which is the resource for a combo_box.
12
12
  # It generates an helper which takes in account selected columns for displaying.
13
13
  #
14
- # @macro [new] options
14
+ # @macro [new] options_details
15
15
  # @param [Hash] options Options to build controller action
16
16
  # @option options [Array] :columns The columns which are used for search and display
17
17
  # All the content columns are used by default.
@@ -29,19 +29,19 @@ module ComboBox
29
29
  # of the class +MODEL+.
30
30
  # @param [Symbol] name Name of the datasource
31
31
  # @param [String, Symbol] name Name of the model to use for searching
32
- # @macro options
32
+ # @macro options_details
33
33
  #
34
34
  # @overload search_for(name, options={})
35
35
  # Defines a controller method +search_for_NAME+ which searches for records
36
36
  # of the class +NAME+.
37
37
  # @param [Symbol] name
38
38
  # Name of the datasource. This name is used to find the model name
39
- # @macro options
39
+ # @macro options_details
40
40
  #
41
41
  # @overload search_for(options={})
42
42
  # Defines a controller method +search_for+ which searches for records corresponding to the
43
43
  # resource controller name. +OrdersController#search_for+ searches for orders.
44
- # @macro options
44
+ # @macro options_details
45
45
  #
46
46
  # @example Search clients with Person model
47
47
  # # app/controller/orders_controller.rb
@@ -76,7 +76,8 @@ module ComboBox
76
76
  end
77
77
  generator = Generator::Base.new(self, action_name, model, options)
78
78
  class_eval(generator.controller_action, "#{__FILE__}:#{__LINE__}")
79
- ActionView::Base.send(:class_eval, generator.view_code, "#{__FILE__}:#{__LINE__}")
79
+ # ActionView::Base.send(:class_eval, generator.view_code, "#{__FILE__}:#{__LINE__}")
80
+ ComboBox::CompiledLabels.send(:class_eval, generator.item_label_code, "#{__FILE__}:#{__LINE__}")
80
81
  end
81
82
 
82
83
  end
@@ -172,9 +172,9 @@ module ComboBox
172
172
  end
173
173
 
174
174
 
175
- def view_code()
175
+ def item_label_code()
176
176
  record = 'record'
177
- code = "def item_label_for_#{@action_name}_in_#{@controller.controller_name}(#{record})\n"
177
+ code = "def self.item_label_for_#{@action_name}_in_#{@controller.controller_name}(#{record})\n"
178
178
  code << " if #{record}.is_a? #{@model.name}\n"
179
179
  code << " return #{item_label(record)}\n"
180
180
  code << " else\n"
@@ -2,22 +2,6 @@ module ComboBox
2
2
  module Helpers
3
3
  module FormTagHelper
4
4
 
5
-
6
- # Returns the list of columns to use in the combo_box for displaying
7
- # the current item
8
- # @param [String, Symbol] action_name Name of the 'search_for' action
9
- # @param [String, Symbol] controller_name Name of the controller of the 'search_for' action
10
- #
11
- # @return [Array] Lists of symbols corresponding to the 'search_for' columns's names
12
- def search_columns_for(action, controller=nil)
13
- method_name = "search_columns_for_#{action}_in_#{controller}"
14
- if self.respond_to?(method_name)
15
- return self.send(method_name)
16
- else
17
- return nil
18
- end
19
- end
20
-
21
5
 
22
6
  # Returns a text field which has the same behavior of +select+ but with a search
23
7
  # action which permits to find easily in very long lists...
@@ -41,9 +25,15 @@ module ComboBox
41
25
  action = choices.split(/\#+/)
42
26
  choices = {:action=>action[1], :controller=>action[0]}
43
27
  end
44
- choices[:controller] ||= controller.controller_name
28
+ choices[:controller] ||= options[:controller]||controller.controller_name
29
+ unless ComboBox::CompiledLabels.methods.include?("item_label_for_#{choices[:action]}_in_#{choices[:controller]}".to_sym)
30
+ "#{choices[:controller].to_s.classify.pluralize}Controller".constantize
31
+ unless ComboBox::CompiledLabels.methods.include?("item_label_for_#{choices[:action]}_in_#{choices[:controller]}".to_sym)
32
+ raise Exception.new("It seems there is no search_for declaration corresponding to #{choices[:action]}")
33
+ end
34
+ end
45
35
  html = ""
46
- html << tag(:input, :type=>:text, "data-combo-box"=>url_for(choices.merge(:format=>:json)), "data-value-container"=>"#{object_name}_#{method}", :value=>send("item_label_for_#{choices[:action]}_in_#{choices[:controller]}", object.send(method)), :size=>html_options.delete(:size)||32)
36
+ html << tag(:input, :type=>:text, "data-combo-box"=>url_for(choices.merge(:format=>:json)), "data-value-container"=>"#{object_name}_#{method}", :value=>ComboBox::CompiledLabels.send("item_label_for_#{choices[:action]}_in_#{choices[:controller]}", object.send(method)), :size=>html_options.delete(:size)||32)
47
37
  html << hidden_field(object_name, method, html_options)
48
38
  return html.html_safe
49
39
  end
data/lib/combo_box.rb CHANGED
@@ -4,6 +4,10 @@ require 'combo_box/engine' if defined?(::Rails)
4
4
  # :include: ../README.rdoc
5
5
  module ComboBox
6
6
  extend ActiveSupport::Autoload
7
+
8
+ # Module used to "stock" labelling methods for items
9
+ module CompiledLabels
10
+ end
7
11
 
8
12
  autoload :Helpers
9
13
  autoload :Generator
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: combo_box
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-12 00:00:00.000000000Z
12
+ date: 2011-09-19 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &19442160 !ruby/object:Gem::Requirement
16
+ requirement: &21071460 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *19442160
24
+ version_requirements: *21071460
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: jquery-rails
27
- requirement: &19441680 !ruby/object:Gem::Requirement
27
+ requirement: &21070980 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *19441680
35
+ version_requirements: *21070980
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: jeweler
38
- requirement: &19441200 !ruby/object:Gem::Requirement
38
+ requirement: &21070500 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.6.4
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *19441200
46
+ version_requirements: *21070500
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rcov
49
- requirement: &19440720 !ruby/object:Gem::Requirement
49
+ requirement: &21070020 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *19440720
57
+ version_requirements: *21070020
58
58
  description: Adds helpers for Rails views and controller in order to manage 'dynamic
59
59
  select'. It uses jQuery UI as support for inobtrusive use in forms. It's not the
60
60
  classic Autocompleter, its use is limited to belongs_to reflections.
@@ -93,7 +93,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
93
  version: '0'
94
94
  segments:
95
95
  - 0
96
- hash: -1073113084261701318
96
+ hash: -2484117035189926183
97
97
  required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  none: false
99
99
  requirements: