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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dbf40283b4ce2fbdbb5ca057c2b4bf3349923dbd
4
- data.tar.gz: d404bf3592c6ae0d822fd2883804a6582094c50b
3
+ metadata.gz: da6917c300db6b44403b55d789ad03e9bf299482
4
+ data.tar.gz: 1642d7d645efd7d2217d9855213711f38d826b9f
5
5
  SHA512:
6
- metadata.gz: d28ca4ed5255a12775f76c0dc8afd771b06d8949c7a466c548053cf921e4448cf016a1a2f52c5617c8b9b54ac665c1868b3219a7e6b5c5be18f19db86948a097
7
- data.tar.gz: 7397b0c680a3aef4fe255c7e4f29c08250258363f6a3568ba53758850e010f9951e9028e6bc7fd29dc454649ce993be8d77af1ac0b94e3e102b4c23ac0574d17
6
+ metadata.gz: 8fd7b08e2b9d68f69a4c63dfac12d5852262fc3ce5b72b53b4f87bc96cf610afa0f077bd7170b1c5c518189412890c73f00f5e7543608d8ccb9f693b73020405
7
+ data.tar.gz: b07fc7793e2ef30305d54eb7ab434be41b91bf7c9ffe3b7c2de648250fe3492b4e466773c6b9e8a1387e976d3780af169f8f4e09580035edc426d88042952b10
@@ -0,0 +1,14 @@
1
+ *.gem
2
+ *.rbc
3
+ Gemfile.lock
4
+ InstalledFiles
5
+ _yardoc
6
+ coverage
7
+ doc/
8
+ lib/bundler/man
9
+ pkg
10
+ rdoc
11
+ spec/reports
12
+ test/tmp
13
+ test/version_tmp
14
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -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
+ [![Build Status](https://travis-ci.org/elementar/html_tables.svg?branch=master)](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
@@ -1,2 +1,5 @@
1
1
  #!/usr/bin/env rake
2
- require "bundler/gem_tasks"
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new('spec')
@@ -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
@@ -1,5 +1,8 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
+ require 'active_support'
4
+ require 'action_view'
5
+
3
6
  require 'html_tables/version'
4
7
  require 'html_tables/config'
5
8
 
@@ -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 = ::Rails.env.development?
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
- def group_by(column_or_lambda, &block)
88
- options[:group] = { block: block, proc: case column_or_lambda
89
- when String, Symbol
90
- ->(obj) { obj.public_send(column_or_lambda) }
91
- when Proc
92
- column_or_lambda
93
- else
94
- raise ArgumentError.new "group_by first argument must be a String, Symbol or Proc"
95
- end }
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
 
@@ -138,6 +138,8 @@ module HtmlTables
138
138
  elsif item.class.respond_to?(:human_enum_name) # simple_enum
139
139
  tmp = item.class.human_enum_name(column, tmp)
140
140
  end
141
+ elsif tmp.class.name == 'Enumerize::Value' # enumerize
142
+ tmp = tmp.text
141
143
  end
142
144
  tmp
143
145
  end
@@ -1,5 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
-
3
1
  module HtmlTables
4
- VERSION = '0.2.5'
2
+ VERSION = '1.1.0'
5
3
  end
@@ -0,0 +1,12 @@
1
+ pt:
2
+ activerecord:
3
+ symbolizes:
4
+ user:
5
+ role:
6
+ manager: Gerente
7
+ admin: Administrador
8
+ enumerize:
9
+ user:
10
+ sex:
11
+ male: Masculino
12
+ female: Feminino
@@ -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
@@ -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: 0.2.5
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: 2015-02-12 00:00:00.000000000 Z
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.2.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