rails_table_for 0.2.1 → 0.2.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
  SHA256:
3
- metadata.gz: bc39558936421adf2e8f1fe5cc4f79d404f423ad2a48ac96aed9b951de5cfb05
4
- data.tar.gz: 2459ffa6e9167052e2a2f1e2fe02817c65eb2dafb9267cff706a0b7be9e4dd4b
3
+ metadata.gz: 155237f1a1d730b42f5163e83f94f851b333abb4629337028eb46921fdb803ea
4
+ data.tar.gz: de618efd0f8849900c52e83db411a7960c12039cfc9e1e5437cc427e4cee7a44
5
5
  SHA512:
6
- metadata.gz: 1ae6589f69b463b6d997b2e4a110c63bdbe682554612cdbc7611b0d665344c14c7f703de6b1f834ca3e8477c9ebb7e35eb762d861114153b6a5c242416f36d98
7
- data.tar.gz: d6f88eb4659eeda945bfda4c9f23cd924c720052651125a7c7f5d2e9d0d44e2af4425d6d9109dc8c8036453616b57b62a8cedd05cf485522f6baf4a083f5e1a2
6
+ metadata.gz: a936961884260f6ffed048e9838fa08b1b089903b5a8d6e81618076215452579e73400025f863ca97aebc3c95669eda880ede96e209b62d91cde3b93ceae4073
7
+ data.tar.gz: 23f1e6a33f112248ca84233af07fcdc815857e348b86a1183cb5bc72b332ae295da34ce229fca428eae3000625cc380b7d541eeb6576c2c5c681a42e35043e47
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # CHANGELOG
2
+ ## Master
3
+
4
+ ---
5
+ ## 0.2.2
6
+
7
+ ### Bugs Fixed:
8
+ - `table_for` method was nested, resulting in initial load rendering "table_for" as text
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_table_for (0.2.1)
4
+ rails_table_for (0.2.2)
5
5
  rails (>= 5)
6
6
 
7
7
  GEM
@@ -1,5 +1,5 @@
1
1
  require 'rails_table_for/railtie'
2
- require 'rails_table_for/action_view_ext'
2
+ require 'rails_table_for/table_helper'
3
3
 
4
4
  module RailsTableFor
5
5
  # Your code goes here...
@@ -3,8 +3,7 @@ require 'rails_table_for/elements/column'
3
3
 
4
4
  module Elements
5
5
  class BlockColumn < Column
6
- include Helpers::AutoLink
7
- attr_reader :title
6
+ include Helpers::AutoLink, ActionView::Helpers::TagHelper
8
7
 
9
8
  def initialize(block, **options)
10
9
  @block = block
@@ -12,9 +11,10 @@ module Elements
12
11
  @auto_link = options[:auto_link] || false
13
12
  end
14
13
 
15
- def value_for(record)
14
+ def td(record)
16
15
  text = @block.call(record)
17
- @auto_link ? auto_link(record, text) : text
16
+ content = @auto_link ? auto_link(record, text) : text
17
+ content_tag :td, content
18
18
  end
19
19
  end
20
20
  end
@@ -1,7 +1,11 @@
1
1
  module Elements
2
2
  class Column
3
- def value_for(record)
4
- raise "Not implemented"
3
+ def th
4
+ content_tag :th, @title
5
+ end
6
+
7
+ def td(record)
8
+ raise 'Not implemented'
5
9
  end
6
10
  end
7
11
  end
@@ -3,8 +3,7 @@ require 'rails_table_for/elements/column'
3
3
 
4
4
  module Elements
5
5
  class FieldColumn < Column
6
- include Helpers::AutoLink
7
- attr_reader :title
6
+ include Helpers::AutoLink, ActionView::Helpers::TagHelper
8
7
 
9
8
  def initialize(field, **options)
10
9
  if field.nil?
@@ -15,9 +14,10 @@ module Elements
15
14
  @auto_link = options[:auto_link] || false
16
15
  end
17
16
 
18
- def value_for(record)
17
+ def td(record)
19
18
  text = record.send(@field)
20
- @auto_link ? auto_link(record, text) : text
19
+ content = @auto_link ? auto_link(record, text) : text
20
+ content_tag :td, content
21
21
  end
22
22
  end
23
23
  end
@@ -43,7 +43,7 @@ module Elements
43
43
  def head
44
44
  content_tag :thead do
45
45
  content_tag :tr do
46
- @columns.map {|column| content_tag :th, column.title }.join.html_safe
46
+ @columns.map(&:th).join.html_safe
47
47
  end
48
48
  end
49
49
  end
@@ -56,7 +56,7 @@ module Elements
56
56
 
57
57
  def body_row(record)
58
58
  content_tag :tr do
59
- @columns.map {|column| content_tag :td, column.value_for(record) }.join.html_safe
59
+ @columns.map {|column| column.td(record) }.join.html_safe
60
60
  end
61
61
  end
62
62
  end
@@ -0,0 +1,21 @@
1
+ require 'rails_table_for/elements/table'
2
+
3
+ module TableHelper
4
+ include ActionView::Helpers::TagHelper
5
+
6
+ def table_for(records, **options)
7
+ options.merge({
8
+ request_url: request.original_url,
9
+ request_params: request.params
10
+ })
11
+ table = Elements::Table.new(options)
12
+ if block_given?
13
+ yield table
14
+ end
15
+ table.build(records)
16
+ end
17
+ end
18
+
19
+ ActionView::Base.class_eval do
20
+ include TableHelper
21
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsTableFor
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_table_for
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Austin Roos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-28 00:00:00.000000000 Z
11
+ date: 2020-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -164,6 +164,7 @@ files:
164
164
  - ".github/ISSUE_TEMPLATE/new-user-story.md"
165
165
  - ".github/workflows/tests.yml"
166
166
  - ".gitignore"
167
+ - CHANGELOG.md
167
168
  - Gemfile
168
169
  - Gemfile.lock
169
170
  - LICENSE
@@ -177,13 +178,13 @@ files:
177
178
  - docs/_config.yml
178
179
  - docs/index.md
179
180
  - lib/rails_table_for.rb
180
- - lib/rails_table_for/action_view_ext.rb
181
181
  - lib/rails_table_for/elements/block_column.rb
182
182
  - lib/rails_table_for/elements/column.rb
183
183
  - lib/rails_table_for/elements/field_column.rb
184
184
  - lib/rails_table_for/elements/table.rb
185
185
  - lib/rails_table_for/helpers/auto_link.rb
186
186
  - lib/rails_table_for/railtie.rb
187
+ - lib/rails_table_for/table_helper.rb
187
188
  - lib/rails_table_for/version.rb
188
189
  - lib/tasks/rails_table_for_tasks.rake
189
190
  - rails_table_for.gemspec
@@ -1,19 +0,0 @@
1
- require 'rails_table_for/elements/table'
2
-
3
- module TableHelper
4
- include ActionView::Helpers::TagHelper
5
-
6
- def table_for(records, **options)
7
- def table_for(records, **options)
8
- table = Elements::Table.new(options)
9
- if block_given?
10
- yield table
11
- end
12
- table.build(records)
13
- end
14
- end
15
- end
16
-
17
- ActionView::Base.class_eval do
18
- include TableHelper
19
- end