railhead_multifetch 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4cbe7e0395dad2f22b236ad5d9ca62990837fd62
4
+ data.tar.gz: 1823dc88a6bfae73d97edc8750d51e4844d550c3
5
+ SHA512:
6
+ metadata.gz: 666f3cc0ff16aa88e22b2af893ecf5d2c8cd445d5f3c05471d80251454a193bcaa5189b1b64bd973d67e8c9874b0d9fbd38072e1acd1377100ff9f4508e8c050
7
+ data.tar.gz: dca125f4f3baaf8ed633ddfbf5fb75838bc478bf447529696de40901efbf012d77b4e0ea077348190c1a6e72f0549cf2bd06b5abb55e94a3e54258eaad4e8d48
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = RailheadMultifetch
2
+
3
+ RailheadMultifetch is a Ruby on Rails plugin that automatically loads multiple cached partials.
4
+
5
+ == Installation
6
+
7
+ Add to your Gemfile:
8
+
9
+ gem 'railhead_multifetch'
10
+
11
+ == Usage
12
+
13
+ Similar to multi_fetch_fragment gem:
14
+
15
+ = render @items, cache: true
16
+
17
+ == License
18
+
19
+ Copyright (c) 2015 Bence Nagy (bence.nagy@gmail.com), released under the MIT license.
@@ -0,0 +1,41 @@
1
+ require 'action_view/digestor'
2
+
3
+
4
+ module RailheadMultifetch
5
+
6
+ def self.included(base)
7
+ base.class_eval do
8
+ alias_method_chain :render_collection, :multifetch
9
+ end
10
+ end
11
+
12
+ def render_collection_with_multifetch
13
+ if ActionController::Base.perform_caching && (@options[:cache].present? or @locals[:cache].present?)
14
+ return nil if @collection.blank?
15
+ results = []
16
+ keymap = {}
17
+ digest = ActionView::PartialDigestor.new(name: @template.virtual_path, finder: @view.lookup_context).digest
18
+
19
+ @collection.each do |object|
20
+ item = @options[:cache].respond_to?(:call) ? @options[:cache].call(object) : object
21
+ key = @view.controller.fragment_cache_key([item, digest])
22
+ keymap[key] = item
23
+ end
24
+ mutable_keys = keymap.keys.map { |key| key.dup }
25
+ cached_results = Rails.cache.read_multi(*mutable_keys)
26
+ @collection = (keymap.keys - cached_results.keys).map { |key| keymap[key] }
27
+ non_cached_results = @collection.present? ? collection_with_template : []
28
+ mutable_keys.each { |key| results << (cached_results[key] || non_cached_results.shift) }
29
+
30
+ if @options.key?(:spacer_template)
31
+ spacer = find_template(@options[:spacer_template]).render(@view, @locals)
32
+ end
33
+ results.join(spacer).html_safe
34
+ else
35
+ render_collection_without_multifetch
36
+ end
37
+ end
38
+ end
39
+
40
+
41
+ ActionView::PartialRenderer.send :include, RailheadMultifetch
@@ -0,0 +1,16 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "railhead_multifetch"
3
+ s.version = "0.0.1"
4
+ s.date = "2015-02-27"
5
+ s.summary = "RailheadMultifetch is a Ruby on Rails plugin that automatically loads multiple cached partials."
6
+ s.email = "bence.nagy@gmail.com"
7
+ s.homepage = "http://github.com/nagybence/railhead_multifetch"
8
+ s.has_rdoc = true
9
+ s.authors = ["Bence Nagy"]
10
+ s.files = ["MIT-LICENSE",
11
+ "README.rdoc",
12
+ "railhead_multifetch.gemspec",
13
+ "lib/railhead_multifetch.rb"]
14
+ s.rdoc_options = ["--main", "README.rdoc"]
15
+ s.license = "MIT"
16
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: railhead_multifetch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Bence Nagy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-27 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: bence.nagy@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - MIT-LICENSE
20
+ - README.rdoc
21
+ - lib/railhead_multifetch.rb
22
+ - railhead_multifetch.gemspec
23
+ homepage: http://github.com/nagybence/railhead_multifetch
24
+ licenses:
25
+ - MIT
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options:
29
+ - "--main"
30
+ - README.rdoc
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 2.4.6
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: RailheadMultifetch is a Ruby on Rails plugin that automatically loads multiple
49
+ cached partials.
50
+ test_files: []