grapple 0.1.7 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE +0 -0
  3. data/README.md +0 -0
  4. data/Rakefile +0 -0
  5. data/app/assets/images/grapple/arrow-down.png +0 -0
  6. data/app/assets/images/grapple/arrow-up.png +0 -0
  7. data/app/assets/images/grapple/loading-bar.gif +0 -0
  8. data/app/assets/images/grapple/minus.png +0 -0
  9. data/app/assets/images/grapple/plus.png +0 -0
  10. data/app/assets/javascripts/grapple-history.js +0 -0
  11. data/app/assets/javascripts/grapple-jquery.js +0 -0
  12. data/app/assets/javascripts/grapple.js +0 -0
  13. data/app/assets/stylesheets/grapple.css +0 -0
  14. data/config/locales/en.yml +4 -1
  15. data/lib/grapple.rb +0 -0
  16. data/lib/grapple/ajax_data_grid_builder.rb +0 -0
  17. data/lib/grapple/base_table_builder.rb +30 -1
  18. data/lib/grapple/components.rb +2 -0
  19. data/lib/grapple/components/actions.rb +17 -0
  20. data/lib/grapple/components/base_component.rb +10 -3
  21. data/lib/grapple/components/column_headings.rb +4 -0
  22. data/lib/grapple/components/html_body.rb +0 -0
  23. data/lib/grapple/components/html_caption.rb +0 -0
  24. data/lib/grapple/components/html_colgroup.rb +0 -0
  25. data/lib/grapple/components/html_component.rb +7 -1
  26. data/lib/grapple/components/html_footer.rb +0 -0
  27. data/lib/grapple/components/html_header.rb +1 -0
  28. data/lib/grapple/components/html_row.rb +0 -0
  29. data/lib/grapple/components/kaminari_infobar.rb +40 -0
  30. data/lib/grapple/components/kaminari_pagination.rb +40 -0
  31. data/lib/grapple/components/search_form.rb +0 -0
  32. data/lib/grapple/components/search_query_field.rb +1 -1
  33. data/lib/grapple/components/search_submit.rb +0 -0
  34. data/lib/grapple/components/toolbar.rb +0 -0
  35. data/lib/grapple/components/will_paginate_infobar.rb +3 -6
  36. data/lib/grapple/components/will_paginate_pagination.rb +2 -1
  37. data/lib/grapple/data_grid_builder.rb +0 -0
  38. data/lib/grapple/engine.rb +0 -0
  39. data/lib/grapple/helpers.rb +0 -0
  40. data/lib/grapple/helpers/table_helper.rb +10 -0
  41. data/lib/grapple/html_table_builder.rb +0 -0
  42. data/spec/builders/ajax_data_grid_builder_spec.rb +2 -2
  43. data/spec/builders/base_table_builder_spec.rb +0 -0
  44. data/spec/builders/data_grid_builder_spec.rb +0 -0
  45. data/spec/builders/html_table_builder_spec.rb +4 -5
  46. data/spec/components/actions_spec.rb +0 -0
  47. data/spec/components/column_headings_spec.rb +0 -0
  48. data/spec/components/html_body_spec.rb +0 -0
  49. data/spec/components/html_colgroup_spec.rb +0 -0
  50. data/spec/components/html_footer_spec.rb +0 -0
  51. data/spec/components/search_form_spec.rb +0 -0
  52. data/spec/components/toolbar_spec.rb +0 -0
  53. data/spec/components/will_paginate_spec.rb +1 -6
  54. data/spec/fixtures/schema.rb +0 -0
  55. data/spec/fixtures/users.yml +0 -0
  56. data/spec/spec_helper.rb +0 -0
  57. data/spec/support/test_environment.rb +0 -0
  58. metadata +13 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 29fe6d42cf2c20b787701ae4129775f325a3a67a
4
- data.tar.gz: 274443c21e688445641107e68db1a937baa4848f
2
+ SHA256:
3
+ metadata.gz: a00ec50832f4583379666e80a35b898efc63c066b1b19018efeccbfadefeb531
4
+ data.tar.gz: fb7475bad8276a7f4867622aaf3fe47d09829853d12841795fb9ce4455697399
5
5
  SHA512:
6
- metadata.gz: 86634330ca55fc613cff43012798c0ab8a5f0e6742c9301e836c20bcc32355c5c43e0a76677c1ffd8cfd6d8936f4ec2eb323ccb17f90e62ece6ddbb7ff9856a8
7
- data.tar.gz: 362d5d6e62826ae54ef5dc6759e964a75f2b05e0486b01799e0c7dac0b5b6f84db1d684ec0a34cb025e1388c60508bd7d87aef7c2e4454f81f50e081e7248476
6
+ metadata.gz: 9255cd578e733a19c272c73e47fc3fae1ac17838aa61f355a0fa150e6bd31d37ba0236a0f825cd441a9e082fb26241ddad3237bf041582ae0312275c9c8a3722
7
+ data.tar.gz: 985d05b1ac0354f7ae92b5a78acf3a2236b2543bc083041009bc084539c09aa315b0f9becb1a99901944b7ece92c853f65ddb6fc6b759b3a19a04c4e4c6bd952
data/LICENSE CHANGED
File without changes
data/README.md CHANGED
File without changes
data/Rakefile CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,2 +1,5 @@
1
1
  en:
2
- no_search_results: "We're sorry. No results were found."
2
+ displaying_x_y_of_z_results: "Displaying %{x} - %{y} of %{z} results"
3
+ no_search_results: "We're sorry. No results were found."
4
+ search: "Search"
5
+ zero_results: "0 results"
File without changes
File without changes
@@ -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
- attr_reader :columns, :records, :template, :params, :namespace
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
@@ -19,6 +19,8 @@ module Grapple
19
19
  autoload :SearchSubmit
20
20
  autoload :WillPaginatePagination
21
21
  autoload :WillPaginateInfobar
22
+ autoload :KaminariPagination
23
+ autoload :KaminariInfobar
22
24
 
23
25
  end
24
26
  end
@@ -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, :records, :template, :params, :builder
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(" ")}\"" : ''
File without changes
File without changes
File without changes
@@ -16,7 +16,13 @@ module Grapple
16
16
  if options[:sort] == params[:sort]
17
17
  options[:dir] = (params[:dir] == 'desc') ? 'asc' : 'desc'
18
18
  end
19
- url_params = params.stringify_keys().merge(options.stringify_keys())
19
+ # Convert ActionController::Parameters to a Hash
20
+ p = if params.respond_to?(:to_unsafe_h)
21
+ params.to_unsafe_h
22
+ else
23
+ params.to_h
24
+ end
25
+ url_params = p.stringify_keys().merge(options.stringify_keys())
20
26
  if @builder.namespace
21
27
  tmp = {}
22
28
  url_params.each do |key, value|
File without changes
@@ -1,6 +1,7 @@
1
1
  module Grapple
2
2
  module Components
3
3
 
4
+ # thead element for tables
4
5
  class HtmlHeader < HtmlComponent
5
6
 
6
7
  setting :components, []
File without changes
@@ -0,0 +1,40 @@
1
+ module Grapple
2
+ module Components
3
+ class KaminariInfobar < HtmlComponent
4
+
5
+ setting :message, "Displaying %s - %s of %s results"
6
+ setting :estimate_message, "Displaying %s - %s of about %s results"
7
+ setting :no_results_message, "0 results"
8
+
9
+ def render
10
+ estimate = false
11
+ begin
12
+ # total_count will throw an error if without_count is being used
13
+ total_count = records.total_count
14
+ rescue Exception => e
15
+ estimate = true
16
+ total_count = ActiveRecord::Base.connection.execute(
17
+ "SELECT reltuples AS approximate_row_count FROM pg_class WHERE relname = '#{records.table_name}'"
18
+ ).first["approximate_row_count"].to_i
19
+ end
20
+
21
+ if total_count > 0
22
+ offset = (records.current_page - 1) * records.current_per_page
23
+ start_range = offset + 1
24
+ end_range = [offset + records.current_per_page, total_count].min
25
+
26
+ start_range = ActiveSupport::NumberHelper.number_to_delimited(start_range)
27
+ end_range = ActiveSupport::NumberHelper.number_to_delimited(end_range)
28
+ total = ActiveSupport::NumberHelper.number_to_delimited(total_count)
29
+
30
+ html = sprintf((estimate ? estimate_message : message), start_range, end_range, total)
31
+ else
32
+ html = no_results_message
33
+ end
34
+
35
+ builder.row "<th colspan=\"#{num_columns}\">#{html}</th>", :class => 'infobar'
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,40 @@
1
+ module Grapple
2
+ module Components
3
+ # Generates paging links using Kaminari.
4
+ #
5
+ # @example
6
+ # <%= table_for(columns, Post.page(2)) do |t| %>
7
+ # <%= t.footer do %>
8
+ # <%= t.pagination %>
9
+ # <% end %>
10
+ # <% end %>
11
+ #
12
+ class KaminariPagination < HtmlComponent
13
+
14
+ setting :no_results_message, :no_search_results
15
+ setting :renderer, nil
16
+
17
+ def render(paginate_parameters = {})
18
+ td_class = ""
19
+ if records.instance_of?(Array)
20
+ html = '&nbsp;'
21
+ elsif !params[:query].blank? and records.empty?
22
+ html = h(t(no_results_message))
23
+ td_class = "class='text-left'"
24
+ else
25
+ begin
26
+ # paginate helper will throw an error if without_count is being used
27
+ html = template.paginate(records)
28
+ rescue Exception => e
29
+ html = template.link_to_prev_page(records, "Previous Page") || ""
30
+ html += " " if html
31
+ html += template.link_to_next_page(records, "Next Page") || ""
32
+ end
33
+ end
34
+
35
+ builder.row "<td colspan=\"#{num_columns}\" #{td_class}>#{html}</td>"
36
+ end
37
+
38
+ end
39
+ end
40
+ end
File without changes
@@ -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
- { :class => search_query_field_class, placeholder: "Search" }
12
+ { class: search_query_field_class, placeholder: I18n.translate(:search) }
13
13
  )
14
14
  end
15
15
 
File without changes
File without changes
@@ -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 = sprintf(message, start_range, end_range, total)
14
+ html = I18n.translate(:displaying_x_y_of_z_results, x: start_range, y: end_range, z: total)
18
15
  else
19
- html = no_results_message
16
+ html = I18n.translate(:zero_results)
20
17
  end
21
18
 
22
- builder.row "<th colspan=\"#{num_columns}\">#{html}</th>", :class => 'infobar'
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 = '&nbsp;'
21
- elsif !params[:query].blank? and records.empty?
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
File without changes
File without changes
File without changes
@@ -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
File without changes
@@ -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
- attr = Grapple::AjaxDataGridBuilder.container_attributes(self, { :id => 'my_table' })
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
File without changes
File without changes
@@ -9,16 +9,15 @@ describe 'Base Table Builder' do
9
9
  end
10
10
 
11
11
  it "container_attributes should be correct" do
12
- attr = Grapple::HtmlTableBuilder.container_attributes(self, { :id => 'my_table' })
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
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -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
File without changes
File without changes
File without changes
File without changes
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.1.7
4
+ version: 0.2.1
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: 2017-03-16 00:00:00.000000000 Z
13
+ date: 2019-11-18 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: 3.2.13
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: 3.2.13
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: 3.2.13
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: 3.2.13
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: 3.2.13
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: 3.2.13
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: 3.2.13
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: 3.2.13
112
+ version: 4.2.11.1
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: will_paginate
115
115
  requirement: !ruby/object:Gem::Requirement
@@ -157,6 +157,8 @@ files:
157
157
  - lib/grapple/components/html_footer.rb
158
158
  - lib/grapple/components/html_header.rb
159
159
  - lib/grapple/components/html_row.rb
160
+ - lib/grapple/components/kaminari_infobar.rb
161
+ - lib/grapple/components/kaminari_pagination.rb
160
162
  - lib/grapple/components/search_form.rb
161
163
  - lib/grapple/components/search_query_field.rb
162
164
  - lib/grapple/components/search_submit.rb
@@ -205,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
207
  version: '0'
206
208
  requirements: []
207
209
  rubyforge_project:
208
- rubygems_version: 2.4.8
210
+ rubygems_version: 2.7.6.2
209
211
  signing_key:
210
212
  specification_version: 4
211
213
  summary: Customizable data grid for Rails