acts_as_indexable 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +38 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +7 -0
  5. data/Gemfile +15 -0
  6. data/Gemfile.lock +197 -0
  7. data/Guardfile +42 -0
  8. data/LICENSE +22 -0
  9. data/README.md +95 -0
  10. data/Rakefile +23 -0
  11. data/acts_as_indexable.gemspec +31 -0
  12. data/app/helpers/acts_as_indexable/acts_as_indexable_helper.rb +12 -0
  13. data/app/views/acts_as_indexable/_index.html.erb +9 -0
  14. data/app/views/acts_as_indexable/_row.html.erb +15 -0
  15. data/app/views/acts_as_indexable/_thead.html.erb +7 -0
  16. data/lib/acts_as_indexable.rb +7 -0
  17. data/lib/acts_as_indexable/attribute.rb +59 -0
  18. data/lib/acts_as_indexable/engine.rb +4 -0
  19. data/lib/acts_as_indexable/version.rb +3 -0
  20. data/lib/acts_as_indexable/view.rb +26 -0
  21. data/spec/dummy/README.rdoc +28 -0
  22. data/spec/dummy/Rakefile +6 -0
  23. data/spec/dummy/app/assets/images/.keep +0 -0
  24. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  25. data/spec/dummy/app/assets/javascripts/widgets.js +2 -0
  26. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  27. data/spec/dummy/app/assets/stylesheets/widgets.css +4 -0
  28. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  29. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  30. data/spec/dummy/app/controllers/widgets_controller.rb +18 -0
  31. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  32. data/spec/dummy/app/helpers/widgets_helper.rb +2 -0
  33. data/spec/dummy/app/mailers/.keep +0 -0
  34. data/spec/dummy/app/models/.keep +0 -0
  35. data/spec/dummy/app/models/concerns/.keep +0 -0
  36. data/spec/dummy/app/models/widget.rb +3 -0
  37. data/spec/dummy/app/views/layouts/application.html.erb +17 -0
  38. data/spec/dummy/app/views/widgets/_date.html.erb +1 -0
  39. data/spec/dummy/app/views/widgets/index.html.erb +4 -0
  40. data/spec/dummy/bin/bundle +3 -0
  41. data/spec/dummy/bin/rails +4 -0
  42. data/spec/dummy/bin/rake +4 -0
  43. data/spec/dummy/bin/setup +29 -0
  44. data/spec/dummy/config.ru +4 -0
  45. data/spec/dummy/config/application.rb +32 -0
  46. data/spec/dummy/config/boot.rb +5 -0
  47. data/spec/dummy/config/database.yml +25 -0
  48. data/spec/dummy/config/environment.rb +5 -0
  49. data/spec/dummy/config/environments/development.rb +41 -0
  50. data/spec/dummy/config/environments/production.rb +79 -0
  51. data/spec/dummy/config/environments/test.rb +42 -0
  52. data/spec/dummy/config/initializers/assets.rb +11 -0
  53. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  54. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  55. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  56. data/spec/dummy/config/initializers/inflections.rb +16 -0
  57. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  58. data/spec/dummy/config/initializers/session_store.rb +3 -0
  59. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  60. data/spec/dummy/config/locales/en.yml +25 -0
  61. data/spec/dummy/config/routes.rb +4 -0
  62. data/spec/dummy/config/secrets.yml +22 -0
  63. data/spec/dummy/db/migrate/20151123200106_create_widgets.rb +10 -0
  64. data/spec/dummy/db/schema.rb +23 -0
  65. data/spec/dummy/db/seeds.rb +6 -0
  66. data/spec/dummy/lib/assets/.keep +0 -0
  67. data/spec/dummy/public/404.html +67 -0
  68. data/spec/dummy/public/422.html +67 -0
  69. data/spec/dummy/public/500.html +66 -0
  70. data/spec/dummy/public/favicon.ico +0 -0
  71. data/spec/factories/widget.rb +8 -0
  72. data/spec/features/acts_as_indexable/view_spec.rb +90 -0
  73. data/spec/helpers/acts_as_indexable_helper_spec.rb +16 -0
  74. data/spec/models/attribute_spec.rb +39 -0
  75. data/spec/spec_helper.rb +30 -0
  76. data/spec/support/database_cleaner.rb +13 -0
  77. data/spec/support/indexable_views.rb +3 -0
  78. metadata +402 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 41a17b0cb05325635f26ed02e36bf5cec3ceef0a
4
+ data.tar.gz: aea1244edeaad2d0a91d3ff9d9a11efc6766efaf
5
+ SHA512:
6
+ metadata.gz: 22073092f6c4302809b150cac179d88e3bb02af1e585713cb688512d605ce03c693eaa6930962419cb0fceda10f8c6bf45b1e557d1731dfb7affd56509abe0a0
7
+ data.tar.gz: 510d320ac919c960cc66f8bc626b57c6d8b2ecb046b7f2347998627b0f2a051fe6418d6fb48766c25d4350605c3aefabbb4ee29122c8c577826051167c9259f2
@@ -0,0 +1,38 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+ /spec/dummy/tmp/
12
+ /spec/dummy/log/
13
+ /spec/dummy/db/*sqlite3
14
+
15
+ ## Specific to RubyMotion:
16
+ .dat*
17
+ .repl_history
18
+ build/
19
+
20
+ ## Documentation cache and generated files:
21
+ /.yardoc/
22
+ /_yardoc/
23
+ /doc/
24
+ /rdoc/
25
+
26
+ ## Environment normalisation:
27
+ /.bundle/
28
+ /vendor/bundle
29
+ /lib/bundler/man/
30
+
31
+ # for a library or gem, you might want to ignore these files since the code is
32
+ # intended to run in multiple environments; otherwise, check them in:
33
+ # Gemfile.lock
34
+ # .ruby-version
35
+ # .ruby-gemset
36
+
37
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
38
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - "2.1.5"
4
+ - "2.2.2"
5
+ script:
6
+ - bundle exec rake migrate
7
+ - bundle exec rspec spec
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Declare your gem's dependencies in acts_as_indexable.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
7
+
8
+ # Declare any dependencies that are still in development here instead of in
9
+ # your gemspec. These might include edge Rails or gems from your path or
10
+ # Git. Remember to move these dependencies to your gemspec before releasing
11
+ # your gem to rubygems.org.
12
+
13
+ # To use a debugger
14
+ # gem 'byebug', group: [:development, :test]
15
+
@@ -0,0 +1,197 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ acts_as_indexable (0.0.1)
5
+ rails (~> 4.2, >= 4.2.3)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionmailer (4.2.5)
11
+ actionpack (= 4.2.5)
12
+ actionview (= 4.2.5)
13
+ activejob (= 4.2.5)
14
+ mail (~> 2.5, >= 2.5.4)
15
+ rails-dom-testing (~> 1.0, >= 1.0.5)
16
+ actionpack (4.2.5)
17
+ actionview (= 4.2.5)
18
+ activesupport (= 4.2.5)
19
+ rack (~> 1.6)
20
+ rack-test (~> 0.6.2)
21
+ rails-dom-testing (~> 1.0, >= 1.0.5)
22
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
23
+ actionview (4.2.5)
24
+ activesupport (= 4.2.5)
25
+ builder (~> 3.1)
26
+ erubis (~> 2.7.0)
27
+ rails-dom-testing (~> 1.0, >= 1.0.5)
28
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
29
+ activejob (4.2.5)
30
+ activesupport (= 4.2.5)
31
+ globalid (>= 0.3.0)
32
+ activemodel (4.2.5)
33
+ activesupport (= 4.2.5)
34
+ builder (~> 3.1)
35
+ activerecord (4.2.5)
36
+ activemodel (= 4.2.5)
37
+ activesupport (= 4.2.5)
38
+ arel (~> 6.0)
39
+ activesupport (4.2.5)
40
+ i18n (~> 0.7)
41
+ json (~> 1.7, >= 1.7.7)
42
+ minitest (~> 5.1)
43
+ thread_safe (~> 0.3, >= 0.3.4)
44
+ tzinfo (~> 1.1)
45
+ addressable (2.3.8)
46
+ arel (6.0.3)
47
+ builder (3.2.2)
48
+ capybara (2.5.0)
49
+ mime-types (>= 1.16)
50
+ nokogiri (>= 1.3.3)
51
+ rack (>= 1.0.0)
52
+ rack-test (>= 0.5.4)
53
+ xpath (~> 2.0)
54
+ capybara-webkit (1.7.1)
55
+ capybara (>= 2.3.0, < 2.6.0)
56
+ json
57
+ coderay (1.1.0)
58
+ database_cleaner (1.5.1)
59
+ diff-lcs (1.2.5)
60
+ erubis (2.7.0)
61
+ factory_girl (4.5.0)
62
+ activesupport (>= 3.0.0)
63
+ factory_girl_rails (4.5.0)
64
+ factory_girl (~> 4.5.0)
65
+ railties (>= 3.0.0)
66
+ ffi (1.9.10)
67
+ formatador (0.2.5)
68
+ globalid (0.3.6)
69
+ activesupport (>= 4.1.0)
70
+ guard (2.13.0)
71
+ formatador (>= 0.2.4)
72
+ listen (>= 2.7, <= 4.0)
73
+ lumberjack (~> 1.0)
74
+ nenv (~> 0.1)
75
+ notiffany (~> 0.0)
76
+ pry (>= 0.9.12)
77
+ shellany (~> 0.0)
78
+ thor (>= 0.18.1)
79
+ guard-compat (1.2.1)
80
+ guard-rspec (4.6.4)
81
+ guard (~> 2.1)
82
+ guard-compat (~> 1.1)
83
+ rspec (>= 2.99.0, < 4.0)
84
+ i18n (0.7.0)
85
+ json (1.8.3)
86
+ launchy (2.4.3)
87
+ addressable (~> 2.3)
88
+ listen (3.0.5)
89
+ rb-fsevent (>= 0.9.3)
90
+ rb-inotify (>= 0.9)
91
+ loofah (2.0.3)
92
+ nokogiri (>= 1.5.9)
93
+ lumberjack (1.0.9)
94
+ mail (2.6.3)
95
+ mime-types (>= 1.16, < 3)
96
+ method_source (0.8.2)
97
+ mime-types (2.99)
98
+ mini_portile (0.6.2)
99
+ minitest (5.8.3)
100
+ nenv (0.2.0)
101
+ nokogiri (1.6.6.4)
102
+ mini_portile (~> 0.6.0)
103
+ notiffany (0.0.8)
104
+ nenv (~> 0.1)
105
+ shellany (~> 0.0)
106
+ pry (0.10.3)
107
+ coderay (~> 1.1.0)
108
+ method_source (~> 0.8.1)
109
+ slop (~> 3.4)
110
+ rack (1.6.4)
111
+ rack-test (0.6.3)
112
+ rack (>= 1.0)
113
+ rails (4.2.5)
114
+ actionmailer (= 4.2.5)
115
+ actionpack (= 4.2.5)
116
+ actionview (= 4.2.5)
117
+ activejob (= 4.2.5)
118
+ activemodel (= 4.2.5)
119
+ activerecord (= 4.2.5)
120
+ activesupport (= 4.2.5)
121
+ bundler (>= 1.3.0, < 2.0)
122
+ railties (= 4.2.5)
123
+ sprockets-rails
124
+ rails-deprecated_sanitizer (1.0.3)
125
+ activesupport (>= 4.2.0.alpha)
126
+ rails-dom-testing (1.0.7)
127
+ activesupport (>= 4.2.0.beta, < 5.0)
128
+ nokogiri (~> 1.6.0)
129
+ rails-deprecated_sanitizer (>= 1.0.1)
130
+ rails-html-sanitizer (1.0.2)
131
+ loofah (~> 2.0)
132
+ railties (4.2.5)
133
+ actionpack (= 4.2.5)
134
+ activesupport (= 4.2.5)
135
+ rake (>= 0.8.7)
136
+ thor (>= 0.18.1, < 2.0)
137
+ rake (10.4.2)
138
+ rb-fsevent (0.9.6)
139
+ rb-inotify (0.9.5)
140
+ ffi (>= 0.5.0)
141
+ rspec (3.4.0)
142
+ rspec-core (~> 3.4.0)
143
+ rspec-expectations (~> 3.4.0)
144
+ rspec-mocks (~> 3.4.0)
145
+ rspec-core (3.4.1)
146
+ rspec-support (~> 3.4.0)
147
+ rspec-expectations (3.4.0)
148
+ diff-lcs (>= 1.2.0, < 2.0)
149
+ rspec-support (~> 3.4.0)
150
+ rspec-mocks (3.4.0)
151
+ diff-lcs (>= 1.2.0, < 2.0)
152
+ rspec-support (~> 3.4.0)
153
+ rspec-rails (3.4.0)
154
+ actionpack (>= 3.0, < 4.3)
155
+ activesupport (>= 3.0, < 4.3)
156
+ railties (>= 3.0, < 4.3)
157
+ rspec-core (~> 3.4.0)
158
+ rspec-expectations (~> 3.4.0)
159
+ rspec-mocks (~> 3.4.0)
160
+ rspec-support (~> 3.4.0)
161
+ rspec-support (3.4.1)
162
+ shellany (0.0.1)
163
+ shoulda-matchers (3.0.1)
164
+ activesupport (>= 4.0.0)
165
+ slop (3.6.0)
166
+ sprockets (3.4.0)
167
+ rack (> 1, < 3)
168
+ sprockets-rails (2.3.3)
169
+ actionpack (>= 3.0)
170
+ activesupport (>= 3.0)
171
+ sprockets (>= 2.8, < 4.0)
172
+ sqlite3 (1.3.11)
173
+ thor (0.19.1)
174
+ thread_safe (0.3.5)
175
+ tzinfo (1.2.2)
176
+ thread_safe (~> 0.1)
177
+ xpath (2.0.0)
178
+ nokogiri (~> 1.3)
179
+
180
+ PLATFORMS
181
+ ruby
182
+
183
+ DEPENDENCIES
184
+ acts_as_indexable!
185
+ capybara (~> 2.5, >= 2.5.0)
186
+ capybara-webkit (~> 1.7, >= 1.7.1)
187
+ database_cleaner (~> 1.4, >= 1.5.1)
188
+ factory_girl_rails (~> 4.5, >= 4.5.0)
189
+ guard-rspec (~> 4.6, >= 4.6.4)
190
+ launchy (~> 2.4, >= 2.4.3)
191
+ pry (~> 0.10, >= 0.10.3)
192
+ rspec-rails (~> 3.4, >= 3.4.0)
193
+ shoulda-matchers (~> 3.0, >= 3.0.1)
194
+ sqlite3 (~> 1.3, >= 1.3.11)
195
+
196
+ BUNDLED WITH
197
+ 1.10.5
@@ -0,0 +1,42 @@
1
+ guard :rspec, cmd: "bundle exec rspec" do
2
+ require "guard/rspec/dsl"
3
+ dsl = Guard::RSpec::Dsl.new(self)
4
+
5
+ # RSpec files
6
+ rspec = dsl.rspec
7
+ watch(rspec.spec_helper) { rspec.spec_dir }
8
+ watch(rspec.spec_support) { rspec.spec_dir }
9
+ watch(rspec.spec_files)
10
+
11
+ # Ruby files
12
+ ruby = dsl.ruby
13
+ dsl.watch_spec_files_for(ruby.lib_files)
14
+
15
+ # Rails files
16
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
17
+ dsl.watch_spec_files_for(rails.app_files)
18
+ dsl.watch_spec_files_for(rails.views)
19
+
20
+ watch(rails.controllers) do |m|
21
+ [
22
+ rspec.spec.("routing/#{m[1]}_routing"),
23
+ rspec.spec.("controllers/#{m[1]}_controller"),
24
+ rspec.spec.("acceptance/#{m[1]}")
25
+ ]
26
+ end
27
+
28
+ # Rails config changes
29
+ watch(rails.spec_helper) { rspec.spec_dir }
30
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
31
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
32
+
33
+ # Capybara features specs
34
+ watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }
35
+ watch(rails.layouts) { |m| rspec.spec.("features/#{m[1]}") }
36
+
37
+ # Turnip features and steps
38
+ watch(%r{^spec/acceptance/(.+)\.feature$})
39
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
40
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
41
+ end
42
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Taylor MacDonald
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,95 @@
1
+ [![Build Status](https://travis-ci.org/tcmacdonald/acts_as_indexable.svg)](https://travis-ci.org/tcmacdonald/acts_as_indexable)
2
+
3
+ # acts_as_indexable
4
+
5
+ This gem is a Rails engine that provides a configurable DSL for rendering tables in index views of your application. It works with any collection of enumerable objects, ActiveRecord or otherwise.
6
+
7
+ # Usage
8
+
9
+ You first need to install the gem via Bundler by adding the following to your application’s Gemfile…
10
+
11
+ gem ‘acts_as_indexable’, ‘~> 0.0.1’
12
+
13
+ In your controller, you need to include the `ActsAsIndexable::View` concern and define the attributes you’d like to render within your table via the `current_attrs` method…
14
+
15
+ class WidgetsController < ApplicationController
16
+ include ActsAsIndexable::View
17
+
18
+ def current_attrs
19
+ {
20
+ id: {},
21
+ title: {},
22
+ created_at: {}
23
+ }
24
+ end
25
+ end
26
+
27
+ Lastly, drop the following helper method into your template, passing your enumerable collection of objects as the first argument…
28
+
29
+ <%= render_indexable Widget.all %>
30
+
31
+ This should render something similar to the following…
32
+
33
+ ![](https://s3.amazonaws.com/helloample/acts_as_indexable/widgets_index.png)
34
+
35
+ Add custom class selectors to your table by passing them along to `render_indexable`, like so...
36
+
37
+ <%= render_indexable Widget.all, class: 'table table-striped' %>
38
+
39
+
40
+ # Customizations
41
+
42
+ For more control over what attributes are exposed, you can define `@current_attrs` directly within an action or `before_filter`. For example…
43
+
44
+ def index
45
+ @current_attrs = {
46
+ id: {},
47
+ username: {}
48
+ }
49
+ end
50
+
51
+ There are number of other customizations you can invoke on each attribute to get the output of your table exactly the way you want it. To customize any attribute, you simply pass the following keys/values within each attribute definition, like so...
52
+
53
+ {
54
+ title: {
55
+ link_to: :self,
56
+ class: 'btn',
57
+ label: 'Name',
58
+ ...
59
+ }
60
+ }
61
+
62
+ Descriptions for the available customization options are as follows...
63
+
64
+ |Key|Description|
65
+ |---|---|
66
+ |`label`|Customize the `th` element for each attribute|
67
+ |`link_to`|Link the attribute's value. Acceptable values are `:self` and `/path/to/:id`|
68
+ |`label`|Customize the `th` element for each attribute|
69
+ |`format`|Format the value according to current locale. Useful for customizing date/time objects|
70
+ |`partial`|Path to custom partial for the contents of `td`|
71
+
72
+
73
+ # Actions
74
+
75
+ Because most index views need a column for relevant CTAs, you can define a special attribute called `actions` to handle this. The declaration for this column deviates from the above conventions slightly, such that you can define multiple links to be rendered...
76
+
77
+ {
78
+ actions: {
79
+ edit: { class: 'btn btn-primary' },
80
+ delete: { class: 'btn btn-secondary' }
81
+ }
82
+ }
83
+
84
+ # Testing
85
+
86
+ bundle exec rspec
87
+
88
+ # License
89
+
90
+ This project rocks and uses MIT-LICENSE.
91
+
92
+
93
+
94
+
95
+
@@ -0,0 +1,23 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'ActsAsIndexable'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ task :migrate do
18
+ rakefile = File.expand_path('../spec/dummy/Rakefile', __FILE__)
19
+ sh("rake -f #{rakefile} db:create db:migrate db:seed db:test:prepare")
20
+ end
21
+
22
+ Bundler::GemHelper.install_tasks
23
+