tuning 4.0.0.1 → 4.0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -0
- data/lib/tuning/extensions/action_view/handlers.rb +30 -0
- data/lib/tuning/railtie.rb +10 -0
- data/lib/tuning/version.rb +1 -1
- data/lib/tuning.rb +1 -0
- data/test/dummy/app/controllers/users_controller.rb +7 -0
- data/test/dummy/app/views/users/index.json.ruby +3 -0
- data/test/dummy/app/views/users/index.xml.ruby +3 -0
- data/test/dummy/config/routes.rb +1 -54
- data/test/dummy/log/test.log +2317 -0
- data/test/view_test.rb +17 -0
- metadata +11 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0081e87effa4ecfe09631c0c22126443a67f18d3
|
4
|
+
data.tar.gz: 3f234d3653f242828c700f97b068cfff2a64bb37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92b149af8b9fa5e62cb30e293d6db0f7d12c994700f14e2177a3aab378d2f80f612d7c830f65f6d580eab22376b38e02624fb62ec97913914d957fdfb5c2b329
|
7
|
+
data.tar.gz: 4317d216eeab34efc94a3704fd29e0ff3f38654e6d4b3b112ed716d4943b49c2dac2f560dcbf51ef5746e61344019dab691cdc0b2d9052baf6595bd22b8d0d67
|
data/README.md
CHANGED
@@ -92,6 +92,15 @@ New extending method to extend layouts:
|
|
92
92
|
<% end %>
|
93
93
|
```
|
94
94
|
|
95
|
+
### Template Handlers
|
96
|
+
|
97
|
+
Ruby template handlers will automatically call to_json or to_xml:
|
98
|
+
```ruby
|
99
|
+
@users.map do |user|
|
100
|
+
user.slice :name
|
101
|
+
end
|
102
|
+
```
|
103
|
+
|
95
104
|
### Records
|
96
105
|
|
97
106
|
Empty strings will be nilify in the database to avoid sql errors or complex queries:
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Tuning
|
2
|
+
module Extensions
|
3
|
+
module ActionView
|
4
|
+
module Handlers
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
class Ruby
|
8
|
+
|
9
|
+
def call(template)
|
10
|
+
<<-STRING
|
11
|
+
output = begin
|
12
|
+
#{template.source}
|
13
|
+
end
|
14
|
+
output#{suffix(template.type.symbol)}
|
15
|
+
STRING
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def suffix(type)
|
21
|
+
if %i(json xml).include?(type)
|
22
|
+
".to_#{type}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/tuning/railtie.rb
CHANGED
@@ -11,6 +11,9 @@ module Tuning
|
|
11
11
|
::ActionView::Base.include(
|
12
12
|
Tuning::Extensions::ActionView::Base
|
13
13
|
)
|
14
|
+
::ActionView::Template::Handlers.include(
|
15
|
+
Tuning::Extensions::ActionView::Handlers
|
16
|
+
)
|
14
17
|
::ActiveRecord::Base.include(
|
15
18
|
Tuning::Extensions::ActiveRecord::Base,
|
16
19
|
Tuning::Validations
|
@@ -20,5 +23,12 @@ module Tuning
|
|
20
23
|
)
|
21
24
|
end
|
22
25
|
|
26
|
+
initializer 'tuning.template_handler' do
|
27
|
+
ActionView::Template.register_template_handler(
|
28
|
+
:ruby,
|
29
|
+
ActionView::Template::Handlers::Ruby.new
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
23
33
|
end
|
24
34
|
end
|
data/lib/tuning/version.rb
CHANGED
data/lib/tuning.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'tuning/extensions/action_controller/base'
|
2
2
|
require 'tuning/extensions/action_mailer/base'
|
3
3
|
require 'tuning/extensions/action_view/base'
|
4
|
+
require 'tuning/extensions/action_view/handlers'
|
4
5
|
require 'tuning/extensions/active_record/base'
|
5
6
|
require 'tuning/validations/complexity'
|
6
7
|
require 'tuning/validations/count'
|
data/test/dummy/config/routes.rb
CHANGED
@@ -1,56 +1,3 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
|
-
|
3
|
-
# See how all your routes lay out with "rake routes".
|
4
|
-
|
5
|
-
# You can have the root of your site routed with "root"
|
6
|
-
# root 'welcome#index'
|
7
|
-
|
8
|
-
# Example of regular route:
|
9
|
-
# get 'products/:id' => 'catalog#view'
|
10
|
-
|
11
|
-
# Example of named route that can be invoked with purchase_url(id: product.id)
|
12
|
-
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
|
13
|
-
|
14
|
-
# Example resource route (maps HTTP verbs to controller actions automatically):
|
15
|
-
# resources :products
|
16
|
-
|
17
|
-
# Example resource route with options:
|
18
|
-
# resources :products do
|
19
|
-
# member do
|
20
|
-
# get 'short'
|
21
|
-
# post 'toggle'
|
22
|
-
# end
|
23
|
-
#
|
24
|
-
# collection do
|
25
|
-
# get 'sold'
|
26
|
-
# end
|
27
|
-
# end
|
28
|
-
|
29
|
-
# Example resource route with sub-resources:
|
30
|
-
# resources :products do
|
31
|
-
# resources :comments, :sales
|
32
|
-
# resource :seller
|
33
|
-
# end
|
34
|
-
|
35
|
-
# Example resource route with more complex sub-resources:
|
36
|
-
# resources :products do
|
37
|
-
# resources :comments
|
38
|
-
# resources :sales do
|
39
|
-
# get 'recent', on: :collection
|
40
|
-
# end
|
41
|
-
# end
|
42
|
-
|
43
|
-
# Example resource route with concerns:
|
44
|
-
# concern :toggleable do
|
45
|
-
# post 'toggle'
|
46
|
-
# end
|
47
|
-
# resources :posts, concerns: :toggleable
|
48
|
-
# resources :photos, concerns: :toggleable
|
49
|
-
|
50
|
-
# Example resource route within a namespace:
|
51
|
-
# namespace :admin do
|
52
|
-
# # Directs /admin/products/* to Admin::ProductsController
|
53
|
-
# # (app/controllers/admin/products_controller.rb)
|
54
|
-
# resources :products
|
55
|
-
# end
|
2
|
+
get 'users' => 'users#index'
|
56
3
|
end
|