redis_snippets 0.0.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.
data/README ADDED
@@ -0,0 +1,12 @@
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) %>
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "redis_snippets"
8
+ gem.summary = "View snippets held in Redis storage."
9
+ gem.description = ""
10
+ gem.email = "martin@wulffeld.org"
11
+ gem.authors = ["Martin Moen Wulffeld"]
12
+ gem.add_dependency(%q<redis>)
13
+ gem.add_dependency(%q<redis-namespace>)
14
+ end
15
+ Jeweler::GemcutterTasks.new
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
18
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,13 @@
1
+ class Admin::SnippetsController < AdminController
2
+ def index
3
+ end
4
+
5
+ def update
6
+ params[:snippets].each do |key, content|
7
+ RedisSnippets::Snippets.update(key.to_sym, params[:snippets][key])
8
+ end
9
+
10
+ flash[:notice] = 'Snippets updated.'
11
+ redirect_to admin_snippets_path
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ module RedisSnippets
2
+ module SnippetsHelper
3
+ def snippet(advert, classes=nil)
4
+ return '' if controller.status == 404
5
+ ad_html = RedisSnippets::Snippets.send(advert)
6
+ return '' if ad_html.blank?
7
+ content_tag(:div, ad_html.html_safe, :class => ['advert', classes || advert.to_s].compact.join(' ').html_safe)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,18 @@
1
+ class RedisSnippets::Snippets
2
+ class << self
3
+ def update(key, content)
4
+ raise "#{key} not in the specified keys." unless RedisSnippetsEngine.config.redis_snippets[:keys].include?(key)
5
+ RedisSnippets::Redis.set("snippets:#{key}", content)
6
+ end
7
+
8
+ def del(key)
9
+ RedisSnippets::Redis.del("snippets:#{key}")
10
+ end
11
+
12
+ # Retrieve snippet.
13
+ def method_missing(method, *args)
14
+ raise "#{method} not in the specified keys." unless RedisSnippetsEngine.config.redis_snippets[:keys].include?(method.to_sym)
15
+ RedisSnippets::Redis.get("snippets:#{method}")
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ <h1>Snippets</h1>
2
+
3
+ <%= form_tag admin_snippets_path, :method => :put, :class => "formtastic" do |f| %>
4
+ <fieldset>
5
+ <ol>
6
+ <% RedisSnippetsEngine.config.redis_snippets[:keys].each do |key| %>
7
+ <li>
8
+ <%= label_tag key.to_s, key.to_s %>
9
+ <%= text_area_tag "snippets[#{key}]", RedisSnippets::Snippets.send(key), :cols => 120, :rows => 10 %>
10
+ </li>
11
+ <% end -%>
12
+ </ol>
13
+ </fieldset>
14
+ <%= submit_tag 'Submit' %>
15
+ <% end -%>
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ Rails.application.routes.draw do
2
+ resource :admin, :controller => 'admin', :only => [:show] do
3
+ resource :snippets, :controller => 'admin/snippets', :only => [:show, :update]
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ require 'redis'
2
+ require 'redis/namespace'
3
+
4
+ class RedisSnippetsEngine < ::Rails::Engine
5
+ engine_name :redis_snippets
6
+ end
7
+
8
+ require 'redis_snippets/railtie'
9
+ require 'redis_snippets/redis'
@@ -0,0 +1,18 @@
1
+ module RedisSnippets
2
+ class Railtie < Rails::Railtie
3
+ # This shouldn't be required when 3.1 arrives.
4
+ # https://github.com/drogus/rails_helpers_fix
5
+ initializer "redis_snippets.include_railties_helpers_fix" do
6
+ helpers_paths = []
7
+ Rails.application.railties.all do |r|
8
+ if r.config.respond_to?(:paths) && r.config.paths.app.helpers
9
+ helpers_paths += r.config.paths.app.helpers.to_a
10
+ end
11
+ end
12
+
13
+ ActiveSupport.on_load(:action_controller) do
14
+ config.helpers_path += helpers_paths
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module RedisSnippets
2
+ class Redis
3
+ class << self
4
+ # Can't do method_missing on get/set as they're defined somewhere by Ruby.
5
+ def get(key)
6
+ RedisSnippetsEngine.config.redis_snippets[:connection].get(key)
7
+ end
8
+
9
+ def set(key, value)
10
+ RedisSnippetsEngine.config.redis_snippets[:connection].set(key, value)
11
+ end
12
+
13
+ def method_missing(method, *args)
14
+ RedisSnippetsEngine.config.redis_snippets[:connection].send(method, *args)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,51 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{redis_snippets}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Martin Moen Wulffeld"]
12
+ s.date = %q{2011-04-23}
13
+ s.description = %q{}
14
+ s.email = %q{martin@wulffeld.org}
15
+ s.extra_rdoc_files = [
16
+ "README"
17
+ ]
18
+ s.files = [
19
+ "README",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "app/controllers/admin/snippets_controller.rb",
23
+ "app/helpers/redis_snippets/snippets_helper.rb",
24
+ "app/models/redis_snippets/snippets.rb",
25
+ "app/views/admin/ads/show.html.erb",
26
+ "config/routes.rb",
27
+ "lib/redis_snippets.rb",
28
+ "lib/redis_snippets/railtie.rb",
29
+ "lib/redis_snippets/redis.rb",
30
+ "redis_snippets.gemspec"
31
+ ]
32
+ s.require_paths = ["lib"]
33
+ s.rubygems_version = %q{1.5.0}
34
+ s.summary = %q{View snippets held in Redis storage.}
35
+
36
+ if s.respond_to? :specification_version then
37
+ s.specification_version = 3
38
+
39
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
40
+ s.add_runtime_dependency(%q<redis>, [">= 0"])
41
+ s.add_runtime_dependency(%q<redis-namespace>, [">= 0"])
42
+ else
43
+ s.add_dependency(%q<redis>, [">= 0"])
44
+ s.add_dependency(%q<redis-namespace>, [">= 0"])
45
+ end
46
+ else
47
+ s.add_dependency(%q<redis>, [">= 0"])
48
+ s.add_dependency(%q<redis-namespace>, [">= 0"])
49
+ end
50
+ end
51
+
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redis_snippets
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Martin Moen Wulffeld
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-04-23 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: redis
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: redis-namespace
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ description: ""
50
+ email: martin@wulffeld.org
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files:
56
+ - README
57
+ files:
58
+ - README
59
+ - Rakefile
60
+ - VERSION
61
+ - app/controllers/admin/snippets_controller.rb
62
+ - app/helpers/redis_snippets/snippets_helper.rb
63
+ - app/models/redis_snippets/snippets.rb
64
+ - app/views/admin/ads/show.html.erb
65
+ - config/routes.rb
66
+ - lib/redis_snippets.rb
67
+ - lib/redis_snippets/railtie.rb
68
+ - lib/redis_snippets/redis.rb
69
+ - redis_snippets.gemspec
70
+ has_rdoc: true
71
+ homepage:
72
+ licenses: []
73
+
74
+ post_install_message:
75
+ rdoc_options: []
76
+
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 3
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 3
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ requirements: []
98
+
99
+ rubyforge_project:
100
+ rubygems_version: 1.5.0
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: View snippets held in Redis storage.
104
+ test_files: []
105
+