jqgrid_for_rails 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,8 @@
1
+ == 0.2.0
2
+
3
+ * enhancements
4
+ * Navigator options fully supported.
5
+
6
+ * bug fix
7
+ * Get pager id from the options hash in any of the formats accepted by
8
+ jqGrid.
data/README.rdoc CHANGED
@@ -11,9 +11,13 @@ https://github.com/Juanmcuello/jqgrid_for_rails_example
11
11
 
12
12
  == Installation
13
13
 
14
- To install it as a plugin just:
14
+ As a gem:
15
15
 
16
- $ rails plugin install git@github.com:Juanmcuello/jqgrid_for_rails.git
16
+ $ gem install jqgrid_for_rails
17
+
18
+ As a plugin:
19
+
20
+ $ rails plugin install git://github.com/Juanmcuello/jqgrid_for_rails.git
17
21
 
18
22
 
19
23
  == Views
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "jqgrid_for_rails/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "jqgrid_for_rails"
7
+ s.version = JqgridForRails::VERSION.dup
8
+ s.platform = Gem::Platform::RUBY
9
+ s.summary = "Simple solution to create jqgrids easily using Rails"
10
+ s.email = "juanmacuello@gmail.com"
11
+ s.homepage = "http://github.com/Juanmcuello/jqgrid_for_rails"
12
+ s.description = "Simple solution to create jqgrids easily using Rails"
13
+ s.authors = ['Juan Manuel Cuello']
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_dependency("will_paginate")
21
+ end
22
+
@@ -60,7 +60,7 @@ module JqgridsHelper
60
60
  #
61
61
  # jqgrid 'invoices_list', options, grid_options
62
62
  #
63
- def jqgrid grid_id, options = {}, grid_options = {}, nav_options = {}
63
+ def jqgrid grid_id, options = {}, grid_options = {}, *nav_options
64
64
 
65
65
  html_output = []
66
66
 
@@ -71,12 +71,12 @@ module JqgridsHelper
71
71
  # Pager
72
72
  if grid_options[:pager]
73
73
 
74
- pager_id = id_from_pager_option(grid_options[:pager])
74
+ pager_id = pager_id_from_options(grid_options)
75
75
 
76
76
  html_output << content_tag(:div, nil, :id => pager_id) if options[:html_tags]
77
77
 
78
- if nav_options
79
- js_output << "jQuery(\"##{grid_id}\").jqGrid(\"navGrid\", \"##{pager_id}\", #{nav_options.to_json});"
78
+ unless nav_options.empty?
79
+ js_output << "jQuery(\"##{grid_id}\").jqGrid(\"navGrid\", \"##{pager_id}\", #{format_nav_options(nav_options)});"
80
80
  end
81
81
  end
82
82
 
@@ -89,12 +89,40 @@ module JqgridsHelper
89
89
 
90
90
  private
91
91
 
92
+ # Extracts the pager id from the options hash.
93
+ #
94
+ # jQgrid accepts three different formats to set the pager id option.
95
+ #
96
+ # 1 - jQuery('#my_pager_div')
97
+ # 2 - #my_pager_div
98
+ # 3 - my_pager_div
99
+ #
100
+ # === Example
101
+ #
102
+ # pager_id_from_options({:pager => "jQuery('#my_pager_id')"})
103
+ # => 'my_pager_id'
104
+ #
105
+ def pager_id_from_options options
106
+ pager_option = options[:pager]
107
+
108
+ # jQuery('#my_pager_div')
109
+ if pager_option =~ /^jQuery\(('|")#\w+('|")\)$/
110
+ pager_option.match(/#\w+/).to_s[1..-1]
111
+ # #my_pager_div
112
+ elsif pager_option =~ /^#\w+$/
113
+ pager_option.match(/#\w+/).to_s[1..-1]
114
+ # my_pager_div
115
+ else
116
+ pager_option
117
+ end
118
+ end
119
+
92
120
  def wrap_with_document_ready! str
93
121
  str.replace("jQuery(document).ready(function() {#{str}});")
94
122
  end
95
123
 
96
- def id_from_pager_option pager_option
97
- pager_option.match(/#\w+/).to_s[1..-1]
124
+ def format_nav_options nav_options
125
+ nav_options.map {|e| (e || {}).to_json}.join(', ')
98
126
  end
99
127
 
100
128
  end
@@ -0,0 +1,4 @@
1
+ module JqgridForRails
2
+ VERSION = "0.2.0".freeze
3
+ end
4
+
@@ -50,11 +50,41 @@ class JqgridsHelperTest < Test::Unit::TestCase
50
50
  jQuery("#' + grid_id + '").jqGrid({
51
51
  "pager":jQuery(\'#' + pager_id + '\')
52
52
  });
53
- jQuery("#grid_id").jqGrid("navGrid", "#gridpager", {});
54
53
  });'
55
54
  expected << js.gsub(/\n\s+/, '') + "\n"
56
55
  expected << '</script>'
57
56
 
58
57
  end
59
58
 
59
+ def test_jqgrid_nav_options
60
+ @template = MockView.new
61
+
62
+ grid_id = 'grid_id'
63
+ pager_id = 'pager_id'
64
+ grid_options = {:pager => "##{pager_id}"}
65
+ options = {:on_document_ready => true, :html_tags => true}
66
+ nav_items = {:del => true}
67
+ del_config = {:closeOnEscape => true}
68
+
69
+ expected = '<table id="'+grid_id+'"></table>' + "\n"
70
+ expected << '<div id="'+pager_id+'"></div>' + "\n"
71
+ expected << "<script>" + "\n"
72
+ str = 'jQuery("#'+grid_id+'").jqGrid({"pager":"#'+pager_id+'"});'
73
+ str << 'jQuery("#'+grid_id+'").jqGrid("navGrid", "#'+pager_id+'", {"del":true}, {}, {}, {"closeOnEscape":true});'
74
+ expected << "jQuery(document).ready(function() {#{str}});" + "\n"
75
+ expected << "</script>"
76
+
77
+ assert_equal(expected, @template.jqgrid(grid_id,options,grid_options,nav_items,nil,nil,del_config))
78
+ end
79
+
80
+ def testi_pager_id_from_options
81
+ @template = MockView.new
82
+
83
+ assert_equal 'my_pager_div', @template.send(:pager_id_from_options, {:pager => "jQuery('#my_pager_div')"})
84
+ assert_equal 'my_pager_div', @template.send(:pager_id_from_options, {:pager => 'jQuery("#my_pager_div")'})
85
+ assert_equal 'my_pager_div', @template.send(:pager_id_from_options, {:pager => "#my_pager_div"})
86
+ assert_equal 'my_pager_div', @template.send(:pager_id_from_options, {:pager => "my_pager_div"})
87
+ end
88
+
89
+
60
90
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jqgrid_for_rails
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Juan Manuel Cuello
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-06 00:00:00 -03:00
18
+ date: 2011-01-25 00:00:00 -03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -42,14 +42,17 @@ extra_rdoc_files: []
42
42
 
43
43
  files:
44
44
  - .gitignore
45
+ - CHANGELOG.rdoc
45
46
  - MIT-LICENSE
46
47
  - README.rdoc
47
48
  - Rakefile
48
49
  - install.rb
50
+ - jqgrid_for_rails.gemspec
49
51
  - lib/app/helpers/jqgrids_helper.rb
50
52
  - lib/jqgrid_for_rails.rb
51
53
  - lib/jqgrid_for_rails/controllers/helpers.rb
52
54
  - lib/jqgrid_for_rails/core_ext.rb
55
+ - lib/jqgrid_for_rails/version.rb
53
56
  - lib/tasks/jqgrid_for_rails.rake
54
57
  - rails/init.rb
55
58
  - test/controllers/helpers_test.rb