actionview-component 1.3.5 → 1.3.6
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/CHANGELOG.md +10 -0
- data/Gemfile.lock +1 -1
- data/lib/action_view/component/base.rb +26 -8
- data/lib/action_view/component/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2e23869593e0482d71b3ea0b082ad050fe3c9a5e1ad4b5e05e5cac866c7f31d
|
4
|
+
data.tar.gz: 9ce7d1453f35246746f90153959c9848baa221042eec5a6376aae59c1433d3f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11bacc8bde616fb29d27bf8fc7b56d5cea3d42c645fd425e56ea638427755ebb89c6b6575702b37f18cf33e56026a7fdbe11582be0bdd610deaea236043ba736
|
7
|
+
data.tar.gz: 59a4a1e938c98e5c942581181e11f4af00d1ac36e49dace1ad42dfc1b10ca8da6cb589d68b07a7adcd3f6a80facab0621cd5be03e1e2eaf082dd18bf0daaf305
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -64,6 +64,7 @@ module ActionView
|
|
64
64
|
@view_renderer ||= view_context.view_renderer
|
65
65
|
@lookup_context ||= view_context.lookup_context
|
66
66
|
@view_flow ||= view_context.view_flow
|
67
|
+
@virtual_path ||= virtual_path
|
67
68
|
|
68
69
|
@content = view_context.capture(&block) if block_given?
|
69
70
|
validate!
|
@@ -84,6 +85,12 @@ module ActionView
|
|
84
85
|
@controller ||= view_context.controller
|
85
86
|
end
|
86
87
|
|
88
|
+
# Looks for the source file path of the initialize method of the instance's class.
|
89
|
+
# Removes the first part of the path and the extension.
|
90
|
+
def virtual_path
|
91
|
+
self.class.source_location.gsub(%r{(.*app/)|(.rb)}, "")
|
92
|
+
end
|
93
|
+
|
87
94
|
class << self
|
88
95
|
def inherited(child)
|
89
96
|
child.include Rails.application.routes.url_helpers unless child < Rails.application.routes.url_helpers
|
@@ -91,11 +98,16 @@ module ActionView
|
|
91
98
|
super
|
92
99
|
end
|
93
100
|
|
101
|
+
def source_location
|
102
|
+
instance_method(:initialize).source_location[0]
|
103
|
+
end
|
104
|
+
|
94
105
|
# Compile template to #call instance method, assuming it hasn't been compiled already.
|
95
106
|
# We could in theory do this on app boot, at least in production environments.
|
96
107
|
# Right now this just compiles the template the first time the component is rendered.
|
97
108
|
def compile
|
98
109
|
return if @compiled && ActionView::Base.cache_template_loading
|
110
|
+
ensure_initializer_defined
|
99
111
|
|
100
112
|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
101
113
|
def call
|
@@ -109,6 +121,17 @@ module ActionView
|
|
109
121
|
|
110
122
|
private
|
111
123
|
|
124
|
+
# Require #initialize to be defined so that we can use
|
125
|
+
# method#source_location to look up the file name
|
126
|
+
# of the component.
|
127
|
+
#
|
128
|
+
# If we were able to only support Ruby 2.7+,
|
129
|
+
# We could just use Module#const_source_location,
|
130
|
+
# rendering this unnecessary.
|
131
|
+
def ensure_initializer_defined
|
132
|
+
raise NotImplementedError.new("#{self} must implement #initialize.") unless self.instance_method(:initialize).owner == self
|
133
|
+
end
|
134
|
+
|
112
135
|
def compiled_template
|
113
136
|
handler = ActionView::Template.handler_for_extension(File.extname(template_file_path).gsub(".", ""))
|
114
137
|
template = File.read(template_file_path)
|
@@ -121,20 +144,15 @@ module ActionView
|
|
121
144
|
end
|
122
145
|
|
123
146
|
def template_file_path
|
124
|
-
|
125
|
-
|
126
|
-
filename = self.instance_method(:initialize).source_location[0]
|
127
|
-
filename_without_extension = filename[0..-(File.extname(filename).length + 1)]
|
128
|
-
sibling_template_files = Dir["#{filename_without_extension}.????.{#{ActionView::Template.template_handler_extensions.join(',')}}"] - [filename]
|
147
|
+
sibling_template_files =
|
148
|
+
Dir["#{source_location.split(".")[0]}.*{#{ActionView::Template.template_handler_extensions.join(',')}}"] - [source_location]
|
129
149
|
|
130
150
|
if sibling_template_files.length > 1
|
131
151
|
raise StandardError.new("More than one template found for #{self}. There can only be one sidecar template file per component.")
|
132
152
|
end
|
133
153
|
|
134
154
|
if sibling_template_files.length == 0
|
135
|
-
raise NotImplementedError.new(
|
136
|
-
"Could not find a template file for #{self}."
|
137
|
-
)
|
155
|
+
raise NotImplementedError.new("Could not find a template file for #{self}.")
|
138
156
|
end
|
139
157
|
|
140
158
|
sibling_template_files[0]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: actionview-component
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GitHub Open Source
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|