datagrid 1.6.3 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,30 +4,28 @@ require "action_view"
4
4
  module Datagrid
5
5
  module Helper
6
6
 
7
- # Returns individual cell value from the given grid, column name and model
8
- # Allows to render custom HTML layout for grid data
9
- #
7
+ # @param grid [Datagrid] grid object
8
+ # @param column [Datagrid::Columns::Column, String, Symbol] column name
9
+ # @param model [Object] an object from grid scope
10
+ # @return [Object] individual cell value from the given grid, column name and model
11
+ # @example
10
12
  # <ul>
11
13
  # <% @grid.columns.each do |column|
12
14
  # <li><%= column.header %>: <%= datagrid_value(@grid, column.name, @resource %></li>
13
15
  # <% end %>
14
16
  # </ul>
15
- #
16
- def datagrid_value(grid, column_name, model)
17
- datagrid_renderer.format_value(grid, column_name, model)
17
+ def datagrid_value(grid, column, model)
18
+ datagrid_renderer.format_value(grid, column, model)
18
19
  end
19
20
 
20
- def datagrid_format_value(grid, column_name, model) #:nodoc:
21
- datagrid_value(grid, column_name, model)
21
+ # @!visibility private
22
+ def datagrid_format_value(grid, column, model)
23
+ datagrid_value(grid, column, model)
22
24
  end
23
25
 
24
26
  # Renders html table with columns defined in grid class.
25
27
  # In the most common used you need to pass paginated collection
26
28
  # to datagrid table because datagrid do not have pagination compatibilities:
27
- #
28
- # assets = grid.assets.page(params[:page])
29
- # datagrid_table(grid, assets, options)
30
- #
31
29
  # Supported options:
32
30
  #
33
31
  # * <tt>:html</tt> - hash of attributes for <table> tag
@@ -38,6 +36,12 @@ module Datagrid
38
36
  # and needs different columns. Default: all defined columns.
39
37
  # * <tt>:partials</tt> - Path for partials lookup.
40
38
  # Default: 'datagrid'.
39
+ # @param grid [Datagrid] grid object
40
+ # @param assets [Array] objects from grid scope
41
+ # @return [String] table tag HTML markup
42
+ # @example
43
+ # assets = grid.assets.page(params[:page])
44
+ # datagrid_table(grid, assets, options)
41
45
  def datagrid_table(grid, assets = grid.assets, **options)
42
46
  datagrid_renderer.table(grid, assets, **options)
43
47
  end
@@ -50,6 +54,8 @@ module Datagrid
50
54
  # Default: true
51
55
  # * <tt>:partials</tt> - Path for partials lookup.
52
56
  # Default: 'datagrid'.
57
+ # @param grid [Datagrid] grid object
58
+ # @return [String] HTML table header tag markup
53
59
  def datagrid_header(grid, options = {})
54
60
  datagrid_renderer.header(grid, options)
55
61
  end
@@ -66,6 +72,7 @@ module Datagrid
66
72
  # * <tt>:partials</tt> - Path for partials lookup.
67
73
  # Default: 'datagrid'.
68
74
  #
75
+ # @example
69
76
  # = datagrid_rows(grid) # Generic table rows Layout
70
77
  #
71
78
  # = datagrid_rows(grid) do |row| # Custom Layout
@@ -93,21 +100,30 @@ module Datagrid
93
100
  # * <tt>:partials</tt> - Path for form partial lookup.
94
101
  # Default: 'datagrid'.
95
102
  # * All options supported by Rails <tt>form_for</tt> helper
103
+ # @param grid [Datagrid] grid object
104
+ # @return [String] form HTML tag markup
96
105
  def datagrid_form_for(grid, options = {})
97
106
  datagrid_renderer.form_for(grid, options)
98
107
  end
99
108
 
100
109
  # Provides access to datagrid columns data.
101
- #
102
- # # Suppose that <tt>grid</tt> has first_name and last_name columns
110
+ # Used in case you want to build html table completelly manually
111
+ # @param grid [Datagrid] grid object
112
+ # @param asset [Object] object from grid scope
113
+ # @param block [Proc] block with Datagrid::Helper::HtmlRow as an argument returning a HTML markup as a String
114
+ # @return [Datagrid::Helper::HtmlRow, String] captured HTML markup if block given otherwise row object
115
+ # @example
116
+ # # Suppose that grid has first_name and last_name columns
103
117
  # <%= datagrid_row(grid, user) do |row| %>
104
118
  # <tr>
105
119
  # <td><%= row.first_name %></td>
106
120
  # <td><%= row.last_name %></td>
107
121
  # </tr>
108
122
  # <% end %>
109
- #
110
- # Used in case you want to build html table completelly manually
123
+ # @example
124
+ # <% row = datagrid_row(grid, user) %>
125
+ # First Name: <%= row.first_name %>
126
+ # Last Name: <%= row.last_name %>
111
127
  def datagrid_row(grid, asset, &block)
112
128
  HtmlRow.new(self, grid, asset).tap do |row|
113
129
  if block_given?
@@ -117,37 +133,47 @@ module Datagrid
117
133
  end
118
134
 
119
135
  # Generates an ascending or descending order url for the given column
136
+ # @param grid [Datagrid] grid object
137
+ # @param column [Datagrid::Columns::Column, String, Symbol] column name
138
+ # @param descending [Boolean] specifies order direction. Ascending if false, otherwise descending.
139
+ # @return [String] order layout HTML markup
120
140
  def datagrid_order_path(grid, column, descending)
121
141
  datagrid_renderer.order_path(grid, column, descending, request)
122
142
  end
123
143
 
124
144
  # Represents a datagrid row that provides access to column values for the given asset
125
- #
145
+ # @example
126
146
  # row = datagrid_row(grid, user)
147
+ # row.class # => Datagrid::Helper::HtmlRow
127
148
  # row.first_name # => "<strong>Bogdan</strong>"
128
149
  # row.grid # => Grid object
129
150
  # row.asset # => User object
151
+ # row.each do |value|
152
+ # puts value
153
+ # end
130
154
  class HtmlRow
131
155
 
132
156
  include Enumerable
133
157
 
134
158
  attr_reader :grid, :asset
135
159
 
136
- def initialize(context, grid, asset) # :nodoc:
160
+ # @!visibility private
161
+ def initialize(context, grid, asset)
137
162
  @context = context
138
163
  @grid = grid
139
164
  @asset = asset
140
165
  end
141
166
 
142
- # Return a column value for given column name
167
+ # @return [Object] a column value for given column name
143
168
  def get(column)
144
169
  @context.datagrid_value(@grid, column, @asset)
145
170
  end
146
171
 
147
172
  # Iterates over all column values that are available in the row
148
- def each
173
+ # param block [Proc] column value iterator
174
+ def each(&block)
149
175
  @grid.columns.each do |column|
150
- yield(get(column))
176
+ block.call(get(column))
151
177
  end
152
178
  end
153
179
 
@@ -1,10 +1,12 @@
1
1
  require "datagrid/columns"
2
2
 
3
3
  module Datagrid
4
+ # Raised when grid order value is incorrect
4
5
  class OrderUnsupported < StandardError
5
6
  end
6
7
  module Ordering
7
8
 
9
+ # @!visibility private
8
10
  def self.included(base)
9
11
  base.extend ClassMethods
10
12
  base.class_eval do
@@ -26,38 +28,37 @@ module Datagrid
26
28
 
27
29
  end
28
30
  base.send :include, InstanceMethods
29
- end # self.included
31
+ end
30
32
 
33
+ # @!visibility private
31
34
  module ClassMethods
32
-
33
35
  def order_unsupported(name, reason)
34
36
  raise Datagrid::OrderUnsupported, "Can not sort #{self.inspect} by ##{name}: #{reason}"
35
37
  end
36
-
37
- end # ClassMethods
38
+ end
38
39
 
39
40
  module InstanceMethods
40
41
 
41
- def assets # :nodoc:
42
+ # @!visibility private
43
+ def assets
42
44
  check_order_valid!
43
45
  apply_order(super)
44
46
  end
45
47
 
46
- # Returns a column definition that is currently used to order assets
47
- #
48
+ # @return [Datagrid::Columns::Column, nil] a column definition that is currently used to order assets
49
+ # @example
48
50
  # class MyGrid
49
51
  # scope { Model }
50
52
  # column(:id)
51
53
  # column(:name)
52
54
  # end
53
- # MyGrid.new(:order => "name").order_column # => #<Column name: "name", ...>
54
- #
55
+ # MyGrid.new(order: "name").order_column # => #<Column name: "name", ...>
55
56
  def order_column
56
- order && column_by_name(order)
57
+ order ? column_by_name(order) : nil
57
58
  end
58
59
 
59
- # Returns true if given grid is ordered by given column.
60
- # <tt>column</tt> can be given as name or as column object
60
+ # @param column [String, Datagrid::Columns::Column]
61
+ # @return [Boolean] true if given grid is ordered by given column.
61
62
  def ordered_by?(column)
62
63
  order_column == column_by_name(column)
63
64
  end
@@ -127,7 +128,6 @@ module Datagrid
127
128
  self.class.order_unsupported(order_column.name, "Order option proc can not handle more than one argument")
128
129
  end
129
130
  end
130
- end # InstanceMethods
131
-
131
+ end
132
132
  end
133
133
  end
@@ -1,7 +1,8 @@
1
1
  require "action_view"
2
2
 
3
3
  module Datagrid
4
- class Renderer #:nodoc:
4
+ # @!visibility private
5
+ class Renderer
5
6
 
6
7
  def self.for(template)
7
8
  new(template)
@@ -124,6 +124,6 @@ RUBY
124
124
 
125
125
  def file_exists?(name)
126
126
  name = Rails.root.join(name) unless name.to_s.first == "/"
127
- File.exists?(name)
127
+ File.exist?(name)
128
128
  end
129
129
  end
@@ -1,4 +1,5 @@
1
1
  module Datagrid
2
+ # @!visibility private
2
3
  module Utils # :nodoc:
3
4
  class << self
4
5
 
@@ -1,3 +1,3 @@
1
1
  module Datagrid
2
- VERSION = "1.6.3"
2
+ VERSION = "1.7.0"
3
3
  end
data/lib/datagrid.rb CHANGED
@@ -23,6 +23,7 @@ module Datagrid
23
23
 
24
24
  autoload :Engine
25
25
 
26
+ # @!visibility private
26
27
  def self.included(base)
27
28
  base.class_eval do
28
29
 
@@ -34,7 +35,7 @@ module Datagrid
34
35
  include ::Datagrid::Ordering
35
36
 
36
37
  end
37
- end # self.included
38
+ end
38
39
 
39
40
  class ConfigurationError < StandardError; end
40
41
  class ArgumentError < ::ArgumentError; end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datagrid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.3
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bogdan Gusiev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-07 00:00:00.000000000 Z
11
+ date: 2023-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: railties
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.0'
19
+ version: '6.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '4.0'
26
+ version: '6.0'
27
27
  description: This allows you to easily build datagrid aka data tables with sortable
28
28
  columns and filters
29
29
  email: agresso@gmail.com
@@ -90,7 +90,7 @@ files:
90
90
  - templates/controller.rb.erb
91
91
  - templates/grid.rb.erb
92
92
  - templates/index.html.erb
93
- homepage: http://github.com/bogdan/datagrid
93
+ homepage: https://github.com/bogdan/datagrid
94
94
  licenses:
95
95
  - MIT
96
96
  metadata:
@@ -107,14 +107,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: '2.0'
110
+ version: '2.7'
111
111
  required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  requirements:
113
113
  - - ">="
114
114
  - !ruby/object:Gem::Version
115
115
  version: '0'
116
116
  requirements: []
117
- rubygems_version: 3.2.3
117
+ rubygems_version: 3.3.7
118
118
  signing_key:
119
119
  specification_version: 4
120
120
  summary: Ruby gem to create datagrids