html_tables 0.2.5 → 1.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 +4 -4
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +14 -0
- data/README.md +2 -0
- data/Rakefile +4 -1
- data/html_tables.gemspec +7 -0
- data/lib/html_tables.rb +3 -0
- data/lib/html_tables/config.rb +1 -1
- data/lib/html_tables/data_table.rb +17 -10
- data/lib/html_tables/renderer.rb +2 -0
- data/lib/html_tables/version.rb +1 -3
- data/spec/locales/pt.yml +12 -0
- data/spec/main_spec.rb +134 -0
- data/spec/spec_helper.rb +40 -0
- metadata +96 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da6917c300db6b44403b55d789ad03e9bf299482
|
4
|
+
data.tar.gz: 1642d7d645efd7d2217d9855213711f38d826b9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fd7b08e2b9d68f69a4c63dfac12d5852262fc3ce5b72b53b4f87bc96cf610afa0f077bd7170b1c5c518189412890c73f00f5e7543608d8ccb9f693b73020405
|
7
|
+
data.tar.gz: b07fc7793e2ef30305d54eb7ab434be41b91bf7c9ffe3b7c2de648250fe3492b4e466773c6b9e8a1387e976d3780af169f8f4e09580035edc426d88042952b10
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.2
|
4
|
+
- 2.1
|
5
|
+
- ruby-head
|
6
|
+
before_install:
|
7
|
+
- gem update --system
|
8
|
+
- gem install bundler
|
9
|
+
script:
|
10
|
+
- bundle exec rspec
|
11
|
+
#gemfile:
|
12
|
+
# - gemfiles/rails41.gemfile
|
13
|
+
# - gemfiles/rails42.gemfile
|
14
|
+
# - gemfiles/rails50.gemfile
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# html_tables
|
2
2
|
|
3
|
+
[](https://travis-ci.org/elementar/html_tables)
|
4
|
+
|
3
5
|
This gem was extracted from some projects on my company. Everyone is welcome to use and improve upon.
|
4
6
|
|
5
7
|
## Installation
|
data/Rakefile
CHANGED
data/html_tables.gemspec
CHANGED
@@ -18,4 +18,11 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.add_dependency 'i18n'
|
19
19
|
gem.add_dependency 'actionpack'
|
20
20
|
gem.add_dependency 'railties'
|
21
|
+
|
22
|
+
gem.add_development_dependency 'rspec', '~> 3.0'
|
23
|
+
gem.add_development_dependency 'rspec-html-matchers'
|
24
|
+
gem.add_development_dependency 'symbolize'
|
25
|
+
gem.add_development_dependency 'enumerize'
|
26
|
+
gem.add_development_dependency 'activerecord', '~> 4.1.0'
|
27
|
+
gem.add_development_dependency 'sqlite3'
|
21
28
|
end
|
data/lib/html_tables.rb
CHANGED
data/lib/html_tables/config.rb
CHANGED
@@ -11,7 +11,7 @@ module HtmlTables
|
|
11
11
|
attr_accessor :use_entity_shortcuts, :url_generator_proc, :default_table_classes
|
12
12
|
|
13
13
|
def initialize
|
14
|
-
@use_entity_shortcuts =
|
14
|
+
@use_entity_shortcuts = ENV['RAILS_ENV'] == 'development'
|
15
15
|
@url_generator_proc = -> obj { url_for(obj) }
|
16
16
|
@default_table_classes = %w(table table-striped table-bordered)
|
17
17
|
end
|
@@ -14,6 +14,8 @@ module HtmlTables
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def auto_generate_columns!
|
17
|
+
raise 'Could not auto generate columns' unless model.respond_to? :accessible_attributes
|
18
|
+
|
17
19
|
model.accessible_attributes.each do |attr|
|
18
20
|
col = model_columns[attr]
|
19
21
|
object_to_yield.column col.name unless col.nil?
|
@@ -23,7 +25,7 @@ module HtmlTables
|
|
23
25
|
def model
|
24
26
|
@model ||= begin
|
25
27
|
n = collection.model_name.constantize if collection.respond_to?(:model_name)
|
26
|
-
n = n.name if n.is_a?(ActiveModel::Name)
|
28
|
+
n = n.name if (defined? ActiveModel) && n.is_a?(ActiveModel::Name)
|
27
29
|
n
|
28
30
|
end
|
29
31
|
@model ||= collection.first.try(:class)
|
@@ -84,15 +86,20 @@ module HtmlTables
|
|
84
86
|
h
|
85
87
|
end
|
86
88
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
89
|
+
# Groups records on the table.
|
90
|
+
# @param [Symbol,Proc] field_or_proc The field name (or +Proc+) which will be used to group the records.
|
91
|
+
# @param [Proc] block Specifies the block to render on each group. It will be rendered as a full-width row.
|
92
|
+
def group_by(field_or_proc, &block)
|
93
|
+
proc = case field_or_proc
|
94
|
+
when String, Symbol
|
95
|
+
lambda { |obj| obj.public_send(field_or_proc) }
|
96
|
+
when Proc
|
97
|
+
field_or_proc
|
98
|
+
else
|
99
|
+
raise ArgumentError, 'group_by first argument must be a String, Symbol or Proc'
|
100
|
+
end
|
101
|
+
|
102
|
+
options[:group] = { block: block, proc: proc }
|
96
103
|
self
|
97
104
|
end
|
98
105
|
|
data/lib/html_tables/renderer.rb
CHANGED
data/lib/html_tables/version.rb
CHANGED
data/spec/locales/pt.yml
ADDED
data/spec/main_spec.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
ActiveRecord::Base.connection.instance_eval do
|
5
|
+
create_table :users do |t|
|
6
|
+
t.string :sex
|
7
|
+
t.string :role
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class User < ActiveRecord::Base
|
12
|
+
extend Enumerize
|
13
|
+
|
14
|
+
enumerize :sex, :in => [:male, :female]
|
15
|
+
symbolize :role, :in => [:manager, :admin]
|
16
|
+
end
|
17
|
+
|
18
|
+
class FakeBuilder < ActionView::Base
|
19
|
+
include HtmlTables::DataTableHelper
|
20
|
+
end
|
21
|
+
|
22
|
+
RSpec.describe HtmlTables::DataTable do
|
23
|
+
|
24
|
+
before do
|
25
|
+
User.create(sex: :female, role: :manager)
|
26
|
+
end
|
27
|
+
|
28
|
+
let(:col0) { [] }
|
29
|
+
let(:col1) { [{ id: 1, name: 'Record One', enabled: true },
|
30
|
+
{ id: 2, name: 'Record Two', enabled: false }].map &OpenStruct.method(:new) }
|
31
|
+
let(:builder) { FakeBuilder.new }
|
32
|
+
let(:user_collection) { User.all }
|
33
|
+
|
34
|
+
describe 'basic usage' do
|
35
|
+
it 'should render nicely when empty' do
|
36
|
+
html = builder.data_table_for col0 do |t|
|
37
|
+
t.column :id
|
38
|
+
t.column :name
|
39
|
+
t.nodata 'No records found'
|
40
|
+
end
|
41
|
+
|
42
|
+
expect(html).to have_tag :tbody do
|
43
|
+
with_tag :tr, count: 1
|
44
|
+
with_tag :td, count: 1, text: 'No records found', with: { colspan: 2 }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should render nicely with records and explicit columns' do
|
49
|
+
html = builder.data_table_for col1 do |t|
|
50
|
+
t.column :id
|
51
|
+
t.column :name
|
52
|
+
t.nodata 'No records found'
|
53
|
+
end
|
54
|
+
|
55
|
+
expect(html).not_to have_tag :td, text: 'No records found'
|
56
|
+
expect(html).to have_tag :tbody do
|
57
|
+
with_tag :tr, text: 'Record One'
|
58
|
+
with_tag :tr, text: 'Record Two'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should translate values from enumerize' do
|
63
|
+
html = builder.data_table_for user_collection do |t|
|
64
|
+
t.column :sex
|
65
|
+
t.nodata 'No records found'
|
66
|
+
end
|
67
|
+
|
68
|
+
expect(html).to have_tag :tbody do
|
69
|
+
with_tag :td, text: 'Feminino'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should show empty cell for empty enumerize field' do
|
74
|
+
user_collection.first.update(sex: nil)
|
75
|
+
updated_collection = user_collection
|
76
|
+
html = builder.data_table_for updated_collection do |t|
|
77
|
+
t.column :sex
|
78
|
+
t.nodata 'No records found'
|
79
|
+
end
|
80
|
+
|
81
|
+
expect(html).to have_tag :tbody do
|
82
|
+
with_tag :td, text: ''
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should translate values from symbolize' do
|
87
|
+
html = builder.data_table_for user_collection do |t|
|
88
|
+
t.column :role
|
89
|
+
t.nodata 'No records found'
|
90
|
+
end
|
91
|
+
|
92
|
+
expect(html).to have_tag :tbody do
|
93
|
+
with_tag :td, text: 'Gerente'
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe 'row class' do
|
99
|
+
it 'should add the row class on the correct rows' do
|
100
|
+
html = builder.data_table_for col1 do |t|
|
101
|
+
t.row_class :disabled, if: -> rec { !rec.enabled }
|
102
|
+
t.column :id
|
103
|
+
t.column :name
|
104
|
+
end
|
105
|
+
|
106
|
+
expect(html).to have_tag :tbody do
|
107
|
+
with_tag :tr, without: { class: 'disabled' }, text: 'Record One'
|
108
|
+
with_tag :tr, with: { class: 'disabled' }, text: 'Record Two'
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe 'totals' do
|
114
|
+
it 'should calculate totals correctly'
|
115
|
+
end
|
116
|
+
|
117
|
+
describe 'grouping' do
|
118
|
+
it 'should group records correctly'
|
119
|
+
end
|
120
|
+
|
121
|
+
describe 'column definition' do
|
122
|
+
it 'should auto-detect columns from ActiveModel compatible models'
|
123
|
+
it 'should allow custom columns'
|
124
|
+
end
|
125
|
+
|
126
|
+
describe 'alignment' do
|
127
|
+
it 'should apply the correct classes when aligning columns'
|
128
|
+
end
|
129
|
+
|
130
|
+
describe 'headers' do
|
131
|
+
it 'should allow overriding the header text'
|
132
|
+
it 'should allow overriding the header style'
|
133
|
+
end
|
134
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'html_tables'
|
2
|
+
require 'rspec-html-matchers'
|
3
|
+
require 'active_record'
|
4
|
+
require 'enumerize'
|
5
|
+
require 'symbolize'
|
6
|
+
|
7
|
+
I18n.load_path += Dir[File.join(File.dirname(__FILE__), 'locales', '*.{rb,yml}')]
|
8
|
+
I18n.available_locales = ["pt"]
|
9
|
+
I18n.default_locale = :"pt"
|
10
|
+
|
11
|
+
ActiveRecord::Base.send :include, Symbolize::ActiveRecord
|
12
|
+
|
13
|
+
silence_warnings do
|
14
|
+
ActiveRecord::Migration.verbose = false
|
15
|
+
ActiveRecord::Base.logger = Logger.new(nil)
|
16
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
17
|
+
end
|
18
|
+
|
19
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
20
|
+
RSpec.configure do |config|
|
21
|
+
config.include RSpecHtmlMatchers
|
22
|
+
|
23
|
+
config.expect_with :rspec do |expectations|
|
24
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
25
|
+
end
|
26
|
+
|
27
|
+
config.mock_with :rspec do |mocks|
|
28
|
+
mocks.verify_partial_doubles = true
|
29
|
+
end
|
30
|
+
|
31
|
+
config.filter_run :focus
|
32
|
+
config.run_all_when_everything_filtered = true
|
33
|
+
|
34
|
+
config.disable_monkey_patching!
|
35
|
+
|
36
|
+
config.default_formatter = 'doc' if config.files_to_run.one?
|
37
|
+
|
38
|
+
config.order = :random
|
39
|
+
Kernel.srand config.seed
|
40
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: html_tables
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fábio David Batista
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -52,6 +52,90 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec-html-matchers
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: symbolize
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: enumerize
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: activerecord
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 4.1.0
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 4.1.0
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: sqlite3
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
55
139
|
description: Simple DSL for HTML data tables
|
56
140
|
email:
|
57
141
|
- fabio@elementarsistemas.com.br
|
@@ -60,6 +144,8 @@ extensions: []
|
|
60
144
|
extra_rdoc_files: []
|
61
145
|
files:
|
62
146
|
- ".gitignore"
|
147
|
+
- ".rspec"
|
148
|
+
- ".travis.yml"
|
63
149
|
- CHANGELOG
|
64
150
|
- Gemfile
|
65
151
|
- LICENSE
|
@@ -76,6 +162,9 @@ files:
|
|
76
162
|
- lib/html_tables/to_label.rb
|
77
163
|
- lib/html_tables/version.rb
|
78
164
|
- lib/html_tables/yielded_object.rb
|
165
|
+
- spec/locales/pt.yml
|
166
|
+
- spec/main_spec.rb
|
167
|
+
- spec/spec_helper.rb
|
79
168
|
homepage: http://elementarsistemas.com.br/
|
80
169
|
licenses: []
|
81
170
|
metadata: {}
|
@@ -95,9 +184,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
184
|
version: '0'
|
96
185
|
requirements: []
|
97
186
|
rubyforge_project:
|
98
|
-
rubygems_version: 2.
|
187
|
+
rubygems_version: 2.4.5.1
|
99
188
|
signing_key:
|
100
189
|
specification_version: 4
|
101
190
|
summary: This gem was extracted from some projects on my company. Everyone is welcome
|
102
191
|
to use and improve upon.
|
103
|
-
test_files:
|
192
|
+
test_files:
|
193
|
+
- spec/locales/pt.yml
|
194
|
+
- spec/main_spec.rb
|
195
|
+
- spec/spec_helper.rb
|