pagelime-rack 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.document +5 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +74 -0
- data/LICENSE.txt +20 -0
- data/README.md +60 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/lib/pagelime-rack.rb +9 -0
- data/lib/pagelime.rb +28 -0
- data/lib/pagelime/configuration.rb +41 -0
- data/lib/pagelime/s3_client.rb +84 -0
- data/lib/pagelime/xml_processor.rb +80 -0
- data/lib/rack/pagelime.rb +53 -0
- data/pagelime-rack.gemspec +70 -0
- data/test/helper.rb +18 -0
- data/test/test_pagelime-rack.rb +7 -0
- metadata +148 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YmE2N2I5M2Q4MjJkOTVlMDkwZDllYjliNzgzYTVmOGI2M2E4MTBiNQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NWM2ZGFhOTNkNzY4ZGU4M2FmZmFhOWE1MzViZmZmODRiZGFkZmI1MQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MmZlZjA0YjZiN2UyYmRmYjdmNDY5NDM3MWNhN2I2Njk3ZjE1ODQ4NTU1OWQ2
|
10
|
+
Y2I4Y2UwMDljZTBkZDNhMmU5MzU0YWIwMTdkNThjMTgwZTM0MjMyNzBkYWY0
|
11
|
+
NjA1YmU2ODE0M2Y3ZTRkNDg4NGI5NTM2NTJhMjQ2ZTgwN2Y4Zjk=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZjYyN2EwNDEwMGIwMWQ0NGZlZGRjNjIyMmY3NTdmNzRlY2Q3NGEyOTQ1MTc4
|
14
|
+
MzZlYTRlZDU0N2Y2OWEyMGNlNTFhZjRiYWE1NDcyNTU4MWExNDMwMmI4M2Jj
|
15
|
+
MjA4NWM1MTY3MjY3OThjM2U3Y2FmNGU2MmNkYTRkNjVmYzU1MjQ=
|
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem "nokogiri"
|
7
|
+
gem "rack"
|
8
|
+
|
9
|
+
# Add dependencies to develop your gem here.
|
10
|
+
# Include everything needed to run rake, tests, features, etc.
|
11
|
+
group :development do
|
12
|
+
gem "shoulda", ">= 0"
|
13
|
+
gem "rdoc", ">= 3.12"
|
14
|
+
gem "bundler", ">= 1.0.0"
|
15
|
+
gem "jeweler", ">= 1.8.4"
|
16
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (4.0.0)
|
5
|
+
i18n (~> 0.6, >= 0.6.4)
|
6
|
+
minitest (~> 4.2)
|
7
|
+
multi_json (~> 1.3)
|
8
|
+
thread_safe (~> 0.1)
|
9
|
+
tzinfo (~> 0.3.37)
|
10
|
+
addressable (2.3.5)
|
11
|
+
atomic (1.1.13)
|
12
|
+
builder (3.2.2)
|
13
|
+
faraday (0.8.8)
|
14
|
+
multipart-post (~> 1.2.0)
|
15
|
+
git (1.2.6)
|
16
|
+
github_api (0.10.1)
|
17
|
+
addressable
|
18
|
+
faraday (~> 0.8.1)
|
19
|
+
hashie (>= 1.2)
|
20
|
+
multi_json (~> 1.4)
|
21
|
+
nokogiri (~> 1.5.2)
|
22
|
+
oauth2
|
23
|
+
hashie (2.0.5)
|
24
|
+
highline (1.6.19)
|
25
|
+
httpauth (0.2.0)
|
26
|
+
i18n (0.6.5)
|
27
|
+
jeweler (1.8.7)
|
28
|
+
builder
|
29
|
+
bundler (~> 1.0)
|
30
|
+
git (>= 1.2.5)
|
31
|
+
github_api (= 0.10.1)
|
32
|
+
highline (>= 1.6.15)
|
33
|
+
nokogiri (= 1.5.10)
|
34
|
+
rake
|
35
|
+
rdoc
|
36
|
+
json (1.8.0)
|
37
|
+
jwt (0.1.8)
|
38
|
+
multi_json (>= 1.5)
|
39
|
+
minitest (4.7.5)
|
40
|
+
multi_json (1.7.9)
|
41
|
+
multi_xml (0.5.5)
|
42
|
+
multipart-post (1.2.0)
|
43
|
+
nokogiri (1.5.10)
|
44
|
+
oauth2 (0.9.2)
|
45
|
+
faraday (~> 0.8)
|
46
|
+
httpauth (~> 0.2)
|
47
|
+
jwt (~> 0.1.4)
|
48
|
+
multi_json (~> 1.0)
|
49
|
+
multi_xml (~> 0.5)
|
50
|
+
rack (~> 1.2)
|
51
|
+
rack (1.5.2)
|
52
|
+
rake (10.1.0)
|
53
|
+
rdoc (4.0.1)
|
54
|
+
json (~> 1.4)
|
55
|
+
shoulda (3.5.0)
|
56
|
+
shoulda-context (~> 1.0, >= 1.0.1)
|
57
|
+
shoulda-matchers (>= 1.4.1, < 3.0)
|
58
|
+
shoulda-context (1.1.5)
|
59
|
+
shoulda-matchers (2.3.0)
|
60
|
+
activesupport (>= 3.0.0)
|
61
|
+
thread_safe (0.1.2)
|
62
|
+
atomic
|
63
|
+
tzinfo (0.3.37)
|
64
|
+
|
65
|
+
PLATFORMS
|
66
|
+
ruby
|
67
|
+
|
68
|
+
DEPENDENCIES
|
69
|
+
bundler (>= 1.0.0)
|
70
|
+
jeweler (>= 1.8.4)
|
71
|
+
nokogiri
|
72
|
+
rack
|
73
|
+
rdoc (>= 3.12)
|
74
|
+
shoulda
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Emil Anticevic
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
Pagelime Rack Plugin
|
2
|
+
=====================
|
3
|
+
|
4
|
+
Easily add the Pagelime CMS to your rack app.
|
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
|
+
One line example:
|
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
|
+
Requirements:
|
15
|
+
|
16
|
+
* Pagelime account (either a standalone from pagelime.com or as a Heroku add-on)
|
17
|
+
* Nokogiri gem
|
18
|
+
|
19
|
+
#### Step 1: Edit the Gemfile
|
20
|
+
edit your `Gemfile` and add
|
21
|
+
|
22
|
+
`gem "pagelime_rack"`
|
23
|
+
|
24
|
+
then run
|
25
|
+
|
26
|
+
`bundle install`
|
27
|
+
|
28
|
+
### Step 2: Set up your Environment variables
|
29
|
+
|
30
|
+
`ENV['PAGELIME_ACCOUNT_KEY'] = "..."
|
31
|
+
ENV['PAGELIME_ACCOUNT_SECRET'] = "..."
|
32
|
+
ENV['PAGELIME_RACK_API_VERSION'] = "1.0"`
|
33
|
+
|
34
|
+
### Step 3: Create some editable regions in your views
|
35
|
+
like so:
|
36
|
+
|
37
|
+
`<div id="my_content" class="cms-editable">this is now editable</div>`
|
38
|
+
|
39
|
+
*The ID and the class are required for the CMS to work*
|
40
|
+
|
41
|
+
Sinatra Sample
|
42
|
+
--------------
|
43
|
+
|
44
|
+
`require 'sinatra'
|
45
|
+
require 'pagelime-rack'
|
46
|
+
|
47
|
+
configure :development do
|
48
|
+
ENV['PAGELIME_ACCOUNT_KEY'] = "..."
|
49
|
+
ENV['PAGELIME_ACCOUNT_SECRET'] = "..."
|
50
|
+
ENV['PAGELIME_RACK_API_VERSION'] = "1.0"
|
51
|
+
end
|
52
|
+
|
53
|
+
use Rack::Pagelime
|
54
|
+
|
55
|
+
get '/page/about' do
|
56
|
+
content_type "text/html"
|
57
|
+
return "<div id=\"content\" class=\"cms-editable\">Hello World!</div>"
|
58
|
+
end`
|
59
|
+
|
60
|
+
Copyright (c) 2011 Pagelime LLC, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "pagelime-rack"
|
18
|
+
gem.homepage = "http://github.com/eanticev/pagelime-rack"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = "Rack Middleware for integrating Pagelime into ruby frameworks"
|
21
|
+
gem.description = "The Pagelime Rack Middleware will process outgoing HTML, look for editable areas, and replace the content with the appropriate HTML from the Pagelime CDN and cache it in memory if possible."
|
22
|
+
gem.email = "emil@pagelime.com"
|
23
|
+
gem.authors = ["Emil Anticevic", "Joel Van Horn"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
task :default => :test
|
36
|
+
|
37
|
+
require 'rdoc/task'
|
38
|
+
Rake::RDocTask.new do |rdoc|
|
39
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
40
|
+
|
41
|
+
rdoc.rdoc_dir = 'rdoc'
|
42
|
+
rdoc.title = "pagelime-rack #{version}"
|
43
|
+
rdoc.rdoc_files.include('README*')
|
44
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.1
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require_relative 'pagelime'
|
2
|
+
require_relative 'pagelime/s3_client'
|
3
|
+
require_relative 'pagelime/xml_processor'
|
4
|
+
require_relative 'rack/pagelime'
|
5
|
+
|
6
|
+
Pagelime.configure do |config|
|
7
|
+
config.client_class = Pagelime::S3Client
|
8
|
+
config.processor_class = Pagelime::XmlProcessor
|
9
|
+
end
|
data/lib/pagelime.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'pagelime/configuration'
|
2
|
+
|
3
|
+
module Pagelime
|
4
|
+
module ClassMethods
|
5
|
+
# Use as Pagelime.configure{|config| config.account_key = ... }
|
6
|
+
def configure(&block)
|
7
|
+
config.configure(&block)
|
8
|
+
end
|
9
|
+
|
10
|
+
def config
|
11
|
+
@config ||= Configuration.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def logger
|
15
|
+
config.logger
|
16
|
+
end
|
17
|
+
|
18
|
+
def client
|
19
|
+
config.client
|
20
|
+
end
|
21
|
+
|
22
|
+
def processor
|
23
|
+
config.processor
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
extend ClassMethods
|
28
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module Pagelime
|
4
|
+
class Configuration
|
5
|
+
|
6
|
+
# only allow getter access unless using configure block
|
7
|
+
attr_accessor :account_key, :account_secret, :api_version, :client_class, :processor_class, :logger
|
8
|
+
attr_reader :client, :processor
|
9
|
+
|
10
|
+
# pass in a configure block to write new values
|
11
|
+
def initialize(defaults = {}, &block)
|
12
|
+
@account_key = ENV['PAGELIME_ACCOUNT_KEY']
|
13
|
+
@account_secret = ENV['PAGELIME_ACCOUNT_SECRET']
|
14
|
+
@api_version = ENV['PAGELIME_RACK_API_VERSION']
|
15
|
+
@logger = Logger.new(STDOUT)
|
16
|
+
|
17
|
+
configure(&block)
|
18
|
+
end
|
19
|
+
|
20
|
+
def configure(&block)
|
21
|
+
if block_given?
|
22
|
+
# pass self to configuration block
|
23
|
+
yield(self)
|
24
|
+
|
25
|
+
# recreate instances in case classes were updated
|
26
|
+
rebuild!
|
27
|
+
end
|
28
|
+
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
def rebuild!
|
33
|
+
if client_class.nil? || processor_class.nil?
|
34
|
+
raise "You must specify client_class and processor_class"
|
35
|
+
end
|
36
|
+
|
37
|
+
@client = client_class.new(account_key, account_secret, api_version)
|
38
|
+
@processor = processor_class.new(@client)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require "base64"
|
2
|
+
require "net/http"
|
3
|
+
|
4
|
+
module Pagelime
|
5
|
+
class S3Client
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def default_format
|
9
|
+
:xml
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
extend ClassMethods
|
14
|
+
|
15
|
+
attr_reader :account_key, :account_secret, :api_version
|
16
|
+
|
17
|
+
def initialize(account_key, account_secret, api_version)
|
18
|
+
# reference config object to ensure we have the latest credentials, etc
|
19
|
+
@account_key = account_key
|
20
|
+
@account_secret = account_secret
|
21
|
+
@api_version = api_version
|
22
|
+
|
23
|
+
#raise "WARNING: Account key, secret, and API version were not specified!" unless configured?
|
24
|
+
end
|
25
|
+
|
26
|
+
def configured?
|
27
|
+
!(account_key.nil?)# || account_secret.nil? || api_version.nil?)
|
28
|
+
end
|
29
|
+
|
30
|
+
# def cms_api_signature(req)
|
31
|
+
# secret = account_secret
|
32
|
+
# signature = Base64.encode64(OpenSSL::HMAC.digest('sha1', secret, req).to_s)
|
33
|
+
# return signature
|
34
|
+
# end
|
35
|
+
|
36
|
+
def fetch_shared(format = self.class.default_format)
|
37
|
+
|
38
|
+
# TODO: check cache (see the rails plugin for info)
|
39
|
+
|
40
|
+
::Pagelime.logger.debug "PAGELIME CMS PLUGIN: NO SHARED CACHE... loading #{format}"
|
41
|
+
|
42
|
+
content = request_content("/cms_assets/heroku/#{account_key}/shared-regions.#{format}")
|
43
|
+
|
44
|
+
# puts "PAGELIME CMS PLUGIN: response XML: #{xml_content}"
|
45
|
+
|
46
|
+
content
|
47
|
+
end
|
48
|
+
|
49
|
+
def fetch(page_path, format = self.class.default_format)
|
50
|
+
|
51
|
+
# TODO: Should element_ids be used anywhere?
|
52
|
+
|
53
|
+
# TODO: Should page_key be used anywhere?
|
54
|
+
page_key = Base64.encode64(page_path)
|
55
|
+
|
56
|
+
# TODO: check cache (see the rails plugin for info)
|
57
|
+
|
58
|
+
Pagelime.logger.debug "PAGELIME CMS PLUGIN: NO '#{page_path}' CACHE... loading #{format}"
|
59
|
+
|
60
|
+
content = request_content("/cms_assets/heroku/#{account_key}/pages#{page_path}.#{format}")
|
61
|
+
|
62
|
+
content
|
63
|
+
end
|
64
|
+
|
65
|
+
def clear(page_path, format = self.class.default_format)
|
66
|
+
Pagelime.logger.warn "#{self.class.name}##{__method__} is not implemented!"
|
67
|
+
end
|
68
|
+
|
69
|
+
def clear_shared(format = self.class.default_format)
|
70
|
+
Pagelime.logger.warn "#{self.class.name}##{__method__} is not implemented!"
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def request_content(url)
|
76
|
+
http.get(url).body
|
77
|
+
end
|
78
|
+
|
79
|
+
def http
|
80
|
+
@http ||= Net::HTTP::new('s3.amazonaws.com', 80)
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require "nokogiri"
|
2
|
+
|
3
|
+
module Pagelime
|
4
|
+
class XmlProcessor
|
5
|
+
|
6
|
+
attr_reader :client
|
7
|
+
attr_reader :format
|
8
|
+
|
9
|
+
def initialize(client)
|
10
|
+
@client = client
|
11
|
+
@format = :xml
|
12
|
+
end
|
13
|
+
|
14
|
+
def process_document(html, page_path = false)
|
15
|
+
doc = Nokogiri::HTML::Document.parse(html)
|
16
|
+
|
17
|
+
# return original HTML if nil returned
|
18
|
+
parse_document(doc, page_path) || html
|
19
|
+
end
|
20
|
+
|
21
|
+
def process_fragment(html, page_path = false)
|
22
|
+
doc = Nokogiri::HTML::DocumentFragment.parse(html)
|
23
|
+
|
24
|
+
# return original HTML if nil returned
|
25
|
+
parse_document(doc, page_path) || html
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
# options = { :page_path => nil, :html => "", :fragment => true }
|
31
|
+
def parse_document(doc, page_path = false)
|
32
|
+
|
33
|
+
unless client.configured?
|
34
|
+
::Pagelime.logger.warn "PAGELIME CMS PLUGIN: Environment variables not configured"
|
35
|
+
return nil
|
36
|
+
end
|
37
|
+
|
38
|
+
# use nokogiri to replace contents
|
39
|
+
editable_regions = doc.css(".cms-editable")
|
40
|
+
shared_regions = doc.css(".cms-shared")
|
41
|
+
|
42
|
+
patch_regions editable_regions, client.fetch(page_path, format)
|
43
|
+
patch_regions shared_regions, client.fetch_shared(format)
|
44
|
+
|
45
|
+
return doc.to_html
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
def patch_regions(editable_regions, xml_content)
|
50
|
+
|
51
|
+
::Pagelime.logger.debug "PAGELIME CMS PLUGIN: parsing xml"
|
52
|
+
|
53
|
+
editable_regions.each do |div|
|
54
|
+
|
55
|
+
# Grab client ID
|
56
|
+
client_id = div["id"]
|
57
|
+
soap = Nokogiri::XML::Document.parse(xml_content)
|
58
|
+
nodes = soap.css("EditableRegion[@ElementID=\"#{client_id}\"]")
|
59
|
+
|
60
|
+
::Pagelime.logger.debug "PAGELIME CMS PLUGIN: looking for region: #{client_id}"
|
61
|
+
::Pagelime.logger.debug "regions found: #{nodes.count}"
|
62
|
+
|
63
|
+
if nodes.any?
|
64
|
+
new_content = nodes[0].css("Html")[0].content
|
65
|
+
|
66
|
+
::Pagelime.logger.debug "PAGELIME CMS PLUGIN: NEW CONTENT:"
|
67
|
+
::Pagelime.logger.debug new_content
|
68
|
+
|
69
|
+
if new_content
|
70
|
+
# div.content = "Replaced content"
|
71
|
+
div.replace new_content
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rack'
|
2
|
+
require 'rack/utils'
|
3
|
+
|
4
|
+
require_relative '../pagelime'
|
5
|
+
|
6
|
+
module Rack
|
7
|
+
class Pagelime
|
8
|
+
include Rack::Utils
|
9
|
+
|
10
|
+
def initialize(app, options = {})
|
11
|
+
@app = app
|
12
|
+
@options = options
|
13
|
+
|
14
|
+
::Pagelime.logger.debug "PAGELIME: Rack Plugin Initialized"
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(env)
|
18
|
+
|
19
|
+
status, headers, response = @app.call(env)
|
20
|
+
|
21
|
+
::Pagelime.logger.debug "PAGELIME: Headers: #{headers}"
|
22
|
+
::Pagelime.logger.debug "PAGELIME: Status: #{status}"
|
23
|
+
::Pagelime.logger.debug "PAGELIME: Response: #{response}"
|
24
|
+
|
25
|
+
if status == 200 && headers["content-type"].include?("text/html")
|
26
|
+
|
27
|
+
body_content = StringIO.new
|
28
|
+
response.each{|part| body_content << part}
|
29
|
+
|
30
|
+
req = Rack::Request.new(env)
|
31
|
+
|
32
|
+
::Pagelime.logger.debug "PAGELIME: Processing For Path: #{req.path}"
|
33
|
+
::Pagelime.logger.debug "PAGELIME: Processing Body (size:#{body_content.length})"
|
34
|
+
|
35
|
+
body = ::Pagelime.html_processor.process_document(body_content, req.path)
|
36
|
+
|
37
|
+
headers['content-length'] = body.length.to_s
|
38
|
+
|
39
|
+
return [status, headers, [body]]
|
40
|
+
|
41
|
+
else
|
42
|
+
|
43
|
+
::Pagelime.logger.debug "PAGELIME: Not touching this request"
|
44
|
+
|
45
|
+
return [status, headers, response]
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "pagelime-rack"
|
8
|
+
s.version = "0.2.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Emil Anticevic", "Joel Van Horn"]
|
12
|
+
s.date = "2013-09-05"
|
13
|
+
s.description = "The Pagelime Rack Middleware will process outgoing HTML, look for editable areas, and replace the content with the appropriate HTML from the Pagelime CDN and cache it in memory if possible."
|
14
|
+
s.email = "emil@pagelime.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.md",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"lib/pagelime-rack.rb",
|
28
|
+
"lib/pagelime.rb",
|
29
|
+
"lib/pagelime/configuration.rb",
|
30
|
+
"lib/pagelime/s3_client.rb",
|
31
|
+
"lib/pagelime/xml_processor.rb",
|
32
|
+
"lib/rack/pagelime.rb",
|
33
|
+
"pagelime-rack.gemspec",
|
34
|
+
"test/helper.rb",
|
35
|
+
"test/test_pagelime-rack.rb"
|
36
|
+
]
|
37
|
+
s.homepage = "http://github.com/eanticev/pagelime-rack"
|
38
|
+
s.licenses = ["MIT"]
|
39
|
+
s.require_paths = ["lib"]
|
40
|
+
s.rubygems_version = "2.0.7"
|
41
|
+
s.summary = "Rack Middleware for integrating Pagelime into ruby frameworks"
|
42
|
+
|
43
|
+
if s.respond_to? :specification_version then
|
44
|
+
s.specification_version = 4
|
45
|
+
|
46
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
47
|
+
s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
|
48
|
+
s.add_runtime_dependency(%q<rack>, [">= 0"])
|
49
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
50
|
+
s.add_development_dependency(%q<rdoc>, [">= 3.12"])
|
51
|
+
s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
|
52
|
+
s.add_development_dependency(%q<jeweler>, [">= 1.8.4"])
|
53
|
+
else
|
54
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
55
|
+
s.add_dependency(%q<rack>, [">= 0"])
|
56
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
57
|
+
s.add_dependency(%q<rdoc>, [">= 3.12"])
|
58
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
59
|
+
s.add_dependency(%q<jeweler>, [">= 1.8.4"])
|
60
|
+
end
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
63
|
+
s.add_dependency(%q<rack>, [">= 0"])
|
64
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
65
|
+
s.add_dependency(%q<rdoc>, [">= 3.12"])
|
66
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
67
|
+
s.add_dependency(%q<jeweler>, [">= 1.8.4"])
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'pagelime-rack'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pagelime-rack
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Emil Anticevic
|
8
|
+
- Joel Van Horn
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-09-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: nokogiri
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ! '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ! '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rack
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: shoulda
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rdoc
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '3.12'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.12'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: bundler
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.0.0
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 1.0.0
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: jeweler
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 1.8.4
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 1.8.4
|
98
|
+
description: The Pagelime Rack Middleware will process outgoing HTML, look for editable
|
99
|
+
areas, and replace the content with the appropriate HTML from the Pagelime CDN and
|
100
|
+
cache it in memory if possible.
|
101
|
+
email: emil@pagelime.com
|
102
|
+
executables: []
|
103
|
+
extensions: []
|
104
|
+
extra_rdoc_files:
|
105
|
+
- LICENSE.txt
|
106
|
+
- README.md
|
107
|
+
files:
|
108
|
+
- .document
|
109
|
+
- Gemfile
|
110
|
+
- Gemfile.lock
|
111
|
+
- LICENSE.txt
|
112
|
+
- README.md
|
113
|
+
- Rakefile
|
114
|
+
- VERSION
|
115
|
+
- lib/pagelime-rack.rb
|
116
|
+
- lib/pagelime.rb
|
117
|
+
- lib/pagelime/configuration.rb
|
118
|
+
- lib/pagelime/s3_client.rb
|
119
|
+
- lib/pagelime/xml_processor.rb
|
120
|
+
- lib/rack/pagelime.rb
|
121
|
+
- pagelime-rack.gemspec
|
122
|
+
- test/helper.rb
|
123
|
+
- test/test_pagelime-rack.rb
|
124
|
+
homepage: http://github.com/eanticev/pagelime-rack
|
125
|
+
licenses:
|
126
|
+
- MIT
|
127
|
+
metadata: {}
|
128
|
+
post_install_message:
|
129
|
+
rdoc_options: []
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ! '>='
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
requirements: []
|
143
|
+
rubyforge_project:
|
144
|
+
rubygems_version: 2.0.7
|
145
|
+
signing_key:
|
146
|
+
specification_version: 4
|
147
|
+
summary: Rack Middleware for integrating Pagelime into ruby frameworks
|
148
|
+
test_files: []
|