snaptable 0.6.4 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +36 -1
  4. data/config/locales/fr.yml +7 -0
  5. data/lib/snaptable/constructor/renderer.rb +9 -3
  6. data/lib/snaptable/{railtie.rb → engine.rb} +4 -2
  7. data/lib/snaptable/version.rb +1 -1
  8. data/lib/snaptable.rb +1 -3
  9. data/test/dummy/Rakefile +6 -0
  10. data/test/dummy/app/assets/javascripts/application.js +13 -0
  11. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  12. data/test/dummy/app/controllers/application_controller.rb +5 -0
  13. data/test/dummy/app/helpers/application_helper.rb +2 -0
  14. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  15. data/test/dummy/bin/bundle +3 -0
  16. data/test/dummy/bin/rails +4 -0
  17. data/test/dummy/bin/rake +4 -0
  18. data/test/dummy/bin/setup +29 -0
  19. data/test/dummy/config/application.rb +26 -0
  20. data/test/dummy/config/boot.rb +5 -0
  21. data/test/dummy/config/database.yml +25 -0
  22. data/test/dummy/config/environment.rb +5 -0
  23. data/test/dummy/config/environments/development.rb +41 -0
  24. data/test/dummy/config/environments/production.rb +79 -0
  25. data/test/dummy/config/environments/test.rb +42 -0
  26. data/test/dummy/config/initializers/assets.rb +11 -0
  27. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  28. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  29. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  30. data/test/dummy/config/initializers/inflections.rb +16 -0
  31. data/test/dummy/config/initializers/mime_types.rb +4 -0
  32. data/test/dummy/config/initializers/session_store.rb +3 -0
  33. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  34. data/test/dummy/config/locales/en.yml +23 -0
  35. data/test/dummy/config/routes.rb +56 -0
  36. data/test/dummy/config/secrets.yml +22 -0
  37. data/test/dummy/config.ru +4 -0
  38. data/test/dummy/public/404.html +67 -0
  39. data/test/dummy/public/422.html +67 -0
  40. data/test/dummy/public/500.html +66 -0
  41. data/test/dummy/public/favicon.ico +0 -0
  42. data/test/integration/navigation_test.rb +8 -0
  43. data/test/snaptable_test.rb +7 -0
  44. data/test/test_helper.rb +20 -0
  45. metadata +90 -55
  46. data/.gitignore +0 -9
  47. data/CODE_OF_CONDUCT.md +0 -13
  48. data/Gemfile +0 -4
  49. data/LICENSE.txt +0 -21
  50. data/README.md +0 -177
  51. data/bin/console +0 -14
  52. data/bin/setup +0 -7
  53. data/lib/snaptable/rails/engine.rb +0 -11
  54. data/lib/snaptable/rails/version.rb +0 -5
  55. data/lib/snaptable/rails.rb +0 -7
  56. data/snaptable.gemspec +0 -30
data/README.md DELETED
@@ -1,177 +0,0 @@
1
- # Snaptable
2
-
3
- A gem that generate HTML tables from your models in order to display them in your admin views. It supports pagination, sorting and searching. It is also possible to customize the tables.
4
-
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- ```ruby
10
- gem 'snaptable'
11
- ```
12
-
13
- And then execute:
14
-
15
- $ bundle
16
-
17
- Or install it yourself as:
18
-
19
- $ gem install snaptable
20
-
21
- Include the assets:
22
-
23
- ```css
24
- # application.css
25
- /*
26
- *= require_self
27
- *= require_tree .
28
- *= require snaptable
29
- */
30
-
31
- ```
32
-
33
- ```js
34
- # application.js
35
- //= require_tree .
36
- //= require snaptable
37
- ```
38
-
39
- ## Usage
40
-
41
- ### Basic table
42
-
43
- In your controller, instantiate a new `Table` with minimum two arguments: the controller itself and the model to use.
44
-
45
- ```ruby
46
- def index
47
- @table = Table.new(self, Article)
48
- end
49
- ```
50
-
51
- Then, in order to enable sorting, call the method `respond` on the table.
52
-
53
- ```ruby
54
- def index
55
- @table = Table.new(self, Article)
56
- @table.respond
57
- end
58
- ```
59
-
60
- Finally, in your view, generate the table where you wish.
61
-
62
- ```html
63
- <div>
64
- <%= @table.present %>
65
- </div>
66
- ```
67
-
68
- The elements in the table are clickable. Click on an element and use the links above the table to edit or destroy it. If you double-click, you are directly redirect to the edit page. Furthermore, the columns are sortable. Click on a label to sort the data by a column.
69
-
70
- ### Options
71
-
72
- You can customize the table when you instantiate it. Pass you own collection in the third argument.
73
-
74
- ```ruby
75
- @articles = Article.last(3)
76
- Table.new(self, Article, @articles)
77
- ```
78
-
79
- Pass the options in the fourth argument. Here is a list:
80
-
81
- * buttons [true]: enable the buttons above the table to add, edit or destroy an element.
82
- * search [false]: enable searching. Add a search field above the table.
83
-
84
- ```ruby
85
- Table.new(self, Article, nil, { search: true, buttons: false })
86
- ```
87
-
88
- You can also configure the table in the view. The `present` method takes a single named argument to let you add a custom buttons bar. Pass the name of a partial to the parameter `buttons` and the content will be added above the table.
89
-
90
- ```erb
91
- <div>
92
- <%= @table.present(buttons: "my_custom_partial") %>
93
- </div>
94
- ```
95
-
96
- ### Custom class
97
-
98
- If you need more control on the displayed fields or on the search, you can easily create your own table.
99
- Create a directory `app/tables`. Then create a file `my_model_table.rb`. Inside declare a class `MyModelTable` that inherits from `BaseTable`.
100
- You must necessarily write a method called `model` that returns the model to use for your table.
101
-
102
- ```ruby
103
- # article_table.rb
104
- class ArticleTable < BaseTable
105
-
106
- def model
107
- Article
108
- end
109
-
110
- end
111
- ```
112
-
113
- From that point, you have a working table, but it acts exactly the same than the basic table. You have few possibilities to change the behavior.
114
- If you want to change the table's columns, write a method `attributes` that returns an array of the model's attributes you want to display. It supports associations by allowing you to put a hash.
115
-
116
- ```ruby
117
- def attributes
118
- [:title, :content, { user: :name }]
119
- end
120
- ```
121
-
122
- You can also change how the URL to edit and delete an element is generated. By default, it uses the element's id, but you can specify an other attribute. Write a method `url` that returns an attribute.
123
-
124
- ```ruby
125
- def url
126
- :slug
127
- end
128
- ```
129
-
130
- By default, the search is done on the string fields of the model. If you want to search on the associations, create a module `Search` inside the class. Then declare a method `self.fields` that returns a hash and `self.associations` that returns an array. Be careful, the search is only possible on string fields.
131
-
132
- ```ruby
133
- class ArticleTable < BaseTable
134
-
135
- def model
136
- Article
137
- end
138
-
139
- def attributes
140
- [:title, :content, { user: :name }]
141
- end
142
-
143
- def url
144
- :slug
145
- end
146
-
147
- module Search
148
-
149
- def self.associations
150
- [:user, :category]
151
- end
152
-
153
- def self.fields
154
- { articles: [:title, :content], user: [:name, :email], category: [:name] }
155
- end
156
-
157
- end
158
- ```
159
-
160
- ### Permission
161
-
162
- if you want to use a permission system, you can enable it in an initializer.
163
-
164
- ```ruby
165
- # initializers/snaptable.rb
166
- Snaptable.use_permission = true
167
- ```
168
-
169
- When the table fetches the data, it will use `current_permission.records(controller, model, token)`. It is up to you to implement the class and its method that respond to those three arguments.
170
-
171
- ## Contributing
172
-
173
- 1. Fork it ( https://github.com/khcr/snaptable/fork )
174
- 2. Create your feature branch (`git checkout -b my-new-feature`)
175
- 3. Commit your changes (`git commit -am 'Add some feature'`)
176
- 4. Push to the branch (`git push origin my-new-feature`)
177
- 5. Create a new Pull Request
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "snaptable"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start
data/bin/setup DELETED
@@ -1,7 +0,0 @@
1
- #!/bin/bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
-
5
- bundle install
6
-
7
- # Do any other automated setup that you need to do here
@@ -1,11 +0,0 @@
1
- module Snaptable
2
- module Rails
3
- class Engine < ::Rails::Engine
4
- require "will_paginate"
5
-
6
- initializer "Snaptable.assets.precompile" do |app|
7
- app.config.assets.precompile +=%w(autotable.js autotable.css)
8
- end
9
- end
10
- end
11
- end
@@ -1,5 +0,0 @@
1
- module Snaptable
2
- module Rails
3
- VERSION = "0.6.4"
4
- end
5
- end
@@ -1,7 +0,0 @@
1
- require 'snaptable/rails/engine'
2
- require 'snaptable/rails/version'
3
-
4
- module Snaptable
5
- module Rails
6
- end
7
- end
data/snaptable.gemspec DELETED
@@ -1,30 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'snaptable/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "snaptable"
8
- spec.version = Snaptable::VERSION
9
- spec.authors = ["khcr"]
10
- spec.email = ["kocher.ke@gmail.com"]
11
-
12
- spec.summary = "A gem that generate HTML tables from your models in order to display them in your admin views."
13
- spec.description = spec.summary
14
- spec.homepage = "http://github.com/khcr/snaptable"
15
- spec.license = "MIT"
16
-
17
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.bindir = "exe"
19
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = ["lib"]
21
-
22
- spec.add_development_dependency "bundler", "~> 1.8"
23
- spec.add_development_dependency "rake", "~> 10.0"
24
-
25
- spec.add_dependency "rails", ">= 4.2.0"
26
- spec.add_dependency "railties", ">= 4.2.0"
27
- spec.add_dependency "will_paginate"
28
- spec.add_dependency "sass-rails"
29
- spec.add_dependency "jquery-rails"
30
- end