sethyates-content_manager 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +21 -0
- data/README.rdoc +9 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/content_manager.gemspec +53 -0
- data/init.rb +1 -0
- data/lib/content_helper.rb +28 -0
- data/lib/content_item.rb +75 -0
- data/lib/rack/content_manager.rb +18 -0
- data/rails/init.rb +1 -0
- data/test/content_manager_test.rb +7 -0
- data/test/test_helper.rb +10 -0
- metadata +77 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2009 Seth Yates
|
2
|
+
Copyright (c) 2009 Independent Digital Media Pty Ltd
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "content_manager"
|
8
|
+
gem.summary = %Q{Simple Content Manager}
|
9
|
+
gem.email = "syates@grandcentralmedia.com.au"
|
10
|
+
gem.homepage = "http://github.com/sethyates/content_manager"
|
11
|
+
gem.authors = ["Seth Yates"]
|
12
|
+
gem.add_dependency('rufus-tokyo', '>= 0.1.12')
|
13
|
+
end
|
14
|
+
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'rake/testtask'
|
20
|
+
Rake::TestTask.new(:test) do |test|
|
21
|
+
test.libs << 'lib' << 'test'
|
22
|
+
test.pattern = 'test/**/*_test.rb'
|
23
|
+
test.verbose = true
|
24
|
+
end
|
25
|
+
|
26
|
+
begin
|
27
|
+
require 'rcov/rcovtask'
|
28
|
+
Rcov::RcovTask.new do |test|
|
29
|
+
test.libs << 'test'
|
30
|
+
test.pattern = 'test/**/*_test.rb'
|
31
|
+
test.verbose = true
|
32
|
+
end
|
33
|
+
rescue LoadError
|
34
|
+
task :rcov do
|
35
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
task :default => :test
|
41
|
+
|
42
|
+
require 'rake/rdoctask'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
if File.exist?('VERSION.yml')
|
45
|
+
config = YAML.load(File.read('VERSION.yml'))
|
46
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
47
|
+
else
|
48
|
+
version = ""
|
49
|
+
end
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "content_manager #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
+
end
|
56
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{content_manager}
|
5
|
+
s.version = "0.1.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Seth Yates"]
|
9
|
+
s.date = %q{2009-06-05}
|
10
|
+
s.email = %q{syates@grandcentralmedia.com.au}
|
11
|
+
s.extra_rdoc_files = [
|
12
|
+
"LICENSE",
|
13
|
+
"README.rdoc"
|
14
|
+
]
|
15
|
+
s.files = [
|
16
|
+
".document",
|
17
|
+
".gitignore",
|
18
|
+
"LICENSE",
|
19
|
+
"README.rdoc",
|
20
|
+
"Rakefile",
|
21
|
+
"VERSION",
|
22
|
+
"content_manager.gemspec",
|
23
|
+
"init.rb",
|
24
|
+
"lib/content_helper.rb",
|
25
|
+
"lib/content_item.rb",
|
26
|
+
"lib/rack/content_manager.rb",
|
27
|
+
"rails/init.rb",
|
28
|
+
"test/content_manager_test.rb",
|
29
|
+
"test/test_helper.rb"
|
30
|
+
]
|
31
|
+
s.homepage = %q{http://github.com/sethyates/content_manager}
|
32
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
33
|
+
s.require_paths = ["lib"]
|
34
|
+
s.rubygems_version = %q{1.3.3}
|
35
|
+
s.summary = %q{Simple Content Manager}
|
36
|
+
s.test_files = [
|
37
|
+
"test/content_manager_test.rb",
|
38
|
+
"test/test_helper.rb"
|
39
|
+
]
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
|
+
s.specification_version = 3
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
46
|
+
s.add_runtime_dependency(%q<rufus-tokyo>, [">= 0.1.12"])
|
47
|
+
else
|
48
|
+
s.add_dependency(%q<rufus-tokyo>, [">= 0.1.12"])
|
49
|
+
end
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<rufus-tokyo>, [">= 0.1.12"])
|
52
|
+
end
|
53
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/rails/init"
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module ContentHelper
|
2
|
+
def render_components(name)
|
3
|
+
querystring = "" # TODO
|
4
|
+
|
5
|
+
env = {
|
6
|
+
"rack.version" => [0, 1],
|
7
|
+
"rack.input" => StringIO.new(""),
|
8
|
+
"rack.errors" => $stderr,
|
9
|
+
"rack.url_scheme" => "http",
|
10
|
+
"rack.run_once" => false,
|
11
|
+
"rack.multithread" => false,
|
12
|
+
"rack.multiprocess" => false,
|
13
|
+
"QUERY_STRING" => querystring,
|
14
|
+
"REQUEST_METHOD" => "GET",
|
15
|
+
"PATH_INFO" => name,
|
16
|
+
"REQUEST_PATH" => name,
|
17
|
+
"REQUEST_URI" => name
|
18
|
+
}
|
19
|
+
|
20
|
+
%w(SERVER_SOFTWARE HTTP_USER_AGENT HTTP_ACCEPT_ENCODING HTTP_ACCEPT_CHARSET
|
21
|
+
HTTP_ACCEPT_LANGUAGE HTTP_KEEP_ALIVE HTTP_COOKIE HTTP_VERSION SERVER_PROTOCOL HTTP_HOST
|
22
|
+
SERVER_NAME SERVER_PORT REMOTE_ADDR SCRIPT_NAME).each { |key| env[key] = request.env[key] }
|
23
|
+
|
24
|
+
resp = ActionController::Dispatcher.new.call(env)
|
25
|
+
raise "Error executing component '#{name}' - #{resp[0]}" unless resp[0] == 200
|
26
|
+
resp[2].body
|
27
|
+
end
|
28
|
+
end
|
data/lib/content_item.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
class ContentItem
|
2
|
+
attr_accessor :attributes
|
3
|
+
|
4
|
+
def self.establish_connection(name)
|
5
|
+
@@connection = Rufus::Tokyo::Table.new("db/#{name}.tdb", "create")
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.connection()
|
9
|
+
@@connection ||= self.establish_connection('contents')
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.mock_attr(*syms)
|
13
|
+
syms.each do |sym|
|
14
|
+
define_method(sym) { "#{attributes[sym.to_s]}" }
|
15
|
+
define_method("#{sym.to_s}=".to_sym) { |val| attributes[sym.to_s] = val }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.wrap_result(attrs)
|
20
|
+
attrs.nil? ? nil : ContentItem.new(attrs)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.find_first_by_url(url)
|
24
|
+
wrap_result connection[url]
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.find_all_by_url(url)
|
28
|
+
[self.find_first_by_url(url)]
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.find(options)
|
32
|
+
options ||= {}
|
33
|
+
connection.query { |q|
|
34
|
+
(options[:conditions] || {}).each { |cond| q.add_condition cond.key, :eq, cond.value }
|
35
|
+
(options[:order] || []).each {|order| q.order_by order }
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.polymorphic_finder(name, *arguments)
|
40
|
+
wrap_result(connection.query {|q| q.add_condition name.to_s, :eq, arguments.first.to_s })
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.method_missing(name, *arguments)
|
44
|
+
if name.to_s =~ /^find_all(_by)?_(.+)$/
|
45
|
+
polymorphic_finder($2, arguments)
|
46
|
+
elsif name.to_s =~ /^find_(first_by|by)_(.+)$/
|
47
|
+
polymorphic_finder($2, arguments).first
|
48
|
+
else
|
49
|
+
super
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def initialize(attrs = {})
|
54
|
+
self.attributes = {}
|
55
|
+
(attrs || {}).each { |key, value| self.attributes[key.to_s] = value.to_s }
|
56
|
+
end
|
57
|
+
|
58
|
+
def save()
|
59
|
+
hash = self.attributes.dup
|
60
|
+
url = hash.delete "url"
|
61
|
+
ContentItem.connection[url] = hash
|
62
|
+
end
|
63
|
+
|
64
|
+
def method_missing(name, *arguments)
|
65
|
+
if arguments.length > 0
|
66
|
+
attributes[name.to_s.chomp('=')] = arguments.first
|
67
|
+
elsif attributes.has_key? name.to_s
|
68
|
+
attributes[name.to_s]
|
69
|
+
else
|
70
|
+
super
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
mock_attr :id, :status, :version, :url, :heading, :summary, :content_type, :sublayout
|
75
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Rack
|
2
|
+
class ContentManager
|
3
|
+
def initialize(app)
|
4
|
+
@app = app
|
5
|
+
end
|
6
|
+
|
7
|
+
def call(env)
|
8
|
+
item = ContentItem.find_first_by_url(env["REQUEST_PATH"])
|
9
|
+
if item.nil?
|
10
|
+
@app.call(env)
|
11
|
+
else
|
12
|
+
response = Rack::Response.new
|
13
|
+
response.write "Hi there"
|
14
|
+
response.finish
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ActionController::Dispatcher.middleware.use ::Rack::ContentManager
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sethyates-content_manager
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Seth Yates
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-06-05 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rufus-tokyo
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.1.12
|
24
|
+
version:
|
25
|
+
description:
|
26
|
+
email: syates@grandcentralmedia.com.au
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.rdoc
|
34
|
+
files:
|
35
|
+
- .document
|
36
|
+
- .gitignore
|
37
|
+
- LICENSE
|
38
|
+
- README.rdoc
|
39
|
+
- Rakefile
|
40
|
+
- VERSION
|
41
|
+
- content_manager.gemspec
|
42
|
+
- init.rb
|
43
|
+
- lib/content_helper.rb
|
44
|
+
- lib/content_item.rb
|
45
|
+
- lib/rack/content_manager.rb
|
46
|
+
- rails/init.rb
|
47
|
+
- test/content_manager_test.rb
|
48
|
+
- test/test_helper.rb
|
49
|
+
has_rdoc: false
|
50
|
+
homepage: http://github.com/sethyates/content_manager
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options:
|
53
|
+
- --charset=UTF-8
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
version:
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.2.0
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: Simple Content Manager
|
75
|
+
test_files:
|
76
|
+
- test/content_manager_test.rb
|
77
|
+
- test/test_helper.rb
|