pagelime_rails 0.1.1 → 0.1.2
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/Heroku.md +77 -1
- data/VERSION +1 -1
- data/lib/app/controllers/pagelime_receiver_controller.rb +1 -0
- data/lib/pagelime_rails.rb +107 -89
- data/pagelime_rails.gemspec +2 -2
- metadata +4 -4
data/Heroku.md
CHANGED
@@ -1,4 +1,80 @@
|
|
1
1
|
Pagelime CMS Addon
|
2
2
|
=====================
|
3
3
|
|
4
|
-
The CMS add-on enables the Pagelime CMS for your app, and allows your team to edit content on your Heroku app without commiting new code, modifying the database, or impacting the release process.
|
4
|
+
The CMS add-on enables the Pagelime CMS for your app, and allows your team to edit content on your Heroku app without commiting new code, modifying the database, or impacting the release process.
|
5
|
+
|
6
|
+
Pagelime is a simple CMS service that allows you to define editable regions in your content without installing any software on your site or app. Simply add a `class="cms-editable"` to any HTML element, and log-in to the Pagelime CMS service to edit your content and images with a nice UI. We host all of the code, content, and data until you publish a page. When you publish a page, we push the content to your site/app via secure FTP or web APIs.
|
7
|
+
|
8
|
+
In your views, make any element editable just by adding a CSS class:
|
9
|
+
`<div id="my_content" class="cms-editable">This content is now editable in Pagelime... no code... no databases... no fuss</div>`
|
10
|
+
|
11
|
+
Getting Started
|
12
|
+
---------------
|
13
|
+
|
14
|
+
### Step 1.
|
15
|
+
Require the **pagelime_rails** gem
|
16
|
+
|
17
|
+
#### For Rails 2
|
18
|
+
edit your `config/environment.rb` file and add:
|
19
|
+
|
20
|
+
`config.gem "pagelime_rails"`
|
21
|
+
|
22
|
+
then run
|
23
|
+
|
24
|
+
`rake gems:install`
|
25
|
+
|
26
|
+
#### For Rails 3
|
27
|
+
edit your `Gemfile` and add
|
28
|
+
|
29
|
+
`gem "pagelime_rails"`
|
30
|
+
|
31
|
+
then run
|
32
|
+
|
33
|
+
`bundle install`
|
34
|
+
|
35
|
+
### Step 2. (Only for Rails 2.3.X)
|
36
|
+
Add the plugin routes to your `config/routes.rb` configuration:
|
37
|
+
|
38
|
+
`map.cms_routes`
|
39
|
+
|
40
|
+
These routes are used by Pagelime to clear any caches after save and publish events on your files.
|
41
|
+
|
42
|
+
*Rails 3 does not need this statement, as the plugin will behave as an engine*
|
43
|
+
|
44
|
+
### Step 3.
|
45
|
+
For any controller that renders views that you want editable, add the acts_as_cms_editable behavior like so:
|
46
|
+
|
47
|
+
class CmsPagesController < ApplicationController
|
48
|
+
# attach the cms behavior to the controller
|
49
|
+
acts_as_cms_editable
|
50
|
+
|
51
|
+
def index
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
You can pass an `:except` parameter just like with a filter like so:
|
56
|
+
|
57
|
+
`acts_as_cms_editable :except => :index`
|
58
|
+
|
59
|
+
### Step 4.
|
60
|
+
Create some editable regions in your views like so:
|
61
|
+
|
62
|
+
`<div id="my_content" class="cms-editable">this is now editable</div>`
|
63
|
+
|
64
|
+
*The ID and the class are required for the CMS to work*
|
65
|
+
|
66
|
+
### Step 5. (OPTIONAL)
|
67
|
+
If you don't want to have your entire controller CMS editable for some reason, you can sorround areas in your view with a code block like so:
|
68
|
+
|
69
|
+
<% cms_content do %>
|
70
|
+
<div id="my_content" class="cms-editable">hello world</div>
|
71
|
+
<% end %>
|
72
|
+
|
73
|
+
### Step 6.
|
74
|
+
Add the pagelime addon to your app from the command line:
|
75
|
+
|
76
|
+
`heroku addons:add pagelime`
|
77
|
+
|
78
|
+
How it works under the hood
|
79
|
+
---------------------------
|
80
|
+
Pagelime is a cloud CMS. It provides a simple WYSIWYG editing interface for your pages, and pushes updated content and images to your app.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
@@ -8,6 +8,7 @@ class PagelimeReceiverController < ApplicationController
|
|
8
8
|
|
9
9
|
page_key = Base64.encode64(params[:path])
|
10
10
|
Rails.cache.delete("cms:#{page_key}")
|
11
|
+
Rails.cache.delete("cms:shared")
|
11
12
|
|
12
13
|
# don't do the prefetch below, as the page isn't done publishing (mySQL transaction hasn't completed) at the point when this gets called
|
13
14
|
=begin
|
data/lib/pagelime_rails.rb
CHANGED
@@ -8,44 +8,89 @@ def pagelime_environment_configured?
|
|
8
8
|
ENV['PAGELIME_HEROKU_API_VERSION']
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
11
|
+
def cms_api_signature(req)
|
12
|
+
secret = ENV['PAGELIME_ACCOUNT_SECRET']
|
13
|
+
signature = Base64.encode64("#{OpenSSL::HMAC.digest('sha1',secret,req)}")
|
14
|
+
return signature
|
15
|
+
end
|
16
|
+
|
17
|
+
def fetch_cms_shared_xml
|
18
|
+
xml_content = Rails.cache.fetch("cms:shared", :expires_in => 1.year) do
|
19
|
+
puts "PAGELIME CMS PLUGIN: NO SHARED CACHE... loading xml"
|
20
|
+
# set input values
|
21
|
+
key = ENV['PAGELIME_ACCOUNT_KEY']
|
22
|
+
|
23
|
+
# get the url that we need to post to
|
24
|
+
http = Net::HTTP::new('s3.amazonaws.com',80)
|
25
|
+
|
26
|
+
# send the request
|
27
|
+
response = http.get("/cms_assets_qa/heroku/#{key}/shared-regions.xml")
|
28
|
+
|
29
|
+
# puts "PAGELIME CMS PLUGIN: response XML: #{response.body}"
|
30
|
+
|
31
|
+
xml_content = response.body
|
32
|
+
|
33
|
+
xml_content
|
34
|
+
end
|
35
|
+
|
36
|
+
return xml_content
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
def fetch_cms_xml(page_path, element_ids)
|
41
|
+
|
42
|
+
page_key = Base64.encode64(page_path)
|
43
|
+
xml_content = Rails.cache.fetch("cms:#{page_key}", :expires_in => 1.year) do
|
44
|
+
puts "PAGELIME CMS PLUGIN: NO '#{page_path}' CACHE... loading xml"
|
45
|
+
# set input values
|
46
|
+
key = ENV['PAGELIME_ACCOUNT_KEY']
|
47
|
+
|
48
|
+
# get the url that we need to post to
|
49
|
+
http = Net::HTTP::new('s3.amazonaws.com',80)
|
50
|
+
|
51
|
+
response = http.get("/cms_assets_qa/heroku/#{key}/pages#{page_path}.xml")
|
52
|
+
|
53
|
+
# puts "PAGELIME CMS PLUGIN: response XML: #{response.body}"
|
54
|
+
|
55
|
+
xml_content = response.body
|
56
|
+
|
57
|
+
xml_content
|
58
|
+
end
|
59
|
+
|
60
|
+
return xml_content
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
def cms_process_html_block_regions(editable_regions, xml_content)
|
65
|
+
|
66
|
+
editable_regions.each do |div|
|
67
|
+
|
68
|
+
# Grab client ID
|
69
|
+
client_id = div["id"]
|
70
|
+
|
71
|
+
puts "PAGELIME CMS PLUGIN: parsing xml"
|
72
|
+
soap = Nokogiri::XML::Document.parse(xml_content)
|
73
|
+
puts "PAGELIME CMS PLUGIN: looking for region: #{client_id}"
|
74
|
+
xpathNodes = soap.css("EditableRegion[@ElementID=\"#{client_id}\"]")
|
75
|
+
puts "regions found: #{xpathNodes.count}"
|
76
|
+
if (xpathNodes.count > 0)
|
77
|
+
new_content = xpathNodes[0].css("Html")[0].content()
|
78
|
+
|
79
|
+
puts "PAGELIME CMS PLUGIN: NEW CONTENT:"
|
80
|
+
puts new_content
|
81
|
+
|
82
|
+
if (new_content)
|
83
|
+
# div.content = "Replaced content"
|
84
|
+
div.replace new_content
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
44
90
|
end
|
45
91
|
|
46
92
|
def cms_process_html_block(page_path=nil, html="")
|
47
93
|
|
48
|
-
begin
|
49
94
|
|
50
95
|
unless pagelime_environment_configured?
|
51
96
|
puts "PAGELIME CMS PLUGIN: Environment variables not configured"
|
@@ -54,71 +99,44 @@ def cms_process_html_block(page_path=nil, html="")
|
|
54
99
|
|
55
100
|
# use nokogiri to replace contents
|
56
101
|
doc = Nokogiri::HTML::DocumentFragment.parse(html)
|
57
|
-
|
58
|
-
|
59
|
-
# Grab client ID
|
60
|
-
client_id = div["id"]
|
61
|
-
|
62
|
-
# Load pagelime content
|
63
|
-
xml_content = fetch_cms_xml(page_path)
|
64
|
-
|
65
|
-
puts "PAGELIME CMS PLUGIN: parsing xml"
|
66
|
-
soap = Nokogiri::XML::Document.parse(xml_content)
|
67
|
-
puts "PAGELIME CMS PLUGIN: looking for region: #{client_id}"
|
68
|
-
xpathNodes = soap.css("EditableRegion[@ElementID=\"#{client_id}\"]")
|
69
|
-
puts "regions found: #{xpathNodes.count}"
|
70
|
-
if (xpathNodes.count > 0)
|
71
|
-
new_content = xpathNodes[0].css("Html")[0].content()
|
72
|
-
|
73
|
-
puts "PAGELIME CMS PLUGIN: NEW CONTENT:"
|
74
|
-
puts new_content
|
75
|
-
|
76
|
-
if (new_content)
|
77
|
-
# div.content = "Replaced content"
|
78
|
-
div.replace new_content
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|
83
|
-
|
84
|
-
return doc.to_html
|
102
|
+
editable_regions = doc.css(".cms-editable")
|
103
|
+
shared_regions = doc.css(".cms-shared")
|
85
104
|
|
86
|
-
|
87
|
-
|
88
|
-
# error
|
89
|
-
puts "PAGELIME CMS PLUGIN: Error rendering block"
|
90
|
-
|
91
|
-
# comment below to disable debug
|
92
|
-
raise
|
93
|
-
|
94
|
-
return html
|
105
|
+
region_client_ids = Array.new
|
95
106
|
|
107
|
+
editable_regions.each do |div|
|
108
|
+
region_client_ids.push div["id"]
|
96
109
|
end
|
97
|
-
|
110
|
+
|
111
|
+
cms_process_html_block_regions(editable_regions, fetch_cms_xml(page_path,region_client_ids))
|
112
|
+
cms_process_html_block_regions(shared_regions,fetch_cms_shared_xml())
|
113
|
+
|
114
|
+
return doc.to_html
|
115
|
+
|
98
116
|
end
|
99
117
|
|
100
118
|
module PagelimeControllerExtensions
|
101
119
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
120
|
+
def acts_as_cms_editable(opts=Hash.new)
|
121
|
+
after_filter :cms_process_rendered_body, :except => opts[:except]
|
122
|
+
include InstanceMethods
|
123
|
+
end
|
106
124
|
|
107
|
-
|
108
|
-
|
125
|
+
module InstanceMethods
|
126
|
+
def cms_process_rendered_body
|
109
127
|
puts "PAGELIME CMS PLUGIN: Processing response body"
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
128
|
+
if pagelime_environment_configured?
|
129
|
+
# response contents loaded into a variable
|
130
|
+
input_content = response.body
|
131
|
+
page_path = request.path
|
132
|
+
html = cms_process_html_block(page_path,input_content)
|
133
|
+
# output the final content
|
134
|
+
response.body = html
|
135
|
+
else
|
136
|
+
puts "PAGELIME CMS PLUGIN: Environment variables not configured"
|
119
137
|
end
|
120
|
-
|
121
|
-
|
138
|
+
end
|
139
|
+
end
|
122
140
|
|
123
141
|
end
|
124
142
|
|
data/pagelime_rails.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{pagelime_rails}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Emil Anticevic"]
|
12
|
-
s.date = %q{2012-01-
|
12
|
+
s.date = %q{2012-01-10}
|
13
13
|
s.description = %q{}
|
14
14
|
s.email = %q{eanticev@gmail.com}
|
15
15
|
s.files = [
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pagelime_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Emil Anticevic
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-01-
|
18
|
+
date: 2012-01-10 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|