nocms 0.1.4 → 0.2.0
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.rdoc +18 -7
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/nocms.rb +124 -21
- data/nocms.gemspec +5 -5
- data/test/test_nocms.rb +9 -3
- metadata +6 -6
data/README.rdoc
CHANGED
@@ -1,18 +1,29 @@
|
|
1
|
-
=
|
1
|
+
= NOCMS
|
2
2
|
|
3
|
-
NOCMS is a web service that allows you to add basic Content Management to any website.
|
4
|
-
few lines of Javascript, and server-
|
3
|
+
NOCMS is a web service that allows you to add basic Content Management to any website.
|
4
|
+
It provides wiki-style editing with a few lines of Javascript, and server-side rendering
|
5
|
+
and user authentication support with just some simple server-side integration.
|
5
6
|
|
6
|
-
If you've ever been involved in hand-to-hand combat with a big, ugly, hard to customize
|
7
|
+
If you've ever been involved in hand-to-hand combat with a big, ugly, hard to customize
|
8
|
+
Content Management System (CMS), then NOCMS might be right for you.
|
9
|
+
|
10
|
+
Website: http://www.nocms.org
|
11
|
+
Mailing List: http://groups.google.com/group/nocms
|
12
|
+
Twitter: http://twitter.com/powcloud
|
13
|
+
|
14
|
+
== Changes
|
15
|
+
|
16
|
+
* 0.2.0
|
17
|
+
* Added Rails support incl. caching
|
18
|
+
* First stab at unit tests
|
19
|
+
* 0.1.0 First prototype of the ruby gem - Sinatra support
|
7
20
|
|
8
|
-
http://www.nocms.org/
|
9
21
|
|
10
22
|
== Note on Patches/Pull Requests
|
11
23
|
|
12
24
|
* Fork the project.
|
13
25
|
* Make your feature addition or bug fix.
|
14
|
-
* Add tests for it. This is important so I don't break it in a
|
15
|
-
future version unintentionally.
|
26
|
+
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
16
27
|
* Commit, do not mess with rakefile, version, or history.
|
17
28
|
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
18
29
|
* Send me a pull request. Bonus points for topic branches.
|
data/Rakefile
CHANGED
@@ -10,7 +10,7 @@ begin
|
|
10
10
|
gem.email = "nocms@powcloud.com"
|
11
11
|
gem.homepage = "http://github.com/powcloud/nocms"
|
12
12
|
gem.authors = ["Darren Rush"]
|
13
|
-
gem.add_development_dependency "
|
13
|
+
gem.add_development_dependency "shoulda"
|
14
14
|
gem.add_dependency "activesupport"
|
15
15
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
16
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/nocms.rb
CHANGED
@@ -3,38 +3,141 @@ require 'net/http'
|
|
3
3
|
require 'uri'
|
4
4
|
require 'cgi'
|
5
5
|
|
6
|
-
@@nocms_pages = nil
|
7
6
|
|
8
7
|
# This is a default, that might be override by the app
|
9
|
-
@@nocms_lang_default = 'en'
|
10
8
|
|
11
|
-
|
12
|
-
|
9
|
+
module NoCMS
|
10
|
+
class Cache < Hash
|
11
|
+
def read(key)
|
12
|
+
self[key]
|
13
|
+
end
|
14
|
+
|
15
|
+
def write(key, value)
|
16
|
+
self[key] = value.to_s
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class Base
|
21
|
+
class << self
|
22
|
+
attr_accessor :site
|
23
|
+
attr_accessor :lang_default
|
24
|
+
|
25
|
+
NoCMS::Base.lang_default = 'en'
|
26
|
+
|
27
|
+
#@@nocms_lang_default = 'en'
|
28
|
+
@@nocms_cache = NoCMS::Cache.new
|
29
|
+
|
30
|
+
def environment
|
31
|
+
return RAILS_ENV if rails?
|
32
|
+
return (!!defined? settings && !settings.environment.nil?) ? settings.environment : 'development-nocms-test'
|
33
|
+
end
|
34
|
+
|
35
|
+
def rails?
|
36
|
+
!!defined? Rails
|
37
|
+
end
|
38
|
+
|
39
|
+
def diagnostic
|
40
|
+
buffer = ''
|
41
|
+
buffer += "NoCMS Diagnostics\n"
|
42
|
+
buffer += " Rails: #{rails?}\n"
|
43
|
+
if rails?
|
44
|
+
buffer += " Cache Store: #{ActionController::Base.cache_store}\n"
|
45
|
+
buffer += " Cache (Object): #{Rails.cache}\n"
|
46
|
+
end
|
47
|
+
|
48
|
+
buffer += " Cache: #{cache.class}\n"
|
49
|
+
buffer += " Environment: #{environment}\n"
|
50
|
+
buffer += " Site Key: #{site}\n"
|
51
|
+
buffer += " Default Language: #{lang_default}\n"
|
52
|
+
buffer
|
53
|
+
end
|
54
|
+
|
55
|
+
def build_key(path, xpath)
|
56
|
+
"NOCMS:#{path}:#{xpath}"
|
57
|
+
end
|
58
|
+
|
59
|
+
def cache()
|
60
|
+
rails? ? Rails.cache : @@nocms_cache
|
61
|
+
end
|
62
|
+
|
63
|
+
def ensure_cache()
|
64
|
+
tmp = cache.read("NOCMS:#{site}:updated_at")
|
65
|
+
updated_at = Marshal.load(tmp) if !tmp.nil?
|
66
|
+
load_cache if updated_at.nil? || updated_at < Time.now - 5*60
|
67
|
+
end
|
68
|
+
|
69
|
+
def load_cache
|
70
|
+
start_time = Time.now
|
71
|
+
raise '[NOCMS] Must specify a site' if NoCMS::Base.site.nil?
|
72
|
+
|
73
|
+
cache.write("NOCMS:#{site}:updated_at", Marshal.dump(Time.now))
|
74
|
+
|
75
|
+
# save this for a bit
|
76
|
+
tmp = cache.read("NOCMS:#{site}:keys")
|
77
|
+
old_keys = !tmp.nil? ? ActiveSupport::JSON.decode(tmp) : {}
|
78
|
+
|
79
|
+
# load the new stuff
|
80
|
+
rq = "http://api.nocms.org/nocms/1.0/export?site=#{site}"
|
81
|
+
json = Net::HTTP.get(URI.parse(rq))
|
82
|
+
new_blocks = ActiveSupport::JSON.decode(json)
|
83
|
+
#Rails.cache["NOCMS:#{site}:json"] = json
|
84
|
+
cache.write("NOCMS:#{site}:keys", new_blocks.collect {|block| build_key(block['block']['path'], block['block']['xpath'])} )
|
85
|
+
# add new keys and update existing
|
86
|
+
new_blocks.each do |block|
|
87
|
+
p = block['block']
|
88
|
+
#@@nocms_pages["#{p['path']}:#{p['xpath']}"] = p['content']
|
89
|
+
key = build_key(p['path'], p['xpath'])
|
90
|
+
cache.write(key, p['content'])
|
91
|
+
old_keys.delete(key)
|
92
|
+
end
|
93
|
+
|
94
|
+
# purge keys that have been deleted
|
95
|
+
old_keys.each {|key| cache.delete(key)}
|
96
|
+
|
97
|
+
updated_count = new_blocks.length
|
98
|
+
deleted_count = old_keys.length
|
99
|
+
|
100
|
+
puts "Loaded #{updated_count} blocks and deleted #{deleted_count} in #{Time.now-start_time}"
|
101
|
+
end
|
102
|
+
|
103
|
+
def can_edit?()
|
104
|
+
environment != :production
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
13
111
|
end
|
14
112
|
|
113
|
+
#module ActionView
|
114
|
+
# class Base
|
115
|
+
|
116
|
+
# def nocms_block2(id, options = {})
|
117
|
+
# "NOCMS WAS HERE!"
|
118
|
+
# end
|
119
|
+
# end
|
120
|
+
#end
|
121
|
+
|
122
|
+
|
123
|
+
|
15
124
|
def nocms_block(id, options = {})
|
16
125
|
raise 'Must specify an element id as the first parameter. :tag and :content are optional params' if id.nil?
|
17
|
-
|
126
|
+
|
127
|
+
#request = ActionController::Base.request ||= Sinatra::Base.request
|
128
|
+
|
18
129
|
tag = options[:tag] ||= 'div'
|
19
|
-
site = options[:site] ||=
|
20
|
-
path = options[:path] ||= request.path_info
|
130
|
+
site = options[:site] ||= NoCMS::Base.site # ||= request.host_with_port
|
131
|
+
path = options[:path] ||= request.path ||= request.path_info
|
21
132
|
lang = options[:lang] ||= request.env['HTTP_ACCEPT_LANGUAGE'].nil? ? nil : request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first ||= 'en'
|
133
|
+
lang_default = NoCMS::Base.lang_default
|
22
134
|
|
23
|
-
|
24
|
-
@@nocms_pages_updated_at = Time.now
|
25
|
-
rq = "http://api.nocms.org/nocms/1.0/export?site=#{site}"
|
26
|
-
json = Net::HTTP.get(URI.parse(rq))
|
27
|
-
results = ActiveSupport::JSON.decode(json)
|
28
|
-
@@nocms_pages = Hash.new
|
29
|
-
results.each do |block|
|
30
|
-
p = block['block']
|
31
|
-
@@nocms_pages["#{p['path']}:#{p['xpath']}"] = p['content']
|
32
|
-
end
|
33
|
-
puts "Loaded #{results.length} blocks"
|
34
|
-
end
|
135
|
+
NoCMS::Base.ensure_cache()
|
35
136
|
|
36
|
-
|
137
|
+
## TODO: exception throw when these are consolidated????
|
138
|
+
content = NoCMS::Base.cache.read(NoCMS::Base.build_key("/#{lang}#{path}", id))
|
139
|
+
content = content ||= NoCMS::Base.cache.read(NoCMS::Base.build_key("/#{lang_default}#{path}", id)) if lang != lang_default
|
140
|
+
content = content ||= options[:default] ||= 'Lorem ipsum'
|
37
141
|
|
38
|
-
# "%#{tag}\##{id}.edit #{content}"
|
39
142
|
"<#{tag} id='#{id}' class='nocms_edit'>#{content}</#{tag}>"
|
40
143
|
end
|
data/nocms.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{nocms}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Darren Rush"]
|
12
|
-
s.date = %q{2010-08-
|
12
|
+
s.date = %q{2010-08-20}
|
13
13
|
s.description = %q{A Ruby client for the NOCMS.org web service API. Provides server-side helpers for Rails/Sinatra/Rack applications. keywords: ruby, rails, sinatra, rack, CMS, content management systems, search, cloud, SAAS, JSON, web service}
|
14
14
|
s.email = %q{nocms@powcloud.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -43,14 +43,14 @@ Gem::Specification.new do |s|
|
|
43
43
|
s.specification_version = 3
|
44
44
|
|
45
45
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
46
|
-
s.add_development_dependency(%q<
|
46
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
47
47
|
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
48
48
|
else
|
49
|
-
s.add_dependency(%q<
|
49
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
50
50
|
s.add_dependency(%q<activesupport>, [">= 0"])
|
51
51
|
end
|
52
52
|
else
|
53
|
-
s.add_dependency(%q<
|
53
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
54
54
|
s.add_dependency(%q<activesupport>, [">= 0"])
|
55
55
|
end
|
56
56
|
end
|
data/test/test_nocms.rb
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class
|
4
|
-
|
5
|
-
|
3
|
+
class NocmsTests < Test::Unit::TestCase
|
4
|
+
NoCMS::Base.site = 'powcloud.com:not-so-secret'
|
5
|
+
|
6
|
+
should "run diagnostics" do
|
7
|
+
puts NoCMS::Base.diagnostic
|
8
|
+
end
|
9
|
+
|
10
|
+
should "load cache" do
|
11
|
+
NoCMS::Base.ensure_cache()
|
6
12
|
end
|
7
13
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nocms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Darren Rush
|
@@ -15,11 +15,11 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-20 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
22
|
+
name: shoulda
|
23
23
|
prerelease: false
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|