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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6dcbc0baecff7159dafaf87120583a68055e931c926679bd8b3300b54232c769
4
- data.tar.gz: b5eda121857a5dd034457e1fda306bfb1fa1e666159d20729feaee2f2da699c1
3
+ metadata.gz: c2e23869593e0482d71b3ea0b082ad050fe3c9a5e1ad4b5e05e5cac866c7f31d
4
+ data.tar.gz: 9ce7d1453f35246746f90153959c9848baa221042eec5a6376aae59c1433d3f7
5
5
  SHA512:
6
- metadata.gz: cf003dfb9c8dc68e7cef33e4c78fa947006b58ec076658586c95bece8a65e98516989cba81a58bcd632a1706c9b7b93b19bd51006b6f8291256dc0062ba4db1c
7
- data.tar.gz: f7707687dee6494852ad1520154d57acff346f4fa6dcdb2bfc0e2f324ed4a4683fe7f2e3b8b1f3a69a38ff4dae0e0a72b53a7f73a3f524d0f7f6e9b07a625fd3
6
+ metadata.gz: 11bacc8bde616fb29d27bf8fc7b56d5cea3d42c645fd425e56ea638427755ebb89c6b6575702b37f18cf33e56026a7fdbe11582be0bdd610deaea236043ba736
7
+ data.tar.gz: 59a4a1e938c98e5c942581181e11f4af00d1ac36e49dace1ad42dfc1b10ca8da6cb589d68b07a7adcd3f6a80facab0621cd5be03e1e2eaf082dd18bf0daaf305
@@ -1,3 +1,13 @@
1
+ # v1.3.6
2
+
3
+ * Allow template file names without format.
4
+
5
+ *Joel Hawksley*
6
+
7
+ * Add support for translations.
8
+
9
+ *Juan Manuel Ramallo*
10
+
1
11
  # v1.3.5
2
12
 
3
13
  * Re-expose `controller` method.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- actionview-component (1.3.5)
4
+ actionview-component (1.3.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -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
- raise NotImplementedError.new("#{self} must implement #initialize.") unless self.instance_method(:initialize).owner == self
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]
@@ -5,7 +5,7 @@ module ActionView
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 3
8
- PATCH = 5
8
+ PATCH = 6
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH].join(".")
11
11
  end
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.5
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-17 00:00:00.000000000 Z
11
+ date: 2019-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler