rails_bridge 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -0
- data/Gemfile +21 -0
- data/Gemfile.lock +154 -0
- data/LICENSE +13 -0
- data/README.rdoc +244 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/app/controllers/rails_bridge/layout_bridge_controller.rb +43 -0
- data/app/views/content.html.erb +13 -0
- data/app/views/rails_bridge/layout_bridge/index.html.erb +6 -0
- data/config/routes.rb +11 -0
- data/lib/generators/content_bridge/USAGE +12 -0
- data/lib/generators/content_bridge/content_bridge_generator.rb +9 -0
- data/lib/generators/content_bridge/templates/content_bridge.rb +47 -0
- data/lib/rails_bridge.rb +16 -0
- data/lib/rails_bridge/content_bridge.rb +137 -0
- data/lib/rails_bridge/content_request.rb +100 -0
- data/lib/rails_bridge/engine.rb +34 -0
- data/rails_bridge.gemspec +186 -0
- data/script/console +2 -0
- data/spec/dummy/.rspec +1 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/rails_bridge/content_bridges/twitter_content_bridge.rb +26 -0
- data/spec/dummy/app/rails_bridge/layout_bridge/layouts/application/content.html.erb +1 -0
- data/spec/dummy/app/rails_bridge/layout_bridge/views/layouts/_partial.html.erb +1 -0
- data/spec/dummy/app/views/layouts/_partial.html.erb +1 -0
- data/spec/dummy/app/views/layouts/alternative.html.erb +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +17 -0
- data/spec/dummy/autotest/discover.rb +2 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +44 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +22 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +26 -0
- data/spec/dummy/config/environments/production.rb +49 -0
- data/spec/dummy/config/environments/test.rb +35 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +2 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/javascripts/application.js +2 -0
- data/spec/dummy/public/javascripts/controls.js +965 -0
- data/spec/dummy/public/javascripts/dragdrop.js +974 -0
- data/spec/dummy/public/javascripts/effects.js +1123 -0
- data/spec/dummy/public/javascripts/prototype.js +6001 -0
- data/spec/dummy/public/javascripts/rails.js +175 -0
- data/spec/dummy/public/stylesheets/.gitkeep +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/spec/spec_helper.rb +33 -0
- data/spec/integration/content_bridge_spec.rb +82 -0
- data/spec/integration/engine_spec.rb +25 -0
- data/spec/requests/layout_bridge_controller_spec.rb +16 -0
- data/spec/spec_helper.rb +62 -0
- data/spec/support/content_bridge_helper.rb +26 -0
- data/spec/support/layout_bridge_helper.rb +2 -0
- data/spec/support/rails_bridge_helper.rb +12 -0
- data/spec/support/test_server_helper.rb +125 -0
- data/spec/unit/content_bridge_spec.rb +59 -0
- data/spec/unit/content_request_spec.rb +84 -0
- data/spec/unit/rails_bridge_spec.rb +11 -0
- metadata +380 -0
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem "activesupport"
|
4
|
+
gem 'typhoeus', '~> 0.2.0'
|
5
|
+
gem 'rails_bridge', :require=>'rails_bridge', :path=>'.'
|
6
|
+
gem 'wdd-ruby-ext', '~> 0.2.3'
|
7
|
+
|
8
|
+
# gem 'ruby-debug19'
|
9
|
+
|
10
|
+
group :test, :development do
|
11
|
+
gem 'rails', '>= 3.0'
|
12
|
+
gem 'jeweler'
|
13
|
+
gem "sqlite3-ruby", :require => "sqlite3"
|
14
|
+
gem "capybara", :git=>'https://github.com/jnicklas/capybara.git', :branch=>'master'
|
15
|
+
gem 'rspec'
|
16
|
+
gem 'rspec-rails'
|
17
|
+
gem 'eventmachine'
|
18
|
+
gem 'dalli'
|
19
|
+
gem 'syntax'
|
20
|
+
gem 'tm_helper', :path=>"/Users/billdoughty/src/capitalthought/tm_helper"
|
21
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
GIT
|
2
|
+
remote: https://github.com/jnicklas/capybara.git
|
3
|
+
revision: af9dd3670419b3e39743e1b15bb271b6aaf4dc15
|
4
|
+
branch: master
|
5
|
+
specs:
|
6
|
+
capybara (0.4.0)
|
7
|
+
celerity (>= 0.7.9)
|
8
|
+
culerity (>= 0.2.4)
|
9
|
+
mime-types (>= 1.16)
|
10
|
+
nokogiri (>= 1.3.3)
|
11
|
+
rack (>= 1.0.0)
|
12
|
+
rack-test (>= 0.5.4)
|
13
|
+
selenium-webdriver (>= 0.0.27)
|
14
|
+
xpath (~> 0.1.2)
|
15
|
+
|
16
|
+
PATH
|
17
|
+
remote: .
|
18
|
+
specs:
|
19
|
+
rails_bridge (0.0.4)
|
20
|
+
activesupport
|
21
|
+
rails_bridge
|
22
|
+
typhoeus (~> 0.2.0)
|
23
|
+
wdd-ruby-ext (~> 0.2.3)
|
24
|
+
|
25
|
+
PATH
|
26
|
+
remote: /Users/billdoughty/src/capitalthought/tm_helper
|
27
|
+
specs:
|
28
|
+
tm_helper (0.0.1)
|
29
|
+
|
30
|
+
GEM
|
31
|
+
remote: http://rubygems.org/
|
32
|
+
specs:
|
33
|
+
abstract (1.0.0)
|
34
|
+
actionmailer (3.0.3)
|
35
|
+
actionpack (= 3.0.3)
|
36
|
+
mail (~> 2.2.9)
|
37
|
+
actionpack (3.0.3)
|
38
|
+
activemodel (= 3.0.3)
|
39
|
+
activesupport (= 3.0.3)
|
40
|
+
builder (~> 2.1.2)
|
41
|
+
erubis (~> 2.6.6)
|
42
|
+
i18n (~> 0.4)
|
43
|
+
rack (~> 1.2.1)
|
44
|
+
rack-mount (~> 0.6.13)
|
45
|
+
rack-test (~> 0.5.6)
|
46
|
+
tzinfo (~> 0.3.23)
|
47
|
+
activemodel (3.0.3)
|
48
|
+
activesupport (= 3.0.3)
|
49
|
+
builder (~> 2.1.2)
|
50
|
+
i18n (~> 0.4)
|
51
|
+
activerecord (3.0.3)
|
52
|
+
activemodel (= 3.0.3)
|
53
|
+
activesupport (= 3.0.3)
|
54
|
+
arel (~> 2.0.2)
|
55
|
+
tzinfo (~> 0.3.23)
|
56
|
+
activeresource (3.0.3)
|
57
|
+
activemodel (= 3.0.3)
|
58
|
+
activesupport (= 3.0.3)
|
59
|
+
activesupport (3.0.3)
|
60
|
+
arel (2.0.6)
|
61
|
+
builder (2.1.2)
|
62
|
+
celerity (0.8.6)
|
63
|
+
childprocess (0.1.6)
|
64
|
+
ffi (~> 0.6.3)
|
65
|
+
culerity (0.2.13)
|
66
|
+
dalli (1.0.0)
|
67
|
+
diff-lcs (1.1.2)
|
68
|
+
erubis (2.6.6)
|
69
|
+
abstract (>= 1.0.0)
|
70
|
+
eventmachine (0.12.10)
|
71
|
+
ffi (0.6.3)
|
72
|
+
rake (>= 0.8.7)
|
73
|
+
git (1.2.5)
|
74
|
+
i18n (0.5.0)
|
75
|
+
jeweler (1.5.2)
|
76
|
+
bundler (~> 1.0.0)
|
77
|
+
git (>= 1.2.5)
|
78
|
+
rake
|
79
|
+
json_pure (1.4.6)
|
80
|
+
mail (2.2.13)
|
81
|
+
activesupport (>= 2.3.6)
|
82
|
+
i18n (>= 0.4.0)
|
83
|
+
mime-types (~> 1.16)
|
84
|
+
treetop (~> 1.4.8)
|
85
|
+
mime-types (1.16)
|
86
|
+
nokogiri (1.4.4)
|
87
|
+
polyglot (0.3.1)
|
88
|
+
rack (1.2.1)
|
89
|
+
rack-mount (0.6.13)
|
90
|
+
rack (>= 1.0.0)
|
91
|
+
rack-test (0.5.6)
|
92
|
+
rack (>= 1.0)
|
93
|
+
rails (3.0.3)
|
94
|
+
actionmailer (= 3.0.3)
|
95
|
+
actionpack (= 3.0.3)
|
96
|
+
activerecord (= 3.0.3)
|
97
|
+
activeresource (= 3.0.3)
|
98
|
+
activesupport (= 3.0.3)
|
99
|
+
bundler (~> 1.0)
|
100
|
+
railties (= 3.0.3)
|
101
|
+
railties (3.0.3)
|
102
|
+
actionpack (= 3.0.3)
|
103
|
+
activesupport (= 3.0.3)
|
104
|
+
rake (>= 0.8.7)
|
105
|
+
thor (~> 0.14.4)
|
106
|
+
rake (0.8.7)
|
107
|
+
rspec (2.3.0)
|
108
|
+
rspec-core (~> 2.3.0)
|
109
|
+
rspec-expectations (~> 2.3.0)
|
110
|
+
rspec-mocks (~> 2.3.0)
|
111
|
+
rspec-core (2.3.1)
|
112
|
+
rspec-expectations (2.3.0)
|
113
|
+
diff-lcs (~> 1.1.2)
|
114
|
+
rspec-mocks (2.3.0)
|
115
|
+
rspec-rails (2.3.1)
|
116
|
+
actionpack (~> 3.0)
|
117
|
+
activesupport (~> 3.0)
|
118
|
+
railties (~> 3.0)
|
119
|
+
rspec (~> 2.3.0)
|
120
|
+
rubyzip (0.9.4)
|
121
|
+
selenium-webdriver (0.1.2)
|
122
|
+
childprocess (~> 0.1.5)
|
123
|
+
ffi (~> 0.6.3)
|
124
|
+
json_pure
|
125
|
+
rubyzip
|
126
|
+
sqlite3-ruby (1.3.2)
|
127
|
+
syntax (1.0.0)
|
128
|
+
thor (0.14.6)
|
129
|
+
treetop (1.4.9)
|
130
|
+
polyglot (>= 0.3.1)
|
131
|
+
typhoeus (0.2.0)
|
132
|
+
tzinfo (0.3.23)
|
133
|
+
wdd-ruby-ext (0.2.3)
|
134
|
+
xpath (0.1.2)
|
135
|
+
nokogiri (~> 1.3)
|
136
|
+
|
137
|
+
PLATFORMS
|
138
|
+
ruby
|
139
|
+
|
140
|
+
DEPENDENCIES
|
141
|
+
activesupport
|
142
|
+
capybara!
|
143
|
+
dalli
|
144
|
+
eventmachine
|
145
|
+
jeweler
|
146
|
+
rails (>= 3.0)
|
147
|
+
rails_bridge!
|
148
|
+
rspec
|
149
|
+
rspec-rails
|
150
|
+
sqlite3-ruby
|
151
|
+
syntax
|
152
|
+
tm_helper!
|
153
|
+
typhoeus (~> 0.2.0)
|
154
|
+
wdd-ruby-ext (~> 0.2.3)
|
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright 2010 Capital Thought, LLC
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use any part of this software or its source code except
|
5
|
+
in compliance with the License. You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.rdoc
ADDED
@@ -0,0 +1,244 @@
|
|
1
|
+
= RailsBridge
|
2
|
+
|
3
|
+
* http://github.com/capitalthought/rails_bridge
|
4
|
+
|
5
|
+
== DESCRIPTION
|
6
|
+
|
7
|
+
Easy embedding of remote content into your Rails app, plus exporting of your Rails layouts templatized for other languages (such as PHP).
|
8
|
+
|
9
|
+
== SYNOPSIS
|
10
|
+
|
11
|
+
RailsBridge has two components.
|
12
|
+
|
13
|
+
=== RailsBridge::ContentBridge
|
14
|
+
Allows for easy embedding of content from a remote server directly into the HTML, XML, or Javascript returned by your Rails application. The remote server may be an external application, a web service, or any other resource available via HTTP on the network.
|
15
|
+
=== RailsBridge::LayoutBridge
|
16
|
+
Allows easy exporting of your Rails HTML layouts as templates for other applications.
|
17
|
+
---
|
18
|
+
== INSTALLATION
|
19
|
+
|
20
|
+
rails_bridge is installed as a Ruby gem.
|
21
|
+
|
22
|
+
gem install rails_bridge
|
23
|
+
|
24
|
+
Include the gem in your Gemfile.
|
25
|
+
|
26
|
+
gem 'rails_bridge'
|
27
|
+
|
28
|
+
---
|
29
|
+
|
30
|
+
== CONTENT BRIDGE
|
31
|
+
|
32
|
+
The content bridge is used to retrieve and cache content from external HTTP servers. This is achieved by defining and executing content requests. Requests are defined using the RailsBridge::ContentBridge class.
|
33
|
+
|
34
|
+
=== Up and Running in 5 minutes
|
35
|
+
|
36
|
+
* Install the gem in your Rails app.
|
37
|
+
* Generate a content bridge using the provided Rails generator
|
38
|
+
rails g content_bridge twitter_status_cacher
|
39
|
+
|
40
|
+
* Edit the generated class file (app/rails_bridge/content_bridges/twitter_status_cacher.rb). The following shows an example.
|
41
|
+
|
42
|
+
require 'json'
|
43
|
+
|
44
|
+
class TwitterStatusCacher < RailsBridge::ContentBridge
|
45
|
+
self.request_timeout = 1000 # miliseconds
|
46
|
+
self.cache_timeout = 60 # seconds
|
47
|
+
self.host = 'api.twitter.com'
|
48
|
+
self.path = '/statuses/user_timeline.json'
|
49
|
+
self.default_content = '<<Twitter unavailable>>'
|
50
|
+
self.on_success {|content| JSON.parse(content).first["text"]}
|
51
|
+
end
|
52
|
+
|
53
|
+
* In your controller:
|
54
|
+
@soopa_latest_tweet = TwitterStatusCacher.get_remote_content(:params=>{:screen_name => 'soopa'})
|
55
|
+
|
56
|
+
That's it! If the request time's out before 1 second, "<<Twitter unavailable>>" will be returned instead.
|
57
|
+
If the request succeeds, the content will be cached locally for 60 seconds and returned for each
|
58
|
+
subsequent call to
|
59
|
+
TwitterStatusCacher.get_remote_content(:params=>{:screen_name => 'soopa'})
|
60
|
+
|
61
|
+
There are other more flexible ways to define reusable content requests. Read on for more details.
|
62
|
+
|
63
|
+
=== Defining reusable requests
|
64
|
+
|
65
|
+
Reusable requests can be defined on the ContentBridge class:
|
66
|
+
|
67
|
+
RailsBridge::ContentBridge.content_request( :server_com ) do |request|
|
68
|
+
request.protocol = 'http' # can be 'http' or 'https'. 'http' is the default
|
69
|
+
request.host = "server.com"
|
70
|
+
request.port = 8080 # default is 80
|
71
|
+
request.path = "/some/path"
|
72
|
+
request.params = {:param1=>'a value', :param2=>'another value'} # URL query params
|
73
|
+
request.default_content = "Content unavailable at this time."
|
74
|
+
request.request_timeout = 1000 # miliseconds
|
75
|
+
request.cache_timeout = 5000 # seconds
|
76
|
+
end
|
77
|
+
|
78
|
+
These requests can then be executed using the automatically generated class method:
|
79
|
+
|
80
|
+
content = RailsBridge::ContentBridge.get_server_com
|
81
|
+
|
82
|
+
This issues an HTTP GET to "http://server.com:8080/some/path?param1=a%20value¶m2=another%20value" and returns the content. If the server is unavailable or returns an error, or if the request times out, the default content is returned instead.
|
83
|
+
|
84
|
+
You can also simply use the url method to define the +protocol+, +host+, +port+, +path+, and +params+ values of a request. The following declaration is equivalent to the definition above.
|
85
|
+
|
86
|
+
RailsBridge::ContentBridge.content_request( :server_com ) do |request|
|
87
|
+
request.url = "http://server.com:8080/some/path?p1=value"
|
88
|
+
request.default_content = "Content unavailable at this time."
|
89
|
+
request.request_timeout = 1000 # miliseconds
|
90
|
+
request.cache_timeout = 5000 # seconds
|
91
|
+
end
|
92
|
+
|
93
|
+
=== Pre-processing returned content
|
94
|
+
|
95
|
+
You may pre-process the content returned by a request by defining an +on_success+ block. The remote content is passed as a parameter and the return value of the block is used in place of the original content.
|
96
|
+
|
97
|
+
RailsBridge::ContentBridge.content_request( :server_com ) do |request|
|
98
|
+
request.url = "http://server.com:8080/some/path"
|
99
|
+
request.params = {:param1=>'a value', :param2=>'another value'}
|
100
|
+
request.default_content = "Content unavailable at this time."
|
101
|
+
request.request_timeout = 1000 # miliseconds
|
102
|
+
request.on_success {|content| JSON.parse(content)}
|
103
|
+
end
|
104
|
+
|
105
|
+
=== Caching
|
106
|
+
|
107
|
+
Content is automatically cached if a cache timeout is defined for the request.
|
108
|
+
|
109
|
+
RailsBridge::ContentBridge.content_request( :server_com ) do |request|
|
110
|
+
request.url = "http://server.com:8080/some/path"
|
111
|
+
request.params = {:param1=>'a value', :param2=>'another value'}
|
112
|
+
request.default_content = "Content unavailable at this time."
|
113
|
+
request.request_timeout = 1000 # miliseconds
|
114
|
+
request.cache_timeout = 3600 # seconds
|
115
|
+
end
|
116
|
+
|
117
|
+
content = RailsBridge::ContentBridge.get_server_com
|
118
|
+
|
119
|
+
The content returned from first request will be cached for 3600 seconds. Subsequent requests issued during that time will return the cached content.
|
120
|
+
|
121
|
+
To explicitly skip the cache, override the cache_timeout with a value of 0. This will also remove any entry in the cache for this request.
|
122
|
+
|
123
|
+
content = RailsBridge::ContentBridge.get_server_com( :cache_timeout=>0 )
|
124
|
+
|
125
|
+
The cache key is derived from the complete URL of the request, including query params, so each request with a unique URL is cached independently.
|
126
|
+
|
127
|
+
When RailsBridge is loaded in a Rails application, the configured Rails cache is used by default. When loaded outside Rails, ActiveSupport::Cache::MemoryStore is used by default.
|
128
|
+
|
129
|
+
=== One-line requests
|
130
|
+
|
131
|
+
If desired, all of the above functionality can be achieved in one line:
|
132
|
+
|
133
|
+
content = RailsBridge::ContentBridge.get_remote_content("http://server.com:8080/some/path?param1=a%20value¶m2=another%20value", {:cache_timeout=>3600, :default_content=>"Content Unavailable", :request_timeout=>1000} )
|
134
|
+
|
135
|
+
=== Setting defaults for a group of requests.
|
136
|
+
|
137
|
+
Default values can be set for a group of requests by sub-classing RailsBridge::ContentBridge and defining them on the class:
|
138
|
+
|
139
|
+
class TwitterStatusCacher < RailsBridge::ContentBridge
|
140
|
+
self.request_timeout = 500 # miliseconds
|
141
|
+
self.cache_timeout = 60 # seconds
|
142
|
+
self.host = 'api.twitter.com'
|
143
|
+
self.path = '/statuses/user_timeline.json'
|
144
|
+
self.on_success {|content| JSON.parse(content)}
|
145
|
+
|
146
|
+
content_request( :hoonpark ) {|r| r.params = {:screen_name => 'hoonpark'}}
|
147
|
+
content_request( :soopa ) {|r| r.params = {:screen_name => 'soopa'}}
|
148
|
+
end
|
149
|
+
|
150
|
+
soopa_latest_tweet = TwitterStatusCacher.get_soopa.first
|
151
|
+
hoonpark_latest_tweet = TwitterStatusCacher.get_hoonpark.first
|
152
|
+
|
153
|
+
=== Setting global defaults
|
154
|
+
|
155
|
+
Global default values can be set directly on the RailsBridge::ContentBridge class. They are used by all inheriting sub-classes unless overridden by the sub-class.
|
156
|
+
|
157
|
+
RailsBridge::ContentBridge.logger = Logger.new(STDOUT)
|
158
|
+
RailsBridge::ContentBridge.cache = ActiveSupport::Cache::MemCacheStore(:compress => true)
|
159
|
+
RailsBridge::ContentBridge.cache_timeout = 5.minutes
|
160
|
+
RailsBridge::ContentBridge.request_timeout = 500 # miliseconds
|
161
|
+
|
162
|
+
I recommend putting these declaration in an initializer file under config/initializers. For example config/initializers/content_bridge.rb.
|
163
|
+
|
164
|
+
=== Overriding request values on execution
|
165
|
+
|
166
|
+
All defined values for a request can be overridden at runtime by passing them in as options to the get method:
|
167
|
+
|
168
|
+
content = RailsBridge::ContentBridge.get_server_com( :params=>{:p1=>'p1'}, :request_timeout=>2000, :cache_timeout=>0 )
|
169
|
+
|
170
|
+
=== Using the provided Rails generator to create ContentBridge classes.
|
171
|
+
|
172
|
+
A generator is included named 'content_bridge' that automates generation of content bridge classes in your application.
|
173
|
+
|
174
|
+
eg.
|
175
|
+
rails g content_bridge my_content_bridge my_request
|
176
|
+
|
177
|
+
will create a class named +MyContentBridge+ containing a prototype request definition named +my_request+ and place it under _app/rails_bridge/content_bridges.
|
178
|
+
|
179
|
+
=== Loading your content bridge classes
|
180
|
+
|
181
|
+
All classes under app/rails_bridge/content_bridges will be loaded automatically during application initialization and reloaded when in running in development.
|
182
|
+
|
183
|
+
---
|
184
|
+
|
185
|
+
== LAYOUT BRIDGE
|
186
|
+
|
187
|
+
The layout bridge lets you export your Rails application layouts templatized for other languages. A controller is automatically included in your app when the 'rails_bridge' gem is installed. You can access it at:
|
188
|
+
|
189
|
+
http://app_hostname/rails_bridge/layouts
|
190
|
+
|
191
|
+
This will show you all of your applications available layouts. To view a layout without content, click the link of one of the layouts. You will see the entire HTML layout with no content. To insert templating content, implement a view for that layout as app/rails_bridge/layouts/<layout_name>/content.html.erb.
|
192
|
+
|
193
|
+
In that view, define content for your content_for's and provide the template code to be yielded to the main content area of your layout.
|
194
|
+
|
195
|
+
Also, any partials that exist under app/rails_bridge/views will take precedence over those in your normal views directory. Take advantage of this to override content for layout partials when rendering your templatized layout.
|
196
|
+
|
197
|
+
---
|
198
|
+
|
199
|
+
== TODO
|
200
|
+
|
201
|
+
* Create a ContentBridge class method to purge the cache.
|
202
|
+
* Put the pre-processor block after the cache get so it can assign to variables on each execution.
|
203
|
+
* Create a Rake task to export LayoutBridge layouts from the command line.
|
204
|
+
* Add test to verify partial precedence and content precedence for layout bridge.
|
205
|
+
|
206
|
+
== DEVELOPMENT
|
207
|
+
|
208
|
+
RailsBridge was developed and tested using Ruby v1.9.2 and Rails v3.0.3. It uses the Typhoeus gem to handle all HTTP requests.
|
209
|
+
|
210
|
+
You may download the source from Github at http://github.com/capitalthought/rails_bridge.
|
211
|
+
|
212
|
+
You can start an IRB session with the RailsBridge code loaded and initialized by running:
|
213
|
+
|
214
|
+
script/console
|
215
|
+
|
216
|
+
|
217
|
+
=== TESTS
|
218
|
+
|
219
|
+
RSpec 2.x is used for the Rails Bridge test suite. To run the suite:
|
220
|
+
|
221
|
+
rake
|
222
|
+
|
223
|
+
or
|
224
|
+
rake spec
|
225
|
+
|
226
|
+
NOTE: The test suite has an additional dependency on the eventmachine gem to to implement the test HTTP server.
|
227
|
+
|
228
|
+
---
|
229
|
+
|
230
|
+
== LICENSE
|
231
|
+
|
232
|
+
Copyright 2010 Capital Thought, LLC
|
233
|
+
|
234
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
235
|
+
you may not use any part of this software or its source code except
|
236
|
+
in compliance with the License. You may obtain a copy of the License at
|
237
|
+
|
238
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
239
|
+
|
240
|
+
Unless required by applicable law or agreed to in writing, software
|
241
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
242
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
243
|
+
See the License for the specific language governing permissions and
|
244
|
+
limitations under the License.
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
begin
|
10
|
+
require 'jeweler'
|
11
|
+
Jeweler::Tasks.new do |gem|
|
12
|
+
gem.name = "rails_bridge"
|
13
|
+
gem.summary = %Q{Bridges Rails with an external application.}
|
14
|
+
gem.description = %Q{Allows for easy embedding of content from a remote HTTP server and exporting of the Rails HTML layout into another template.}
|
15
|
+
gem.email = "billdoughty@capitalthought.com"
|
16
|
+
gem.homepage = "http://github.com/capitalthought/rails_bridge"
|
17
|
+
gem.authors = ["shock"]
|
18
|
+
gem.add_development_dependency "typhoeus", "~> 0.2.0"
|
19
|
+
gem.add_development_dependency "activesupport", ">= 2.3.8"
|
20
|
+
end
|
21
|
+
Jeweler::GemcutterTasks.new
|
22
|
+
rescue LoadError
|
23
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
24
|
+
end
|
25
|
+
|
26
|
+
require 'rake'
|
27
|
+
require 'rake/rdoctask'
|
28
|
+
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
|
31
|
+
RSpec::Core::RakeTask.new( :spec ) do |t|
|
32
|
+
t.pattern = Dir.glob('spec/**/*_spec.rb')
|
33
|
+
t.rspec_opts = '--format progress'
|
34
|
+
# t.rcov = true
|
35
|
+
end
|
36
|
+
|
37
|
+
task :default => :spec
|
38
|
+
|
39
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
40
|
+
rdoc.rdoc_dir = 'rdoc'
|
41
|
+
rdoc.title = 'RailsBridge'
|
42
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
43
|
+
rdoc.rdoc_files.include('README.rdoc')
|
44
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
+
end
|
46
|
+
|