grapple 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cbdfba833204a62c126fb91ec6b95e6b17a76654
4
- data.tar.gz: ee880107cf1becc73adc3c46d0f908be8b7ff465
3
+ metadata.gz: 05a1ffcbbb6eeed509347c518f1690d9d2eb8874
4
+ data.tar.gz: f4d3ba52e44f0a96d25cea11ffdd31d91b7db986
5
5
  SHA512:
6
- metadata.gz: 1976ae3090721348125616fdb2703bf5e568849c366c62904a81de9b6359a072522cc2fa8307d13e983961f1e9546ad54dac01ac6fc51e29bed25486eb262865
7
- data.tar.gz: 591e70f06fbf5ef355a692fc082a7016a77d993a021b3f6f89c9aaff91c2eb22303825fe4f6d8496e372fffca403116aa3176a7b41938fb444363ecdabcc174e
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
- "grapple-ajax-history" => options[:history] === false ? '0' : '1'
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
- # TODO: why are we deleting the label and url?
14
- label = action.delete(:label)
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 => 'column-headers'
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(column[:label], table_url(additional_parameters.merge({:sort => column[:sort]})))
31
+ content = template.link_to(label, table_url(additional_parameters.merge({sort: column[:sort]})))
29
32
  else
30
- content = column[:label]
33
+ content = label
31
34
  end
32
35
 
33
36
  cell_classes = ' class="' + cell_classes.join(' ') + '"'
@@ -2,6 +2,7 @@ module Grapple
2
2
  module Components
3
3
  class HtmlRow < HtmlComponent
4
4
 
5
+ # TODO: should be able to take a block for the content
5
6
  def render(content, *options)
6
7
  (indent + template.content_tag(:tr, content.html_safe, *options) + "\n").html_safe
7
8
  end
@@ -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({}, { :class => form_classes.join(' ') })
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(search_query_param.to_s, params[search_query_param.to_sym], { :class => search_query_field_class })
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
@@ -2,8 +2,10 @@ module Grapple
2
2
  module Components
3
3
  class SearchSubmit < HtmlComponent
4
4
 
5
+ setting :label, 'Filter'
6
+
5
7
  def render
6
- template.submit_tag(t(:filter))
8
+ template.submit_tag(t(label))
7
9
  end
8
10
 
9
11
  end
@@ -9,6 +9,7 @@ module Grapple
9
9
  helper :footer, Grapple::Components::HtmlFooter
10
10
 
11
11
  def table(content)
12
+ # TODO: support attributes on the table tag
12
13
  "<table>#{content}</table>\n".html_safe
13
14
  end
14
15
 
@@ -0,0 +1,11 @@
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
+ 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
@@ -14,7 +14,7 @@ describe 'search form' do
14
14
 
15
15
  html = builder.search_form()
16
16
 
17
- puts html
17
+ #puts html
18
18
 
19
19
  expect(html).to have_tag('form.search-form', with: {method: "post"}) do
20
20
  with_tag('input', with: {type: "hidden", name: "page"})
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.1
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