grapple 0.1.8 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/app/assets/javascripts/grapple-history.js +114 -32
- data/app/assets/javascripts/grapple-jquery.js +19 -34
- data/app/assets/javascripts/grapple.js +0 -3
- data/config/locales/en.yml +4 -1
- data/lib/grapple/base_table_builder.rb +30 -1
- data/lib/grapple/components.rb +2 -0
- data/lib/grapple/components/actions.rb +17 -0
- data/lib/grapple/components/base_component.rb +10 -3
- data/lib/grapple/components/column_headings.rb +4 -0
- data/lib/grapple/components/html_header.rb +1 -0
- data/lib/grapple/components/kaminari_pagination.rb +2 -2
- data/lib/grapple/components/search_query_field.rb +1 -1
- data/lib/grapple/components/will_paginate_infobar.rb +3 -6
- data/lib/grapple/components/will_paginate_pagination.rb +2 -1
- data/lib/grapple/helpers/table_helper.rb +10 -0
- data/spec/builders/ajax_data_grid_builder_spec.rb +2 -2
- data/spec/builders/html_table_builder_spec.rb +4 -5
- data/spec/components/will_paginate_spec.rb +1 -6
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d49408d1a5288a086cb3cb5016d2c6e68b09691
|
4
|
+
data.tar.gz: 6cbd12c3529aa3bb347771430e6bffab4926924b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4fb86706c0372306b4381daa0224257b16589318d2726e9451294696e2bc5707359c29b6a2fcb907266bdca4493f7d385975b0c7e0d501cb6ec0f5cd017bb5c
|
7
|
+
data.tar.gz: 13e5c2b134d2930a836db20d3c8ea619cafccd0f69e43201171f178f1b1e3d9244468973878b8b85b4f3cd5c2d8da8cbc667df5ce9d9603ff695f612733f61f2
|
data/README.md
CHANGED
@@ -189,7 +189,7 @@ Render the table using `table_for` in `app/views/posts/_table.html.erb`
|
|
189
189
|
|
190
190
|
## History w/AJAX (back button)
|
191
191
|
|
192
|
-
|
192
|
+
Uses the native `window.history` API by default. If History.js is present it will use that instead for compatibility with older browsers (https://github.com/browserstate/history.js/).
|
193
193
|
|
194
194
|
``` javascript
|
195
195
|
// app/assets/javascripts/application.js
|
@@ -4,25 +4,62 @@
|
|
4
4
|
var urlQuery = Grapple.Util.urlQuery,
|
5
5
|
parseUrlQuery = Grapple.Util.parseUrlQuery;
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
this.api = History;
|
7
|
+
// History.js for backwards compatibility with older browsers
|
8
|
+
// https://github.com/browserstate/history.js/
|
9
|
+
var LegacyHistory = function() {
|
10
|
+
var api = History;
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
}
|
12
|
+
// Initialization of history.js can be delayed
|
13
|
+
// if it was do it now
|
14
|
+
if(api.options && api.options.delayInit) {
|
15
|
+
api.options.delayInit = false;
|
16
|
+
api.init();
|
19
17
|
}
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
this.api = api;
|
19
|
+
};
|
20
|
+
|
21
|
+
LegacyHistory.prototype = {
|
22
|
+
push: function(params) {
|
23
|
+
return this.api.pushState(null, document.title, '?' + params);
|
24
|
+
},
|
25
|
+
get: function() {
|
26
|
+
return urlQuery(this.api.getState().url);
|
27
|
+
},
|
28
|
+
bind: function(callback) {
|
29
|
+
$(window).bind('statechange', callback);
|
30
|
+
},
|
31
|
+
unbind: function(callback) {
|
32
|
+
$(window).unbind('statechange', callback);
|
23
33
|
}
|
24
|
-
|
25
|
-
|
34
|
+
};
|
35
|
+
|
36
|
+
// Native Browser History API
|
37
|
+
var ModernHistory = function() {
|
38
|
+
|
39
|
+
};
|
40
|
+
|
41
|
+
ModernHistory.prototype = {
|
42
|
+
push: function(params) {
|
43
|
+
if(window.history && window.history.pushState) {
|
44
|
+
return window.history.pushState(params, document.title, '?' + params);
|
45
|
+
}
|
46
|
+
},
|
47
|
+
get: function() {
|
48
|
+
if(window.history) {
|
49
|
+
return window.history.state || urlQuery(document.location.toString());
|
50
|
+
}
|
51
|
+
},
|
52
|
+
bind: function(callback) {
|
53
|
+
$(window).bind('popstate', callback);
|
54
|
+
},
|
55
|
+
unbind: function(callback) {
|
56
|
+
$(window).unbind('popstate', callback);
|
57
|
+
}
|
58
|
+
};
|
59
|
+
|
60
|
+
var GrappleHistory = function(grappleTable) {
|
61
|
+
this.grappleTable = grappleTable;
|
62
|
+
this._historyChangeCallback = null;
|
26
63
|
};
|
27
64
|
|
28
65
|
// Don't clutter the url with rails form parameters
|
@@ -30,10 +67,20 @@ GrappleHistory.IGNORE_PARAMS = { 'utf8': true, 'authenticity_token': true };
|
|
30
67
|
|
31
68
|
GrappleHistory.prototype = {
|
32
69
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
70
|
+
init: function() {
|
71
|
+
// Use the History.js wrapper if History.js has been loaded
|
72
|
+
this.api = typeof History !== 'undefined' && History.init ? new LegacyHistory() : new ModernHistory();
|
73
|
+
this._subscribeToTableChange();
|
74
|
+
this._subscribeToHistoryChange();
|
75
|
+
},
|
76
|
+
|
77
|
+
/**
|
78
|
+
* Add an entry to the history
|
79
|
+
* @param {String} params
|
80
|
+
*/
|
81
|
+
_addHistoryEntry: function(params) {
|
82
|
+
var namespace = this.grappleTable.namespace;
|
83
|
+
var historyParams = parseUrlQuery(this.api.get());
|
37
84
|
var newParams = parseUrlQuery(params);
|
38
85
|
|
39
86
|
// Remove any parameters from the current state
|
@@ -57,14 +104,45 @@ GrappleHistory.prototype = {
|
|
57
104
|
historyParams[x] = newParams[x];
|
58
105
|
}
|
59
106
|
|
60
|
-
this.api.
|
107
|
+
this.api.push($.param(historyParams));
|
61
108
|
},
|
62
109
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
110
|
+
/**
|
111
|
+
* Listen for changes to the table to add them to the history
|
112
|
+
*/
|
113
|
+
_subscribeToTableChange: function() {
|
114
|
+
var self = this;
|
115
|
+
this._beforeLoadCallback = function(e, params) {
|
116
|
+
self._unsubscribeFromTableChange();
|
117
|
+
self._unsubscribeFromHistoryChange();
|
118
|
+
// Don't add params to history if this was triggered by history change
|
119
|
+
if(self._ignoreNextLoad) {
|
120
|
+
self._ignoreNextLoad = false;
|
121
|
+
}
|
122
|
+
else {
|
123
|
+
self._addHistoryEntry(params);
|
124
|
+
}
|
125
|
+
};
|
126
|
+
this.grappleTable.element.on('grapple:before_load', this._beforeLoadCallback);
|
127
|
+
},
|
128
|
+
|
129
|
+
/**
|
130
|
+
* Stop listening for changes to the table
|
131
|
+
*/
|
132
|
+
_unsubscribeFromTableChange: function() {
|
133
|
+
if(this._beforeLoadCallback) {
|
134
|
+
this.grappleTable.element.unbind('grapple:before_load', this._beforeLoadCallback);
|
135
|
+
this._beforeLoadCallback = null;
|
136
|
+
}
|
137
|
+
},
|
138
|
+
|
139
|
+
/**
|
140
|
+
* Listen for changes to the history (back button clicks)
|
141
|
+
*/
|
142
|
+
_subscribeToHistoryChange: function() {
|
143
|
+
var api = this.api, namespace = this.grappleTable.namespace, self = this;
|
144
|
+
this._historyChangeCallback = function(event) {
|
145
|
+
var params = parseUrlQuery(api.get());
|
68
146
|
// Only include the parameters for this namespace
|
69
147
|
if(namespace) {
|
70
148
|
var r = new RegExp('^' + namespace + '\\[([^\\]]+)\\]$')
|
@@ -74,15 +152,19 @@ GrappleHistory.prototype = {
|
|
74
152
|
}
|
75
153
|
}
|
76
154
|
}
|
77
|
-
|
155
|
+
self._ignoreNextLoad = true;
|
156
|
+
self.grappleTable.loadTable($.param(params));
|
78
157
|
};
|
79
|
-
|
158
|
+
this.api.bind(this._historyChangeCallback);
|
80
159
|
},
|
81
160
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
161
|
+
/**
|
162
|
+
* Stop listening for history changes
|
163
|
+
*/
|
164
|
+
_unsubscribeFromHistoryChange: function() {
|
165
|
+
if(this._historyChangeCallback) {
|
166
|
+
this.api.unbind(this._historyChangeCallback);
|
167
|
+
this._historyChangeCallback = null;
|
86
168
|
}
|
87
169
|
}
|
88
170
|
|
@@ -1,8 +1,5 @@
|
|
1
1
|
(function(Grapple, $) {
|
2
2
|
'use strict';
|
3
|
-
|
4
|
-
var urlQuery = Grapple.Util.urlQuery,
|
5
|
-
parseUrlQuery = Grapple.Util.parseUrlQuery;
|
6
3
|
|
7
4
|
var overrideLink = function(clickable, anchor, callback) {
|
8
5
|
var href = $(anchor).attr('href');
|
@@ -15,8 +12,8 @@ var overrideLink = function(clickable, anchor, callback) {
|
|
15
12
|
/**
|
16
13
|
* Creates a new instance of the Grapple AJAX widget.
|
17
14
|
*
|
18
|
-
* @param {String} Selector for the table container element.
|
19
|
-
* @param {Object} Hash of options for the table (url, namespace, history)
|
15
|
+
* @param {String} element - Selector for the table container element.
|
16
|
+
* @param {Object} options - Hash of options for the table (url, namespace, history)
|
20
17
|
*/
|
21
18
|
var GrappleTable = function(element, options) {
|
22
19
|
options = options || {};
|
@@ -24,14 +21,12 @@ var GrappleTable = function(element, options) {
|
|
24
21
|
this.url = options.url || this.element.data('grapple-ajax-url');
|
25
22
|
this.namespace = options.namespace || this.element.data('grapple-ajax-namespace') || null;
|
26
23
|
this.currentParams = options.params || '';
|
24
|
+
this.plugins = {};
|
27
25
|
if(typeof options.history !== 'undefined' && options.history !== true) {
|
28
|
-
this.history = options.history;
|
26
|
+
this.plugins.history = options.history;
|
29
27
|
}
|
30
28
|
else if(this.element.data('grapple-ajax-history') == 1 || options.history === true) {
|
31
|
-
this.history = new Grapple.History(this
|
32
|
-
}
|
33
|
-
else {
|
34
|
-
this.history = null;
|
29
|
+
this.plugins.history = new Grapple.History(this);
|
35
30
|
}
|
36
31
|
this.init();
|
37
32
|
};
|
@@ -44,7 +39,7 @@ GrappleTable.NON_TABLE_RESPONSE = '<!DOCTYPE html>';
|
|
44
39
|
GrappleTable.prototype = {
|
45
40
|
|
46
41
|
/**
|
47
|
-
*
|
42
|
+
* Initialize the grapple table
|
48
43
|
*/
|
49
44
|
init: function() {
|
50
45
|
var self = this;
|
@@ -56,39 +51,29 @@ GrappleTable.prototype = {
|
|
56
51
|
self.initSorting();
|
57
52
|
self.initSearchForm();
|
58
53
|
self.initPagination();
|
59
|
-
self.
|
54
|
+
self.initPlugins();
|
60
55
|
|
61
56
|
self.element.removeClass(GrappleTable.CSS_AJAX_LOADING);
|
62
57
|
},
|
63
58
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
this.
|
70
|
-
self.onHistoryChange(params);
|
71
|
-
});
|
59
|
+
/**
|
60
|
+
* Initialize plugins
|
61
|
+
*/
|
62
|
+
initPlugins: function() {
|
63
|
+
for(var name in this.plugins) {
|
64
|
+
this.plugins[name].init();
|
72
65
|
}
|
73
66
|
},
|
74
67
|
|
75
|
-
onHistoryChange: function(params) {
|
76
|
-
this._showLoading();
|
77
|
-
this._updateTable($.param(params));
|
78
|
-
},
|
79
|
-
|
80
68
|
/**
|
81
|
-
*
|
69
|
+
* Load the table contents
|
70
|
+
* @param {String} params - Query string of parameters to load the table with
|
71
|
+
* @fires Grapple#grapple:before_load
|
72
|
+
* @fires Grapple#grapple:after_load
|
82
73
|
*/
|
83
74
|
loadTable: function(params) {
|
84
|
-
this.element.trigger('grapple:before_load');
|
75
|
+
this.element.trigger('grapple:before_load', params);
|
85
76
|
this._showLoading();
|
86
|
-
|
87
|
-
if(this.history) {
|
88
|
-
this.history.unsubscribe();
|
89
|
-
this.history.add(params);
|
90
|
-
}
|
91
|
-
|
92
77
|
this._updateTable(params);
|
93
78
|
},
|
94
79
|
|
@@ -117,7 +102,7 @@ GrappleTable.prototype = {
|
|
117
102
|
}
|
118
103
|
$.ajax(url, {
|
119
104
|
success: function(data) {
|
120
|
-
// HACK
|
105
|
+
// HACK: handle full page responses
|
121
106
|
var nonTableKeyIndex = data.indexOf(GrappleTable.NON_TABLE_RESPONSE);
|
122
107
|
if(nonTableKeyIndex > -1 && nonTableKeyIndex < 100) {
|
123
108
|
data = "Failed to load table";
|
data/config/locales/en.yml
CHANGED
@@ -2,6 +2,12 @@ module Grapple
|
|
2
2
|
class BaseTableBuilder
|
3
3
|
|
4
4
|
# Create a helper
|
5
|
+
# @param name [Symbol]
|
6
|
+
# The name of the helper
|
7
|
+
# @param klass [Grapple::Components::BaseComponent]
|
8
|
+
# The component class
|
9
|
+
# @param settings [Hash]
|
10
|
+
# Settings for the component
|
5
11
|
def self.helper(name, klass, settings = {})
|
6
12
|
class_eval <<-RUBY_EVAL
|
7
13
|
def #{name}(*arguments, &block)
|
@@ -13,6 +19,10 @@ module Grapple
|
|
13
19
|
end
|
14
20
|
|
15
21
|
# Update settings for a helper
|
22
|
+
# @param helper_name [Symbol]
|
23
|
+
# The name of the helper
|
24
|
+
# @param options [Hash]
|
25
|
+
# Settings to update for the component
|
16
26
|
def self.configure(helper_name, *options)
|
17
27
|
settings = options[0] || {}
|
18
28
|
method = :"settings_for_#{helper_name}"
|
@@ -24,7 +34,22 @@ module Grapple
|
|
24
34
|
define_singleton_method(method) { settings }
|
25
35
|
end
|
26
36
|
|
27
|
-
|
37
|
+
# An Array of columns
|
38
|
+
# @return [Array<Hash>]
|
39
|
+
attr_reader :columns
|
40
|
+
|
41
|
+
# An Array, ActiveRecord::Collection or Enumerable of records to be displayed in the table
|
42
|
+
# @return [Enumerable]
|
43
|
+
attr_reader :records
|
44
|
+
|
45
|
+
# @return [ActionView::Base]
|
46
|
+
attr_reader :template
|
47
|
+
|
48
|
+
# Request parameters
|
49
|
+
attr_reader :params
|
50
|
+
|
51
|
+
# @return [String] namespace for the grapple table
|
52
|
+
attr_reader :namespace
|
28
53
|
|
29
54
|
def initialize(template, columns, records, params = {}, *options)
|
30
55
|
@template = template
|
@@ -37,14 +62,18 @@ module Grapple
|
|
37
62
|
@helper_instances = {}
|
38
63
|
end
|
39
64
|
|
65
|
+
# Default options for the component
|
66
|
+
# @return [Hash]
|
40
67
|
def default_options
|
41
68
|
{ }
|
42
69
|
end
|
43
70
|
|
71
|
+
# HTML to insert before the <table> tag
|
44
72
|
def before_table
|
45
73
|
''
|
46
74
|
end
|
47
75
|
|
76
|
+
# HTML to insert after the </table> tag
|
48
77
|
def after_table
|
49
78
|
''
|
50
79
|
end
|
data/lib/grapple/components.rb
CHANGED
@@ -1,5 +1,22 @@
|
|
1
1
|
module Grapple
|
2
2
|
module Components
|
3
|
+
|
4
|
+
# Render links that apply to the table
|
5
|
+
# @example
|
6
|
+
# <%
|
7
|
+
# actions = [
|
8
|
+
# { label: :new_user, url: new_user_path },
|
9
|
+
# { label: :export_users, url: export_users_path }
|
10
|
+
# ]
|
11
|
+
# %>
|
12
|
+
# <%= table_for(columns, @users) do |t| %>
|
13
|
+
# <%= t.header do %>
|
14
|
+
# <%= t.toolbar do %>
|
15
|
+
# <%= t.actions actions %>
|
16
|
+
# <% end %>
|
17
|
+
# <%= t.column_headings %>
|
18
|
+
# <% end %>
|
19
|
+
# <% end %>
|
3
20
|
class Actions < HtmlComponent
|
4
21
|
|
5
22
|
setting :link_to_helper, :link_to
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module Grapple
|
2
2
|
module Components
|
3
|
+
|
4
|
+
# Base class for components
|
3
5
|
class BaseComponent
|
4
6
|
|
5
7
|
cattr_accessor :default_settings
|
@@ -11,8 +13,12 @@ module Grapple
|
|
11
13
|
@@default_settings[self.name][name] = default
|
12
14
|
end
|
13
15
|
|
14
|
-
attr_reader :columns
|
15
|
-
|
16
|
+
attr_reader :columns
|
17
|
+
attr_reader :records
|
18
|
+
attr_reader :template
|
19
|
+
attr_reader :params
|
20
|
+
attr_reader :builder
|
21
|
+
|
16
22
|
def initialize(columns, records, template, params, builder, settings = {})
|
17
23
|
@template = template
|
18
24
|
@columns = columns
|
@@ -23,7 +29,7 @@ module Grapple
|
|
23
29
|
self.send(:"#{name}=", value)
|
24
30
|
end
|
25
31
|
end
|
26
|
-
|
32
|
+
|
27
33
|
def render(*options, &block)
|
28
34
|
raise StandardError.new("Component must override render method")
|
29
35
|
end
|
@@ -71,6 +77,7 @@ module Grapple
|
|
71
77
|
template.with_output_buffer(&block).html_safe
|
72
78
|
end
|
73
79
|
|
80
|
+
# Renders a block if present, otherwise renders the components with options
|
74
81
|
def block_or_components(components, options, &block)
|
75
82
|
block.nil? ? render_components(components, options, &block).join : capture_block(&block)
|
76
83
|
end
|
@@ -34,6 +34,10 @@ module Grapple
|
|
34
34
|
content = label
|
35
35
|
end
|
36
36
|
|
37
|
+
if column[:class]
|
38
|
+
column[:class].split(" ").each{|c| cell_classes << c}
|
39
|
+
end
|
40
|
+
|
37
41
|
cell_classes = ' class="' + cell_classes.join(' ') + '"'
|
38
42
|
title = column[:title] ? " title=\"#{h(column[:title])}\"" : ''
|
39
43
|
liner_classes = liner_classes.length ? " class=\"#{liner_classes.join(" ")}\"" : ''
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module Grapple
|
2
2
|
module Components
|
3
|
-
# Generates paging links using
|
3
|
+
# Generates paging links using Kaminari.
|
4
4
|
#
|
5
5
|
# @example
|
6
|
-
# <%= table_for(columns, Post.
|
6
|
+
# <%= table_for(columns, Post.page(2)) do |t| %>
|
7
7
|
# <%= t.footer do %>
|
8
8
|
# <%= t.pagination %>
|
9
9
|
# <% end %>
|
@@ -9,7 +9,7 @@ module Grapple
|
|
9
9
|
template.text_field_tag(
|
10
10
|
search_query_param.to_s,
|
11
11
|
params[search_query_param.to_sym],
|
12
|
-
{ :
|
12
|
+
{ class: search_query_field_class, placeholder: I18n.translate(:search) }
|
13
13
|
)
|
14
14
|
end
|
15
15
|
|
@@ -2,9 +2,6 @@ module Grapple
|
|
2
2
|
module Components
|
3
3
|
class WillPaginateInfobar < HtmlComponent
|
4
4
|
|
5
|
-
setting :message, "Displaying %s - %s of %s results"
|
6
|
-
setting :no_results_message, "0 results"
|
7
|
-
|
8
5
|
def render
|
9
6
|
if records.total_entries > 0
|
10
7
|
start_range = records.offset + 1
|
@@ -14,12 +11,12 @@ module Grapple
|
|
14
11
|
end_range = ActiveSupport::NumberHelper.number_to_delimited(end_range)
|
15
12
|
total = ActiveSupport::NumberHelper.number_to_delimited(records.total_entries)
|
16
13
|
|
17
|
-
html =
|
14
|
+
html = I18n.translate(:displaying_x_y_of_z_results, x: start_range, y: end_range, z: total)
|
18
15
|
else
|
19
|
-
html =
|
16
|
+
html = I18n.translate(:zero_results)
|
20
17
|
end
|
21
18
|
|
22
|
-
builder.row "<th colspan=\"#{num_columns}\">#{html}</th>", :
|
19
|
+
builder.row "<th colspan=\"#{num_columns}\">#{html}</th>", class: 'infobar'
|
23
20
|
end
|
24
21
|
|
25
22
|
end
|
@@ -16,9 +16,10 @@ module Grapple
|
|
16
16
|
|
17
17
|
def render(paginate_parameters = {})
|
18
18
|
td_class = ""
|
19
|
+
|
19
20
|
if records.instance_of?(Array)
|
20
21
|
html = ' '
|
21
|
-
elsif
|
22
|
+
elsif params.has_key?(:query) && records.empty?
|
22
23
|
html = h(t(no_results_message))
|
23
24
|
td_class = "class='text-left'"
|
24
25
|
else
|
@@ -5,6 +5,16 @@ module Grapple
|
|
5
5
|
@@builder = Grapple::DataGridBuilder
|
6
6
|
mattr_accessor :builder
|
7
7
|
|
8
|
+
# Render a grapple table
|
9
|
+
# @param columns [Enumerable]
|
10
|
+
# @param records [Enumerable]
|
11
|
+
# @option args :container [Boolean]
|
12
|
+
# If true the table will be rendered with a container div around it
|
13
|
+
# @option args :html [Hash]
|
14
|
+
# HTML attributes for the `<table>` element
|
15
|
+
# @option args :builder [Grapple::BaseTableBuilder]
|
16
|
+
# The table builder to use to render the table
|
17
|
+
# @option args :params
|
8
18
|
def table_for(columns, records, *args, &block)
|
9
19
|
options = args[0] || {}
|
10
20
|
# Don't render the container for AJAX requests by default
|
@@ -9,11 +9,11 @@ describe 'Ajax Data Grid Builder' do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
it "container_attributes should be correct" do
|
12
|
-
|
12
|
+
builder = Grapple::AjaxDataGridBuilder.new(self, [], [], {}, id: 'my_table')
|
13
|
+
attr = builder.container_attributes()
|
13
14
|
expect(attr[:id]).to eq "my_table"
|
14
15
|
expect(attr[:class]).to include("grapple")
|
15
16
|
expect(attr[:data]['grapple-ajax-url']).to eq '/mock/path'
|
16
|
-
puts attr
|
17
17
|
end
|
18
18
|
|
19
19
|
end
|
@@ -9,16 +9,15 @@ describe 'Base Table Builder' do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
it "container_attributes should be correct" do
|
12
|
-
|
12
|
+
builder = Grapple::HtmlTableBuilder.new(self, users_columns, users_records, {}, id: 'my_table')
|
13
|
+
attr = builder.container_attributes()
|
13
14
|
expect(attr[:class]).to include("grapple")
|
14
15
|
end
|
15
16
|
|
16
17
|
it "table should be correct" do
|
17
18
|
builder = Grapple::HtmlTableBuilder.new(self, users_columns, users_records, {})
|
18
19
|
|
19
|
-
html = builder.table("<tr><td>TEST</td></tr>")
|
20
|
-
|
21
|
-
#puts html
|
20
|
+
html = builder.table("<tr><td>TEST</td></tr>".html_safe)
|
22
21
|
|
23
22
|
expect(html).to have_tag('table') do
|
24
23
|
with_tag("tr", count: 1) do
|
@@ -29,4 +28,4 @@ describe 'Base Table Builder' do
|
|
29
28
|
end
|
30
29
|
end
|
31
30
|
|
32
|
-
end
|
31
|
+
end
|
@@ -20,14 +20,9 @@ describe 'will_paginate' do
|
|
20
20
|
it "should be valid" do
|
21
21
|
records = User.all.paginate({ page: 1, per_page: 3 })
|
22
22
|
builder = Grapple::DataGridBuilder.new(self, columns, records, {})
|
23
|
-
puts builder.infobar()
|
24
|
-
puts builder.pagination()
|
25
23
|
|
26
24
|
records = User.where('id < 0').paginate({ page: 1, per_page: 3 })
|
27
|
-
builder = Grapple::DataGridBuilder.new(self, columns, records, {:query => 'test'})
|
28
|
-
puts builder.infobar()
|
29
|
-
puts builder.pagination()
|
30
|
-
|
25
|
+
builder = Grapple::DataGridBuilder.new(self, columns, records, {:query => 'test'})
|
31
26
|
end
|
32
27
|
|
33
28
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grapple
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edward Potocko
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2020-12-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: actionpack
|
@@ -18,28 +18,28 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: 4.2.11.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - ">="
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version:
|
28
|
+
version: 4.2.11.1
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: activesupport
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
33
|
- - ">="
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version:
|
35
|
+
version: 4.2.11.1
|
36
36
|
type: :runtime
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
40
|
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version:
|
42
|
+
version: 4.2.11.1
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
name: rspec-rails
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
@@ -88,28 +88,28 @@ dependencies:
|
|
88
88
|
requirements:
|
89
89
|
- - ">="
|
90
90
|
- !ruby/object:Gem::Version
|
91
|
-
version:
|
91
|
+
version: 4.2.11.1
|
92
92
|
type: :development
|
93
93
|
prerelease: false
|
94
94
|
version_requirements: !ruby/object:Gem::Requirement
|
95
95
|
requirements:
|
96
96
|
- - ">="
|
97
97
|
- !ruby/object:Gem::Version
|
98
|
-
version:
|
98
|
+
version: 4.2.11.1
|
99
99
|
- !ruby/object:Gem::Dependency
|
100
100
|
name: activerecord
|
101
101
|
requirement: !ruby/object:Gem::Requirement
|
102
102
|
requirements:
|
103
103
|
- - ">="
|
104
104
|
- !ruby/object:Gem::Version
|
105
|
-
version:
|
105
|
+
version: 4.2.11.1
|
106
106
|
type: :development
|
107
107
|
prerelease: false
|
108
108
|
version_requirements: !ruby/object:Gem::Requirement
|
109
109
|
requirements:
|
110
110
|
- - ">="
|
111
111
|
- !ruby/object:Gem::Version
|
112
|
-
version:
|
112
|
+
version: 4.2.11.1
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: will_paginate
|
115
115
|
requirement: !ruby/object:Gem::Requirement
|
@@ -207,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
207
207
|
version: '0'
|
208
208
|
requirements: []
|
209
209
|
rubyforge_project:
|
210
|
-
rubygems_version: 2.
|
210
|
+
rubygems_version: 2.6.14.1
|
211
211
|
signing_key:
|
212
212
|
specification_version: 4
|
213
213
|
summary: Customizable data grid for Rails
|