grapple 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/app/assets/javascripts/grapple-jquery.js +1 -1
- data/lib/grapple/ajax_data_grid_builder.rb +4 -2
- data/lib/grapple/components/actions.rb +2 -3
- data/lib/grapple/components/base_component.rb +5 -0
- data/lib/grapple/components/column_headings.rb +6 -3
- data/lib/grapple/components/html_row.rb +1 -0
- data/lib/grapple/components/search_form.rb +5 -1
- data/lib/grapple/components/search_query_field.rb +5 -1
- data/lib/grapple/components/search_submit.rb +3 -1
- data/lib/grapple/html_table_builder.rb +1 -0
- data/spec/builders/base_table_builder_spec.rb +11 -0
- data/spec/builders/data_grid_builder_spec.rb +35 -0
- data/spec/builders/html_table_builder_spec.rb +32 -0
- data/spec/components/search_form_spec.rb +1 -1
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05a1ffcbbb6eeed509347c518f1690d9d2eb8874
|
4
|
+
data.tar.gz: f4d3ba52e44f0a96d25cea11ffdd31d91b7db986
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c550c8ab022ee4f4dfef99e54c84815a0db0e27bba5c1179e46a5f764949b8a1ab5e0bbc8bdffbefb84de45f0c6b46156c337fe847b95855c3c640384aecf9dc
|
7
|
+
data.tar.gz: f95c0dbc95ad4b2b1df1119da1d40caadf932d03dc4094556fc315ff4042e777f081a44b878d62381d708129ae081f75c2993dda809798b3abd078aa1dcb9033
|
@@ -16,7 +16,7 @@ var overrideLink = function(clickable, anchor, callback) {
|
|
16
16
|
* Creates a new instance of the Grapple AJAX widget.
|
17
17
|
*
|
18
18
|
* @param {String} Selector for the table container element.
|
19
|
-
* @param {Object} Hash of options for the table (url, history)
|
19
|
+
* @param {Object} Hash of options for the table (url, namespace, history)
|
20
20
|
*/
|
21
21
|
var GrappleTable = function(element, options) {
|
22
22
|
options = options || {};
|
@@ -13,7 +13,9 @@ module Grapple
|
|
13
13
|
|
14
14
|
data = {
|
15
15
|
"grapple-ajax-url" => options[:url] || template.url_for(action: 'table'),
|
16
|
-
|
16
|
+
# History is disabled by default, override container_attributes
|
17
|
+
# in an initializer to enable it by default
|
18
|
+
"grapple-ajax-history" => options[:history] == true ? '1' : '0'
|
17
19
|
}
|
18
20
|
|
19
21
|
return {
|
@@ -35,4 +37,4 @@ module Grapple
|
|
35
37
|
end
|
36
38
|
|
37
39
|
end
|
38
|
-
end
|
40
|
+
end
|
@@ -10,9 +10,8 @@ module Grapple
|
|
10
10
|
if action.kind_of?(String)
|
11
11
|
html << action
|
12
12
|
else
|
13
|
-
|
14
|
-
|
15
|
-
url = action.delete(:url)
|
13
|
+
label = t(action[:label])
|
14
|
+
url = action[:url]
|
16
15
|
html << template.send(link_to_helper, label, url, action)
|
17
16
|
end
|
18
17
|
end
|
@@ -50,7 +50,10 @@ module Grapple
|
|
50
50
|
end
|
51
51
|
|
52
52
|
# Shortcut for translations
|
53
|
+
# Won't try to translate strings, just symbols
|
53
54
|
def t(*args)
|
55
|
+
# Don't translate strings
|
56
|
+
return args[0] if args.length == 1 && args[0].kind_of?(String)
|
54
57
|
begin
|
55
58
|
return template.t(*args) if template.method_defined?(:t)
|
56
59
|
ensure
|
@@ -58,6 +61,7 @@ module Grapple
|
|
58
61
|
end
|
59
62
|
end
|
60
63
|
|
64
|
+
# Number of columns in the table
|
61
65
|
def num_columns
|
62
66
|
@columns.length
|
63
67
|
end
|
@@ -71,6 +75,7 @@ module Grapple
|
|
71
75
|
block.nil? ? render_components(components, options, &block).join : capture_block(&block)
|
72
76
|
end
|
73
77
|
|
78
|
+
# Render an array of components
|
74
79
|
def render_components(components, options, &block)
|
75
80
|
html = []
|
76
81
|
components.each do |component|
|
@@ -4,12 +4,13 @@ module Grapple
|
|
4
4
|
|
5
5
|
setting :alignment_classes, { left: 'text-left', center: 'text-center', right: 'text-right' }
|
6
6
|
setting :tooltip_class, 'table-tooltip'
|
7
|
+
setting :row_class, 'column-headers'
|
7
8
|
|
8
9
|
def render(url_params = {})
|
9
10
|
cols = columns.collect do |column|
|
10
11
|
indent + column_header(column, url_params)
|
11
12
|
end
|
12
|
-
builder.row cols.join("\n"), :class =>
|
13
|
+
builder.row cols.join("\n"), :class => row_class
|
13
14
|
end
|
14
15
|
|
15
16
|
def column_header(column, additional_parameters = {})
|
@@ -19,15 +20,17 @@ module Grapple
|
|
19
20
|
liner_classes = []
|
20
21
|
liner_classes << tooltip_class if column[:title].present?
|
21
22
|
|
23
|
+
label = t(column[:label] || '')
|
24
|
+
|
22
25
|
if column[:sort] && params.present?
|
23
26
|
cell_classes << 'sortable'
|
24
27
|
if column[:sort] == params[:sort]
|
25
28
|
liner_classes << (params[:dir] == 'desc' ? 'sort-desc' : 'sort-asc')
|
26
29
|
cell_classes << 'sorted'
|
27
30
|
end
|
28
|
-
content = template.link_to(
|
31
|
+
content = template.link_to(label, table_url(additional_parameters.merge({sort: column[:sort]})))
|
29
32
|
else
|
30
|
-
content =
|
33
|
+
content = label
|
31
34
|
end
|
32
35
|
|
33
36
|
cell_classes = ' class="' + cell_classes.join(' ') + '"'
|
@@ -9,8 +9,12 @@ module Grapple
|
|
9
9
|
def render(*options, &block)
|
10
10
|
options = options[0] ? options[0] : {}
|
11
11
|
form_classes = [form_class]
|
12
|
+
form_path = options[:form_path] || {}
|
13
|
+
form_options = options[:form_options] || {}
|
14
|
+
form_options[:class] = form_classes.join(' ')
|
15
|
+
|
12
16
|
html = ''
|
13
|
-
html << template.form_tag(
|
17
|
+
html << template.form_tag(form_path, form_options)
|
14
18
|
html << template.hidden_field_tag(page_param, 1)
|
15
19
|
# TODO: don't use tables for vertical alignment
|
16
20
|
html << '<table><tr>'
|
@@ -6,7 +6,11 @@ module Grapple
|
|
6
6
|
setting :search_query_field_class, 'search-query'
|
7
7
|
|
8
8
|
def render(*options, &block)
|
9
|
-
template.text_field_tag(
|
9
|
+
template.text_field_tag(
|
10
|
+
search_query_param.to_s,
|
11
|
+
params[search_query_param.to_sym],
|
12
|
+
{ :class => search_query_field_class }
|
13
|
+
)
|
10
14
|
end
|
11
15
|
|
12
16
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Base Table Builder' do
|
4
|
+
include GrappleSpecHelper
|
5
|
+
|
6
|
+
before do
|
7
|
+
@output_buffer = ''
|
8
|
+
mock_everything
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
it "should be correct" do
|
13
|
+
builder = Grapple::DataGridBuilder.new(self, users_columns, users_records, {})
|
14
|
+
|
15
|
+
html = builder.search_submit
|
16
|
+
expect(html).to have_tag('input', with: { type: "submit"})
|
17
|
+
|
18
|
+
html = builder.search_query_field
|
19
|
+
expect(html).to have_tag('input', with: { type: "text"})
|
20
|
+
|
21
|
+
html = builder.search_form
|
22
|
+
expect(html).to have_tag('form')
|
23
|
+
|
24
|
+
html = builder.actions
|
25
|
+
expect(html).to have_tag('div.actions')
|
26
|
+
|
27
|
+
html = builder.toolbar
|
28
|
+
expect(html).to have_tag('tr.toolbar')
|
29
|
+
|
30
|
+
html = builder.column_headings
|
31
|
+
expect(html).to have_tag('tr.column-headers')
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Base Table Builder' do
|
4
|
+
include GrappleSpecHelper
|
5
|
+
|
6
|
+
before do
|
7
|
+
@output_buffer = ''
|
8
|
+
mock_everything
|
9
|
+
end
|
10
|
+
|
11
|
+
it "container_attributes should be correct" do
|
12
|
+
attr = Grapple::HtmlTableBuilder.container_attributes(self, { :id => 'my_table' })
|
13
|
+
expect(attr[:class]).to include("grapple")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "table should be correct" do
|
17
|
+
builder = Grapple::HtmlTableBuilder.new(self, users_columns, users_records, {})
|
18
|
+
|
19
|
+
html = builder.table("<tr><td>TEST</td></tr>")
|
20
|
+
|
21
|
+
#puts html
|
22
|
+
|
23
|
+
expect(html).to have_tag('table') do
|
24
|
+
with_tag("tr", count: 1) do
|
25
|
+
with_tag("td", count: 1) do
|
26
|
+
with_text("TEST")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
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.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edward Potocko
|
@@ -167,6 +167,9 @@ files:
|
|
167
167
|
- lib/grapple/helpers/table_helper.rb
|
168
168
|
- lib/grapple/html_table_builder.rb
|
169
169
|
- spec/builders/ajax_data_grid_builder_spec.rb
|
170
|
+
- spec/builders/base_table_builder_spec.rb
|
171
|
+
- spec/builders/data_grid_builder_spec.rb
|
172
|
+
- spec/builders/html_table_builder_spec.rb
|
170
173
|
- spec/components/actions_spec.rb
|
171
174
|
- spec/components/column_headings_spec.rb
|
172
175
|
- spec/components/html_body_spec.rb
|