wallaby-view 0.1.1 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +51 -16
- data/lib/wallaby/view.rb +18 -42
- data/lib/wallaby/view/action_viewable.rb +18 -13
- data/lib/wallaby/view/custom_lookup_context.rb +2 -2
- data/lib/wallaby/view/custom_prefixes.rb +24 -16
- data/lib/wallaby/view/themeable.rb +22 -25
- data/lib/wallaby/view/version.rb +1 -1
- metadata +62 -15
- data/lib/action_view/partial_renderer.rb +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3a499676db69e41f08251a98cd380af6875ac62ec9dee5f0e0a3b417ea04c8d
|
4
|
+
data.tar.gz: f614b7e34a5d24843550ccd17fd8f30e2f684c3d8a0198cab0ff09e6e9bea76b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2011712b90441fab47976d2b9b381b6e7a879dbf5959be12bb5730ffb15472fc38f29985b615e46ea67821a7ab9657fa496750c71a904900a90e6c6c9cc0775
|
7
|
+
data.tar.gz: de63a2f32221fabbbfd905368ba74e95ba2342a96eda42b8d0e52f021e3e029387f25da8cb4be58f077156bb47fb4c24f69400120daa74af11ba90ce3aa4f306
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Wallaby::View
|
1
|
+
# [Wallaby::View](https://github.com/wallaby-rails/wallaby-view)
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/wallaby-view.svg)](https://badge.fury.io/rb/wallaby-view)
|
4
4
|
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
|
@@ -7,11 +7,14 @@
|
|
7
7
|
[![Test Coverage](https://api.codeclimate.com/v1/badges/d3e924dd70cc12562eab/test_coverage)](https://codeclimate.com/github/wallaby-rails/wallaby-view/test_coverage)
|
8
8
|
[![Inch CI](https://inch-ci.org/github/wallaby-rails/wallaby-view.svg?branch=master)](https://inch-ci.org/github/wallaby-rails/wallaby-view)
|
9
9
|
|
10
|
-
|
10
|
+
**Wallaby::View** extends Rails template/partial inheritance chain to be able to:
|
11
|
+
|
12
|
+
- organize partials in `#{controller_path}/#{action}` fashion on top of Rails' controller fashion by extending Rails' [\_prefixes](https://github.com/rails/rails/blob/master/actionview/lib/action_view/view_paths.rb#L90).
|
13
|
+
- configure the theme (a set of layout/templates/partials starting with the theme prefix).
|
11
14
|
|
12
15
|
## Install
|
13
16
|
|
14
|
-
Add
|
17
|
+
Add **Wallaby::View** to `Gemfile`.
|
15
18
|
|
16
19
|
```ruby
|
17
20
|
gem 'wallaby-view'
|
@@ -23,7 +26,7 @@ And re-bundle.
|
|
23
26
|
bundle install
|
24
27
|
```
|
25
28
|
|
26
|
-
Include
|
29
|
+
Include **Wallaby::View** in the controller (e.g. **ApplicationController**):
|
27
30
|
|
28
31
|
```ruby
|
29
32
|
# app/controllers/application_controller
|
@@ -43,18 +46,18 @@ class ApplicationController < ActionController::Base
|
|
43
46
|
end
|
44
47
|
|
45
48
|
# app/controllers/admin/application_controller
|
46
|
-
class Admin::ApplicationController < ApplicationController
|
49
|
+
class Admin::ApplicationController < ::ApplicationController
|
47
50
|
self.theme_name = 'secure'
|
48
51
|
end
|
49
52
|
|
50
53
|
# app/controllers/admin/users_controller
|
51
54
|
class Admin::UsersController < Admin::ApplicationController
|
52
55
|
self.theme_name = 'account'
|
53
|
-
self.
|
56
|
+
self.prefix_options = { edit: 'form' }
|
54
57
|
end
|
55
58
|
```
|
56
59
|
|
57
|
-
By using
|
60
|
+
By using **Wallaby::View**, a template/partial for the `admin/application#edit` action will be looked up in the following folder order from top to bottom:
|
58
61
|
|
59
62
|
- app/views/admin/application/edit
|
60
63
|
- app/views/admin/application
|
@@ -63,40 +66,72 @@ By using `Wallaby::View`, the lookup folder order of `admin/application#edit` ac
|
|
63
66
|
- app/views/application/edit
|
64
67
|
- app/views/application
|
65
68
|
|
66
|
-
Then it
|
69
|
+
Then it depends on how a relative partial should be shared, the partial can be created in one of the above folders.
|
70
|
+
For example, if a `form` partial is designed specifically for `admin/application#edit` action, then it can be created in `admin/application/edit` folder as below:
|
71
|
+
|
72
|
+
```erb
|
73
|
+
<%# app/views/admin/application/edit/_form.html.erb %>
|
74
|
+
a form for `admin/application#edit`
|
75
|
+
```
|
76
|
+
|
77
|
+
Then in the `admin/application#edit` template, rendering the relative `form` partial will result in using the above partial.
|
67
78
|
|
68
79
|
```erb
|
69
80
|
<%# app/views/admin/application/edit.html.erb %>
|
70
81
|
<% render 'form' %>
|
71
|
-
|
72
|
-
<%# app/views/secure/edit/_form.html.erb %>
|
73
|
-
This form partial is under `secure` theme and `edit` action,
|
74
|
-
but still can be rendered by `admin/application#edit` action
|
75
82
|
```
|
76
83
|
|
77
|
-
For `admin/users#edit` action, since `
|
84
|
+
For `admin/users#edit` action, since `prefix_options` option is set, `edit` will be mapped to `form`, and `form` will be added to the prefixes as well.
|
78
85
|
Therefore, the lookup folder order of `admin/users#edit` becomes:
|
79
86
|
|
87
|
+
- app/views/admin/users/edit
|
80
88
|
- app/views/admin/users/form
|
81
89
|
- app/views/admin/users
|
90
|
+
- app/views/secure/edit
|
82
91
|
- app/views/secure/form
|
83
92
|
- app/views/secure
|
93
|
+
- app/views/admin/application/edit
|
84
94
|
- app/views/admin/application/form
|
85
95
|
- app/views/admin/application
|
96
|
+
- app/views/secure/edit
|
86
97
|
- app/views/secure/form
|
87
98
|
- app/views/secure
|
99
|
+
- app/views/application/edit
|
88
100
|
- app/views/application/form
|
89
101
|
- app/views/application
|
90
102
|
|
103
|
+
## Advanced Usage
|
104
|
+
|
105
|
+
It is possible to override the `_prefixes` method to make more changes to the prefixes before suffixing them with the action name:
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
class ApplicationController < ActionController::Base
|
109
|
+
include Wallaby::View
|
110
|
+
|
111
|
+
def _prefixes
|
112
|
+
super do |prefixes|
|
113
|
+
prefixes << 'last_resort'
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
```
|
118
|
+
|
119
|
+
Then the lookup folder order of e.g. `application#edit` becomes:
|
120
|
+
|
121
|
+
- app/views/application/edit
|
122
|
+
- app/views/application
|
123
|
+
- app/views/last_resort/edit
|
124
|
+
- app/views/last_resort
|
125
|
+
|
91
126
|
## Documentation
|
92
127
|
|
93
128
|
- [API Reference](https://www.rubydoc.info/gems/wallaby-view)
|
94
|
-
- [Change Logs](CHANGELOG.md)
|
129
|
+
- [Change Logs](https://github.com/wallaby-rails/wallaby-view/blob/master/CHANGELOG.md)
|
95
130
|
|
96
131
|
## Want to contribute?
|
97
132
|
|
98
|
-
Raise an issue, discuss and resolve!
|
133
|
+
Raise an [issue](https://github.com/wallaby-rails/wallaby-view/issues/new), discuss and resolve!
|
99
134
|
|
100
135
|
## License
|
101
136
|
|
102
|
-
This project uses [MIT License](LICENSE).
|
137
|
+
This project uses [MIT License](https://github.com/wallaby-rails/wallaby-view/blob/master/LICENSE).
|
data/lib/wallaby/view.rb
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'request_store'
|
4
|
-
require 'action_view/partial_renderer'
|
5
|
-
|
6
3
|
require 'wallaby/view/version'
|
7
4
|
require 'wallaby/view/action_viewable'
|
8
5
|
require 'wallaby/view/themeable'
|
@@ -11,48 +8,18 @@ require 'wallaby/view/custom_prefixes'
|
|
11
8
|
|
12
9
|
module Wallaby # :nodoc:
|
13
10
|
# To extend Rails prefixes and improve lookup performance.
|
11
|
+
#
|
12
|
+
# For example, include {Wallaby::View} module in the controller:
|
13
|
+
#
|
14
|
+
# ```
|
15
|
+
# # app/controllers/application_controller
|
16
|
+
# class ApplicationController < ActionController::Base
|
17
|
+
# include Wallaby::View
|
18
|
+
# end
|
19
|
+
# ```
|
14
20
|
module View
|
15
21
|
extend ActiveSupport::Concern
|
16
22
|
|
17
|
-
# This is the method executed when this module is included by other modules.
|
18
|
-
#
|
19
|
-
# Basically, it renames the methods so that it is possible
|
20
|
-
# to access the original methods after overriding them:
|
21
|
-
#
|
22
|
-
# 1. Rename the following original methods:
|
23
|
-
#
|
24
|
-
# - rename {https://github.com/rails/rails/blob/master/actionview/lib/action_view/view_paths.rb#L97
|
25
|
-
# lookup_context} to {Wallaby::View::ActionViewable#original_lookup_context original_lookup_context}
|
26
|
-
# - rename {https://github.com/rails/rails/blob/master/actionview/lib/action_view/view_paths.rb#L90 _prefixes}
|
27
|
-
# to {Wallaby::View::ActionViewable#original_prefixes original_prefixes}
|
28
|
-
#
|
29
|
-
# 2. Override the original methods:
|
30
|
-
#
|
31
|
-
# - rename {Wallaby::View::ActionViewable#override_lookup_context override_lookup_context}
|
32
|
-
# to {Wallaby::View::ActionViewable#lookup_context lookup_context}
|
33
|
-
# - rename {Wallaby::View::ActionViewable#override_prefixes override_prefixes}
|
34
|
-
# to {Wallaby::View::ActionViewable#\_prefixes \_prefixes}
|
35
|
-
# @param mod [Module]
|
36
|
-
def self.included(mod)
|
37
|
-
mod.send :alias_method, :original_lookup_context, :lookup_context
|
38
|
-
mod.send :alias_method, :original_prefixes, :_prefixes
|
39
|
-
mod.send :alias_method, :lookup_context, :override_lookup_context
|
40
|
-
mod.send :alias_method, :_prefixes, :override_prefixes
|
41
|
-
end
|
42
|
-
|
43
|
-
# Util method to check if the given subject responds to the given method.
|
44
|
-
#
|
45
|
-
# If so, it will send the message and return the result. Otherwise, nil.
|
46
|
-
# @param subject [Object]
|
47
|
-
# @param method_id [Symbol, String]
|
48
|
-
# @param args [Array]
|
49
|
-
# @return [Object, nil]
|
50
|
-
def self.try_to(subject, method_id, *args, &block)
|
51
|
-
return unless subject.respond_to?(method_id)
|
52
|
-
|
53
|
-
subject.public_send(method_id, *args, &block)
|
54
|
-
end
|
55
|
-
|
56
23
|
COMMA = ',' # :nodoc:
|
57
24
|
EMPTY_STRING = '' # :nodoc:
|
58
25
|
DOT_RB = '.rb' # :nodoc:
|
@@ -62,5 +29,14 @@ module Wallaby # :nodoc:
|
|
62
29
|
|
63
30
|
include ActionViewable
|
64
31
|
include Themeable
|
32
|
+
|
33
|
+
included do
|
34
|
+
# NOTE: Basically, it renames the methods so that it is possible
|
35
|
+
# to access the original methods after overriding them:
|
36
|
+
alias_method :original_lookup_context, :lookup_context
|
37
|
+
alias_method :original_prefixes, :_prefixes
|
38
|
+
alias_method :lookup_context, :override_lookup_context
|
39
|
+
alias_method :_prefixes, :override_prefixes
|
40
|
+
end
|
65
41
|
end
|
66
42
|
end
|
@@ -7,17 +7,22 @@ module Wallaby
|
|
7
7
|
module ActionViewable
|
8
8
|
extend ActiveSupport::Concern
|
9
9
|
|
10
|
-
|
11
|
-
# @!attribute prefix_options
|
12
|
-
# It stores the options for {#_prefixes}. It can inherit options from superclass.
|
13
|
-
# @return [Hash] prefix options
|
14
|
-
end
|
15
|
-
|
16
|
-
class_methods do
|
10
|
+
module ClassMethods # :nodoc:
|
11
|
+
# @!attribute [w] prefix_options
|
17
12
|
attr_writer :prefix_options
|
18
13
|
|
14
|
+
# @!attribute [r] prefix_options
|
15
|
+
# It stores the options for {#_prefixes #_prefixes}. It can inherit options from superclass.
|
16
|
+
# @return [Hash] prefix options
|
19
17
|
def prefix_options
|
20
|
-
@prefix_options ||=
|
18
|
+
@prefix_options ||= superclass.try(:prefix_options).try(:dup) || {}
|
19
|
+
end
|
20
|
+
|
21
|
+
# Add prefix options
|
22
|
+
# @param new_options [Hash]
|
23
|
+
# @return [Hash] merged prefix options
|
24
|
+
def merge_prefix_options(new_options)
|
25
|
+
prefix_options.merge!(new_options)
|
21
26
|
end
|
22
27
|
end
|
23
28
|
|
@@ -33,7 +38,7 @@ module Wallaby
|
|
33
38
|
# Override
|
34
39
|
# {https://github.com/rails/rails/blob/master/actionview/lib/action_view/view_paths.rb#L97 lookup_context}
|
35
40
|
# to provide caching for template/partial lookup.
|
36
|
-
# @return {
|
41
|
+
# @return {CustomLookupContext}
|
37
42
|
|
38
43
|
# (see #lookup_context)
|
39
44
|
def override_lookup_context
|
@@ -43,12 +48,12 @@ module Wallaby
|
|
43
48
|
|
44
49
|
# @!method _prefixes(prefixes: nil, controller_path: nil, action_name: nil, themes: nil, options: nil, &block)
|
45
50
|
# Override {https://github.com/rails/rails/blob/master/actionview/lib/action_view/view_paths.rb#L90 _prefixes}
|
46
|
-
# to allow other (e.g. {
|
47
|
-
# {
|
51
|
+
# to allow other (e.g. {CustomPrefixes#action_name},
|
52
|
+
# {CustomPrefixes#themes}) to be added to the prefixes list.
|
48
53
|
# @param prefixes [Array<String>] the base prefixes
|
49
54
|
# @param action_name [String] the action name to add to the prefixes list
|
50
55
|
# @param themes [String] the theme name to add to the prefixes list
|
51
|
-
# @param options [Hash] the options
|
56
|
+
# @param options [Hash] the options that {CustomPrefixes} accepts
|
52
57
|
# @return [Array<String>]
|
53
58
|
|
54
59
|
# (see #_prefixes)
|
@@ -63,7 +68,7 @@ module Wallaby
|
|
63
68
|
prefixes: prefixes || original_prefixes,
|
64
69
|
action_name: action_name || params[:action],
|
65
70
|
themes: themes || self.class.themes,
|
66
|
-
options:
|
71
|
+
options: self.class.prefix_options.merge(options || {}), &block
|
67
72
|
)
|
68
73
|
end
|
69
74
|
end
|
@@ -4,11 +4,11 @@ module Wallaby
|
|
4
4
|
module View
|
5
5
|
# Custom lookup context to cache lookup results.
|
6
6
|
class CustomLookupContext < ::ActionView::LookupContext
|
7
|
-
# Convert an ActionView::LookupContext instance into {
|
7
|
+
# Convert an ActionView::LookupContext instance into {CustomLookupContext}
|
8
8
|
# @param lookup_context [ActionView::LookupContext]
|
9
9
|
# @param details [Hash]
|
10
10
|
# @param prefixes [Array<String>]
|
11
|
-
# @return [
|
11
|
+
# @return [CustomLookupContext]
|
12
12
|
def self.convert(lookup_context, details: nil, prefixes: nil)
|
13
13
|
return lookup_context if lookup_context.is_a? self
|
14
14
|
|
@@ -7,17 +7,20 @@ module Wallaby
|
|
7
7
|
# @!attribute [r] prefixes
|
8
8
|
# Base prefixes to extend
|
9
9
|
# @return [Array<String>]
|
10
|
-
# @see
|
10
|
+
# @see ActionViewable#_prefixes
|
11
11
|
attr_reader :prefixes
|
12
|
+
|
12
13
|
# @!attribute [r] action_name
|
13
14
|
# Action name to be added
|
14
15
|
# @return [String]
|
15
16
|
attr_reader :action_name
|
17
|
+
|
16
18
|
# @!attribute [r] themes
|
17
19
|
# Themes to be inserted
|
18
20
|
# @return [Array<Hash>]
|
19
|
-
# @see
|
21
|
+
# @see Themeable#.themes
|
20
22
|
attr_reader :themes
|
23
|
+
|
21
24
|
# @!attribute [r] options
|
22
25
|
# Options for extending the given prefixes
|
23
26
|
# @return [Hash]
|
@@ -28,6 +31,7 @@ module Wallaby
|
|
28
31
|
# Wallaby::View::CustomPrefixes.execute(
|
29
32
|
# prefixes: ['users', 'application'], action_name: 'index'
|
30
33
|
# )
|
34
|
+
#
|
31
35
|
# # => [
|
32
36
|
# # 'users/index',
|
33
37
|
# # 'users',
|
@@ -39,6 +43,7 @@ module Wallaby
|
|
39
43
|
# prefixes: ['users', 'application'], action_name: 'index',
|
40
44
|
# themes: [{ theme_name: 'secure', theme_path: 'users' }]
|
41
45
|
# )
|
46
|
+
#
|
42
47
|
# # => [
|
43
48
|
# # 'users/index',
|
44
49
|
# # 'users',
|
@@ -50,8 +55,9 @@ module Wallaby
|
|
50
55
|
# @example To extend given prefixes with mapped action:
|
51
56
|
# Wallaby::View::CustomPrefixes.execute(
|
52
57
|
# prefixes: ['users', 'application'], action_name: 'edit',
|
53
|
-
# options: {
|
58
|
+
# options: { 'edit' => 'form' }
|
54
59
|
# )
|
60
|
+
#
|
55
61
|
# # => [
|
56
62
|
# # 'users/form',
|
57
63
|
# # 'users',
|
@@ -88,35 +94,37 @@ module Wallaby
|
|
88
94
|
# @return [Array<String>]
|
89
95
|
def execute(&block)
|
90
96
|
new_prefixes(&block).each_with_object([]) do |prefix, array|
|
91
|
-
# Extend the prefix with
|
92
|
-
array << "#{prefix}/#{
|
97
|
+
# Extend the prefix with actions
|
98
|
+
actions.each { |action| array << "#{prefix}/#{action}" }
|
99
|
+
array << prefix
|
93
100
|
end
|
94
101
|
end
|
95
102
|
|
96
|
-
|
103
|
+
protected
|
97
104
|
|
105
|
+
# @yield [array] To allow the array to be further modified
|
106
|
+
# @yieldparam [Array<String>] array
|
98
107
|
# @return [Array<String>]
|
99
108
|
def new_prefixes
|
100
109
|
prefixes.dup.try do |array|
|
101
110
|
insert_themes_into array
|
102
111
|
|
103
112
|
# Be able to change the array in overriding methods
|
104
|
-
# in {
|
113
|
+
# in {ActionViewable#override_prefixes}
|
105
114
|
new_array = yield array if block_given?
|
106
115
|
|
107
|
-
# If the above block doesn't return
|
108
|
-
# it's assumed that `array` is changed
|
116
|
+
# If the above block doesn't return a new array, it returns the old `array`.
|
109
117
|
new_array.is_a?(Array) ? new_array : array
|
110
118
|
end
|
111
119
|
end
|
112
120
|
|
113
|
-
# Action
|
114
|
-
|
115
|
-
|
116
|
-
@suffix ||= mapped_action_name || action_name
|
121
|
+
# @return [Array<String>] Action names
|
122
|
+
def actions
|
123
|
+
@actions ||= [action_name, *mapped_action_name].compact
|
117
124
|
end
|
118
125
|
|
119
|
-
# Insert theme
|
126
|
+
# Insert theme names into the prefixes
|
127
|
+
# @param [Array<String>] array
|
120
128
|
def insert_themes_into(array)
|
121
129
|
themes.each do |theme|
|
122
130
|
index = array.index theme[:theme_path]
|
@@ -125,9 +133,9 @@ module Wallaby
|
|
125
133
|
end
|
126
134
|
|
127
135
|
# Map the {#action_name} using `options[:mapping_actions]`
|
128
|
-
# @return [String
|
136
|
+
# @return [Array<String>] mapped action name
|
129
137
|
def mapped_action_name
|
130
|
-
options[:mapping_actions].try(:[], action_name)
|
138
|
+
Array((options[:mapping_actions] || options).try(:[], action_name))
|
131
139
|
end
|
132
140
|
end
|
133
141
|
end
|
@@ -6,8 +6,7 @@ module Wallaby
|
|
6
6
|
module Themeable
|
7
7
|
extend ActiveSupport::Concern
|
8
8
|
|
9
|
-
|
10
|
-
# @!attribute theme_name
|
9
|
+
module ClassMethods # :nodoc:
|
11
10
|
# The theme name is used to specify the layout and prefixes
|
12
11
|
# so that a set of theme implementation for the frontend (html/css/javascript)
|
13
12
|
# can be applied
|
@@ -27,6 +26,7 @@ module Wallaby
|
|
27
26
|
#
|
28
27
|
# def index
|
29
28
|
# _prefixes
|
29
|
+
#
|
30
30
|
# # =>
|
31
31
|
# # [
|
32
32
|
# # 'admin/application/index',
|
@@ -37,8 +37,22 @@ module Wallaby
|
|
37
37
|
# # 'application'
|
38
38
|
# # ]
|
39
39
|
# end
|
40
|
-
#
|
40
|
+
# end
|
41
|
+
# @param theme_name [String]
|
42
|
+
# @param options [Hash] same options as Rails'
|
43
|
+
# {https://api.rubyonrails.org/classes/ActionView/Layouts/ClassMethods.html#method-i-layout
|
44
|
+
# layout} method
|
45
|
+
def theme_name=(theme_name, **options, &block)
|
46
|
+
layout theme_name, options, &block
|
47
|
+
@theme_path = theme_name && controller_path || nil
|
48
|
+
@theme_name = theme_name || nil
|
49
|
+
end
|
50
|
+
|
51
|
+
# @!attribute [r] theme_name
|
41
52
|
# @return [String, nil] theme name
|
53
|
+
def theme_name
|
54
|
+
defined?(@theme_name) && @theme_name || superclass.try(:theme_name)
|
55
|
+
end
|
42
56
|
|
43
57
|
# @!attribute [r] theme
|
44
58
|
# @example Once theme is set, the metadata will be set as well:
|
@@ -46,6 +60,7 @@ module Wallaby
|
|
46
60
|
# self.theme_name = 'secure'
|
47
61
|
#
|
48
62
|
# self.theme
|
63
|
+
#
|
49
64
|
# # =>
|
50
65
|
# # {
|
51
66
|
# # theme_name: 'secure',
|
@@ -53,35 +68,17 @@ module Wallaby
|
|
53
68
|
# # }
|
54
69
|
# end
|
55
70
|
# @return [Hash] theme metadata
|
56
|
-
|
57
|
-
# @!attribute [r] themes
|
58
|
-
# @return [Array<Hash>] a list of {.theme} metadata
|
59
|
-
end
|
60
|
-
|
61
|
-
class_methods do
|
62
|
-
# (see .theme_name)
|
63
|
-
def theme_name=(theme_name, **options, &block)
|
64
|
-
layout theme_name, options, &block
|
65
|
-
@theme_path = theme_name && controller_path || nil
|
66
|
-
@theme_name = theme_name || nil
|
67
|
-
end
|
68
|
-
|
69
|
-
# (see .theme_name)
|
70
|
-
def theme_name
|
71
|
-
defined?(@theme_name) && @theme_name || View.try_to(superclass, :theme_name)
|
72
|
-
end
|
73
|
-
|
74
|
-
# (see .theme)
|
75
71
|
def theme
|
76
72
|
defined?(@theme_name) && @theme_name && {
|
77
73
|
theme_name: @theme_name,
|
78
74
|
theme_path: @theme_path
|
79
|
-
} ||
|
75
|
+
} || superclass.try(:theme)
|
80
76
|
end
|
81
77
|
|
82
|
-
#
|
78
|
+
# @!attribute [r] themes
|
79
|
+
# @return [Array<Hash>] a list of {#theme} metadata
|
83
80
|
def themes
|
84
|
-
list =
|
81
|
+
list = superclass.try(:themes) || []
|
85
82
|
list.prepend theme if defined?(@theme_name) && @theme_name
|
86
83
|
list.compact
|
87
84
|
end
|
data/lib/wallaby/view/version.rb
CHANGED
metadata
CHANGED
@@ -1,22 +1,25 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wallaby-view
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tian Chen
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: railties
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 4.2.0
|
20
|
+
- - "<="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 6.2.0
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -24,28 +27,31 @@ dependencies:
|
|
24
27
|
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: 4.2.0
|
30
|
+
- - "<="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 6.2.0
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
34
|
+
name: github-markup
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
37
|
- - ">="
|
32
38
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
34
|
-
type: :
|
39
|
+
version: '0'
|
40
|
+
type: :development
|
35
41
|
prerelease: false
|
36
42
|
version_requirements: !ruby/object:Gem::Requirement
|
37
43
|
requirements:
|
38
44
|
- - ">="
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
46
|
+
version: '0'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
48
|
+
name: minitest-rails
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
51
|
- - ">="
|
46
52
|
- !ruby/object:Gem::Version
|
47
53
|
version: '0'
|
48
|
-
type: :
|
54
|
+
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
51
57
|
requirements:
|
@@ -53,7 +59,35 @@ dependencies:
|
|
53
59
|
- !ruby/object:Gem::Version
|
54
60
|
version: '0'
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
62
|
+
name: redcarpet
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: simplecov
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: sqlite3
|
57
91
|
requirement: !ruby/object:Gem::Requirement
|
58
92
|
requirements:
|
59
93
|
- - ">="
|
@@ -80,6 +114,20 @@ dependencies:
|
|
80
114
|
- - ">="
|
81
115
|
- !ruby/object:Gem::Version
|
82
116
|
version: '0'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: yard
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
83
131
|
description: Wallaby View to extend Rails layout/template/partial inheritance chain.
|
84
132
|
email:
|
85
133
|
- me@tian.im
|
@@ -89,7 +137,6 @@ extra_rdoc_files: []
|
|
89
137
|
files:
|
90
138
|
- LICENSE
|
91
139
|
- README.md
|
92
|
-
- lib/action_view/partial_renderer.rb
|
93
140
|
- lib/wallaby/view.rb
|
94
141
|
- lib/wallaby/view/action_viewable.rb
|
95
142
|
- lib/wallaby/view/custom_lookup_context.rb
|
@@ -103,7 +150,7 @@ metadata:
|
|
103
150
|
homepage_uri: https://github.com/wallaby-rails/wallaby-view
|
104
151
|
source_code_uri: https://github.com/wallaby-rails/wallaby-view
|
105
152
|
changelog_uri: https://github.com/wallaby-rails/wallaby-view/blob/master/CHANGELOG.md
|
106
|
-
post_install_message:
|
153
|
+
post_install_message:
|
107
154
|
rdoc_options: []
|
108
155
|
require_paths:
|
109
156
|
- lib
|
@@ -118,8 +165,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
165
|
- !ruby/object:Gem::Version
|
119
166
|
version: '0'
|
120
167
|
requirements: []
|
121
|
-
rubygems_version: 3.
|
122
|
-
signing_key:
|
168
|
+
rubygems_version: 3.1.2
|
169
|
+
signing_key:
|
123
170
|
specification_version: 4
|
124
171
|
summary: Wallaby View to extend Rails layout/template/partial inheritance chain.
|
125
172
|
test_files: []
|
@@ -1,42 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ActionView # :nodoc:
|
4
|
-
# Re-open ActionView::PartialRenderer to disable logging for partials
|
5
|
-
# that have been rendered for more than once.
|
6
|
-
#
|
7
|
-
# Every log requires the IO. Reducing the logs will dramatically improve the performance.
|
8
|
-
# @see #instrument
|
9
|
-
class PartialRenderer
|
10
|
-
protected
|
11
|
-
|
12
|
-
# @!method original_instrument(name, **options, &block)
|
13
|
-
# Original method of {#instrument}
|
14
|
-
# @param name [String]
|
15
|
-
# @param options [Hash]
|
16
|
-
# @yield [payload]
|
17
|
-
# @yieldparam payload [Hash] payload object for instrument
|
18
|
-
# @return [ActionView::OutputBuffer]
|
19
|
-
alias original_instrument instrument
|
20
|
-
|
21
|
-
# Logs for partial rendering. Only one log will be printed
|
22
|
-
# even if a partial has been rendered for more than once.
|
23
|
-
#
|
24
|
-
# To disable this feature and see all logs,
|
25
|
-
# set `ENV['ALL_PARTIAL_LOGS']` to `true`
|
26
|
-
# @param name [String]
|
27
|
-
# @param options [Hash]
|
28
|
-
# @yield [payload]
|
29
|
-
# @yieldparam payload [Hash] payload object for instrument
|
30
|
-
# @return [ActionView::OutputBuffer]
|
31
|
-
def instrument(name, **options, &block)
|
32
|
-
identifier = options[:identifier] || @template.try(:identifier) || @path
|
33
|
-
instrumented = RequestStore.store[:instrumented] ||= {}
|
34
|
-
|
35
|
-
return yield({}) if !ENV['ALL_PARTIAL_LOGS'] && instrumented[identifier]
|
36
|
-
|
37
|
-
original_instrument(name, **options, &block).tap do
|
38
|
-
instrumented[identifier] ||= true
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|