rails_table_for 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 196a31693ea615bd92c3a724f62b77aed87d49ea8ba6e03f14f837d89ef71fdc
4
+ data.tar.gz: 79d0ddb507018db890e1b43cc40ad1339a043f2c7816115d249645f7f938a44b
5
+ SHA512:
6
+ metadata.gz: f763178e11affb323f2d98c316475674b4db6028b23098525a85d3d4398aad0a8e7bce0948268820f4ea1fe715f9bf6d089f5017501841bc4e2be758ed44b828
7
+ data.tar.gz: 02533fb2c93ab495ba51184d84da0815581282921b765e3ca48b9e7be3b63d7d12c4518bb0f10c6be79bae8dfd1467e5f4cb4b3bfd4f06da574972bb517c51e9
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .byebug_history
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in rails_table_for.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,66 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rails_table_for (0.1.0)
5
+ actionview (>= 5)
6
+ activerecord (>= 5)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actionview (6.0.2.2)
12
+ activesupport (= 6.0.2.2)
13
+ builder (~> 3.1)
14
+ erubi (~> 1.4)
15
+ rails-dom-testing (~> 2.0)
16
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
17
+ activemodel (6.0.2.2)
18
+ activesupport (= 6.0.2.2)
19
+ activerecord (6.0.2.2)
20
+ activemodel (= 6.0.2.2)
21
+ activesupport (= 6.0.2.2)
22
+ activesupport (6.0.2.2)
23
+ concurrent-ruby (~> 1.0, >= 1.0.2)
24
+ i18n (>= 0.7, < 2)
25
+ minitest (~> 5.1)
26
+ tzinfo (~> 1.1)
27
+ zeitwerk (~> 2.2)
28
+ builder (3.2.4)
29
+ bump (0.9.0)
30
+ byebug (11.1.1)
31
+ concurrent-ruby (1.1.6)
32
+ crass (1.0.6)
33
+ erubi (1.9.0)
34
+ i18n (1.8.2)
35
+ concurrent-ruby (~> 1.0)
36
+ loofah (2.4.0)
37
+ crass (~> 1.0.2)
38
+ nokogiri (>= 1.5.9)
39
+ mini_portile2 (2.4.0)
40
+ minitest (5.14.0)
41
+ nokogiri (1.10.9)
42
+ mini_portile2 (~> 2.4.0)
43
+ rails-dom-testing (2.0.3)
44
+ activesupport (>= 4.2.0)
45
+ nokogiri (>= 1.6)
46
+ rails-html-sanitizer (1.3.0)
47
+ loofah (~> 2.3)
48
+ rake (13.0.1)
49
+ thread_safe (0.3.6)
50
+ tzinfo (1.2.6)
51
+ thread_safe (~> 0.1)
52
+ zeitwerk (2.3.0)
53
+
54
+ PLATFORMS
55
+ ruby
56
+
57
+ DEPENDENCIES
58
+ bump (~> 0.9)
59
+ bundler (~> 2.1, >= 2.1.4)
60
+ byebug (~> 11.1, >= 11.1.1)
61
+ minitest (~> 5.14)
62
+ rails_table_for!
63
+ rake (~> 13.0, >= 13.0.1)
64
+
65
+ BUNDLED WITH
66
+ 2.1.4
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # RailsTableFor
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rails_table_for`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rails_table_for'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rails_table_for
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rails_table_for.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+ task default: :test
4
+
5
+ Rake::TestTask.new do |task|
6
+ task.pattern = 'test/*_test.rb'
7
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rails_table_for"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,8 @@
1
+ require 'rails_table_for/table_helper'
2
+ require 'rails_table_for/version'
3
+ require 'action_view'
4
+
5
+ module RailsTableFor
6
+ class Error < StandardError; end
7
+ # Your code goes here...
8
+ end
@@ -0,0 +1,14 @@
1
+ require 'rails_table_for/column'
2
+
3
+ class BlockColumn < Column
4
+ attr_reader :title
5
+
6
+ def initialize(block, title)
7
+ @block = block
8
+ @title = title
9
+ end
10
+
11
+ def value_for(record)
12
+ @block.call(record)
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ class Column
2
+ def value_for(record)
3
+ raise "Not implemented"
4
+ end
5
+ end
@@ -0,0 +1,17 @@
1
+ require 'rails_table_for/column'
2
+
3
+ class FieldColumn < Column
4
+ attr_reader :title
5
+
6
+ def initialize(field, title = nil)
7
+ if field.nil?
8
+ raise ArgumentError.new("Field cannot be nil")
9
+ end
10
+ @field = field
11
+ @title = title || field.to_s.humanize
12
+ end
13
+
14
+ def value_for(record)
15
+ record.send(@field)
16
+ end
17
+ end
@@ -0,0 +1,61 @@
1
+ require 'rails_table_for/block_column'
2
+ require 'rails_table_for/field_column'
3
+
4
+ class Table
5
+ include ActionView::Helpers::TagHelper
6
+
7
+ attr_accessor :output_buffer
8
+
9
+ def initialize(**options)
10
+ columns = options[:columns] || []
11
+ @columns = columns.map do |field|
12
+ FieldColumn.new(field)
13
+ end
14
+ @options = options
15
+ end
16
+
17
+ def column(field=nil, **options, &block)
18
+ if field.nil? && !block_given?
19
+ raise 'Must provide either field or block'
20
+ end
21
+ title = options[:title] || options['title']
22
+
23
+ if block_given?
24
+ @columns << BlockColumn.new(block, title)
25
+ else
26
+ @columns << FieldColumn.new(field, title)
27
+ end
28
+ end
29
+
30
+ def build(records)
31
+ return '' if records.nil? || records.empty?
32
+ table(records)
33
+ end
34
+
35
+ private
36
+ def table(records)
37
+ content_tag :table, class: @options[:class] do
38
+ [head, body(records)].join.html_safe
39
+ end
40
+ end
41
+
42
+ def head
43
+ content_tag :thead do
44
+ content_tag :tr do
45
+ @columns.map {|column| content_tag :th, column.title }.join.html_safe
46
+ end
47
+ end
48
+ end
49
+
50
+ def body(records)
51
+ content_tag :tbody do
52
+ records.map {|record| body_row(record) }.join.html_safe
53
+ end
54
+ end
55
+
56
+ def body_row(record)
57
+ content_tag :tr do
58
+ @columns.map {|column| content_tag :td, column.value_for(record) }.join.html_safe
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,17 @@
1
+ require 'rails_table_for/table'
2
+
3
+ module TableHelper
4
+ include ActionView::Helpers::TagHelper
5
+
6
+ def table_for(records, **options)
7
+ table = Table.new(options)
8
+ if block_given?
9
+ yield table
10
+ end
11
+ table.build(records)
12
+ end
13
+ end
14
+
15
+ ActionView::Base.class_eval do
16
+ include TableHelper
17
+ end
@@ -0,0 +1,3 @@
1
+ module RailsTableFor
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,33 @@
1
+
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rails_table_for/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'rails_table_for'
8
+ spec.version = RailsTableFor::VERSION
9
+ spec.authors = ['Austin Roos']
10
+ spec.email = ['roos.austin@gmail.com']
11
+
12
+ spec.summary = %q{HTML tables for ActiveRecord collections, made simple}
13
+ spec.description = %q{Generate HTML tables for ActiveRecord collections, with many customizations available}
14
+ spec.homepage = 'https://acroos.github.io/rails_table_for'
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_dependency 'actionview', '>= 5'
26
+ spec.add_dependency 'activerecord', '>= 5'
27
+
28
+ spec.add_development_dependency 'bump', '~> 0.9'
29
+ spec.add_development_dependency 'bundler', '~> 2.1', '>= 2.1.4'
30
+ spec.add_development_dependency 'byebug', '~> 11.1', '>= 11.1.1'
31
+ spec.add_development_dependency 'minitest', '~> 5.14'
32
+ spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.1'
33
+ end
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_table_for
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Austin Roos
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-03-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: actionview
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activerecord
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bump
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.9'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.1'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 2.1.4
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '2.1'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 2.1.4
75
+ - !ruby/object:Gem::Dependency
76
+ name: byebug
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '11.1'
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 11.1.1
85
+ type: :development
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '11.1'
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 11.1.1
95
+ - !ruby/object:Gem::Dependency
96
+ name: minitest
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '5.14'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: '5.14'
109
+ - !ruby/object:Gem::Dependency
110
+ name: rake
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: '13.0'
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: 13.0.1
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '13.0'
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: 13.0.1
129
+ description: Generate HTML tables for ActiveRecord collections, with many customizations
130
+ available
131
+ email:
132
+ - roos.austin@gmail.com
133
+ executables: []
134
+ extensions: []
135
+ extra_rdoc_files: []
136
+ files:
137
+ - ".gitignore"
138
+ - Gemfile
139
+ - Gemfile.lock
140
+ - README.md
141
+ - Rakefile
142
+ - bin/console
143
+ - bin/setup
144
+ - lib/rails_table_for.rb
145
+ - lib/rails_table_for/block_column.rb
146
+ - lib/rails_table_for/column.rb
147
+ - lib/rails_table_for/field_column.rb
148
+ - lib/rails_table_for/table.rb
149
+ - lib/rails_table_for/table_helper.rb
150
+ - lib/rails_table_for/version.rb
151
+ - rails_table_for.gemspec
152
+ homepage: https://acroos.github.io/rails_table_for
153
+ licenses: []
154
+ metadata: {}
155
+ post_install_message:
156
+ rdoc_options: []
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ requirements: []
170
+ rubygems_version: 3.0.3
171
+ signing_key:
172
+ specification_version: 4
173
+ summary: HTML tables for ActiveRecord collections, made simple
174
+ test_files: []