admino 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb6f069c49996e9bf994e63b48c08fc778387606
4
- data.tar.gz: 5a189da715fb212272cb14396cc1351ef3b6765b
3
+ metadata.gz: cb9eedd24736483e6944b06a6b6b0952aeb20408
4
+ data.tar.gz: a0f73747f2038acbc6faffbafc02ea4845339826
5
5
  SHA512:
6
- metadata.gz: 76abf92afbb96a5d7afcda73150b01aa7f12c6173dbfe1f3ff038f35827727baac685c41b7d6afdd5e7a9f63222671ff335d842840bf2bb7beb40387e49f60a2
7
- data.tar.gz: 47cfae8cb1f1703424e58d7cbe0ba62353e7d9494fd6fbc1403101ce1dd3bc234443dff57b79979eba5fffe54c0f657bcd26a096db3492ffa9f5c12cc39b2211
6
+ metadata.gz: 0214c1c5f397f0d75874b0e83a93f75bdb3e0afb6d292ca398b4d98457af4dc6c25c09f41edb99a33e42d2d4ba9ab3ff546fe3733f1fa001515aa4ba77bdda19
7
+ data.tar.gz: bb590aa9fa115d5dbd0f91f027b4430df595a31d3675f4649232d16ec0b8e32484c4683a45ce966a818913d80d3e84d5495a059431133d46cbd7d480d4174d09
@@ -1,3 +1,7 @@
1
+ # v0.0.7
2
+
3
+ * `#scope_params` does not change request params
4
+
1
5
  # v0.0.6
2
6
 
3
7
  * Moved the filter group params inside of the `:query` hash
@@ -10,14 +14,14 @@
10
14
  # v0.0.4
11
15
 
12
16
  * Rename Group into FilterGroup
13
- * Rename FilterGroup#available_scopes into #scopes
14
- * Rename Sorting#available_scopes into #scopes
15
- * Removed nil scope in FilterGroup
17
+ * Rename `FilterGroup#available_scopes` into `#scopes`
18
+ * Rename `Sorting#available_scopes` into `#scopes`
19
+ * Removed nil scope in `FilterGroup`
16
20
  * Clicking on an active filter scope link will deactivate it
17
21
 
18
22
  # v0.0.3
19
23
 
20
- * Fixed bug in SortingPresenter with default scope
24
+ * Fixed bug in `SortingPresenter` with default scope
21
25
 
22
26
  # v0.0.2
23
27
 
data/README.md CHANGED
@@ -371,12 +371,12 @@ Admino offers a [Showcase collection presenter](https://github.com/stefanoverna/
371
371
  </tr>
372
372
  <thead>
373
373
  <tbody>
374
- <tr id='task_1' class='is-even'>
374
+ <tr class='is-even'>
375
375
  <td role='title'>Call mum ASAP</td>
376
376
  <td role='completed'>✓</td>
377
377
  <td role='due-date'>2013-02-04</td>
378
378
  </tr>
379
- <tr id='task_2' class='is-odd'>
379
+ <tr class='is-odd'>
380
380
  <!-- ... -->
381
381
  </tr>
382
382
  <tbody>
@@ -407,7 +407,7 @@ Often tables need to offer some kind of action associated with the records. The
407
407
  </tr>
408
408
  <thead>
409
409
  <tbody>
410
- <tr id='task_1' class='is-even'>
410
+ <tr class='is-even'>
411
411
  <!-- ... -->
412
412
  <td role='actions'>
413
413
  <a href='/admin/tasks/1' role='show'>Show</a>
@@ -570,6 +570,46 @@ This will enable you to generate row actions even faster, simply declaring them
570
570
  <% end %>
571
571
  ```
572
572
 
573
+ ### Showcase::Traits::Record
574
+
575
+ As funny it may sound, it is strongly suggested to pass to the table presenter an array of records which in turn have been already presented. This enables you to use as columns not only the raw attributes of the model, but all the methods defined in the presenter.
576
+
577
+ Furthermore, if the record presenter includes the `Showcase::Traits::Record` trait, each row of the table will automatically have an unique id attribute thanks to the [`#dom_id` method](https://github.com/stefanoverna/showcase#dom_id).
578
+
579
+ ```ruby
580
+ class TaskPresenter < Showcase::Presenter
581
+ include Showcase::Traits::Record
582
+
583
+ def truncated_title
584
+ h.truncate(title, length: 50)
585
+ end
586
+ end
587
+ ```
588
+
589
+ ```erb
590
+ <% tasks = present_collection(@tasks)
591
+
592
+ <%= Admino::Table::Presenter.new(tasks, Task, self).to_html do |row, record| %>
593
+ <%= row.column :truncated_title, 'Title' %>
594
+ <% end %>
595
+ ```
596
+
597
+ ```html
598
+ <table>
599
+ <thead>
600
+ <th role='truncated-title'>Title</th>
601
+ <thead>
602
+ <tbody>
603
+ <tr id='task_1' class='is-even'>
604
+ <td role='truncated-title'>Call mum ASAP</td>
605
+ </tr>
606
+ <tr id='task_2' class='is-odd'>
607
+ <td role='truncated-title'>Buy some milk</td>
608
+ </tr>
609
+ <tbody>
610
+ </table>
611
+ ```
612
+
573
613
  ### I18n
574
614
 
575
615
  Column titles are generated using the model [`#human_attribute_name`](http://apidock.com/rails/ActiveRecord/Base/human_attribute_name/class) method, so if you already translated the model attribute names, you're good to go. To translate actions, please refer to the following YAML file:
@@ -31,7 +31,7 @@ module Admino
31
31
  end
32
32
 
33
33
  def is_scope_active?(scope)
34
- active_scope == scope
34
+ active_scope == scope.to_sym
35
35
  end
36
36
 
37
37
  def value
@@ -1,6 +1,7 @@
1
1
  require 'i18n'
2
2
  require 'showcase'
3
3
  require 'showcase/helpers/html_options'
4
+ require 'active_support/core_ext/object/deep_dup'
4
5
  require 'active_support/core_ext/array/extract_options'
5
6
  require 'active_support/hash_with_indifferent_access'
6
7
  require 'active_support/core_ext/hash'
@@ -29,7 +30,7 @@ module Admino
29
30
 
30
31
  def scope_params(scope)
31
32
  params = ActiveSupport::HashWithIndifferentAccess.new(
32
- h.request.query_parameters
33
+ h.request.query_parameters.deep_dup
33
34
  )
34
35
 
35
36
  params[:query] ||= {}
@@ -23,7 +23,7 @@ module Admino
23
23
  end
24
24
 
25
25
  def is_scope_active?(scope)
26
- active_scope == scope
26
+ active_scope == scope.to_sym
27
27
  end
28
28
 
29
29
  def ascending?
@@ -1,4 +1,5 @@
1
1
  require 'showcase'
2
+ require 'active_support/core_ext/object/deep_dup'
2
3
 
3
4
  module Admino
4
5
  module Query
@@ -25,7 +26,9 @@ module Admino
25
26
  end
26
27
 
27
28
  def scope_params(scope)
28
- params = ActiveSupport::HashWithIndifferentAccess.new(h.request.query_parameters)
29
+ params = ActiveSupport::HashWithIndifferentAccess.new(
30
+ h.request.query_parameters.deep_dup
31
+ )
29
32
 
30
33
  if is_scope_active?(scope)
31
34
  params.merge!(sorting: scope.to_s, sort_order: ascending? ? 'desc' : 'asc')
@@ -1,4 +1,4 @@
1
1
  module Admino
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
4
4
 
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'active_support/hash_with_indifferent_access'
2
3
 
3
4
  module Admino
4
5
  module Query
@@ -16,7 +17,9 @@ module Admino
16
17
  let(:request_object) do
17
18
  double(
18
19
  'ActionDispatch::Request',
19
- query_parameters: { 'query' => { 'field' => 'value', 'filter_group' => 'bar' } },
20
+ query_parameters: ActiveSupport::HashWithIndifferentAccess.new(
21
+ 'query' => { 'field' => 'value', 'filter_group' => 'bar' }
22
+ ),
20
23
  path: '/'
21
24
  )
22
25
  end
@@ -87,6 +90,7 @@ module Admino
87
90
 
88
91
  describe '#scope_params' do
89
92
  let(:scope_active) { false }
93
+ subject { presenter.scope_params(:foo) }
90
94
 
91
95
  before do
92
96
  filter_group.stub(:is_scope_active?).with(:foo).and_return(scope_active)
@@ -96,7 +100,12 @@ module Admino
96
100
  let(:scope_active) { true }
97
101
 
98
102
  it 'deletes the filter_group param' do
99
- expect(presenter.scope_params(:foo)[:query]).not_to have_key 'filter_group'
103
+ expect(subject[:query]).not_to have_key 'filter_group'
104
+ end
105
+
106
+ it 'keeps the request parameters intact' do
107
+ presenter.scope_params(:foo)
108
+ expect(request_object.query_parameters[:query][:filter_group]).to be_present
100
109
  end
101
110
  end
102
111
 
@@ -104,12 +113,12 @@ module Admino
104
113
  let(:scope_active) { false }
105
114
 
106
115
  it 'is set as filter group value' do
107
- expect(presenter.scope_params(:foo)[:query][:filter_group]).to eq 'foo'
116
+ expect(subject[:query][:filter_group]).to eq 'foo'
108
117
  end
109
118
  end
110
119
 
111
120
  it 'preserves the other params' do
112
- expect(presenter.scope_params(:foo)[:query][:field]).to eq 'value'
121
+ expect(subject[:query][:field]).to eq 'value'
113
122
  end
114
123
  end
115
124
 
@@ -56,7 +56,7 @@ module Admino
56
56
  let(:params) { { 'query' => { 'foo' => 'bar' } } }
57
57
 
58
58
  it 'returns true if the provided scope is the one currently active' do
59
- expect(filter_group.is_scope_active?(:bar)).to be_true
59
+ expect(filter_group.is_scope_active?('bar')).to be_true
60
60
  end
61
61
  end
62
62
  end
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'active_support/hash_with_indifferent_access'
2
3
 
3
4
  module Admino
4
5
  module Query
@@ -15,7 +16,9 @@ module Admino
15
16
  let(:request_object) do
16
17
  double(
17
18
  'ActionDispatch::Request',
18
- query_parameters: { 'sorting' => 'by_date', 'other' => 'value' },
19
+ query_parameters: ActiveSupport::HashWithIndifferentAccess.new(
20
+ 'sorting' => 'by_date', 'other' => 'value'
21
+ ),
19
22
  path: '/'
20
23
  )
21
24
  end
@@ -107,6 +110,11 @@ module Admino
107
110
  expect(subject[:other]).to eq 'value'
108
111
  end
109
112
 
113
+ it 'keeps the request parameters intact' do
114
+ subject
115
+ expect(request_object.query_parameters[:sorting]).to eq 'by_date'
116
+ end
117
+
110
118
  it 'sets the sorting param as the scope' do
111
119
  expect(subject[:sorting]).to eq 'by_title'
112
120
  end
@@ -37,14 +37,21 @@ module Admino
37
37
  expect(result).to have_tag('table tbody tr', count: 2)
38
38
  end
39
39
 
40
- it 'adds a record idenfier to each collection row' do
41
- expect(result).to have_tag('tbody tr#post_1')
42
- expect(result).to have_tag('tbody tr#post_2')
40
+ context 'if the record responds to #dom_id' do
41
+ before do
42
+ first_post.stub(:dom_id).and_return('post_1')
43
+ second_post.stub(:dom_id).and_return('post_2')
44
+ end
45
+
46
+ it 'adds a record identifier to each collection row' do
47
+ expect(result).to have_tag('tbody tr#post_1:first-child')
48
+ expect(result).to have_tag('tbody tr#post_2:last-child')
49
+ end
43
50
  end
44
51
 
45
52
  it 'adds zebra classes to each collection row' do
46
- expect(result).to have_tag('tbody #post_1.is-even')
47
- expect(result).to have_tag('tbody #post_2.is-odd')
53
+ expect(result).to have_tag('tbody tr.is-even:first-child')
54
+ expect(result).to have_tag('tbody tr.is-odd:last-child')
48
55
  end
49
56
 
50
57
  it 'delegates thead columns creation to .to_html HeadRow' do
@@ -126,11 +133,11 @@ module Admino
126
133
  end
127
134
 
128
135
  it "allows customizing the tbody_tr html attributes" do
129
- expect(presenter.to_html).to have_tag(:tr, with: { id: 'post_1', class: 'index-0' })
136
+ expect(presenter.to_html).to have_tag("tbody tr.index-0:first-child")
130
137
  end
131
138
 
132
139
  it 'allows customizing zebra classes' do
133
- expect(presenter.to_html).to have_tag(:tr, with: { id: 'post_1', class: 'one' })
140
+ expect(presenter.to_html).to have_tag("tbody tr.one:first-child")
134
141
  end
135
142
  end
136
143
 
@@ -64,10 +64,6 @@ class Post < Struct.new(:key, :dom_id)
64
64
  def to_key
65
65
  [key]
66
66
  end
67
-
68
- def dom_id
69
- "post_#{key}"
70
- end
71
67
  end
72
68
 
73
69
  require 'action_view'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: admino
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefano Verna
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-22 00:00:00.000000000 Z
11
+ date: 2014-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: showcase