smart_managing 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 49cbf703ed43cf9df32be9fd23c6f7b5a8362d05
4
+ data.tar.gz: a217f2218b52f4ef1ec58b442d3a183ee0f33bc1
5
+ SHA512:
6
+ metadata.gz: 17dd2d044b7bd782c35f8ab23d1a9ab447b142b2d3b88022acdb9629c7b8ca870bd3977d73a61bd56c31ce27d049c1bd909382b981b8304e87e1392d19239775
7
+ data.tar.gz: 09d9e5cc327d0c3961f1ec28275969520f3d774d912e1b5dc2031f7a395c73176737ddf8562855c528b86572c580c554567daa3b9ea9f9e7ad48a11316d0d29d
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,114 @@
1
+ # SmartManaging
2
+
3
+ SmartManaging is a tool which allow create easily a beautiful management interface while keeping the agility and the power of Rails.
4
+
5
+ ## Install in an existing project
6
+
7
+ SmartManging uses SmartListing, SimpleForm and Twitter-Bootsrap. You must to
8
+ install it before to install SmartManaging.
9
+
10
+ To install SmartManaging you have to add this in your Gemfile :
11
+ ```ruby
12
+ gem 'smart_listing', github: 'GCorbel/smart_listing', branch: 'refactoring'
13
+ gem 'smart_managing'
14
+ ```
15
+
16
+ Bundle it by using the command `bundle install`.
17
+
18
+ Finally, you must to add this line in you controller :
19
+ ```ruby
20
+ include SmartManaging::ControllerHelpers
21
+ ```
22
+
23
+ ## Start from scratch
24
+
25
+ Here is an example of managing interface in less than 30 seconds
26
+
27
+ Create the application :
28
+ ```console
29
+ rails new UserManagement --skip-bundle
30
+ cd UserManagement
31
+ ```
32
+
33
+ Add this in your Gemfile :
34
+ ```ruby
35
+ gem 'smart_listing', github: 'GCorbel/smart_listing', branch: 'refactoring'
36
+ gem 'smart_managing'
37
+ ```
38
+
39
+ Run this command to download the gem with Bundler :
40
+ ```console
41
+ bundle install
42
+ ```
43
+
44
+ Install SimpleForm by typing this command :
45
+ ```console
46
+ rails generate simple_form:install
47
+ ```
48
+
49
+ Install SmartManaging by running this command :
50
+ ```console
51
+ rails generate smart_managing:install
52
+ ```
53
+
54
+ Create a new model, for example :
55
+ ```console
56
+ rails generate model User name email age:integer
57
+ rake db:migrate
58
+ ```
59
+
60
+ Edit the `config/routes.rb` and add :
61
+ ```ruby
62
+ resources :users
63
+ ```
64
+
65
+ Open the file `app/assets/javascripts/application.js` and, before `//= require_tree .`, add this :
66
+ ```
67
+ //= require bootstrap
68
+ //= require smart_listing
69
+ ```
70
+
71
+ Rename the file `app/assets/stylesheets/application.css` to `app/assets/stylesheets/application.css.scss` and, at the bottom of the file, add this :
72
+ ```scss
73
+ @import "bootstrap-sprockets";
74
+ @import "bootstrap";
75
+ ```
76
+
77
+ Create a file named `app/controllers/users_controller.rb` and add this :
78
+ ```ruby
79
+ class UsersController < ApplicationController
80
+ include SmartManaging::ControllerHelpers
81
+ # ... Your code
82
+ end
83
+ ```
84
+
85
+ For a more simple controller, you can use [inherited_resources](https://github.com/josevalim/inherited_resources) but it's not mandatory.
86
+
87
+ Done! You can start the application by running `rails server` and go to http://localhost:3000.
88
+
89
+ ## Customize the managers
90
+ You can change the behavior of the SmartManaging for a specific model by creating a directory `app/managers` and a manager object. For exemple, you can have the file `user_manager.rb` which contain :
91
+
92
+ ```ruby
93
+ class UserManager < SmartManaging::Base
94
+ def editable_attributes
95
+ ['name']
96
+ end
97
+
98
+ def attributes
99
+ ['name', 'email']
100
+ end
101
+ end
102
+ ```
103
+
104
+ This will show only the names and emails and allow to edit only the names.
105
+
106
+ A manager class must inherited from `SmartManaging::Base` and override his methods, for the complete list of overrideable methods, you can check [this file](https://github.com/GCorbel/smart_managing/blob/master/app/managers/smart_managing/base.rb).
107
+
108
+ You can specify a manager in the controller by overriding the `manager` method. For example, you can do this :
109
+
110
+ ```ruby
111
+ def manager
112
+ @manager ||= CustomManager.new(self)
113
+ end
114
+ ```
data/Rakefile ADDED
@@ -0,0 +1,21 @@
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 = 'SmartManaging'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+ Bundler::GemHelper.install_tasks
21
+
@@ -0,0 +1,32 @@
1
+ module SmartManaging
2
+ module ApplicationHelper
3
+ delegate :attributes, :editable_attributes, :number_of_attributes,
4
+ to: :manager
5
+
6
+ def colspan
7
+ number_of_attributes + 1
8
+ end
9
+
10
+ def resource_name
11
+ controller_name.to_sym
12
+ end
13
+
14
+ def new_item_path
15
+ new_polymorphic_path(klass)
16
+ end
17
+
18
+ private
19
+
20
+ def klass
21
+ controller_name.classify.constantize
22
+ end
23
+
24
+ def resource_name
25
+ controller_name.to_sym
26
+ end
27
+
28
+ def singular_resource_name
29
+ resource_name.to_s.singularize.to_sym
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,35 @@
1
+ module SmartManaging
2
+ class Base
3
+ attr_accessor :controller
4
+
5
+ def initialize(controller)
6
+ @controller = controller
7
+ end
8
+
9
+ def number_of_attributes
10
+ attributes.size
11
+ end
12
+
13
+ def attributes
14
+ klass.columns.map(&:name)
15
+ end
16
+
17
+ def klass
18
+ controller_name.classify.constantize
19
+ end
20
+
21
+ def editable_attributes
22
+ attributes - SmartManaging::UNEDITABLE_ATTRIBUTES
23
+ end
24
+
25
+ def model_sym
26
+ controller_name.to_s.singularize.to_sym
27
+ end
28
+
29
+ private
30
+
31
+ def controller_name
32
+ controller.controller_name
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,16 @@
1
+ <td colspan="<%= colspan %>">
2
+ <%= simple_form_for object, remote: true,
3
+ wrapper: :smart_managing_form,
4
+ html: { class: 'form-horizontal' } do |f| %>
5
+ <% editable_attributes.each do |attr| %>
6
+ <%= f.input attr %>
7
+ <% end %>
8
+ <div class="form-group">
9
+ <label class="control-label col-md-3"></label>
10
+ <div class="col-md-5">
11
+ <%= f.button :submit, "Save", class: "btn btn-primary" %>
12
+ <button class="btn btn-link cancel">Cancel</button>
13
+ </div>
14
+ </div>
15
+ <% end %>
16
+ </td>
@@ -0,0 +1,10 @@
1
+ <% attributes.each do |attr| %>
2
+ <td>
3
+ <%= object.send(attr) %>
4
+ </td>
5
+ <% end %>
6
+ <td class="actions">
7
+ <%= smart_listing_item_actions [
8
+ {name: :edit, url: edit_polymorphic_path(object)},
9
+ {name: :destroy, url: polymorphic_path(object), confirmation: 'Sure?'}] %>
10
+ </td>
@@ -0,0 +1,19 @@
1
+ <table class="table table-striped">
2
+ <thead>
3
+ <% attributes.each do |attr| %>
4
+ <th><%= attr.humanize %></th>
5
+ <% end %>
6
+ <th></th>
7
+ </thead>
8
+ <tbody>
9
+ <% smart_listing.collection.each do |resource| %>
10
+ <tr class="editable" data-id="<%= resource.id %>">
11
+ <%= smart_listing.render object: resource, partial: 'item',
12
+ locals: { object: resource } %>
13
+ </tr>
14
+ <% end %>
15
+ <%= smart_listing.item_new colspan: colspan, link: new_item_path %>
16
+ </tbody>
17
+ </table>
18
+ <%= smart_listing.paginate %>
19
+ <%= smart_listing.pagination_per_page_links %>
@@ -0,0 +1 @@
1
+ <%= smart_listing_render %>
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
@@ -0,0 +1,9 @@
1
+ class SmartManaging::InstallGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ desc 'Copy initializer files'
5
+ def copy_initializer
6
+ template 'initializer.rb', 'config/initializers/smart_managing.rb'
7
+ template 'simple_form_smart_managing.rb', 'config/initializers/simple_form_smart_managing.rb'
8
+ end
9
+ end
@@ -0,0 +1 @@
1
+ Dir["#{Rails.root}/app/managers/*.rb"].each {|file| require file }
@@ -0,0 +1,12 @@
1
+ SimpleForm.setup do |config|
2
+ config.wrappers :smart_managing_form, tag: 'div', class: 'control-group form-group', error_class: 'has-error' do |b|
3
+ b.use :html5
4
+ b.use :placeholder
5
+ b.use :label, class: 'col-md-3'
6
+ b.wrapper tag: 'div' do |ba|
7
+ ba.use :input, class: 'form-control', wrap_with: { tag: 'div', class: 'col-md-5' }
8
+ ba.use :error, wrap_with: { tag: 'span', class: 'help-inline' }
9
+ ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,50 @@
1
+ module SmartManaging
2
+ module ControllerHelpers
3
+
4
+ def index
5
+ smart_listing_create partial: 'list'
6
+ respond_to do |format|
7
+ format.html { render formats: :html }
8
+ format.js { render formats: :js }
9
+ end
10
+ end
11
+
12
+ private
13
+
14
+ def self.included(c)
15
+ return unless c < ActionController::Base
16
+ c.helper_method :manager
17
+ c.include SmartListing::Helper::ControllerExtensions
18
+ c.helper SmartListing::Helper
19
+ c.respond_to :html, :js
20
+ end
21
+
22
+ def manager
23
+ @manager ||= manager_class.new(self)
24
+ end
25
+
26
+ def manager_class
27
+ custom_class? ? custom_class : SmartManaging::Base
28
+ end
29
+
30
+ def custom_class?
31
+ Object.const_defined?(custom_manager_name)
32
+ end
33
+
34
+ def custom_class
35
+ custom_manager_name.constantize
36
+ end
37
+
38
+ def custom_manager_name
39
+ "#{controller_name.classify}Manager"
40
+ end
41
+
42
+ def _prefixes
43
+ super << 'smart_managing'
44
+ end
45
+
46
+ def build_resource_params
47
+ [params.fetch(manager.model_sym, {}).permit(manager.attributes)]
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,4 @@
1
+ module SmartManaging
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module SmartManaging
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,11 @@
1
+ require 'jquery-rails'
2
+ require 'coffee-rails'
3
+ require 'bootstrap-sass'
4
+ require 'smart_listing'
5
+ require 'simple_form'
6
+ require 'smart_managing/engine'
7
+ require 'smart_managing/controller_helpers'
8
+
9
+ module SmartManaging
10
+ UNEDITABLE_ATTRIBUTES = ['id', 'created_at', 'updated_at']
11
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :smart_managing do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,216 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smart_managing
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Guirec Corbel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: smart_listing
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: jquery-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: coffee-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bootstrap-sass
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.3'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simple_form
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 3.1.0.rc2
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 3.1.0.rc2
97
+ - !ruby/object:Gem::Dependency
98
+ name: sqlite3
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.3'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.3'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec-rails
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.1'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.1'
125
+ - !ruby/object:Gem::Dependency
126
+ name: capybara
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '2.4'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '2.4'
139
+ - !ruby/object:Gem::Dependency
140
+ name: capybara-webkit
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '1.3'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '1.3'
153
+ - !ruby/object:Gem::Dependency
154
+ name: database_cleaner
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '1.3'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '1.3'
167
+ description:
168
+ email:
169
+ - guirec.corbel@gmail.com
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - MIT-LICENSE
175
+ - README.md
176
+ - Rakefile
177
+ - app/helpers/smart_managing/application_helper.rb
178
+ - app/managers/smart_managing/base.rb
179
+ - app/views/smart_managing/_form.html.erb
180
+ - app/views/smart_managing/_item.html.erb
181
+ - app/views/smart_managing/_list.html.erb
182
+ - app/views/smart_managing/index.html.erb
183
+ - config/routes.rb
184
+ - lib/generators/smart_managing/install/install_generator.rb
185
+ - lib/generators/smart_managing/install/templates/initializer.rb
186
+ - lib/generators/smart_managing/install/templates/simple_form_smart_managing.rb
187
+ - lib/smart_managing.rb
188
+ - lib/smart_managing/controller_helpers.rb
189
+ - lib/smart_managing/engine.rb
190
+ - lib/smart_managing/version.rb
191
+ - lib/tasks/smart_managing_tasks.rake
192
+ homepage: https://github.com/GCorbel/smart_managing
193
+ licenses:
194
+ - MIT
195
+ metadata: {}
196
+ post_install_message:
197
+ rdoc_options: []
198
+ require_paths:
199
+ - lib
200
+ required_ruby_version: !ruby/object:Gem::Requirement
201
+ requirements:
202
+ - - ">="
203
+ - !ruby/object:Gem::Version
204
+ version: '0'
205
+ required_rubygems_version: !ruby/object:Gem::Requirement
206
+ requirements:
207
+ - - ">="
208
+ - !ruby/object:Gem::Version
209
+ version: '0'
210
+ requirements: []
211
+ rubyforge_project:
212
+ rubygems_version: 2.4.2
213
+ signing_key:
214
+ specification_version: 4
215
+ summary: Easy way to create a managing interface.
216
+ test_files: []