tabulatr2 0.8.1 → 0.8.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: 3c3ba40f552d220b7d52deb96bf187e7cdd6aa71
4
- data.tar.gz: 76696b532827ff7d6edeb20bd86e32ac9c18858f
3
+ metadata.gz: b1dc69e34a9977e78a0969398cdbbb39bd2601f4
4
+ data.tar.gz: b4c0b9bd6cb6e97829767fc3f2a85942e49cfb11
5
5
  SHA512:
6
- metadata.gz: 11f4ef2d45cc07067e61eaa077c969114b84eb7c0f51568ca658083fa5fdcadb44c62d4239937eac8f61bd0c553e86b28be6107857306e16969dfc935ec41cd3
7
- data.tar.gz: 8e3f374395f9e50cc813590a275a6dae58589b244a029ba35cdbccaa77feb9b520f8888522f32736b7a3f4b43fc6d8b1b2124f8abe1b434a8db126420319ae09
6
+ metadata.gz: f4fa0da835396c1cc9e355559a74934e723a00fccbc26e5db23bd84ff2b603c198f0cf9b74126f5a1e9be09e59a37cd1d9e082a276c029adc7e67973228a025b
7
+ data.tar.gz: 9c33aa54ee60d5035b02e229dcc37c0e9db393261a48ac4aa641a8cf1ba7b7c04e426d0af454cdcbb9a958dac8edfea69067d80179de68158c826a347b431bca
data/CHANGELOG.md ADDED
File without changes
data/Gemfile CHANGED
@@ -2,7 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'tabulatr2', path: './', require: 'tabulatr'
5
+ gem 'tabulatr2', path: './'
6
6
 
7
7
  gem 'jquery-rails'
8
8
  gem 'slim'
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  Require tabulatr2 in your Gemfile:
9
9
  ```ruby
10
- gem 'tabulatr2', github: 'provideal/tabulatr2', require: 'tabulatr'
10
+ gem 'tabulatr2', github: 'provideal/tabulatr2'
11
11
  ```
12
12
  After that run `bundle install`.
13
13
 
@@ -82,7 +82,7 @@ class ProductTabulatrData < Tabulatr::Data
82
82
  filter_sql: "vendors.street || '' || vendors.zipcode || '' vendors.city" do
83
83
  "#{vendor.house_number} #{vendor.street}, #{vendor.zipcode} #{vendor.city}"
84
84
  end
85
- column :edit_link do
85
+ column :edit_link do
86
86
  link_to "edit #{title}", product_path(id)
87
87
  end
88
88
  column :updated_at do
@@ -114,7 +114,7 @@ _Hint:_ If you want to prefilter your table, you can do that too! Just pass an `
114
114
 
115
115
  ### View
116
116
 
117
- In the view we can use all the attributes which are defined in our `ProductTabulatrData` class.
117
+ In the view we can use all the attributes which are defined in our `ProductTabulatrData` class.
118
118
 
119
119
  ```erb
120
120
  <%= table_for Product do |t|
@@ -36,8 +36,9 @@
36
36
  .tabulatr-info-string-wrapper data-table-id=table_id
37
37
  = render '/tabulatr/tabulatr_info_string', opts
38
38
 
39
- .tabulatr-fuzzy-search-field-wrapper data-table-id=table_id
40
- = render '/tabulatr/tabulatr_fuzzy_search_field', opts
39
+ - if tabulatr_data.search?
40
+ .tabulatr-fuzzy-search-field-wrapper data-table-id=table_id
41
+ = render '/tabulatr/tabulatr_fuzzy_search_field', opts
41
42
 
42
43
  .tabulatr-filter-dialog-wrapper data-table-id=table_id
43
44
  = render '/tabulatr/tabulatr_filter_dialog', opts
@@ -93,6 +93,10 @@ class Tabulatr::Data
93
93
  self.class.instance_variable_get("@table_columns")
94
94
  end
95
95
 
96
+ def search?
97
+ self.class.instance_variable_get('@search')
98
+ end
99
+
96
100
  #--
97
101
  # Params
98
102
  #++
@@ -25,30 +25,34 @@ module Tabulatr::Data::DSL
25
25
 
26
26
  def column(name, sort_sql: nil, filter_sql: nil, sql: nil, table_column_options: {}, &block)
27
27
  @columns ||= HashWithIndifferentAccess.new
28
+ table_column = Tabulatr::Renderer::Column.from(table_column_options.merge(name: name, klass: @base))
29
+ @table_columns ||= Tabulatr::Renderer::Columns.new(nil)
30
+ @table_columns << table_column
31
+
28
32
  @columns[name.to_sym] = {
29
33
  name: name,
30
34
  sort_sql: sort_sql || sql,
31
35
  filter_sql: filter_sql || sql,
32
- output: block
36
+ output: block,
37
+ table_column: table_column
33
38
  }
34
-
35
- @table_columns ||= Tabulatr::Renderer::Columns.new(nil)
36
- @table_columns << Tabulatr::Renderer::Column.from(table_column_options.merge(name: name))
37
39
  end
38
40
 
39
41
  def association(assoc, name, sort_sql: nil, filter_sql: nil, sql: nil, table_column_options: {}, &block)
40
42
  @table_columns ||= Tabulatr::Renderer::Columns.new
41
43
  @assocs ||= HashWithIndifferentAccess.new
42
44
  @assocs[assoc.to_sym] ||= {}
45
+ @table_columns ||= Tabulatr::Renderer::Columns.new(nil)
46
+ table_column = Tabulatr::Renderer::Association.from(table_column_options.merge(name: name, table_name: assoc, klass: @base))
47
+ @table_columns << table_column
48
+
43
49
  @assocs[assoc.to_sym][name.to_sym] = {
44
50
  name: name,
45
51
  sort_sql: sort_sql || sql,
46
52
  filter_sql: filter_sql || sql,
47
- output: block
53
+ output: block,
54
+ table_column: table_column
48
55
  }
49
-
50
- @table_columns ||= Tabulatr::Renderer::Columns.new(nil)
51
- @table_columns << Tabulatr::Renderer::Association.from(table_column_options.merge(name: name, table_name: assoc))
52
56
  end
53
57
 
54
58
  def search(*args, &block)
@@ -45,18 +45,13 @@ module Tabulatr::Data::Formatting
45
45
  if opts[:output]
46
46
  view.instance_exec(record, &opts[:output])
47
47
  else
48
- record.send(name)
48
+ opts[:table_column].value_for(record, view)
49
49
  end
50
50
  end
51
51
 
52
52
  def format_association(record, table_name, name, opts, view)
53
53
  return view.instance_exec(record, &opts[:output]) if opts[:output]
54
- assoc = record.class.reflect_on_association(table_name.to_sym)
55
- val = if assoc.collection?
56
- record.try(table_name).try(:map, &name).join(', ')
57
- else
58
- record.try(table_name).try(:send, name)
59
- end
54
+ opts[:table_column].value_for(record, view)
60
55
  end
61
56
 
62
57
 
@@ -26,7 +26,7 @@ class Tabulatr::Renderer::Column
26
26
 
27
27
  attr_accessor *%i{name header width align valign wrap type th_html filter_html
28
28
  filter checkbox_value checkbox_label filter_width range_filter_symbol
29
- sortable format_methods table_name block klass format map}
29
+ sortable table_name block klass format map}
30
30
 
31
31
  def self.from(
32
32
  name: nil,
@@ -48,10 +48,10 @@ class Tabulatr::Renderer
48
48
  end
49
49
 
50
50
  def build_table(&block)
51
+ tdc = "#{@klass.name}TabulatrData".constantize.new(@klass)
51
52
  if block_given?
52
53
  @columns = ColumnsFromBlock.process @klass, &block
53
54
  else
54
- tdc = "#{@klass.name}TabulatrData".constantize.new(@klass)
55
55
  @columns = tdc.table_columns
56
56
  end
57
57
 
@@ -59,7 +59,8 @@ class Tabulatr::Renderer
59
59
  columns: @columns,
60
60
  table_options: @table_options,
61
61
  klass: @klass,
62
- classname: @classname
62
+ classname: @classname,
63
+ tabulatr_data: tdc
63
64
  })
64
65
  end
65
66
 
@@ -22,5 +22,5 @@
22
22
  #++
23
23
 
24
24
  module Tabulatr
25
- VERSION = "0.8.1"
25
+ VERSION = "0.8.2"
26
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tabulatr2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Horn
@@ -65,7 +65,7 @@ files:
65
65
  - .gitignore
66
66
  - .rspec
67
67
  - .travis.yml
68
- - Changelog.textile
68
+ - CHANGELOG.md
69
69
  - Gemfile
70
70
  - LICENSE
71
71
  - README.md
data/Changelog.textile DELETED
@@ -1,124 +0,0 @@
1
- h1. Changelog for tabulatr
2
-
3
- * Fixed <tt>:filter_width</tt> not working for <tt>select</tt> filters.
4
- * Giving a Hash as <tt>:format</tt> option gives the corresponding value.
5
- * We now allow column presets:
6
- <pre>
7
- Tabulatr.config do |config|
8
- #...
9
- config.column_presets({
10
- config.column_presets({
11
- :action_column => {:width => '100px'},
12
- :smallint => { :width => '55px', :filter_width => '30px', :align => 'right' },
13
- :id => :smallint,
14
- :sid => { :width => '200px', :filter_width => '170px', :filter => :like },
15
- :title => { :filter => :like },
16
- :count => { :map => false, :width => '40px', :filter => false, :align => 'right' },
17
- :moo => { :width => '155px', :filter_width => '120px', :align => 'right' }
18
- })
19
- end
20
- </pre>
21
-
22
- Now, every column will check whether there is as entry corresponding to its name in this table and get the content as 'default' options.
23
-
24
- <pre>
25
- <%= table_for @regions do |t|
26
- t.column :id
27
- t.column :sid
28
- # ...
29
- end %>
30
- </pre>
31
-
32
- so, the :id column has all the options defined above. The :action_column entry is used for 'action' columns.
33
-
34
- But even better, you can use arbitrary presets:
35
-
36
- <pre>
37
- t.column :foo, :preset => :moo
38
- </pre>
39
-
40
- gets the :moo preset.
41
-
42
- h2. 0.4.2
43
-
44
- * Fixed two more bugs breaking ruby 1.8 compatibility. (Thanks to <a href="https://github.com/moabite">moabite</a> for reporting)
45
-
46
- h2. 0.4.1
47
-
48
- * Fixed a "bug" breaking ruby 1.8 compatibility. (Thanks to <a href="https://github.com/moabite">moabite</a> for reporting)
49
-
50
- h2. 0.4.0
51
-
52
- * Mongoid now really works.
53
- * A lot of cleanup in the finder code (million thanks to <a href="https://github.com/plukevdh">plukevdh</a>)
54
- * You can use <tt>table_for</tt> for 'normal' arrays that weren't found with <tt>find_for_table</tt>.
55
- * Added a :name_mapping option to find_for_table to allow filtering by compund expressions, example:
56
-
57
- <pre>
58
- @customers = Customer.find_for_table(params,
59
- name_mapping: {
60
- name: '("addresses"."firstname" || \' \' || "addresses"."lastname")',
61
- address: '("addresses"."street" || \' \' || "addresses"."zip_code" || \' \' || "addresses"."city")'
62
- },
63
- default_order: 'updated_at desc'
64
- )
65
- </pre>
66
-
67
- * Added Mysql2Adapter to the ActiveRecord connection list (thanks to <a href="https://github.com/AaronLasseigne">AaronLasseigne</a>).
68
- * Monkeypatch mongoid only if it is present. (thanks to <a href="https://github.com/rwz">rwz</a>)
69
-
70
- h2. 0.3.0
71
-
72
- * Converted into a Rails 3.1 engine and moved css and images to use the new asset pipeline. Works with 3.0.x -- 'opefully. Thanks to all that reported the problem.
73
- * Header cells are now auto translated. Thanks to <a href="https://github.com/niedhui">niedhui</a>!
74
-
75
- h2. 0.2.1
76
-
77
- * Fixed a ruby 1.8 syntax issue. (Thanks to <a href="https://github.com/TBAA">TBAA</a> for reporting.)
78
-
79
- h2. 0.2.0
80
-
81
- * Mongoid can also be used in place of ActiveRecord
82
- * fixed handling of the primary_key column and name
83
- * Added dom_id to tables tr. Thanks to <a href="https://github.com/sterrym">sterrym (Tim Glen)</a>!
84
- * Added note on "Request-URI Too Large error" to README
85
-
86
- h2. 0.1.3
87
-
88
- * nicer table headers. Thanks to <a href="https://github.com/troya2" target="_blank">troya2 (Troy Anderson)</a>!
89
-
90
- h2. 0.1.2
91
-
92
- * Fixed bug with nil exception on 'empty' belongs_to association. Thanks to <a href="https://github.com/dgm" target="_blank">dgm</a>!
93
-
94
- h2. 0.1.1
95
-
96
- * Fixed bug with "Select ..." buttons introduced in 0.1.0.
97
- * Added tests for these buttons.
98
-
99
- h2. v0.1.0
100
-
101
- * new <tt>find_for_table</tt> option <tt>:stateful</tt>. If
102
-
103
- <pre>
104
- MyFancyModel.find_for_table params, :stateful => session
105
- </pre>
106
-
107
- is given, the current sorting, filtering, selecting and paging information is stored to the session and restored when reopened. Great for procession specifically filtered lists.
108
-
109
- h2. v0.0.5 (2011-03-28)
110
-
111
- * new column option :map (defaults to true) to disable automatic mapping on the enries of the association as in
112
-
113
- <pre>
114
- <%= table_for @products do |t|
115
- ...
116
- t.association :tags, :title # mapped to all tags
117
- t.association :tags, :count, :map => false # called on the list-of-tags
118
- end %>
119
- </pre>
120
-
121
-
122
- h2. v0.0.4 (2011-03-27)
123
-
124
- * fixed the path to paging/sorting images installed by generator. Thanks to <a href="https://github.com/sdsykes" target="_blank">sdsykes</a>!