cache_replace 0.1.0 → 0.1.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,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- OTFlYjk2NzQ1NGE4YWVlOWQ0ODUwMTBiZmY5MjZjN2Q1NzQ0MDlhMw==
5
- data.tar.gz: !binary |-
6
- NGE2MzkxNzJkMjAxYjliMWE5Y2Q3YmFlOGY1M2I0ZTZhNWFhNDhkZA==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- NzVhNGYzNjljMDhhYjQ1OGM4YjljMDM4ZmY1MjhhODNjYTQxMTJhZTQwMDNl
10
- Yjc1MzU3NDE3NDU4MDkxY2MwZjU0NDkyZWMwYjQ4MzcwZWQwZWVkYTBhNjM3
11
- OWE5NWE2MzI0ZjQ1Njc0YjRmZTRmODE0ODdhMThlNDNhNWZiOGE=
12
- data.tar.gz: !binary |-
13
- MDE4Yzg2MGY1Y2VmNTBjZDI1YTc1MWI5NzJjMmUwYjEzMTg0NGVhZDEwN2Jl
14
- OWFlODZjNzJhMGJmNjE0MTNjZDllM2QzZWE0ZGQ4YmI5ZGRmMzU3YzAzYzNi
15
- MTdkZGE0MzdmYjgzYWEwN2I2ZTJiYjgwYTk0YTg5NTZlOGJmY2Y=
2
+ SHA1:
3
+ metadata.gz: 1fdfb8b93279830fbfaf4e14856028a4fd8cfea9
4
+ data.tar.gz: cb6b4afa1b7309bc9d2bc8627a46858288b94706
5
+ SHA512:
6
+ metadata.gz: 3e5d137737c96f4d19e12947f9bbf45397520b2447def412b9bfc0ffbe939ba292e445f8c7cf2c1297ebd97441eff6400b04884ef1b0eeb19fde22ecf2baed8a
7
+ data.tar.gz: defef139ad82c419deaa67d0d7addddfbfca095d9b9c41f0eb5f4e97a586e1009398df972683092050c86d1871c59c389c3b4bdc4b06e20ad745ed08726f5451
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.0.0
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+
data/README.md CHANGED
@@ -1,34 +1,40 @@
1
+ [![Build Status](https://api.travis-ci.org/teeparham/cache_replace.png)](https://travis-ci.org/teeparham/cache_replace)
2
+
1
3
  # Rails rendering extension for more server-side html caching
2
4
 
3
5
  ## Why do I need this?
4
6
 
5
- To squeeze the last drop out of server-side HTML caching in Rails. Use this only after you have configured as
6
- much in-memory caching as possible using standard techniques such as Russian Doll caching.
7
+ To improve fragment caching efficiency in Rails by only caching the things that change.
8
+ Use this gem after you have configured as much in-memory caching as possible using standard techniques such as Russian Doll caching.
7
9
 
8
10
  ## Install
9
11
 
10
12
  Add this line to your Gemfile:
11
13
 
12
- gem 'cache_replace'
14
+ ```ruby
15
+ gem 'cache_replace'
16
+ ```
13
17
 
14
18
  Add this line to a helper file, likely your ApplicationHelper:
15
19
 
16
- include CacheReplace
20
+ ```ruby
21
+ include CacheReplace
22
+ ```
17
23
 
18
24
  ## Use
19
25
 
20
26
  This gem allows you to easily cache a partial of static html and replace inner dynamic html. Here is an example
21
- scenario where this is helpful:
27
+ scenario:
22
28
 
23
29
  You have some html that would be cached, except for some uncacheable code nested in the DOM. For example:
24
30
 
25
31
  ##### file.html.haml:
26
- ```
32
+ ```haml
27
33
  = render 'container'
28
34
  ```
29
35
 
30
36
  ##### _container.html.haml:
31
- ```
37
+ ```haml
32
38
  .lots
33
39
  .of
34
40
  .htmls
@@ -36,19 +42,19 @@ You have some html that would be cached, except for some uncacheable code nested
36
42
  ```
37
43
 
38
44
  ##### _dynamic.html.haml:
39
- ```
45
+ ```haml
40
46
  = complicated_uncacheable_stuff
41
47
  ```
42
48
 
43
- Sad times. You can't cache anything without resorting to madness. Oh snap! But you can:
49
+ In the scenario above, you can't cache anything without resorting to madness. With `cache_replace`, you can:
44
50
 
45
51
  ##### file.html.haml:
46
- ```
52
+ ```haml
47
53
  = render_cached 'container', replace: 'dynamic'
48
54
  ```
49
55
 
50
56
  ##### _container.html.haml:
51
- ```
57
+ ```haml
52
58
  - cache "container" do
53
59
  .lots
54
60
  .of
@@ -57,14 +63,14 @@ Sad times. You can't cache anything without resorting to madness. Oh snap! But y
57
63
  ```
58
64
 
59
65
  ##### _dynamic.html.haml:
60
- ```
66
+ ``` haml
61
67
  = complicated_uncacheable_stuff
62
68
  ```
63
69
 
64
- In the above example, you could also remove the `_dynamic.html.haml` file and do this:
70
+ In the above example, you could also remove the `_dynamic.html.haml` file like so:
65
71
 
66
72
  ##### file.html.haml:
67
- ```
73
+ ```haml
68
74
  = render_cached 'container', replace: {dynamic: complicated_uncacheable_stuff}
69
75
  ```
70
76
 
@@ -85,13 +91,13 @@ render_cached "container", replace: ["inner"]
85
91
 
86
92
  #### Map of keys to replace with values
87
93
  ```ruby
88
- render_cached "container", replace: {special_link: special_link(object)}
94
+ render_cached "container", replace: {key_name: a_helper_method(object)}
89
95
  ```
90
96
 
91
97
  #### Yield to a hash of keys to replace with values
92
98
  ```ruby
93
99
  render_cached "container" do
94
- {special_link: special_link(object)}
100
+ {key_name: a_helper_method(object)}
95
101
  end
96
102
  ```
97
103
 
@@ -24,6 +24,6 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "rake", ">= 10.0"
25
25
  spec.add_development_dependency "test-unit", ">= 2.5"
26
26
  spec.add_development_dependency "mocha", ">= 0.13"
27
- spec.add_development_dependency "shoulda", ">= 3.3"
27
+ spec.add_development_dependency "shoulda-context"
28
28
  spec.add_development_dependency "pry", ">= 0.9"
29
29
  end
@@ -1,3 +1,3 @@
1
1
  module CacheReplace
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/cache_replace.rb CHANGED
@@ -3,7 +3,8 @@ require 'cache_replace/version'
3
3
  module CacheReplace
4
4
  # Supports 4 options:
5
5
  #
6
- # 1. Single partial to replace
6
+ # 1. Single partial to replace.
7
+ # "inner" is the key name and "_inner.*" is the partial file name.
7
8
  #
8
9
  # render_cached "container", replace: "inner"
9
10
  #
@@ -13,12 +14,12 @@ module CacheReplace
13
14
  #
14
15
  # 3. Map of keys to replace with values
15
16
  #
16
- # render_cached "container", replace: {special_link: special_link(object)}
17
+ # render_cached "container", replace: {key_name: a_helper_method(object)}
17
18
  #
18
19
  # 4. Yield to a hash of keys to replace with values
19
20
  #
20
21
  # render_cached "container" do
21
- # {special_link: special_link(object)}
22
+ # {key_name: a_helper_method(object)}
22
23
  # end
23
24
  #
24
25
  def render_cached(static_partial, options={})
@@ -53,7 +54,7 @@ private
53
54
 
54
55
  def replace_from_hash(fragment, hash)
55
56
  hash.each do |key, value|
56
- fragment.sub! cache_replace_key(key), value
57
+ fragment.sub! cache_replace_key(key), value.to_s
57
58
  end
58
59
  end
59
60
  end
@@ -46,6 +46,10 @@ class CacheReplaceTest < Test::Unit::TestCase
46
46
  should "render with map of keys" do
47
47
  assert_equal "Fanny pack keytar viral mustache.", @renderer.render_cached("container", replace: {inner: "keytar"})
48
48
  end
49
+
50
+ should "render with map of keys with a nil value" do
51
+ assert_equal "Fanny pack viral mustache.", @renderer.render_cached("container", replace: {inner: nil})
52
+ end
49
53
 
50
54
  should "render with hash block" do
51
55
  output = @renderer.render_cached("container") do
data/test/test_helper.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'test/unit'
2
- require 'shoulda'
2
+ require 'shoulda-context'
3
3
  require 'mocha/setup'
4
4
  require 'cache_replace'
5
- require 'pry'
5
+ require 'pry'
metadata CHANGED
@@ -1,111 +1,111 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cache_replace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tee Parham
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-19 00:00:00.000000000 Z
11
+ date: 2013-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '10.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: test-unit
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '2.5'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '2.5'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: mocha
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ! '>='
73
+ - - '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0.13'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ! '>='
80
+ - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.13'
83
83
  - !ruby/object:Gem::Dependency
84
- name: shoulda
84
+ name: shoulda-context
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ! '>='
87
+ - - '>='
88
88
  - !ruby/object:Gem::Version
89
- version: '3.3'
89
+ version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ! '>='
94
+ - - '>='
95
95
  - !ruby/object:Gem::Version
96
- version: '3.3'
96
+ version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: pry
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ! '>='
101
+ - - '>='
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0.9'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ! '>='
108
+ - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0.9'
111
111
  description: Rails rendering extension for more server-side html caching
@@ -116,6 +116,8 @@ extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
118
  - .gitignore
119
+ - .ruby-version
120
+ - .travis.yml
119
121
  - Gemfile
120
122
  - LICENSE.txt
121
123
  - README.md
@@ -135,12 +137,12 @@ require_paths:
135
137
  - lib
136
138
  required_ruby_version: !ruby/object:Gem::Requirement
137
139
  requirements:
138
- - - ! '>='
140
+ - - '>='
139
141
  - !ruby/object:Gem::Version
140
142
  version: '0'
141
143
  required_rubygems_version: !ruby/object:Gem::Requirement
142
144
  requirements:
143
- - - ! '>='
145
+ - - '>='
144
146
  - !ruby/object:Gem::Version
145
147
  version: '0'
146
148
  requirements: []