easytable 0.0.1 → 0.0.2

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: a43109a490eb45d7d920aa7611ea8524bc3f2991
4
- data.tar.gz: 58e82f3536c6a6215e73a4d9c7be66d4b0953f9a
3
+ metadata.gz: ab1191a7e5415effc91360c1b3d40029e1b6b306
4
+ data.tar.gz: 919c58134f5dd0cc60091009da614e10cbadc8db
5
5
  SHA512:
6
- metadata.gz: 907901666355a7c61f5753ee33cf7b76cd42560965ddeb1df3e565ae0f60205fc12122548eaa816d3cf468e56bff2b3741e4ce03556e020c6164357d8c546dbe
7
- data.tar.gz: 8eefdef470328a572904f4b10596bfa5abcecd6d083699ea3480cf30d5d065ff0aa671a683775452fd11d1de42eb6aded8a91a5850c8781d765cba4ec406f086
6
+ metadata.gz: 89fcc4a74c9f75527faa7497cb5910120fa25dbdc8b25748d0e8e2a7350c1507dc28d1a6af52a987aedfcf6d525be8f8a457bc478d7ea92a78602d45dc34dfab
7
+ data.tar.gz: feb1d98466e17d18ef32244971e977e0d57417f1df86e1a9a67ab938f57fa1f38f27ad442e6a7ff0f17159d5f4c8782e293e7fc0029a1719e55b12b2fbb6e254
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Anton
1
+ Copyright (c) 2013 Anton Zimin
2
2
 
3
3
  MIT License
4
4
 
@@ -0,0 +1,45 @@
1
+ $border-radius: 8px 8px 0 0;
2
+ $border-color: #FFFFFF;
3
+
4
+ table.easy-table {
5
+ background-color: white;
6
+ border: 1px solid #CDC9C1;
7
+ border-radius: $border-radius;
8
+ line-height: 19px;
9
+ width: 100%;
10
+ thead {
11
+ color: #3C3B4E;
12
+ font-size: 15px;
13
+ line-height: 23px;
14
+ tr {
15
+ border-radius: $border-radius;
16
+ th {
17
+ background-color: #D8D4CC;
18
+ border-left: 1px solid $border-color;
19
+ padding: 4px;
20
+ }
21
+ th:first-child {
22
+ border-radius: 5px 0 0;
23
+ }
24
+ th:last-child {
25
+ border-radius: 0 5px 0 0;
26
+ }
27
+ }
28
+ }
29
+ tbody {
30
+ color: #5A5A5A;
31
+ tr {
32
+ border-bottom: 1px solid #F0EBE2;
33
+ td {
34
+ border-left: 1px solid $border-color;
35
+ padding: 4px;
36
+ }
37
+ }
38
+ tr:nth-child(2n+1) {
39
+ background-color: #F5F5F5;
40
+ }
41
+ tr:hover {
42
+ background: #DDD9D0;
43
+ }
44
+ }
45
+ }
data/easytable.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["anton@active-bridge.com"]
11
11
  spec.description = %q{adds helper methods to generate simple table}
12
12
  spec.summary = %q{adds helper methods to generate simple table}
13
- spec.homepage = "https://github.com/antonzimin/simpletable"
13
+ spec.homepage = "https://github.com/antonzimin/easytable"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -0,0 +1,20 @@
1
+ require 'active_record'
2
+
3
+ module CustomHelpers
4
+ def to_array_by_keys(keys)
5
+ values = []
6
+ obj_keys = self.attributes.keys
7
+ keys.each do |key|
8
+ values << self.send(key) if obj_keys.include?(key.to_s)
9
+ end
10
+ values
11
+ end
12
+ end
13
+
14
+ module ActiveRecord
15
+ class Base
16
+ prepend CustomHelpers
17
+ end
18
+ end
19
+
20
+
@@ -1,3 +1,3 @@
1
1
  module Easytable
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,46 @@
1
+ require 'easytable/view_helpers'
2
+
3
+ module Easytable
4
+ module ActionView
5
+
6
+ def render_table_for(table_header: [], columns: [], **opts)
7
+ if columns.is_a?(ActiveRecord::Relation)
8
+ columns = columns.map { |record| record.to_array_by_keys(table_header) }
9
+ table_header = table_header.map!(&:to_s).map!(&:humanize)
10
+ end
11
+ table_class = opts[:class] || :'easy-table'
12
+ content_tag(:table, id: opts[:id], class: table_class) {
13
+ thead(table_header).concat(tbody(columns))
14
+ }
15
+ end
16
+
17
+ ::ActionView::Base.send :include, self
18
+
19
+ private
20
+
21
+ def thead(table_header)
22
+ content_tag :thead do
23
+ content_tag :tr do
24
+ table_header.collect { |title| concat content_tag(:th, title) }.join()
25
+ end
26
+ end
27
+ end
28
+
29
+ def tbody(columns)
30
+ content_tag :tbody do
31
+ if columns.any?
32
+ columns.collect { |line|
33
+ content_tag :tr do
34
+ line.collect { |value| concat content_tag(:td, value) }.to_s.html_safe
35
+ end
36
+ }.join().html_safe
37
+ else
38
+ content_tag :td, colspan: 999 do
39
+ 'No records found'
40
+ end.html_safe
41
+ end
42
+ end
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module Easytable
2
+ require 'engine' if defined?(Rails)
3
+ end
data/lib/engine.rb ADDED
@@ -0,0 +1,2 @@
1
+ class Engine < ::Rails::Engine
2
+ end
@@ -0,0 +1,4 @@
1
+ require 'action_view'
2
+ require 'active_support'
3
+ require 'easytable/active_record'
4
+ require 'easytable/view_helpers/action_view'
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ include ActionView::Helpers
4
+ include ActionView::Context
5
+ include Easytable::ActionView
6
+
7
+ describe Easytable::ActionView do
8
+ describe 'Empty table' do
9
+
10
+ let(:header) { [] }
11
+ let(:columns) { [] }
12
+ subject { render_table_for(table_header: header, columns: columns) }
13
+
14
+ it 'should render table tag' do
15
+ expect(subject).to include('table', '/table')
16
+ end
17
+
18
+ it 'should render empty header' do
19
+ expect(subject).to include('<thead><tr></tr></thead>')
20
+ end
21
+
22
+ it 'should render empty body' do
23
+ expect(subject).to include('No records found')
24
+ end
25
+ end
26
+
27
+ describe 'Table with header' do
28
+ let(:header) { ['Title', 'Description'] }
29
+ let(:columns) { [] }
30
+ subject { render_table_for(table_header: header, columns: columns) }
31
+
32
+ it 'should render header data' do
33
+ expect(subject).to include('<thead><tr><th>Title</th><th>Description</th></tr></thead>')
34
+ end
35
+ end
36
+
37
+ describe 'Table with columns' do
38
+ let(:header) { [] }
39
+ let(:columns) { [[1, 'first line'], [2, 'second line']] }
40
+ subject { render_table_for(table_header: header, columns: columns) }
41
+
42
+ it 'should render columns data' do
43
+ expect(subject).to include('<tbody><tr><td>1</td><td>first line</td></tr><tr><td>2</td><td>second line</td></tr></tbody>')
44
+ end
45
+ end
46
+
47
+ describe 'Private methods' do
48
+ describe '#thead' do
49
+ subject { self.send(:thead, []) }
50
+
51
+ it 'should render header only' do
52
+ expect(subject).to start_with('<thead>')
53
+ expect(subject).to end_with('</thead>')
54
+ expect(subject).to include('<tr></tr>')
55
+ end
56
+ end
57
+
58
+ describe '#tbody' do
59
+ subject { self.send(:tbody, []) }
60
+
61
+ it 'should render table body only' do
62
+ expect(subject).to start_with('<tbody>')
63
+ expect(subject).to end_with('</tbody>')
64
+ expect(subject).to include('No records found')
65
+ end
66
+ end
67
+ end
68
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easytable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Zimin
@@ -14,28 +14,28 @@ dependencies:
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  description: adds helper methods to generate simple table
@@ -45,15 +45,22 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
- - .gitignore
48
+ - ".gitignore"
49
49
  - Gemfile
50
50
  - LICENSE.txt
51
51
  - README.md
52
52
  - Rakefile
53
+ - app/assets/stylelsheets/easytable.css.scss
53
54
  - easytable.gemspec
54
55
  - lib/easytable.rb
56
+ - lib/easytable/active_record.rb
55
57
  - lib/easytable/version.rb
56
- homepage: https://github.com/antonzimin/simpletable
58
+ - lib/easytable/view_helpers.rb
59
+ - lib/easytable/view_helpers/action_view.rb
60
+ - lib/engine.rb
61
+ - spec/spec_helper.rb
62
+ - spec/view_helpers/action_view_spec.rb
63
+ homepage: https://github.com/antonzimin/easytable
57
64
  licenses:
58
65
  - MIT
59
66
  metadata: {}
@@ -63,12 +70,12 @@ require_paths:
63
70
  - lib
64
71
  required_ruby_version: !ruby/object:Gem::Requirement
65
72
  requirements:
66
- - - '>='
73
+ - - ">="
67
74
  - !ruby/object:Gem::Version
68
75
  version: '0'
69
76
  required_rubygems_version: !ruby/object:Gem::Requirement
70
77
  requirements:
71
- - - '>='
78
+ - - ">="
72
79
  - !ruby/object:Gem::Version
73
80
  version: '0'
74
81
  requirements: []
@@ -77,4 +84,6 @@ rubygems_version: 2.0.3
77
84
  signing_key:
78
85
  specification_version: 4
79
86
  summary: adds helper methods to generate simple table
80
- test_files: []
87
+ test_files:
88
+ - spec/spec_helper.rb
89
+ - spec/view_helpers/action_view_spec.rb