actionview_precompiler 0.2.0 → 0.2.1

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: 8f61275e9c390cf6a14ce7a3fa9bc4fb4473887547e7da8f07587cd26144b8c7
4
- data.tar.gz: c125ff85f50d91ca77b80ee0eef47cb51e70373a17e2fc8c99d3b826e1176348
3
+ metadata.gz: 6c8e4204b2ff2f95e85606497693d399460c4c31a8f946706a503be04b03d5f8
4
+ data.tar.gz: 8aa824e50eaa357b9f0084756c9399f928b8ead2e2a04fe24ab2bbbe4b611400
5
5
  SHA512:
6
- metadata.gz: 9e6d53ba2a4eb030cff6d57635a7d0e77eec0016e1c1af6255f9f134d438030ec4f45669bcd506dd00b1f8d36a64138b9690c3cd4f17dcfc4fe9e7c7562ec72f
7
- data.tar.gz: bcc61e6a911a98886b74bfc8df1c29b6b6b3efabfbc50bf0178b34f3a7948867bfeaa7f2aec79945363fa34146b974909893c3e405033540b2bbcee0024c74cc
6
+ metadata.gz: dbfa31585cea6678aec9b4e0b7fa592f439e4d2f3aa9428faa7583a9c32a701a880343e66843c8ef7afa9d146b8a2542a078c2de622211750fe8c516ddbe0bed
7
+ data.tar.gz: b1655ba9a3639df1ac3d26b15297d3909e1fbfb6f323152f3a8bf3aca956d229d7d848bbc291a438c2aa5069a0d889f4f1c4b14280868ab33011160611847219
@@ -78,8 +78,14 @@ module ActionviewPrecompiler
78
78
  @templates.each do |template|
79
79
  parser = TemplateParser.new(template.fullpath)
80
80
  parser.render_calls.each do |render_call|
81
- @locals_sets[render_call.virtual_path] ||= []
82
- @locals_sets[render_call.virtual_path] << render_call.locals_keys.map(&:to_s).sort
81
+ virtual_path = render_call.virtual_path
82
+ unless virtual_path.include?("/")
83
+ # Not necessarily true, since the perfix is based on the current
84
+ # controller, but is a safe bet most of the time.
85
+ virtual_path = "#{template.prefix}/#{virtual_path}"
86
+ end
87
+ @locals_sets[virtual_path] ||= []
88
+ @locals_sets[virtual_path] << render_call.locals_keys.map(&:to_s).sort
83
89
  end
84
90
  end
85
91
 
@@ -2,7 +2,7 @@ module ActionviewPrecompiler
2
2
  RenderCall = Struct.new(:render_type, :template, :locals, :locals_keys) do
3
3
  def virtual_path
4
4
  if render_type == :partial
5
- @virtual_path ||= template.gsub(%r{/([^/]*)\z}, '/_\1')
5
+ @virtual_path ||= template.gsub(%r{(/|^)([^/]*)\z}, '\1_\2')
6
6
  else
7
7
  template
8
8
  end
@@ -61,7 +61,7 @@ module ActionviewPrecompiler
61
61
 
62
62
  RENDER_TYPE_KEYS = [:partial, :template, :layout]
63
63
  IGNORED_KEYS = [:formats]
64
- ALL_KNOWN_KEYS = [*RENDER_TYPE_KEYS, *IGNORED_KEYS, :locals]
64
+ ALL_KNOWN_KEYS = [*RENDER_TYPE_KEYS, *IGNORED_KEYS, :locals, :object, :collection, :as]
65
65
 
66
66
  def parse_render_from_options(options_hash)
67
67
  keys = options_hash.keys
@@ -93,6 +93,25 @@ module ActionviewPrecompiler
93
93
  locals_keys = []
94
94
  end
95
95
 
96
+ if options_hash.key?(:object) || options_hash.key?(:collection)
97
+ return nil if options_hash.key?(:object) && options_hash.key?(:collection)
98
+ return nil unless options_hash.key?(:partial)
99
+
100
+ as = if options_hash.key?(:as)
101
+ parse_str(options_hash[:as]) || parse_sym(options_hash[:as])
102
+ elsif File.basename(template) =~ /\A_?(.*?)(?:\.\w+)*\z/
103
+ $1
104
+ end
105
+
106
+ return nil unless as
107
+
108
+ locals_keys << as.to_sym
109
+ if options_hash.key?(:collection)
110
+ locals_keys << :"#{as}_counter"
111
+ locals_keys << :"#{as}_iteration"
112
+ end
113
+ end
114
+
96
115
  RenderCall.new(render_type, template, locals, locals_keys)
97
116
  end
98
117
 
@@ -7,6 +7,10 @@ module ActionviewPrecompiler
7
7
  attr_reader :filename, :basename, :handler
8
8
 
9
9
  class FakeTemplate
10
+ def identifier
11
+ "fake_template"
12
+ end
13
+
10
14
  def type
11
15
  nil
12
16
  end
@@ -1,3 +1,3 @@
1
1
  module ActionviewPrecompiler
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionview_precompiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Hawthorn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-26 00:00:00.000000000 Z
11
+ date: 2019-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview