jquelpers 0.0.1 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ == 24-11-2010
2
+ * Adding Autocompletion & Auto load of js&css files
3
+
4
+ == 20-11-2010
5
+ * Adding calculator helper working with jQuery Calculator http://keith-wood.name/calculator.html
6
+
1
7
  == 18-11-2010
2
8
  Major Commit
3
9
  * Support for Ajax in Tabs
data/Manifest CHANGED
@@ -4,5 +4,9 @@ README.textile
4
4
  Rakefile
5
5
  lib/jquelpers.rb
6
6
  lib/jquelpers/accordion_helper.rb
7
+ lib/jquelpers/autocomplete_helper.rb
8
+ lib/jquelpers/calculator_helper.rb
7
9
  lib/jquelpers/datepicker_helper.rb
10
+ lib/jquelpers/includes_helper.rb
11
+ lib/jquelpers/jquelpers.rb
8
12
  lib/jquelpers/tabs_helper.rb
@@ -1,21 +1,81 @@
1
- h1. What Is It?
1
+ h1. What Is Jquelpers?
2
2
 
3
- These are some view helpers I use in Rails to better integrate jQuery UI into my sites.
3
+ This is a collection of helpers for Ruby on Rails.
4
+ Jquelpers is a contraction of Jquery and Helpers.
5
+ Currently it aim to support all the plugins composing Jquery-UI library, but others plugins are note forbidden (like the calculator)
4
6
 
5
- I hope you find them useful.
7
+ Jquelpers is a fork of jquery-ui-rails-helpers by CodeOfficer (https://github.com/CodeOfficer/jquery-ui-rails-helpers)
6
8
 
7
- original work by CodeOfficer
8
- https://github.com/CodeOfficer/jquery-ui-rails-helpers
9
+ I hope you'll find Jquelpers useful.
9
10
 
10
- h2. Warning !
11
- This fork is not anymore compatible with the original plugin.
12
- If you decide to use this fork, you will have to rewrite your apps (for the best !)
11
+ h3. Warning !
13
12
 
13
+ This fork is not anymore compatible with the original jquery-ui-rails-helpers plugin.
14
+ If you decide to use this fork, you will have to rewrite your apps (for the best !).
15
+
16
+ This gem works with Rails 2.3.8 ; I did'nt try anywhere else, but this should work with Rails 3.0 (tell me if it does'nt)
17
+
18
+ h2. Let's start
19
+
20
+ Install
21
+ <pre><code>
22
+ gem install jquelpers
23
+ </code></pre>
24
+
25
+ And require it
26
+ <pre><code>
27
+ config.gem 'jquelpers'
28
+ </code></pre>
29
+
30
+ Set the defaut options. (in progress....)
31
+ <pre><code>
32
+ Jquelpers.default=
33
+ { :tabs => {:html=> {:class => "styleit"}},
34
+ :accordions => {:html=> {}, :jquery=> ""},
35
+ :datepicker => {:html=> {}, :jquery=> "showButtonPanel: true, showOn: \"both\", buttonImageOnly: true, buttonImage: '/images/calendar.png', " },
36
+ :calculator => {:html=> {}, :jquery=> "useThemeRoller: true, showOn: \"both\", buttonImageOnly: true, buttonImage: '/images/calculator.png', "},
37
+ :autocomplete => {:jquery=> "minLength: 2,"}
38
+ }
39
+ </code></pre>
40
+
41
+ Set the location of your files, these are default (if you have the same files you can skip this step)
42
+ note the %{l} it is the I18n wildcard, working with I18n.locale !
43
+ <pre><code>
44
+ Jquelpers.js_files = [
45
+ [:jquery, "jquery-1.4.4.min"],
46
+ [:core, "jquery.ui.core.min"],
47
+ [:widget, "jquery.ui.widget.min"],
48
+ [:tabs, "jquery.ui.tabs.min"],
49
+ [:accordion, "jquery.ui.accordion.min"],
50
+ [:calculator, "jquery.calculator.min"],
51
+ [:calculator_I18n, "jquery.calculator-%{l}"],
52
+ [:datepicker, "jquery.ui.datepicker.min"],
53
+ [:datepicker_I18n, "jquery.ui.datepicker-%{l}"],
54
+ [:position, "jquery.ui.position.min"],
55
+ [:autocomplete, "jquery.ui.autocomplete.min"]
56
+ ]
57
+ Jquelpers.css_files = [
58
+ [:UI, "UI-custom/jquery-ui-1.8.6.custom"],
59
+ [:calculator, "jquery.calculator.alt"]
60
+ ]
61
+ </code></pre>
62
+
63
+ h3. IncludesHelper
64
+
65
+ IncludesHelpers allow Jquelpers to manage when and wich files have to included in the rendered page.
66
+ <pre><code>
67
+ jquelpers_include_javascript(options = {})
68
+ jquelpers_include_stylesheet(options = {})
69
+ </code></pre>
70
+
71
+ they have all options of <i>javascript_include_tag & stylesheet_link_tag</i>
72
+ plus <i>:always => true</i> for including all files all time (bypass clever loading)
73
+
74
+ Application layout, or any layouts is a good place for these.
14
75
 
15
76
  h2. TabsHelper
16
77
 
17
78
  This helper simplifies the code required to use the jQuery UI Tab plugin.
18
-
19
79
  <pre><code>
20
80
  <% tabs_for :tabs_container :jquery => "collapsible = true" do |tab| %>
21
81
  <% tab.create('Tab 1') do %>
@@ -26,28 +86,9 @@ This helper simplifies the code required to use the jQuery UI Tab plugin.
26
86
  <% end %>
27
87
  </code></pre>
28
88
 
29
- The above will generate this HTML in your view: ( to be corrected with the new behaviours)
30
-
31
- <pre><code>
32
- <div id="tabs">
33
- <ul>
34
- <li><a href="#tabs_container_0"><span>Tab 1</span></a></li>
35
- <li><a href="#tabs_container_1"><span>Tab 2</span></a></li>
36
- </ul>
37
- <div id="tabs_container_0">
38
- # ... insert tab contents
39
- </div>
40
- <div id="tabs_container_1">
41
- # ... insert tab contents
42
- </div>
43
- </div>
44
- </code></pre>
45
-
46
89
  Tabs will be rendered in the order you create them.
47
-
48
90
  You can easily render a tab conditionally by appending your condition to the end of
49
91
  the 'create' block as such ... (Cancan gem in this exemple)
50
-
51
92
  <pre><code>
52
93
  <% tab.create('My Profile') do %>
53
94
  # ... insert tab contents
@@ -56,7 +97,6 @@ the 'create' block as such ... (Cancan gem in this exemple)
56
97
 
57
98
  You can pass HTML options or JQuery options to either the parent DIV or any individual tab's
58
99
  DIV (there is no JQuery options for each tab.) as you like ...
59
-
60
100
  <pre><code>
61
101
  <% tabs_for :tabs_container :jquery => "collapsible = true", :class => 'zippy' do |tab| %>
62
102
  <% tab.create('Tab 1', :style => 'background: #FFF') do %>
@@ -64,18 +104,20 @@ DIV (there is no JQuery options for each tab.) as you like ...
64
104
  <% end %>
65
105
  <% end %>
66
106
  </code></pre>
107
+
67
108
  <strike>
68
109
  The default DOM ID for the parent div is ... id="tabs" ... unless you pass in an HTML
69
110
  option with a different value. And you SHOULD pass an id.
70
111
  </strike>
71
112
  Dom id's are automaticaly genrated, but you can override them (I told you, you can pass html options)
72
113
 
114
+ one additonal option is <i>:include => :force</i> in order to load right now all files used by this helpers, could be useful for ajax responses where clever loading is not yet very clever...
115
+ This option is avaiable for all the helpers included in Jquelpers
116
+
73
117
  h2. AccordionsHelper
74
118
 
75
119
  This helper simplifies the code required to use JQuery UIs Accordion plugin.
76
-
77
120
  Usage is identical to the Tabs helper.
78
-
79
121
  <pre><code>
80
122
  <% accordions_for do |accordion| %>
81
123
  <% accordion.create("accordion_title") do %>
@@ -87,25 +129,62 @@ Usage is identical to the Tabs helper.
87
129
  h2. DatepickerHelper
88
130
 
89
131
  This helper simplifies the code required to use JQuery UIs Datepicker plugin.
90
-
91
132
  Usage is identical to others helpers.
92
-
93
133
  <pre><code>
94
134
  <% form_for do |f| %>
95
135
  <% f.datepicker :date, :jquery => "any option" %>
96
136
  <% end %>
97
137
  </code></pre>
98
-
99
138
  or outside a form_for :
100
139
  <pre><code>
101
140
  <% datepicker_tag :object_name, :date, :jquery => "any option" %>
102
141
  </code></pre>
103
142
 
143
+ h2. AutocompleteHelper
144
+
145
+ Fork from https://github.com/chris/auto_complete_jquery
146
+
147
+ This helper simplifies the code required to use JQuery UIs Autocomplete plugin.
148
+ Usage is identical to others helpers.
149
+ <pre><code>
150
+ <% form_for do |f| %>
151
+ <% f.autocomplete :drink, :source => "autocomplete_url",:jquery => "any option" %>
152
+ <% end %>
153
+ </code></pre>
154
+ or outside a form_for :
155
+ <pre><code>
156
+ <% autocomplete_tag :object_name, :drink, :source =>["Water", "Wine", "Juice", "Beer"], :jquery => "any option" %>
157
+ </code></pre>
158
+
159
+ :source have to be set and can be an array (for static completion), or a string contening the url of a webservice.
160
+
161
+ if you have to develop the webservice also you can use the <i>jq_ac_for</i> method in any controller.
162
+ <pre><code>
163
+ jq_ac_for :item, :category
164
+ </code></pre>
165
+ Which create an action named jq_ac_for_item_category wich look in the database (to be transformed for a class agnostic search) and give a basic response with found 'category' in the 'Item' class
166
+
167
+ h2. CalculatorHelper
168
+
169
+ For the jQuery Calculator from Keith Wood. (NOT in jquery UI)
170
+ http://keith-wood.name/calculator.html
171
+ This helper simplifies the code required this plugin.
172
+
173
+ Usage is identical to others helpers.
174
+ <pre><code>
175
+ <% form_for do |f| %>
176
+ <% f.calculator :price, :jquery => "any option" %>
177
+ <% end %>
178
+ </code></pre>
179
+ or outside a form_for :
180
+ <pre><code>
181
+ <% calculator_tag :object_name, :calculator, :jquery => "any option" %>
182
+ </code></pre>
183
+
104
184
  h2. Todo.
105
- h3. Gemification (will come soon)
106
- h3. I18n the DatepickerHelper
107
- h3. Autoload Jquery and Jquery UI
108
- h3. write documentation
109
- h3. Write tests (if some body explain me why and how)
110
- h3. Other helpers (Autocompletion will come, ... any idea ?)
185
+
186
+ * Real support of default options. (one the way)
187
+ * Improve Clever load for js&css files (for Ajax requests)
188
+ * write documentation
189
+ * Write tests (if somebody explain me why and how)
111
190
 
data/Rakefile CHANGED
@@ -3,13 +3,14 @@ require 'rake'
3
3
  require 'echoe'
4
4
 
5
5
  Echoe.new('jquelpers') do |p|
6
- p.description = "Provide Rails helpers for jquery-UI plugins"
7
- p.url = "http://github.com/elmatou/jquery-ui-rails-helpers/"
6
+ p.description = "Provide Rails helpers for jquery plugins"
7
+ p.summary = "Jquery is really great, rails too, but I want more Ruby and less Javascript in my code !"
8
+ p.install_message= "Ok ! Now require me in your app, and start enjoying !!"
9
+ p.url = "http://github.com/elmatou/jquelpers/"
8
10
  p.author = "El Matou"
9
11
  p.email = "elmatou@gmail.com"
10
- p.version = "0.0.1"
11
- p.changes = "First release (testing)"
12
- p.development_dependencies = []
12
+ p.version = "0.0.4"
13
+ p.changes = "auto-load js&css files. adding Calculator&Autcompletion helpers"
13
14
  end
14
15
 
15
16
  Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
@@ -2,21 +2,22 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{jquelpers}
5
- s.version = "0.0.1"
5
+ s.version = "0.0.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["El Matou"]
9
- s.date = %q{2010-11-19}
10
- s.description = %q{Provide Rails helpers for jquery-UI plugins}
9
+ s.date = %q{2010-11-24}
10
+ s.description = %q{Provide Rails helpers for jquery plugins}
11
11
  s.email = %q{elmatou@gmail.com}
12
- s.extra_rdoc_files = ["CHANGELOG", "README.textile", "lib/jquelpers.rb", "lib/jquelpers/accordion_helper.rb", "lib/jquelpers/datepicker_helper.rb", "lib/jquelpers/tabs_helper.rb"]
13
- s.files = ["CHANGELOG", "Manifest", "README.textile", "Rakefile", "lib/jquelpers.rb", "lib/jquelpers/accordion_helper.rb", "lib/jquelpers/datepicker_helper.rb", "lib/jquelpers/tabs_helper.rb", "jquelpers.gemspec"]
14
- s.homepage = %q{http://github.com/elmatou/jquery-ui-rails-helpers/}
12
+ s.extra_rdoc_files = ["CHANGELOG", "README.textile", "lib/jquelpers.rb", "lib/jquelpers/accordion_helper.rb", "lib/jquelpers/autocomplete_helper.rb", "lib/jquelpers/calculator_helper.rb", "lib/jquelpers/datepicker_helper.rb", "lib/jquelpers/includes_helper.rb", "lib/jquelpers/jquelpers.rb", "lib/jquelpers/tabs_helper.rb"]
13
+ s.files = ["CHANGELOG", "Manifest", "README.textile", "Rakefile", "lib/jquelpers.rb", "lib/jquelpers/accordion_helper.rb", "lib/jquelpers/autocomplete_helper.rb", "lib/jquelpers/calculator_helper.rb", "lib/jquelpers/datepicker_helper.rb", "lib/jquelpers/includes_helper.rb", "lib/jquelpers/jquelpers.rb", "lib/jquelpers/tabs_helper.rb", "jquelpers.gemspec"]
14
+ s.homepage = %q{http://github.com/elmatou/jquelpers/}
15
+ s.post_install_message = %q{Ok ! Now require me in your app, and start enjoying !!}
15
16
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Jquelpers", "--main", "README.textile"]
16
17
  s.require_paths = ["lib"]
17
18
  s.rubyforge_project = %q{jquelpers}
18
19
  s.rubygems_version = %q{1.3.7}
19
- s.summary = %q{Provide Rails helpers for jquery-UI plugins}
20
+ s.summary = %q{Jquery is really great, rails too, but I want more Ruby and less Javascript in my code !}
20
21
 
21
22
  if s.respond_to? :specification_version then
22
23
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -1,4 +1,37 @@
1
+ require 'jquelpers/jquelpers'
2
+ require 'jquelpers/includes_helper'
3
+
1
4
  require 'jquelpers/accordion_helper'
2
5
  require 'jquelpers/tabs_helper'
3
6
  require 'jquelpers/datepicker_helper'
7
+ require 'jquelpers/calculator_helper'
8
+ require 'jquelpers/autocomplete_helper'
9
+
10
+ if Object.const_defined?(:Rails) && File.directory?(Rails.root.to_s + "/public")
11
+ # FormBuilder Helpers
12
+ ActionView::Helpers::FormHelper.send(:include, Jquelpers::DatepickerHelper)
13
+ ActionView::Base.send(:include, Jquelpers::DatepickerHelper)
14
+
15
+ ActionController::Base.send(:include, AutoCompleteJquery)
16
+
17
+ ActionView::Helpers::FormHelper.send(:include, Jquelpers::CalculatorHelper)
18
+ ActionView::Base.send(:include, Jquelpers::CalculatorHelper)
19
+
20
+ ActionView::Helpers::FormHelper.send(:include, Jquelpers::AutocompleteHelper)
21
+ ActionView::Base.send(:include, Jquelpers::AutocompleteHelper)
22
+
23
+ # Non FormBuilder Helpers
24
+ ActionView::Base.send(:include, Jquelpers::IncludesHelper)
25
+ ActionView::Base.send(:include, Jquelpers::AccordionHelper)
26
+ ActionView::Base.send(:include, Jquelpers::TabsHelper)
4
27
 
28
+ # install files
29
+ # unless File.exists?(RAILS_ROOT + '/public/javascripts/calendar_date_select/calendar_date_select.js')
30
+ # ['/public', '/public/javascripts/calendar_date_select', '/public/stylesheets/calendar_date_select', '/public/images/calendar_date_select', '/public/javascripts/calendar_date_select/locale'].each do |dir|
31
+ # source = File.dirname(__FILE__) + "/../#{dir}"
32
+ # dest = RAILS_ROOT + dir
33
+ # FileUtils.mkdir_p(dest)
34
+ # FileUtils.cp(Dir.glob(source+'/*.*'), dest)
35
+ # end
36
+ # end
37
+ end
@@ -1,11 +1,18 @@
1
- module AccordionHelper
2
-
1
+ module Jquelpers::AccordionHelper
2
+
3
+ jquery_options = ""
4
+ html_options = {}
3
5
  def accordion_for(method, options ={}, &block )
4
6
  raise ArgumentError, "Missing block" unless block_given?
5
-
7
+
6
8
  options = {:id => method.to_s }.merge!(options)
9
+
10
+ Jquelpers.need_stylesheet :UI
11
+ Jquelpers.need_javascript :jquery, :core, :widget, :accordion
12
+
13
+ jquelpers_include_specifics if options.delete(:include) === :force
7
14
  concat javascript_tag "$(document).ready(function() {$(\"##{options[:id]}\").accordion({#{options.delete(:jquery)}}); });"
8
- concat AccordionHelper::AccordionRenderer.new( options, &block ).render
15
+ concat AccordionRenderer.new( options, &block ).render
9
16
  end
10
17
 
11
18
  class AccordionRenderer
@@ -0,0 +1,28 @@
1
+ module Jquelpers::AutocompleteHelper
2
+
3
+ def autocomplete_tag(object, method, options = {})
4
+
5
+ # source = options.delete(:source)
6
+ jquery = "source: " << (options[:source].is_a?(Array)? options.delete(:source).inspect : options.delete(:source).inspect)
7
+
8
+ # jquery << Jquelpers.default[:autocomplete][:jquery] << (options.delete(:jquery).to_s ||= "")
9
+ # options = (Jquelpers.default[:autocomplete][:html] ||= {}).merge(options)
10
+
11
+
12
+ Jquelpers.need_stylesheet :UI
13
+ Jquelpers.need_javascript :jquery, :core, :widget, :position, :autocomplete
14
+ jquelpers_include_specifics if options.delete(:include) === :force
15
+ concat text_field(object.class.name.downcase, method, options)
16
+ javascript_tag "$(document).ready(function() {$(#{object.class.name.downcase}_#{method.to_s}).autocomplete({#{jquery}}); });"
17
+ end
18
+ end
19
+
20
+ module ActionView
21
+ module Helpers
22
+ class FormBuilder
23
+ def autocomplete(method, options = {})
24
+ @template.autocomplete_tag(@object, method, options.merge(:object => @object))
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,26 @@
1
+ module Jquelpers::CalculatorHelper
2
+
3
+
4
+ def calculator_tag(object, method, options = {})
5
+ jquery = Jquelpers.default[:calculator][:jquery] << (options.delete(:jquery).to_s ||= "")
6
+ options = (Jquelpers.default[:calculator][:html] ||= {}).merge(options)
7
+
8
+ Jquelpers.need_stylesheet :UI, :calculator
9
+ Jquelpers.need_javascript :jquery, :calculator, :calculator_I18n
10
+
11
+ jquelpers_include_specifics if options.delete(:include) === :force
12
+
13
+ concat text_field(object.class.name.downcase, method, options)
14
+ javascript_tag "$(document).ready(function() {$(#{object.class.name.downcase}_#{method.to_s}).calculator({#{jquery}}); });"
15
+ end
16
+ end
17
+
18
+ module ActionView
19
+ module Helpers
20
+ class FormBuilder
21
+ def calculator(method, options = {})
22
+ @template.calculator_tag(@object, method, options.merge(:object => @object))
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,6 +1,13 @@
1
- module DatepickerHelper
1
+ module Jquelpers::DatepickerHelper
2
+
2
3
  def datepicker_tag(object, method, options = {})
3
- jquery = options.delete(:jquery)
4
+ jquery = Jquelpers.default[:datepicker][:jquery] << (options.delete(:jquery).to_s ||= "")
5
+ options = (Jquelpers.default[:datepicker][:html] ||= {}).merge(options)
6
+
7
+ Jquelpers.need_stylesheet :UI
8
+ Jquelpers.need_javascript :jquery, :core, :widget, :datepicker, :datepicker_I18n
9
+
10
+ jquelpers_include_specifics if options.delete(:include) === :force
4
11
  concat text_field(object.class.name.downcase, method, options)
5
12
  javascript_tag "$(document).ready(function() {$(#{object.class.name.downcase}_#{method.to_s}).datepicker({#{jquery}}); });"
6
13
  end
@@ -14,4 +21,4 @@ module ActionView
14
21
  end
15
22
  end
16
23
  end
17
- end
24
+ end
@@ -0,0 +1,31 @@
1
+ module Jquelpers::IncludesHelper
2
+ def jquelpers_include_javascript(options = {})
3
+ Jquelpers::Javascript_files.each { |f| Jquelpers.need_javascript f[0] } if options.delete(:always)
4
+ concat javascript_include_tag(Jquelpers.need_javascript, options)
5
+ Jquelpers.flush_js
6
+ end
7
+
8
+ def jquelpers_include_stylesheet(options = {})
9
+ Jquelpers::Stylesheet_files.each { |f| Jquelpers.need_stylesheet f[1] } if options.delete(:always)
10
+ concat stylesheet_link_tag(Jquelpers.need_stylesheet, options)
11
+ Jquelpers.flush_css
12
+ end
13
+
14
+ ##### below : in progress
15
+
16
+ def jquelpers_test
17
+ Jquelpers.need_javascript.each { |f| concat f.to_s + "<br />"}
18
+ Jquelpers.need_stylesheet.each { |f| concat f.to_s + "<br />"}
19
+ end
20
+
21
+ def jquelpers_include_specifics(*args)
22
+ concat javascript_include_tag(Jquelpers.need_javascript)
23
+ concat stylesheet_link_tag(Jquelpers.need_stylesheet)
24
+ # javascript_include_tag args.each {|a| Javascript_files.assoc(a)[1] }
25
+ end
26
+
27
+ def jquelpers_include(*options)
28
+ jquelpers_include_stylesheet(options)
29
+ jquelpers_include_javascript(options)
30
+ end
31
+ end
@@ -0,0 +1,155 @@
1
+ module Jquelpers
2
+
3
+ Javascript_files = [
4
+ [:jquery, "jquery-1.4.4.min"],
5
+ [:core, "jquery.ui.core.min"],
6
+ [:widget, "jquery.ui.widget.min"],
7
+ [:tabs, "jquery.ui.tabs.min"],
8
+ [:accordion, "jquery.ui.accordion.min"],
9
+ [:calculator, "jquery.calculator.min"],
10
+ [:calculator_I18n, "jquery.calculator-%{l}"],
11
+ [:datepicker, "jquery.ui.datepicker.min"],
12
+ [:datepicker_I18n, "jquery.ui.datepicker-%{l}"],
13
+ [:position, "jquery.ui.position.min"],
14
+ [:autocomplete, "jquery.ui.autocomplete.min"]
15
+ ]
16
+ Stylesheet_files = [
17
+ [:UI, "UI-custom/jquery-ui-1.8.6.custom"],
18
+ [:calculator, "jquery.calculator.alt"]
19
+ ]
20
+
21
+ @needed_javascript = Array.new
22
+ @needed_stylesheet = Array.new
23
+
24
+ def self.flush_js
25
+ @needed_javascript.clear
26
+ end
27
+ def self.flush_css
28
+ @needed_stylesheet.clear
29
+ end
30
+
31
+ def self.check_if_local(path, arg)
32
+ File.file?(RAILS_ROOT + "/public/#{path}#{arg.sub("%{l}", I18n.locale.to_s)}") ? arg.sub("%{l}", I18n.locale.to_s) : nil
33
+ end
34
+
35
+ def self.need_javascript(*args)
36
+ args.each {|a| @needed_javascript << check_if_local("javascripts/", Javascript_files.assoc(a)[1] + ".js")}
37
+ @needed_javascript.uniq
38
+ end
39
+
40
+ def self.need_stylesheet(*args)
41
+ args.each {|a| @needed_stylesheet << check_if_local("stylesheets/", Stylesheet_files.assoc(a)[1] + ".css")}
42
+ @needed_stylesheet.uniq
43
+ end
44
+
45
+ def self.default=(hash)
46
+ @jquelpers_default = hash || {}
47
+ end
48
+ def self.default
49
+ @jquelpers_default
50
+ end
51
+
52
+ def self.js_files=(array)
53
+ # @js_files = Javascript_files.collect {|a| a.assoc(array.assoc(a)) || a }
54
+ end
55
+
56
+
57
+ # les fichiers utils par ordre de précedence avec %{l} pour symboliser la langue d'un fichier de localisation.
58
+ #
59
+ # @javascript = RequiredFiles.new([
60
+ # [:jquery, "jquery-1.4.4.min.js"],
61
+ # [:core, "jquery.ui.core.min.js"],
62
+ # [:widget, "jquery.ui.widget.min.js"],
63
+ # [:tabs, "jquery.ui.tabs.min.js"],
64
+ # [:accordion, "jquery.ui.accordion.min.js"],
65
+ # [:calculator, "jquery.calculator.min.js"],
66
+ # [:calculator_I18n, "jquery.calculator-%{l}.js"],
67
+ # [:datepicker, "jquery.ui.datepicker.min.js"],
68
+ # [:datepicker_I18n, "jquery.ui.datepicker-%{l}.js"]
69
+ # ])
70
+ #
71
+ # class RequiredFiles
72
+ # def initialize(id)
73
+ # id = id.to_a # nettoyage et formatage de l'array, c'est un peu court pour le moment
74
+ # @list = Array.new(id)
75
+ # @load = Array.new
76
+ # end
77
+ #
78
+ # class UnknownRequiredFiles < StandardError; end
79
+ #
80
+ # attr_reader :load
81
+ # attr_writer :list
82
+ #
83
+ #
84
+ #
85
+ # def self.need(*args)
86
+ # path = "javascripts/"
87
+ # args.each {|a| @needed_javascript << file?(path + @list.assoc(a)[1])}
88
+ # @needed_javascript.uniq
89
+ # end
90
+ #
91
+ # def self.dont_need(*args)
92
+ # args.each {|a| @needed_javascript.delete(@list.assoc(a)[1])}
93
+ # @needed_javascript.uniq
94
+ # end
95
+ #
96
+ # def self.clear
97
+ # @toload.clear
98
+ # end
99
+ #
100
+ # def file?(arg)
101
+ # File.file?(RAILS_ROOT + "/public/#{arg.sub("%{l}", I18n.locale.to_s)}") ? arg.sub("%{l}", I18n.locale.to_s) : nil
102
+ # end
103
+ #
104
+ # end
105
+ end
106
+
107
+
108
+
109
+ module AutoCompleteJquery # from https://github.com/chris/auto_complete_jquery
110
+
111
+ def self.included(base)
112
+ base.extend(ClassMethods)
113
+ end
114
+
115
+ #
116
+ # Example:
117
+ #
118
+ # # Controller
119
+ # class BlogController < ApplicationController
120
+ # auto_complete_for :post, :title
121
+ # end
122
+ #
123
+ # # View
124
+ # <%= text_field_with_auto_complete :post, title %>
125
+ #
126
+ # By default, auto_complete_for limits the results to 10 entries,
127
+ # and sorts by the given field.
128
+ #
129
+ # auto_complete_for takes a third parameter, an options hash to
130
+ # the find method used to search for the records:
131
+ #
132
+ # auto_complete_for :post, :title, :limit => 15, :order => 'created_at DESC'
133
+ #
134
+ # For help on defining text input fields with autocompletion,
135
+ # see ActionView::Helpers::JavaScriptHelper.
136
+ #
137
+ module ClassMethods
138
+ def jq_ac_for(object, method, options = {})
139
+ define_method("jq_ac_for_#{object}_#{method}") do
140
+ object_constant = object.to_s.camelize.constantize
141
+
142
+ find_options = {
143
+ :conditions => [ "LOWER(#{method}) LIKE ?", '%' + params[:term].downcase + '%' ],
144
+ :order => "#{method} ASC",
145
+ :select => "#{object_constant.table_name}.#{method}",
146
+ :limit => 10 }.merge!(options)
147
+
148
+ @items = object_constant.find(:all, find_options).collect(&method)
149
+
150
+ render :text => @items.uniq.inspect
151
+ end
152
+ end
153
+ end
154
+
155
+ end
@@ -1,11 +1,16 @@
1
- module TabsHelper
2
-
1
+ module Jquelpers::TabsHelper
2
+
3
3
  def tabs_for(method, options = {}, &block )
4
4
  raise ArgumentError, "Missing block" unless block_given?
5
-
5
+
6
+ Jquelpers.need_stylesheet :UI
7
+ Jquelpers.need_javascript :jquery, :core, :widget, :tabs
8
+ jquelpers_include_specifics if options.delete(:include) === :force
9
+
6
10
  options = {:id => method.to_s }.merge!(options)
11
+
7
12
  concat javascript_tag "$(document).ready(function() {$(\"##{options[:id]}\").tabs({#{options.delete(:jquery)}}); });"
8
- concat TabsHelper::TabsRenderer.new(options, &block ).render
13
+ concat TabsRenderer.new(options, &block ).render
9
14
  end
10
15
 
11
16
  class TabsRenderer
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jquelpers
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - El Matou
@@ -15,11 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-19 00:00:00 +01:00
18
+ date: 2010-11-24 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
22
- description: Provide Rails helpers for jquery-UI plugins
22
+ description: Provide Rails helpers for jquery plugins
23
23
  email: elmatou@gmail.com
24
24
  executables: []
25
25
 
@@ -30,7 +30,11 @@ extra_rdoc_files:
30
30
  - README.textile
31
31
  - lib/jquelpers.rb
32
32
  - lib/jquelpers/accordion_helper.rb
33
+ - lib/jquelpers/autocomplete_helper.rb
34
+ - lib/jquelpers/calculator_helper.rb
33
35
  - lib/jquelpers/datepicker_helper.rb
36
+ - lib/jquelpers/includes_helper.rb
37
+ - lib/jquelpers/jquelpers.rb
34
38
  - lib/jquelpers/tabs_helper.rb
35
39
  files:
36
40
  - CHANGELOG
@@ -39,14 +43,18 @@ files:
39
43
  - Rakefile
40
44
  - lib/jquelpers.rb
41
45
  - lib/jquelpers/accordion_helper.rb
46
+ - lib/jquelpers/autocomplete_helper.rb
47
+ - lib/jquelpers/calculator_helper.rb
42
48
  - lib/jquelpers/datepicker_helper.rb
49
+ - lib/jquelpers/includes_helper.rb
50
+ - lib/jquelpers/jquelpers.rb
43
51
  - lib/jquelpers/tabs_helper.rb
44
52
  - jquelpers.gemspec
45
53
  has_rdoc: true
46
- homepage: http://github.com/elmatou/jquery-ui-rails-helpers/
54
+ homepage: http://github.com/elmatou/jquelpers/
47
55
  licenses: []
48
56
 
49
- post_install_message:
57
+ post_install_message: Ok ! Now require me in your app, and start enjoying !!
50
58
  rdoc_options:
51
59
  - --line-numbers
52
60
  - --inline-source
@@ -81,6 +89,6 @@ rubyforge_project: jquelpers
81
89
  rubygems_version: 1.3.7
82
90
  signing_key:
83
91
  specification_version: 3
84
- summary: Provide Rails helpers for jquery-UI plugins
92
+ summary: Jquery is really great, rails too, but I want more Ruby and less Javascript in my code !
85
93
  test_files: []
86
94