cobranding 1.2.3 → 1.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.
- checksums.yaml +4 -4
- data/.gitignore +5 -6
- data/Appraisals +20 -0
- data/README.rdoc +6 -2
- data/Rakefile +20 -0
- data/cobranding.gemspec +6 -5
- data/gemfiles/rails_3.2.gemfile +7 -0
- data/gemfiles/rails_4.0.gemfile +7 -0
- data/gemfiles/rails_4.1.gemfile +7 -0
- data/gemfiles/rails_4.2.gemfile +7 -0
- data/lib/cobranding/layout.rb +6 -1
- data/lib/cobranding/version.rb +1 -1
- data/spec/helper_spec.rb +1 -1
- data/spec/layout_spec.rb +11 -3
- data/spec/spec_helper.rb +1 -4
- metadata +37 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f291bfa3856e3e76f1fc6ab2618ae4400f3f271
|
4
|
+
data.tar.gz: c28bdccd62fa0b946537c065ac920f42fd3006ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1f27079073f1fecd0aad1c542eb61ec1623c3a5920ba5c61b3ae4df4a208a5223a84f190847182a9a5f463d635a010432e13765a148abdc332f4b209d1da1e9
|
7
|
+
data.tar.gz: ac4ccf60123df1aedbff68697f9bc330f9657bd90451a3c4792c20227eeb1096d1da3b4b4f294f2b66eadccb2c3f9a6ed7fa991c93cdf12831aa8321a87913aa
|
data/.gitignore
CHANGED
data/Appraisals
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# Install gems for all appraisal definitions:
|
2
|
+
#
|
3
|
+
# $ appraisal install
|
4
|
+
#
|
5
|
+
# To run tests on different versions:
|
6
|
+
#
|
7
|
+
# $ appraisal activerecord_x.x rspec spec
|
8
|
+
|
9
|
+
[
|
10
|
+
[ '3.2', '~> 3.2.0' ],
|
11
|
+
[ '4.0', '~> 4.0.0' ],
|
12
|
+
[ '4.1', '~> 4.1.0' ],
|
13
|
+
[ '4.2', '~> 4.2.0' ],
|
14
|
+
].each do |ver_name, ver_req|
|
15
|
+
# Note: for the rake task to work, these definition names must be the same as the corresponding
|
16
|
+
# filename produced in "gemfiles/", i.e. all characters must be in this set: [A-Za-z0-9_.]
|
17
|
+
appraise "rails_#{ver_name}" do
|
18
|
+
gem 'actionpack', ver_req
|
19
|
+
end
|
20
|
+
end
|
data/README.rdoc
CHANGED
@@ -4,11 +4,11 @@ This gem allows you too pull marked up HTML from a URL and use it as a layout in
|
|
4
4
|
|
5
5
|
== Fetching the layout
|
6
6
|
|
7
|
-
To fetch the layout from a service, you can
|
7
|
+
To fetch the layout from a service, you can call
|
8
8
|
|
9
9
|
Cobranding::Layout.get(url, options)
|
10
10
|
|
11
|
-
Where +url+ and +options+ are values passed to +
|
11
|
+
Where +url+ and +options+ are values passed to +RestClient+. Additional options available are
|
12
12
|
|
13
13
|
* base_url: set the base url for expanding any relative URLs in the markup
|
14
14
|
* method: set to :post to perform a POST instead of a GET request
|
@@ -67,3 +67,7 @@ If the tag includes a block, it will only be called if there was an error evalua
|
|
67
67
|
== Persisting
|
68
68
|
|
69
69
|
If you have layouts that don't need to be real time, you can persist them to a data store and update them asynchronously via a background job. You simply need to include Cobranding::PersistentLayout in your model. To render the layout, you can then pass in model.layout to the cobranding_layout helper instead of a URL.
|
70
|
+
|
71
|
+
== Limitations
|
72
|
+
|
73
|
+
The result of Cobranding::Helper#cobranding_layout (or Cobranding::Layout#evaluate) will be a string with UTF-8 encoding, regardless of the encoding reported by the server. If you need the result to be a different encoding, you can call force_encoding on the result.
|
data/Rakefile
CHANGED
@@ -1 +1,21 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
# Note: if you get this error: "Bundler could not find compatible versions for gem ..."
|
6
|
+
# try deleting Gemfile.lock (usually happens when switching branches).
|
7
|
+
|
8
|
+
task default: :appraise_all
|
9
|
+
|
10
|
+
task :appraise_all do
|
11
|
+
success_map = {}
|
12
|
+
Pathname.glob('gemfiles/*.gemfile').each do |f|
|
13
|
+
appraise_def = f.basename('.gemfile').to_s
|
14
|
+
success = system('appraisal', appraise_def, 'rspec', 'spec')
|
15
|
+
success_map[appraise_def] = success
|
16
|
+
end
|
17
|
+
puts "\n===== Test Summary ====="
|
18
|
+
success_map.each do |appraise_def, success|
|
19
|
+
puts "#{appraise_def}: #{success ? 'no failures (but check pending)' : 'failed'}"
|
20
|
+
end
|
21
|
+
end
|
data/cobranding.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'cobranding/version'
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'cobranding'
|
7
|
-
spec.version = Cobranding::VERSION
|
7
|
+
spec.version = Cobranding::VERSION.dup # dup for 1.9's rubygems
|
8
8
|
spec.authors = ['Brian Durand', 'Milan Dobrota']
|
9
9
|
spec.email = ['mdobrota@tribpub.com']
|
10
10
|
spec.summary = 'Provides Rails view layouts from an HTTP service'
|
@@ -16,11 +16,12 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
17
|
spec.require_paths = ['lib']
|
18
18
|
|
19
|
-
spec.add_runtime_dependency 'actionpack', '>= 3.
|
20
|
-
spec.add_runtime_dependency 'rest-client', '
|
19
|
+
spec.add_runtime_dependency 'actionpack', '>= 3.2', '< 4.3'
|
20
|
+
spec.add_runtime_dependency 'rest-client', '~> 1.6'
|
21
21
|
|
22
|
-
spec.add_development_dependency 'rspec', '~> 2.
|
23
|
-
spec.add_development_dependency 'webmock', '~> 1.
|
22
|
+
spec.add_development_dependency 'rspec', '~> 2.99'
|
23
|
+
spec.add_development_dependency 'webmock', '~> 1.21.0'
|
24
24
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
25
25
|
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
+
spec.add_development_dependency 'appraisal'
|
26
27
|
end
|
data/lib/cobranding/layout.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# NOTE this file should be in utf-8 encoding so #evaluate generates a string with
|
3
|
+
# this encoding. Otherwise on ruby 1.9 it'll be US-ASCII.
|
1
4
|
require 'erb'
|
2
5
|
require 'digest/md5'
|
3
6
|
require 'rest-client'
|
@@ -10,7 +13,7 @@ module Cobranding
|
|
10
13
|
UNQUOTED_RELATIVE_URL = /(<\w+\s((src)|(href))=)\/(.*?)(>|(\s[^>]*?>))/i
|
11
14
|
|
12
15
|
class << self
|
13
|
-
# Get the layout HTML from a service. The options can be any of the options accepted by
|
16
|
+
# Get the layout HTML from a service. The options can be any of the options accepted by RestClient
|
14
17
|
# or +:base_url+. Any relative URLs found in the HTML will be expanded to absolute URLs using either the
|
15
18
|
# +:base_url+ option or the +url+ as the base.
|
16
19
|
#
|
@@ -172,6 +175,8 @@ module Cobranding
|
|
172
175
|
suffix = options[:suffix] if options
|
173
176
|
suffix = "_for_cobranding" unless prefix or suffix
|
174
177
|
evaluator = Object.new
|
178
|
+
# "src" is erb code, which contains the code `force_encoding(__ENCODING__)`.
|
179
|
+
# __ENCODING__ is the current file's encoding (see magic comment above).
|
175
180
|
eval <<-EOS
|
176
181
|
def evaluator.evaluate
|
177
182
|
#{src}
|
data/lib/cobranding/version.rb
CHANGED
data/spec/helper_spec.rb
CHANGED
data/spec/layout_spec.rb
CHANGED
@@ -9,7 +9,7 @@ describe Cobranding::Layout do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
cache = ActiveSupport::Cache::MemoryStore.new
|
12
|
-
Rails.stub
|
12
|
+
Rails.stub(:cache).and_return(cache)
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should be able to evaluate a template from HTML" do
|
@@ -84,14 +84,14 @@ describe Cobranding::Layout do
|
|
84
84
|
end
|
85
85
|
|
86
86
|
it "should be able to get a layout from a URL with a POST" do
|
87
|
-
stub_request(:post, "localhost/layout").with(:
|
87
|
+
stub_request(:post, "localhost/layout").with(:body => {"site" => "1"}, :headers => {'Content-Type'=>'application/x-www-form-urlencoded'}).to_return(:status => [200, "Success"], :body => "<html>{{test_tag}}</html>")
|
88
88
|
layout = Cobranding::Layout.get("http://localhost/layout", :method => :post, :site => 1)
|
89
89
|
layout.evaluate(@context).should == "<html>Woo woo</html>"
|
90
90
|
end
|
91
91
|
|
92
92
|
it "should be able to get a layout from a URL without caching" do
|
93
93
|
stub_request(:get, "localhost/layout?site=1").to_return(:status => [200, "Success"], :body => "<html>{{test_tag}}</html>")
|
94
|
-
Rails.stub
|
94
|
+
Rails.stub(:cache).and_return(nil)
|
95
95
|
layout = Cobranding::Layout.get("http://localhost/layout", :params => {:site => 1})
|
96
96
|
layout.evaluate(@context).should == "<html>Woo woo</html>"
|
97
97
|
end
|
@@ -148,4 +148,12 @@ describe Cobranding::Layout do
|
|
148
148
|
end
|
149
149
|
layout.evaluate(@context).should == "this is Woo woo stuff"
|
150
150
|
end
|
151
|
+
|
152
|
+
it "returns a UTF-8 encoded string" do
|
153
|
+
layout = Cobranding::Layout.new("<html>Test</html>")
|
154
|
+
expect(layout.evaluate(@context).encoding.name).to eq 'UTF-8'
|
155
|
+
unless Gem::Requirement.new('~> 1.9.1').satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
|
156
|
+
warn "Please also run this test on ruby 1.9 (#{File.basename(__FILE__)}:#{__LINE__})."
|
157
|
+
end
|
158
|
+
end
|
151
159
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cobranding
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Durand
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-05-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
@@ -17,56 +17,62 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 3.
|
20
|
+
version: '3.2'
|
21
|
+
- - "<"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '4.3'
|
21
24
|
type: :runtime
|
22
25
|
prerelease: false
|
23
26
|
version_requirements: !ruby/object:Gem::Requirement
|
24
27
|
requirements:
|
25
28
|
- - ">="
|
26
29
|
- !ruby/object:Gem::Version
|
27
|
-
version: 3.
|
30
|
+
version: '3.2'
|
31
|
+
- - "<"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.3'
|
28
34
|
- !ruby/object:Gem::Dependency
|
29
35
|
name: rest-client
|
30
36
|
requirement: !ruby/object:Gem::Requirement
|
31
37
|
requirements:
|
32
|
-
- - "
|
38
|
+
- - "~>"
|
33
39
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
40
|
+
version: '1.6'
|
35
41
|
type: :runtime
|
36
42
|
prerelease: false
|
37
43
|
version_requirements: !ruby/object:Gem::Requirement
|
38
44
|
requirements:
|
39
|
-
- - "
|
45
|
+
- - "~>"
|
40
46
|
- !ruby/object:Gem::Version
|
41
|
-
version: '
|
47
|
+
version: '1.6'
|
42
48
|
- !ruby/object:Gem::Dependency
|
43
49
|
name: rspec
|
44
50
|
requirement: !ruby/object:Gem::Requirement
|
45
51
|
requirements:
|
46
52
|
- - "~>"
|
47
53
|
- !ruby/object:Gem::Version
|
48
|
-
version: 2.
|
54
|
+
version: '2.99'
|
49
55
|
type: :development
|
50
56
|
prerelease: false
|
51
57
|
version_requirements: !ruby/object:Gem::Requirement
|
52
58
|
requirements:
|
53
59
|
- - "~>"
|
54
60
|
- !ruby/object:Gem::Version
|
55
|
-
version: 2.
|
61
|
+
version: '2.99'
|
56
62
|
- !ruby/object:Gem::Dependency
|
57
63
|
name: webmock
|
58
64
|
requirement: !ruby/object:Gem::Requirement
|
59
65
|
requirements:
|
60
66
|
- - "~>"
|
61
67
|
- !ruby/object:Gem::Version
|
62
|
-
version: 1.
|
68
|
+
version: 1.21.0
|
63
69
|
type: :development
|
64
70
|
prerelease: false
|
65
71
|
version_requirements: !ruby/object:Gem::Requirement
|
66
72
|
requirements:
|
67
73
|
- - "~>"
|
68
74
|
- !ruby/object:Gem::Version
|
69
|
-
version: 1.
|
75
|
+
version: 1.21.0
|
70
76
|
- !ruby/object:Gem::Dependency
|
71
77
|
name: bundler
|
72
78
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,6 +101,20 @@ dependencies:
|
|
95
101
|
- - "~>"
|
96
102
|
- !ruby/object:Gem::Version
|
97
103
|
version: '10.0'
|
104
|
+
- !ruby/object:Gem::Dependency
|
105
|
+
name: appraisal
|
106
|
+
requirement: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
type: :development
|
112
|
+
prerelease: false
|
113
|
+
version_requirements: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
98
118
|
description: Provides Rails view layouts from an HTTP service.
|
99
119
|
email:
|
100
120
|
- mdobrota@tribpub.com
|
@@ -103,11 +123,16 @@ extensions: []
|
|
103
123
|
extra_rdoc_files: []
|
104
124
|
files:
|
105
125
|
- ".gitignore"
|
126
|
+
- Appraisals
|
106
127
|
- Gemfile
|
107
128
|
- License.txt
|
108
129
|
- README.rdoc
|
109
130
|
- Rakefile
|
110
131
|
- cobranding.gemspec
|
132
|
+
- gemfiles/rails_3.2.gemfile
|
133
|
+
- gemfiles/rails_4.0.gemfile
|
134
|
+
- gemfiles/rails_4.1.gemfile
|
135
|
+
- gemfiles/rails_4.2.gemfile
|
111
136
|
- lib/cobranding.rb
|
112
137
|
- lib/cobranding/helper.rb
|
113
138
|
- lib/cobranding/layout.rb
|