Top Level Namespace
Defined Under Namespace
Modules: Pagelime, PagelimeControllerExtensions, PagelimeHelper
Classes: PagelimeReceiverController
Instance Method Summary
collapse
Instance Method Details
#cms_api_signature(req) ⇒ Object
11
12
13
14
15
|
# File 'lib/pagelime_rails.rb', line 11
def cms_api_signature(req)
secret = ENV['PAGELIME_ACCOUNT_SECRET']
signature = Base64.encode64("#{OpenSSL::HMAC.digest('sha1',secret,req)}")
return signature
end
|
#cms_process_html_block(page_path = nil, html = "", fragment = true) ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/pagelime_rails.rb', line 92
def cms_process_html_block(page_path=nil, html="",fragment=true)
unless pagelime_environment_configured?
puts "PAGELIME CMS PLUGIN: Environment variables not configured"
return html
end
doc = fragment ? Nokogiri::HTML::DocumentFragment.parse(html) : Nokogiri::HTML::Document.parse(html)
editable_regions = doc.css(".cms-editable")
shared_regions = doc.css(".cms-shared")
region_client_ids = Array.new
editable_regions.each do |div|
region_client_ids.push div["id"]
end
cms_process_html_block_regions(editable_regions, fetch_cms_xml(page_path,region_client_ids))
cms_process_html_block_regions(shared_regions,fetch_cms_shared_xml())
return doc.to_html
end
|
#cms_process_html_block_regions(editable_regions, xml_content) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/pagelime_rails.rb', line 64
def cms_process_html_block_regions(editable_regions, xml_content)
editable_regions.each do |div|
client_id = div["id"]
puts "PAGELIME CMS PLUGIN: parsing xml"
soap = Nokogiri::XML::Document.parse(xml_content)
puts "PAGELIME CMS PLUGIN: looking for region: #{client_id}"
xpathNodes = soap.css("EditableRegion[@ElementID=\"#{client_id}\"]")
puts "regions found: #{xpathNodes.count}"
if (xpathNodes.count > 0)
new_content = xpathNodes[0].css("Html")[0].content()
puts "PAGELIME CMS PLUGIN: NEW CONTENT:"
puts new_content
if (new_content)
div.replace new_content
end
end
end
end
|
#fetch_cms_shared_xml ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/pagelime_rails.rb', line 17
def fetch_cms_shared_xml
xml_content = Rails.cache.fetch("cms:shared", :expires_in => 1.year) do
puts "PAGELIME CMS PLUGIN: NO SHARED CACHE... loading xml"
key = ENV['PAGELIME_ACCOUNT_KEY']
http = Net::HTTP::new('s3.amazonaws.com',80)
response = http.get("/cms_assets/heroku/#{key}/shared-regions.xml")
xml_content = response.body
xml_content
end
return xml_content
end
|
#fetch_cms_xml(page_path, element_ids) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/pagelime_rails.rb', line 40
def fetch_cms_xml(page_path, element_ids)
page_key = Base64.encode64(page_path)
xml_content = Rails.cache.fetch("cms:#{page_key}", :expires_in => 1.year) do
puts "PAGELIME CMS PLUGIN: NO '#{page_path}' CACHE... loading xml"
key = ENV['PAGELIME_ACCOUNT_KEY']
http = Net::HTTP::new('s3.amazonaws.com',80)
response = http.get("/cms_assets/heroku/#{key}/pages#{page_path}.xml")
xml_content = response.body
xml_content
end
return xml_content
end
|
#initialize_pagelime_plugin ⇒ Object
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
# File 'lib/pagelime_rails.rb', line 143
def initialize_pagelime_plugin
puts "PAGELIME CMS PLUGIN: initializing"
%w{ models controllers helpers }.each do |dir|
path = File.join(File.dirname(__FILE__), 'app', dir)
$LOAD_PATH << path
if Rails::VERSION::MAJOR == 2
ActiveSupport::Dependencies.load_paths << path
ActiveSupport::Dependencies.load_once_paths.delete(path)
elsif Rails::VERSION::MAJOR == 3
ActiveSupport::Dependencies.autoload_paths << path
ActiveSupport::Dependencies.autoload_once_paths.delete(path)
end
end
ActionController::Base.extend PagelimeControllerExtensions
require "app/helpers/pagelime_helper"
ActionView::Base.send :include, PagelimeHelper
end
|
#pagelime_environment_configured? ⇒ Boolean
5
6
7
8
9
|
# File 'lib/pagelime_rails.rb', line 5
def pagelime_environment_configured?
ENV['PAGELIME_ACCOUNT_KEY'] != nil &&
ENV['PAGELIME_ACCOUNT_SECRET'] != nil &&
ENV['PAGELIME_HEROKU_API_VERSION']
end
|