nocms 0.2.0 → 0.3.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.
Files changed (5) hide show
  1. data/README.rdoc +23 -9
  2. data/VERSION +1 -1
  3. data/lib/nocms.rb +51 -41
  4. data/nocms.gemspec +2 -2
  5. metadata +4 -4
@@ -1,22 +1,36 @@
1
1
  = NOCMS
2
2
 
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.
3
+ NOCMS is a web service that allows you to add basic WYSIWYG Content Management to any website.
4
+ It provides wiki-style editing with a few lines of Javascript. Add just a few lines more to
5
+ your application and you get server-side rendering and 'editor' authentication.
6
6
 
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.
7
+ The NOCMS gem provides server-side integration with api.nocms.org for ruby applications built on the Rails or Sinatra frameworks.
8
+
9
+ NOCMS is for you if:
10
+ * You want to add WYSIWYG editing to an existing static website
11
+ * Wordpress, Drupal and similar OSS Content Management Systems are too much for your needs
12
+ * You want to add basic CMS functions to your existing web app
13
+
14
+ FEATURES (NOCMS RUBY GEM)
15
+ * Wiki-style WYSIWYG editing with just 3 lines of Javascript
16
+ * Server-side rendering of content for SEO purposes and improved performance
17
+ * Caching via native Rails.cache or a custom Sinatra cache (Hash)
18
+ * nocms_block() view helper for adding editable blocks to your pages/views
9
19
 
10
20
  Website: http://www.nocms.org
11
21
  Mailing List: http://groups.google.com/group/nocms
12
22
  Twitter: http://twitter.com/powcloud
13
23
 
14
24
  == Changes
15
-
25
+ * 0.3.0
26
+ * FEA: Add path_has_content? which returns true if the given path has content in the cache in either the current language or the default language
27
+ * 0.2.1
28
+ * BUG: Fix a serialization bug for the keys list, now using Sets
16
29
  * 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
30
+ * FEA: Added Rails support incl. caching
31
+ * FEA: First stab at unit tests
32
+ * 0.1.0
33
+ * FEA: First prototype of the ruby gem - Sinatra support
20
34
 
21
35
 
22
36
  == Note on Patches/Pull Requests
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -2,9 +2,7 @@ require 'active_support'
2
2
  require 'net/http'
3
3
  require 'uri'
4
4
  require 'cgi'
5
-
6
-
7
- # This is a default, that might be override by the app
5
+ require 'set'
8
6
 
9
7
  module NoCMS
10
8
  class Cache < Hash
@@ -24,7 +22,6 @@ module NoCMS
24
22
 
25
23
  NoCMS::Base.lang_default = 'en'
26
24
 
27
- #@@nocms_lang_default = 'en'
28
25
  @@nocms_cache = NoCMS::Cache.new
29
26
 
30
27
  def environment
@@ -37,14 +34,9 @@ module NoCMS
37
34
  end
38
35
 
39
36
  def diagnostic
40
- buffer = ''
41
- buffer += "NoCMS Diagnostics\n"
37
+ buffer = "NoCMS Diagnostics\n"
42
38
  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
-
39
+ buffer += "\tCache Store: #{ActionController::Base.cache_store}\n\tCache (Object): #{Rails.cache}\n" if rails?
48
40
  buffer += " Cache: #{cache.class}\n"
49
41
  buffer += " Environment: #{environment}\n"
50
42
  buffer += " Site Key: #{site}\n"
@@ -66,6 +58,21 @@ module NoCMS
66
58
  load_cache if updated_at.nil? || updated_at < Time.now - 5*60
67
59
  end
68
60
 
61
+ def path_has_content?(request, path = nil, options = {})
62
+ path ||= options.delete(:path) || request.path || request.path_info
63
+
64
+ ensure_cache()
65
+
66
+ lang = options.delete(:lang) || request.env['HTTP_ACCEPT_LANGUAGE'].nil? ? nil : request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first || 'en'
67
+ lang_default = NoCMS::Base.lang_default
68
+
69
+ tmp = cache.read("NOCMS:#{site}:paths")
70
+ paths = !tmp.nil? ? Set.new(ActiveSupport::JSON.decode(tmp)) : Set.new
71
+
72
+ return paths.include? "/#{lang}#{path}" if lang==lang_default
73
+ paths.include?("/#{lang}#{path}") || paths.include?("/#{lang_default}#{path}")
74
+ end
75
+
69
76
  def load_cache
70
77
  start_time = Time.now
71
78
  raise '[NOCMS] Must specify a site' if NoCMS::Base.site.nil?
@@ -74,22 +81,28 @@ module NoCMS
74
81
 
75
82
  # save this for a bit
76
83
  tmp = cache.read("NOCMS:#{site}:keys")
77
- old_keys = !tmp.nil? ? ActiveSupport::JSON.decode(tmp) : {}
84
+ old_keys = !tmp.nil? ? Set.new(ActiveSupport::JSON.decode(tmp)) : Set.new
78
85
 
79
86
  # load the new stuff
80
87
  rq = "http://api.nocms.org/nocms/1.0/export?site=#{site}"
81
88
  json = Net::HTTP.get(URI.parse(rq))
82
89
  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'])} )
90
+
91
+ keys = Set.new
92
+ paths = Set.new
93
+
85
94
  # add new keys and update existing
86
95
  new_blocks.each do |block|
87
96
  p = block['block']
88
- #@@nocms_pages["#{p['path']}:#{p['xpath']}"] = p['content']
89
97
  key = build_key(p['path'], p['xpath'])
98
+ keys << key
99
+ paths << p['path']
90
100
  cache.write(key, p['content'])
91
101
  old_keys.delete(key)
92
102
  end
103
+
104
+ cache.write("NOCMS:#{site}:paths", ActiveSupport::JSON.encode(paths))
105
+ cache.write("NOCMS:#{site}:keys", ActiveSupport::JSON.encode(keys))
93
106
 
94
107
  # purge keys that have been deleted
95
108
  old_keys.each {|key| cache.delete(key)}
@@ -103,41 +116,38 @@ module NoCMS
103
116
  def can_edit?()
104
117
  environment != :production
105
118
  end
106
-
107
119
  end
108
-
109
120
  end
110
-
111
121
  end
112
122
 
113
- #module ActionView
114
- # class Base
115
-
116
- # def nocms_block2(id, options = {})
117
- # "NOCMS WAS HERE!"
118
- # end
119
- # end
120
- #end
123
+ def path_has_content?(path=nil, options={})
124
+ NoCMS::Base.path_has_content?(request,path,options)
125
+ end
121
126
 
127
+ def nocms_block(id, options = {})
122
128
 
129
+ tag = options.delete(:tag) || 'div'
130
+ site = options.delete(:site) || NoCMS::Base.site # ||= request.host_with_port
131
+ path = options.delete(:path) || request.path || request.path_info
132
+ lang = options.delete(: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
123
134
 
124
- def nocms_block(id, options = {})
125
135
  raise 'Must specify an element id as the first parameter. :tag and :content are optional params' if id.nil?
126
-
127
- #request = ActionController::Base.request ||= Sinatra::Base.request
128
-
129
- tag = options[:tag] ||= 'div'
130
- site = options[:site] ||= NoCMS::Base.site # ||= request.host_with_port
131
- path = options[:path] ||= request.path ||= request.path_info
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
136
+ raise 'Path could not be determined, pass :path and ensure it is not nil' if path.nil?
137
+ raise 'Site could not be determined. Please set the NoCMS site variable per the documentation' if site.nil?
134
138
 
135
139
  NoCMS::Base.ensure_cache()
136
140
 
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'
141
+ content = NoCMS::Base.cache.read(NoCMS::Base.build_key("/#{lang}#{path}", id))
142
+ content ||= NoCMS::Base.cache.read(NoCMS::Base.build_key("/#{lang_default}#{path}", id)) if lang != lang_default
143
+ content ||= options.delete(:default) || 'Lorem ipsum'
144
+
145
+ attr_class = ['nocms_edit']
146
+ add_classes = options.delete(:class)
147
+ attr_class += add_classes.split(' ') if !add_classes.nil?
148
+
149
+ attributes = options.collect { |k,v| "#{k}='#{v}'" } if options.length > 0
141
150
 
142
- "<#{tag} id='#{id}' class='nocms_edit'>#{content}</#{tag}>"
143
- end
151
+ "<#{tag} id='#{id}' #{attributes} class='#{attr_class.join(" ").strip}'>#{content}</#{tag}>"
152
+ end
153
+
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{nocms}
8
- s.version = "0.2.0"
8
+ s.version = "0.3.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-20}
12
+ s.date = %q{2010-08-23}
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 = [
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: 23
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 0.2.0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Darren Rush
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-20 00:00:00 -07:00
18
+ date: 2010-08-23 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency