rails-add_ons 0.6.0 → 1.0.0
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 +4 -4
- data/README.md +8 -0
- data/app/assets/javascripts/rails/add_ons/application.js +0 -1
- data/app/components/component/collection_table.rb +3 -3
- data/app/concerns/resources_controller/location_history.rb +31 -0
- data/app/concerns/resources_controller/resource_inflections.rb +16 -0
- data/app/concerns/resources_controller/resources.rb +11 -0
- data/app/concerns/resources_controller/rest_actions.rb +78 -0
- data/app/concerns/resources_controller/rest_resource_urls.rb +32 -0
- data/app/controllers/resources_controller/base.rb +0 -173
- data/app/services/rails/add_ons/service/base.rb +0 -39
- data/app/services/rails/add_ons/service/messages.rb +5 -1
- data/lib/rails-add_ons.rb +6 -2
- data/lib/rails/add_ons/version.rb +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec4d8cc8f06e8437cdf7dea6ca365162b767474d
|
4
|
+
data.tar.gz: 9d53aaeeabdc8e86ecc1a860f74e56d2ce5050b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87f4b1f8b9ed7cdb73302ec4b54bd6f638010e13a6e8fa6c58ca4cb656b09f7529fed13309d67dbeb154f363cfbd4a0e04cc5b86302c0c19d2251de41573cb0a
|
7
|
+
data.tar.gz: 7ee7d995a3a4b19690224dacb0138dc6a7ba723ec5e9ae6c196177c0f8e5845bd39b416339978a1451c2eaee0deb5a650e23543da59b7e1dab4f259117513585
|
data/README.md
CHANGED
@@ -12,6 +12,14 @@ You have to add
|
|
12
12
|
|
13
13
|
to your applications javascript include file to use bootstrap-sass.
|
14
14
|
|
15
|
+
### Update path to 1.0.0
|
16
|
+
|
17
|
+
You may want to add
|
18
|
+
|
19
|
+
//= require tether
|
20
|
+
|
21
|
+
to your applications javascript include file, as it was removed.
|
22
|
+
|
15
23
|
## Installation
|
16
24
|
Add this line to your application's Gemfile:
|
17
25
|
|
@@ -17,9 +17,9 @@ module Component
|
|
17
17
|
@columns[name] = options
|
18
18
|
end
|
19
19
|
|
20
|
-
def timestamps
|
21
|
-
column(:created_at)
|
22
|
-
column(:updated_at)
|
20
|
+
def timestamps(options = {})
|
21
|
+
column(:created_at, options)
|
22
|
+
column(:updated_at, options)
|
23
23
|
end
|
24
24
|
|
25
25
|
def association(name, options = {}, &block)
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module ResourcesController::LocationHistory
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
if respond_to?(:before_action)
|
6
|
+
before_action :store_location
|
7
|
+
else
|
8
|
+
before_filter :store_location
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def store_location
|
15
|
+
truncate_location_history(9)
|
16
|
+
location_history[Time.zone.now] = request.referer
|
17
|
+
end
|
18
|
+
|
19
|
+
def location_history
|
20
|
+
session[:location_history] ||= {}
|
21
|
+
end
|
22
|
+
|
23
|
+
def last_location
|
24
|
+
location_history.sort.last.try(:last)
|
25
|
+
end
|
26
|
+
|
27
|
+
def truncate_location_history(count = 0)
|
28
|
+
return if location_history.size <= count
|
29
|
+
session[:location_history] = session[:location_history].sort.last(count).to_h
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module ResourcesController::ResourceInflections
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
helper_method :inflections
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def inflections
|
11
|
+
{
|
12
|
+
resource_name: resource_class.model_name.human(count: 1),
|
13
|
+
collection_name: resource_class.model_name.human(count: 2)
|
14
|
+
}
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module ResourcesController::RestActions
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
include ActionController::MimeResponds
|
6
|
+
|
7
|
+
respond_to :html
|
8
|
+
responders :flash
|
9
|
+
|
10
|
+
if respond_to?(:before_action)
|
11
|
+
before_action :load_collection, only: [:index]
|
12
|
+
before_action :load_resource, only: [:show, :edit, :destroy, :update]
|
13
|
+
before_action :initialize_resource, only: [:new]
|
14
|
+
before_action :initialize_resource_for_create, only: [:create]
|
15
|
+
else
|
16
|
+
before_filter :load_collection, only: [:index]
|
17
|
+
before_filter :load_resource, only: [:show, :edit, :destroy, :update]
|
18
|
+
before_filter :initialize_resource, only: [:new]
|
19
|
+
before_filter :initialize_resource_for_create, only: [:create]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def index; end
|
24
|
+
def new; end
|
25
|
+
def show; end
|
26
|
+
def edit; end
|
27
|
+
|
28
|
+
def update
|
29
|
+
if Rails::VERSION::MAJOR < 4
|
30
|
+
@resource.update_attributes(permitted_params)
|
31
|
+
else
|
32
|
+
@resource.update(permitted_params)
|
33
|
+
end
|
34
|
+
respond_with @resource
|
35
|
+
end
|
36
|
+
|
37
|
+
def destroy
|
38
|
+
@resource.destroy
|
39
|
+
respond_with @resource
|
40
|
+
end
|
41
|
+
|
42
|
+
def create
|
43
|
+
@resource.save
|
44
|
+
respond_with @resource
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def after_create_location
|
50
|
+
->(controller) { resource_path(@resource) }
|
51
|
+
end
|
52
|
+
|
53
|
+
def load_collection_scope
|
54
|
+
resource_class
|
55
|
+
end
|
56
|
+
def load_collection
|
57
|
+
@collection = load_collection_scope.all
|
58
|
+
end
|
59
|
+
|
60
|
+
def load_resource_scope
|
61
|
+
resource_class
|
62
|
+
end
|
63
|
+
def load_resource
|
64
|
+
@resource = load_resource_scope.find(params[:id])
|
65
|
+
end
|
66
|
+
|
67
|
+
def initialize_resource
|
68
|
+
@resource = resource_class.new
|
69
|
+
end
|
70
|
+
|
71
|
+
def initialize_resource_for_create
|
72
|
+
@resource = resource_class.new(permitted_params)
|
73
|
+
end
|
74
|
+
|
75
|
+
def permitted_params
|
76
|
+
raise "not implemented"
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module ResourcesController::RestResourceUrls
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
helper_method :new_resource_path
|
6
|
+
helper_method :collection_path
|
7
|
+
helper_method :resource_path
|
8
|
+
helper_method :edit_resource_path
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def new_resource_path
|
14
|
+
resource_router.send(:url_for, { action: :new, only_path: true })
|
15
|
+
end
|
16
|
+
|
17
|
+
def collection_path
|
18
|
+
resource_router.send(:url_for, { action: :index, only_path: true })
|
19
|
+
end
|
20
|
+
|
21
|
+
def resource_path(resource)
|
22
|
+
resource_router.send(:url_for, { action: :show, id: resource, only_path: true })
|
23
|
+
end
|
24
|
+
|
25
|
+
def edit_resource_path(resource)
|
26
|
+
resource_router.send(:url_for, { action: :edit, id: resource, only_path: true })
|
27
|
+
end
|
28
|
+
|
29
|
+
def resource_router
|
30
|
+
self
|
31
|
+
end
|
32
|
+
end
|
@@ -2,179 +2,6 @@ module ResourcesController
|
|
2
2
|
class Base < ::FrontendController
|
3
3
|
layout 'rails/add_ons/application'
|
4
4
|
|
5
|
-
module RestActions
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
included do
|
9
|
-
include ActionController::MimeResponds
|
10
|
-
|
11
|
-
respond_to :html
|
12
|
-
responders :flash
|
13
|
-
|
14
|
-
if respond_to?(:before_action)
|
15
|
-
before_action :load_collection, only: [:index]
|
16
|
-
before_action :load_resource, only: [:show, :edit, :destroy, :update]
|
17
|
-
before_action :initialize_resource, only: [:new]
|
18
|
-
before_action :initialize_resource_for_create, only: [:create]
|
19
|
-
else
|
20
|
-
before_filter :load_collection, only: [:index]
|
21
|
-
before_filter :load_resource, only: [:show, :edit, :destroy, :update]
|
22
|
-
before_filter :initialize_resource, only: [:new]
|
23
|
-
before_filter :initialize_resource_for_create, only: [:create]
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def index; end
|
28
|
-
def new; end
|
29
|
-
def show; end
|
30
|
-
def edit; end
|
31
|
-
|
32
|
-
def update
|
33
|
-
if Rails::VERSION::MAJOR < 4
|
34
|
-
@resource.update_attributes(permitted_params)
|
35
|
-
else
|
36
|
-
@resource.update(permitted_params)
|
37
|
-
end
|
38
|
-
respond_with @resource
|
39
|
-
end
|
40
|
-
|
41
|
-
def destroy
|
42
|
-
@resource.destroy
|
43
|
-
respond_with @resource
|
44
|
-
end
|
45
|
-
|
46
|
-
def create
|
47
|
-
@resource.save
|
48
|
-
respond_with @resource
|
49
|
-
end
|
50
|
-
|
51
|
-
private
|
52
|
-
|
53
|
-
def after_create_location
|
54
|
-
->(controller) { resource_path(@resource) }
|
55
|
-
end
|
56
|
-
|
57
|
-
def load_collection_scope
|
58
|
-
resource_class
|
59
|
-
end
|
60
|
-
def load_collection
|
61
|
-
@collection = load_collection_scope.all
|
62
|
-
end
|
63
|
-
|
64
|
-
def load_resource_scope
|
65
|
-
resource_class
|
66
|
-
end
|
67
|
-
def load_resource
|
68
|
-
@resource = load_resource_scope.find(params[:id])
|
69
|
-
end
|
70
|
-
|
71
|
-
def initialize_resource
|
72
|
-
@resource = resource_class.new
|
73
|
-
end
|
74
|
-
|
75
|
-
def initialize_resource_for_create
|
76
|
-
@resource = resource_class.new(permitted_params)
|
77
|
-
end
|
78
|
-
|
79
|
-
def permitted_params
|
80
|
-
raise "not implemented"
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
module Resources
|
85
|
-
extend ActiveSupport::Concern
|
86
|
-
|
87
|
-
included do
|
88
|
-
helper_method :resource_class
|
89
|
-
end
|
90
|
-
|
91
|
-
def resource_class
|
92
|
-
self.class.resource_class
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
module RestResourceUrls
|
97
|
-
extend ActiveSupport::Concern
|
98
|
-
|
99
|
-
included do
|
100
|
-
helper_method :new_resource_path
|
101
|
-
helper_method :collection_path
|
102
|
-
helper_method :resource_path
|
103
|
-
helper_method :edit_resource_path
|
104
|
-
end
|
105
|
-
|
106
|
-
private
|
107
|
-
|
108
|
-
def new_resource_path
|
109
|
-
resource_router.send(:url_for, { action: :new, only_path: true })
|
110
|
-
end
|
111
|
-
|
112
|
-
def collection_path
|
113
|
-
resource_router.send(:url_for, { action: :index, only_path: true })
|
114
|
-
end
|
115
|
-
|
116
|
-
def resource_path(resource)
|
117
|
-
resource_router.send(:url_for, { action: :show, id: resource, only_path: true })
|
118
|
-
end
|
119
|
-
|
120
|
-
def edit_resource_path(resource)
|
121
|
-
resource_router.send(:url_for, { action: :edit, id: resource, only_path: true })
|
122
|
-
end
|
123
|
-
|
124
|
-
def resource_router
|
125
|
-
self
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
module ResourceInflections
|
130
|
-
extend ActiveSupport::Concern
|
131
|
-
|
132
|
-
included do
|
133
|
-
helper_method :inflections
|
134
|
-
end
|
135
|
-
|
136
|
-
private
|
137
|
-
|
138
|
-
def inflections
|
139
|
-
{
|
140
|
-
resource_name: resource_class.model_name.human(count: 1),
|
141
|
-
collection_name: resource_class.model_name.human(count: 2)
|
142
|
-
}
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
module LocationHistory
|
147
|
-
extend ActiveSupport::Concern
|
148
|
-
|
149
|
-
included do
|
150
|
-
if respond_to?(:before_action)
|
151
|
-
before_action :store_location
|
152
|
-
else
|
153
|
-
before_filter :store_location
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
private
|
158
|
-
|
159
|
-
def store_location
|
160
|
-
truncate_location_history(9)
|
161
|
-
location_history[Time.zone.now] = request.referer
|
162
|
-
end
|
163
|
-
|
164
|
-
def location_history
|
165
|
-
session[:location_history] ||= {}
|
166
|
-
end
|
167
|
-
|
168
|
-
def last_location
|
169
|
-
location_history.sort.last.try(:last)
|
170
|
-
end
|
171
|
-
|
172
|
-
def truncate_location_history(count = 0)
|
173
|
-
return if location_history.size <= count
|
174
|
-
session[:location_history] = session[:location_history].sort.last(count).to_h
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
5
|
include RestActions
|
179
6
|
include Resources
|
180
7
|
include RestResourceUrls
|
@@ -104,45 +104,6 @@ module Rails
|
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
-
module Messages
|
108
|
-
private
|
109
|
-
|
110
|
-
def initialize_messages
|
111
|
-
@messages = []
|
112
|
-
end
|
113
|
-
|
114
|
-
def say(what, &block)
|
115
|
-
@indent ||= 0
|
116
|
-
if block_given?
|
117
|
-
@indent += 1
|
118
|
-
output "#{output_prefix}#{(" " * @indent)}#{what}..."
|
119
|
-
block_result = yield
|
120
|
-
say_done
|
121
|
-
@indent -= 1
|
122
|
-
block_result
|
123
|
-
else
|
124
|
-
output "#{output_prefix}#{(" " * @indent)}#{what}"
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
def say_done
|
129
|
-
say " => Done"
|
130
|
-
end
|
131
|
-
|
132
|
-
def output_prefix
|
133
|
-
"[#{self.class.name}] "
|
134
|
-
end
|
135
|
-
|
136
|
-
def output(what)
|
137
|
-
@messages << what
|
138
|
-
puts what
|
139
|
-
end
|
140
|
-
|
141
|
-
def copy_messages_to_result
|
142
|
-
@result.instance_variable_set(:@messages, @messages)
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
107
|
include Errors
|
147
108
|
include Resultable
|
148
109
|
include Callbacks
|
data/lib/rails-add_ons.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
require 'haml-rails'
|
2
2
|
require 'font-awesome-rails'
|
3
|
-
|
3
|
+
begin
|
4
|
+
require 'twitter_bootstrap_components_rails'
|
5
|
+
rescue LoadError
|
6
|
+
puts "[Rails AddOns]: WARNING - Could not require twitter_bootstrap_components_rails."
|
7
|
+
end
|
4
8
|
require 'simple_form'
|
5
9
|
require 'responders' if Rails::VERSION::MAJOR > 3
|
6
10
|
require 'rails-i18n'
|
7
11
|
require 'active_model/model' if Rails::VERSION::MAJOR < 4
|
8
12
|
|
9
|
-
require 'rails/add_ons'
|
13
|
+
require 'rails/add_ons'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-add_ons
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roberto Vasquez Angel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -190,7 +190,12 @@ files:
|
|
190
190
|
- app/components/component/collection_table.rb
|
191
191
|
- app/components/component/resource_table.rb
|
192
192
|
- app/concerns/api_controller_concerns/exception_handling.rb
|
193
|
+
- app/concerns/resources_controller/location_history.rb
|
193
194
|
- app/concerns/resources_controller/pagination.rb
|
195
|
+
- app/concerns/resources_controller/resource_inflections.rb
|
196
|
+
- app/concerns/resources_controller/resources.rb
|
197
|
+
- app/concerns/resources_controller/rest_actions.rb
|
198
|
+
- app/concerns/resources_controller/rest_resource_urls.rb
|
194
199
|
- app/concerns/resources_controller/sorting.rb
|
195
200
|
- app/controllers/api/resources_controller/base.rb
|
196
201
|
- app/controllers/api/service_controller/base.rb
|