tableficate 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +24 -14
- data/changelog.markdown +3 -0
- data/lib/tableficate/active_record_extension.rb +11 -6
- data/lib/tableficate/finder.rb +3 -2
- data/lib/tableficate/helper.rb +1 -1
- data/lib/tableficate/version.rb +1 -1
- data/spec/active_record_extension_spec.rb +21 -2
- metadata +16 -16
data/README.markdown
CHANGED
@@ -13,20 +13,28 @@ If you're using Bundler, add this to your Gemfile:
|
|
13
13
|
|
14
14
|
## Support
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
16
|
+
<table>
|
17
|
+
<tr>
|
18
|
+
<td><strong>Ruby</strong></td>
|
19
|
+
<td>1.9</td>
|
20
|
+
</tr>
|
21
|
+
<tr>
|
22
|
+
<td><strong>Rails</strong></td>
|
23
|
+
<td>3.1</td>
|
24
|
+
</tr>
|
25
|
+
<tr>
|
26
|
+
<td><strong>Database Framework</strong></td>
|
27
|
+
<td>ActiveRecord</td>
|
28
|
+
</tr>
|
29
|
+
<tr>
|
30
|
+
<td><strong>Templating</strong></td>
|
31
|
+
<td>Any templating engine can be used. The default theme uses ERB.</td>
|
32
|
+
</tr>
|
33
|
+
<tr>
|
34
|
+
<td><strong>Pagination</strong></td>
|
35
|
+
<td>Any pagination can be used. The default theme has built-in support for Kaminari and will_paginate.</td>
|
36
|
+
</tr>
|
37
|
+
</table>
|
30
38
|
|
31
39
|
## Basic Usage
|
32
40
|
Let's say that we want to create a table that lists active accounts in the system with their time of creation and the name on the account.
|
@@ -118,6 +126,8 @@ The theme can then be applied to a table.
|
|
118
126
|
<%= table_for @records, theme: 'foo' do |t| %>
|
119
127
|
...
|
120
128
|
<% end %>
|
129
|
+
|
130
|
+
[Find out more about themes.](https://github.com/sei-mi/tableficate/wiki/Custom-Themes)
|
121
131
|
|
122
132
|
## Changes Needed to Upgrade From 0.2
|
123
133
|
|
data/changelog.markdown
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
## 0.3.1
|
2
|
+
* converting scope to an array through functions like `all` no longer breaks
|
3
|
+
|
1
4
|
## 0.3.0
|
2
5
|
* tables no longer take the :html option, all non-recognized options are passed through as HTML attributes
|
3
6
|
* The `options` attribute on a variety of objects has been removed. It has been replaced with specialized functions such as `label_options` and `collection` with all unrecognized options placed into the `attrs` attribute.
|
@@ -1,18 +1,23 @@
|
|
1
1
|
module Tableficate
|
2
2
|
module ActiveRecordExtension
|
3
|
+
module Functions
|
4
|
+
attr_accessor :tableficate_data
|
5
|
+
end
|
6
|
+
|
3
7
|
extend ActiveSupport::Concern
|
4
8
|
|
5
9
|
included do
|
6
10
|
extend Tableficate::Finder
|
7
11
|
|
8
12
|
self.scope :tableficate_ext, ->{} do
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
+
include Functions
|
14
|
+
|
15
|
+
def to_a
|
16
|
+
a = super.extend(Functions)
|
17
|
+
|
18
|
+
a.tableficate_data = self.tableficate_data
|
13
19
|
|
14
|
-
|
15
|
-
@tableficate_data || {}
|
20
|
+
a
|
16
21
|
end
|
17
22
|
end
|
18
23
|
end
|
data/lib/tableficate/finder.rb
CHANGED
@@ -92,9 +92,10 @@ module Tableficate
|
|
92
92
|
sorting[:column] = column.to_sym
|
93
93
|
sorting[:dir] = ['asc', 'desc'].include?(dir) ? dir : 'asc'
|
94
94
|
end
|
95
|
-
scope.
|
95
|
+
scope.tableficate_data = {}
|
96
|
+
scope.tableficate_data[:current_sort] = sorting
|
96
97
|
filters_with_field = @filter ? @filter.select{|name, options| not options.is_a?(Proc) and options and options.has_key?(:field)} : {}
|
97
|
-
scope.
|
98
|
+
scope.tableficate_data[:field_map] = Hash[filters_with_field.map{|name, options| [name, options[:field]]}]
|
98
99
|
scope
|
99
100
|
end
|
100
101
|
|
data/lib/tableficate/helper.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Tableficate
|
2
2
|
module Helper
|
3
3
|
def table_for(rows, options = {})
|
4
|
-
t = Tableficate::Table.new(self, rows, options, rows.
|
4
|
+
t = Tableficate::Table.new(self, rows, options, rows.tableficate_data)
|
5
5
|
yield(t)
|
6
6
|
t.template.render(partial: Tableficate::Utils::template_path(t.template, 'table_for', t.theme), locals: {table: t})
|
7
7
|
end
|
data/lib/tableficate/version.rb
CHANGED
@@ -3,7 +3,26 @@ require 'spec_helper'
|
|
3
3
|
describe 'Tableficate::ActiveRecordExtention' do
|
4
4
|
it 'should add and retreive data from the scope' do
|
5
5
|
scope = NobelPrizeWinner.tableficate_ext
|
6
|
-
scope.
|
7
|
-
scope.
|
6
|
+
scope.tableficate_data = {}
|
7
|
+
scope.tableficate_data[:name] = 'Aaron'
|
8
|
+
scope.tableficate_data.should == {name: 'Aaron'}
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'maintains functionality if converted to an array' do
|
12
|
+
scope = NobelPrizeWinner.tableficate_ext.to_a
|
13
|
+
scope.tableficate_data = {}
|
14
|
+
scope.tableficate_data[:name] = 'Aaron'
|
15
|
+
scope.tableficate_data.should == {name: 'Aaron'}
|
16
|
+
|
17
|
+
class NobelPrizeWinnerWithDefaultSorting < Tableficate::Base
|
18
|
+
scope :nobel_prize_winner
|
19
|
+
|
20
|
+
default_sort(:first_name)
|
21
|
+
end
|
22
|
+
scope = NobelPrizeWinnerWithDefaultSorting.tableficate({}).all
|
23
|
+
scope.tableficate_data[:current_sort].should == {column: :first_name, dir: 'asc'}
|
24
|
+
|
25
|
+
scope = NobelPrizeWinnerWithDefaultSorting.tableficate({}).find(1,2)
|
26
|
+
scope.tableficate_data[:current_sort].should == {column: :first_name, dir: 'asc'}
|
8
27
|
end
|
9
28
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tableficate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-01-
|
12
|
+
date: 2012-01-06 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &70275949519680 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.1'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70275949519680
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &70275949517100 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70275949517100
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70275949515400 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70275949515400
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: genspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &70275949511500 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70275949511500
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: sqlite3
|
60
|
-
requirement: &
|
60
|
+
requirement: &70275949510000 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70275949510000
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: capybara
|
71
|
-
requirement: &
|
71
|
+
requirement: &70275949508160 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70275949508160
|
80
80
|
description: A DSL for Rails that provides easy table creation with sorting and filtering.
|
81
81
|
email:
|
82
82
|
- alasseigne@sei-mi.com
|
@@ -239,7 +239,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
239
239
|
version: '0'
|
240
240
|
segments:
|
241
241
|
- 0
|
242
|
-
hash: -
|
242
|
+
hash: -3271381889509859658
|
243
243
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
244
244
|
none: false
|
245
245
|
requirements:
|
@@ -248,7 +248,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
248
248
|
version: '0'
|
249
249
|
segments:
|
250
250
|
- 0
|
251
|
-
hash: -
|
251
|
+
hash: -3271381889509859658
|
252
252
|
requirements: []
|
253
253
|
rubyforge_project: tableficate
|
254
254
|
rubygems_version: 1.8.6
|