redis_snippets 0.0.4 → 0.0.5

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.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # Redis Snippets
2
+
3
+ ## Background
4
+
5
+ Easily store snippets of content in Redis.
6
+
7
+ ## How
8
+
9
+ It's a Rails 3 engine so add redis-snippets to your Gemfile and put this in an initializer:
10
+
11
+ ``` ruby
12
+ App::Application.config.redis_snippets = {
13
+ :connection => ::Redis::Namespace.new("my_namespace", :redis => ::Redis.new),
14
+ :keys => [:key1, :key2]
15
+ }
16
+ ```
17
+
18
+ You should then be able to access /admin/snippets/.
19
+
20
+ In your views use helper snippet().
21
+
22
+ ``` ruby
23
+ <%= snippet(:key1) %>
24
+ ```
25
+
26
+ ## Multi Site
27
+
28
+ If you're using one app to serve multiple sites a little more configuration is necessary.
29
+
30
+ ``` ruby
31
+ App::Application.config.redis_snippets = {
32
+ :connection => ::Redis::Namespace.new("my_namespace", :redis => ::Redis.new),
33
+ :multi_site => true,
34
+ :keys => [:key1, :key2]
35
+ }
36
+ ```
37
+
38
+ And add this method to your ApplicationController:
39
+
40
+ ``` ruby
41
+ helper_method :redis_snippet_site_key
42
+ def redis_snippet_site_key
43
+ request.host
44
+ end
45
+ ```
46
+
47
+ ## Requirements
48
+
49
+ * redis
50
+ * redis-namespace
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
@@ -1,10 +1,13 @@
1
1
  class Admin::SnippetsController < AdminController
2
+ include RedisSnippets::Help
3
+
2
4
  def index
3
5
  end
4
6
 
5
7
  def update
6
8
  params[:snippets].each do |key, content|
7
- RedisSnippets::Snippets.update(key.to_sym, params[:snippets][key])
9
+ raise "#{key} not in the specified keys." unless RedisSnippetsEngine.config.redis_snippets[:keys].include?(key.to_sym)
10
+ RedisSnippets::Snippets.update(snippet_key(key), params[:snippets][key])
8
11
  end
9
12
 
10
13
  flash[:notice] = 'Snippets updated.'
@@ -1,12 +1,14 @@
1
1
  module RedisSnippets
2
2
  module SnippetsHelper
3
+ include RedisSnippets::Help
4
+
3
5
  def snippet_content(snippet_name)
4
- RedisSnippets::Snippets.send(snippet_name)
6
+ RedisSnippets::Snippets.send(snippet_key(snippet_name))
5
7
  end
6
8
 
7
9
  # Return true if snippet has content.
8
10
  def snippet_has_content?(snippet_name)
9
- !RedisSnippets::Snippets.send(snippet_name).blank?
11
+ !snippet_content(snippet_name).blank?
10
12
  end
11
13
 
12
14
  def snippet(snippet_name, classes=nil)
@@ -1,7 +1,6 @@
1
1
  class RedisSnippets::Snippets
2
2
  class << self
3
3
  def update(key, content)
4
- raise "#{key} not in the specified keys." unless RedisSnippetsEngine.config.redis_snippets[:keys].include?(key)
5
4
  RedisSnippets::Redis.set("snippets:#{key}", content)
6
5
  end
7
6
 
@@ -11,7 +10,6 @@ class RedisSnippets::Snippets
11
10
 
12
11
  # Retrieve snippet.
13
12
  def method_missing(method, *args)
14
- raise "#{method} not in the specified keys." unless RedisSnippetsEngine.config.redis_snippets[:keys].include?(method.to_sym)
15
13
  RedisSnippets::Redis.get("snippets:#{method}")
16
14
  end
17
15
  end
@@ -6,7 +6,7 @@
6
6
  <% RedisSnippetsEngine.config.redis_snippets[:keys].each do |key| %>
7
7
  <li>
8
8
  <%= label_tag key.to_s, key.to_s %>
9
- <%= text_area_tag "snippets[#{key}]", RedisSnippets::Snippets.send(key), :cols => 120, :rows => 10 %>
9
+ <%= text_area_tag "snippets[#{key}]", RedisSnippets::Snippets.send(snippet_key(key)), :cols => 120, :rows => 10 %>
10
10
  </li>
11
11
  <% end -%>
12
12
  </ol>
@@ -0,0 +1,13 @@
1
+ module RedisSnippets
2
+ module Help
3
+ # If multi_site => true the symbol returned will have the key returned with a prefix.
4
+ # This prefix is defined in your application using the redis_snippet_site_key method.
5
+ # redis_snippet_site_key should simply return a unique string per site. For instance
6
+ # it could be the domain of the site.
7
+ def snippet_key(key)
8
+ s = RedisSnippetsEngine.config.redis_snippets[:multi_site] ? redis_snippet_site_key + ':' : ''
9
+ s << key.to_s
10
+ s.to_sym
11
+ end
12
+ end
13
+ end
@@ -7,3 +7,4 @@ end
7
7
 
8
8
  require 'redis_snippets/railtie'
9
9
  require 'redis_snippets/redis'
10
+ require 'redis_snippets/help'
@@ -4,19 +4,19 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{redis_snippets}
8
- s.version = "0.0.4"
7
+ s.name = "redis_snippets"
8
+ s.version = "0.0.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{Martin Moen Wulffeld}]
12
- s.date = %q{2011-07-21}
13
- s.description = %q{}
14
- s.email = %q{martin@wulffeld.org}
11
+ s.authors = ["Martin Moen Wulffeld"]
12
+ s.date = "2012-01-17"
13
+ s.description = ""
14
+ s.email = "martin@wulffeld.org"
15
15
  s.extra_rdoc_files = [
16
- "README"
16
+ "README.md"
17
17
  ]
18
18
  s.files = [
19
- "README",
19
+ "README.md",
20
20
  "Rakefile",
21
21
  "VERSION",
22
22
  "app/controllers/admin/snippets_controller.rb",
@@ -25,13 +25,14 @@ Gem::Specification.new do |s|
25
25
  "app/views/admin/snippets/show.html.erb",
26
26
  "config/routes.rb",
27
27
  "lib/redis_snippets.rb",
28
+ "lib/redis_snippets/help.rb",
28
29
  "lib/redis_snippets/railtie.rb",
29
30
  "lib/redis_snippets/redis.rb",
30
31
  "redis_snippets.gemspec"
31
32
  ]
32
- s.require_paths = [%q{lib}]
33
- s.rubygems_version = %q{1.8.5}
34
- s.summary = %q{View snippets held in Redis storage.}
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = "1.8.13"
35
+ s.summary = "View snippets held in Redis storage."
35
36
 
36
37
  if s.respond_to? :specification_version then
37
38
  s.specification_version = 3
metadata CHANGED
@@ -1,60 +1,46 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: redis_snippets
3
- version: !ruby/object:Gem::Version
4
- hash: 23
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 4
10
- version: 0.0.4
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Martin Moen Wulffeld
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-07-21 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-01-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: redis
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &2160253380 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
32
22
  type: :runtime
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: redis-namespace
36
23
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *2160253380
25
+ - !ruby/object:Gem::Dependency
26
+ name: redis-namespace
27
+ requirement: &2160252900 !ruby/object:Gem::Requirement
38
28
  none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
46
33
  type: :runtime
47
- version_requirements: *id002
48
- description: ""
34
+ prerelease: false
35
+ version_requirements: *2160252900
36
+ description: ''
49
37
  email: martin@wulffeld.org
50
38
  executables: []
51
-
52
39
  extensions: []
53
-
54
- extra_rdoc_files:
55
- - README
56
- files:
57
- - README
40
+ extra_rdoc_files:
41
+ - README.md
42
+ files:
43
+ - README.md
58
44
  - Rakefile
59
45
  - VERSION
60
46
  - app/controllers/admin/snippets_controller.rb
@@ -63,41 +49,32 @@ files:
63
49
  - app/views/admin/snippets/show.html.erb
64
50
  - config/routes.rb
65
51
  - lib/redis_snippets.rb
52
+ - lib/redis_snippets/help.rb
66
53
  - lib/redis_snippets/railtie.rb
67
54
  - lib/redis_snippets/redis.rb
68
55
  - redis_snippets.gemspec
69
56
  homepage:
70
57
  licenses: []
71
-
72
58
  post_install_message:
73
59
  rdoc_options: []
74
-
75
- require_paths:
60
+ require_paths:
76
61
  - lib
77
- required_ruby_version: !ruby/object:Gem::Requirement
62
+ required_ruby_version: !ruby/object:Gem::Requirement
78
63
  none: false
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- hash: 3
83
- segments:
84
- - 0
85
- version: "0"
86
- required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
69
  none: false
88
- requirements:
89
- - - ">="
90
- - !ruby/object:Gem::Version
91
- hash: 3
92
- segments:
93
- - 0
94
- version: "0"
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
95
74
  requirements: []
96
-
97
75
  rubyforge_project:
98
- rubygems_version: 1.8.5
76
+ rubygems_version: 1.8.13
99
77
  signing_key:
100
78
  specification_version: 3
101
79
  summary: View snippets held in Redis storage.
102
80
  test_files: []
103
-
data/README DELETED
@@ -1,12 +0,0 @@
1
- Shove this in an initializer and smoke it:
2
-
3
- App::Application.config.redis_snippets = {
4
- :connection => ::Redis::Namespace.new("my_namespace", :redis => ::Redis.new),
5
- :keys => [:key1, :key2]
6
- }
7
-
8
- Access /admin/snippets/.
9
-
10
- Then use helper snippet().
11
-
12
- <%= snippet(:key1) %>