title_estuary 1.0.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +46 -1
- data/VERSION +1 -1
- data/lib/title_estuary/high_voltage_support.rb +17 -0
- data/lib/title_estuary.rb +11 -1
- data/tasks/test.task +1 -0
- data/test/high_voltage_integration_test.rb +50 -0
- data/test/test_helper.rb +12 -2
- data/test/vendor/high_voltage/app/controllers/high_voltage/pages_controller.rb +26 -0
- data/test/vendor/high_voltage/config/high_voltage_routes.rb +5 -0
- data/test/vendor/high_voltage/init.rb +2 -0
- data/test/vendor/high_voltage/install.rb +1 -0
- data/test/vendor/high_voltage/lib/high_voltage/extensions/routes.rb +15 -0
- data/test/vendor/high_voltage/lib/high_voltage.rb +5 -0
- data/test/vendor/high_voltage/test/pages_controller_test.rb +44 -0
- data/test/vendor/high_voltage/test/test_helper.rb +14 -0
- data/test/vendor/high_voltage/uninstall.rb +1 -0
- metadata +13 -2
data/README.rdoc
CHANGED
@@ -101,4 +101,49 @@ or from a view:
|
|
101
101
|
# in RAILS_ROOT/app/view/projects/index.html.erb:
|
102
102
|
<% content_for :page_title do %>
|
103
103
|
Some complex page title
|
104
|
-
<% end %>
|
104
|
+
<% end %>
|
105
|
+
|
106
|
+
=== Integration with Inherited Resources
|
107
|
+
|
108
|
+
When included in a controller class that inherits
|
109
|
+
from <tt>InheritedResources::Base</tt>, Title Estuary
|
110
|
+
uses <tt>:resource_class</tt> when building default
|
111
|
+
page names.
|
112
|
+
|
113
|
+
@see TitleEstuary::InheritedResourcesSupport
|
114
|
+
@see http://github.com/josevalim/inherites_resources
|
115
|
+
|
116
|
+
=== Integration with High Voltage
|
117
|
+
|
118
|
+
When included in a controller class that inherits
|
119
|
+
from <tt>HighVoltage::PagesController</tt>,
|
120
|
+
Title Estuary uses the page title as the default title.
|
121
|
+
It also changes the i18n key scheme to
|
122
|
+
"page.title.<controller>.<page_name>" to let you
|
123
|
+
define different titles for each page. For example:
|
124
|
+
|
125
|
+
en:
|
126
|
+
page:
|
127
|
+
title:
|
128
|
+
pages:
|
129
|
+
faq: "Frequently Asked Questions"
|
130
|
+
|
131
|
+
*Nota Bene*: if you include +TitleEstuary+ in
|
132
|
+
your +ApplicationController+, you'll need to
|
133
|
+
re-include it in the +PagesController+. If you're using
|
134
|
+
High Voltage's default controller, you can do so in an
|
135
|
+
initializer:
|
136
|
+
|
137
|
+
# in RAILS_ROOT/config/initializers/page_titles_for_high_voltage:
|
138
|
+
HighVoltage::PagesController.class_eval do
|
139
|
+
include TitleEstuary
|
140
|
+
end
|
141
|
+
|
142
|
+
If, on the other hand, you're defining your own
|
143
|
+
+PagesController+, you can include it there:
|
144
|
+
|
145
|
+
# in RAILS_ROOT/app/controllers/pages_controller.rb:
|
146
|
+
# An example custom PagesController.
|
147
|
+
class PagesController < HighVoltage::PagesController
|
148
|
+
include TitleEstuary
|
149
|
+
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.1
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module TitleEstuary
|
2
|
+
|
3
|
+
module HighVoltageSupport
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
def default_page_title_from_controller_and_action
|
8
|
+
params[:action] == 'show' ? params[:id].titleize : super
|
9
|
+
end
|
10
|
+
|
11
|
+
def page_title_i18n_key
|
12
|
+
"page.title.pages.#{params[:id]}"
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/lib/title_estuary.rb
CHANGED
@@ -6,14 +6,24 @@ module TitleEstuary
|
|
6
6
|
# <tt>#page_title</tt> as an action and makes that
|
7
7
|
# method available to helpers and views; it also
|
8
8
|
# auto-includes TitleEstuary::InheritedResourcesSupport
|
9
|
+
# and TitleEstuary::HighVoltageSupport
|
9
10
|
# if applicable.
|
11
|
+
#
|
12
|
+
# @see http://github.com/josevalim/inherited_resources/
|
13
|
+
# @see http://github.com/thoughtbot/high_voltage
|
10
14
|
def self.included(base)
|
11
15
|
base.send :include, TitleEstuary::InstanceMethods
|
12
16
|
base.hide_action(:page_title) if base.respond_to?(:hide_action)
|
13
17
|
base.helper_method(:page_title, :page_title=) if base.respond_to?(:helper_method)
|
14
|
-
if Object.const_defined?(:InheritedResources) &&
|
18
|
+
if Object.const_defined?(:InheritedResources) &&
|
19
|
+
base <= ::InheritedResources::Base
|
15
20
|
base.send :include, TitleEstuary::InheritedResourcesSupport
|
16
21
|
end
|
22
|
+
if Object.const_defined?(:HighVoltage) &&
|
23
|
+
HighVoltage.const_defined?(:PagesController) &&
|
24
|
+
base <= ::HighVoltage::PagesController
|
25
|
+
base.send :include, TitleEstuary::HighVoltageSupport
|
26
|
+
end
|
17
27
|
end
|
18
28
|
|
19
29
|
module InstanceMethods
|
data/tasks/test.task
CHANGED
@@ -12,6 +12,7 @@ if Object.const_defined?(:LOAD_TITLE_ESTUARY_BUILD_TASKS) && LOAD_TITLE_ESTUARY_
|
|
12
12
|
fl.include "#{TITLE_ESTUARY_PROJECT_ROOT}/test/**/*_test.rb"
|
13
13
|
fl.exclude "#{TITLE_ESTUARY_PROJECT_ROOT}/test/test_helper.rb"
|
14
14
|
fl.exclude "#{TITLE_ESTUARY_PROJECT_ROOT}/test/lib/**/*.rb"
|
15
|
+
fl.exclude "#{TITLE_ESTUARY_PROJECT_ROOT}/test/vendor/**/*.rb"
|
15
16
|
end
|
16
17
|
|
17
18
|
Rake::TestTask.new(:test) do |t|
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class PagesController < HighVoltage::PagesController
|
4
|
+
include TitleEstuary
|
5
|
+
end
|
6
|
+
|
7
|
+
ActionController::Routing::Routes.draw do |map|
|
8
|
+
map.resources :pages, :only => [:show]
|
9
|
+
end
|
10
|
+
|
11
|
+
class HighVoltageIntegrationTest < ActionController::TestCase
|
12
|
+
include PageTitleMacros
|
13
|
+
tests PagesController
|
14
|
+
|
15
|
+
context 'a RESTful controller using both Title Estuary and Inherited Resources' do
|
16
|
+
|
17
|
+
context 'with custom page titles that involve interpolation' do
|
18
|
+
|
19
|
+
setup do
|
20
|
+
clear_translations!
|
21
|
+
end
|
22
|
+
|
23
|
+
should 'have high-voltage support installed' do
|
24
|
+
assert ::PagesController < TitleEstuary::HighVoltageSupport
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'on a GET to :show for a page with no i18n title set' do
|
28
|
+
setup do
|
29
|
+
get :show, :id => 'info'
|
30
|
+
end
|
31
|
+
should 'set the page title to the requested page name, titleized' do
|
32
|
+
assert_page_title_is 'Info'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'on a GET to :show for a page with an i18n title set' do
|
37
|
+
setup do
|
38
|
+
define_translation 'page.title.pages.faq', "FAQ"
|
39
|
+
get :show, :id => 'faq'
|
40
|
+
end
|
41
|
+
should 'use the requested page name as the action in the key' do
|
42
|
+
assert_page_title_is 'FAQ'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -17,10 +17,20 @@ test_dir = File.dirname(__FILE__)
|
|
17
17
|
require 'action_controller/test_case'
|
18
18
|
require 'action_controller/test_process'
|
19
19
|
I18n.reload!
|
20
|
-
ActionController::Base.view_paths = File.join(
|
20
|
+
ActionController::Base.view_paths = File.join(test_dir, 'views')
|
21
21
|
class ApplicationController < ActionController::Base; end
|
22
22
|
|
23
23
|
# load title_estuary:
|
24
24
|
ActiveSupport::Dependencies.load_paths << File.expand_path(File.join(test_dir, '..', 'lib'))
|
25
25
|
require_dependency 'title_estuary'
|
26
|
-
Shoulda.autoload_macros File.join(test_dir, '..')
|
26
|
+
Shoulda.autoload_macros File.join(test_dir, '..')
|
27
|
+
|
28
|
+
# load external libraries vendored for testing:
|
29
|
+
Dir.glob("#{test_dir}/vendor/*/app/*").each do |vendor_rails_app_dir|
|
30
|
+
ActiveSupport::Dependencies.load_paths << vendor_rails_app_dir
|
31
|
+
$LOAD_PATH << vendor_rails_app_dir
|
32
|
+
end
|
33
|
+
Dir.glob("#{test_dir}/vendor/*/lib").each do |vendor_lib_dir|
|
34
|
+
ActiveSupport::Dependencies.load_paths << vendor_lib_dir
|
35
|
+
$LOAD_PATH << vendor_lib_dir
|
36
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class HighVoltage::PagesController < ApplicationController
|
2
|
+
unloadable
|
3
|
+
before_filter :ensure_valid
|
4
|
+
|
5
|
+
def show
|
6
|
+
render :template => current_page
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def ensure_valid
|
12
|
+
unless template_exists?(current_page)
|
13
|
+
render :nothing => true, :status => 404 and return false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def current_page
|
18
|
+
"pages/#{params[:id].to_s.downcase}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def template_exists?(path)
|
22
|
+
view_paths.find_template(path, response.template.template_format)
|
23
|
+
rescue ActionView::MissingTemplate
|
24
|
+
false
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
@@ -0,0 +1,15 @@
|
|
1
|
+
if defined?(ActionController::Routing::RouteSet)
|
2
|
+
class ActionController::Routing::RouteSet
|
3
|
+
def load_routes_with_high_voltage!
|
4
|
+
lib_path = File.dirname(__FILE__)
|
5
|
+
high_voltage_routes = File.join(lib_path, *%w[.. .. .. config high_voltage_routes.rb])
|
6
|
+
unless configuration_files.include?(high_voltage_routes)
|
7
|
+
add_configuration_file(high_voltage_routes)
|
8
|
+
end
|
9
|
+
load_routes_without_high_voltage!
|
10
|
+
end
|
11
|
+
|
12
|
+
alias_method_chain :load_routes!, :high_voltage
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ApplicationController < ActionController::Base
|
4
|
+
end
|
5
|
+
|
6
|
+
require "high_voltage/pages_controller"
|
7
|
+
require File.join(File.dirname(__FILE__), '..', 'config', 'high_voltage_routes')
|
8
|
+
|
9
|
+
class HighVoltage::PagesControllerTest < ActionController::TestCase
|
10
|
+
|
11
|
+
HighVoltage::PagesController.view_paths << "/tmp"
|
12
|
+
|
13
|
+
context "on GET to a page that exists" do
|
14
|
+
setup do
|
15
|
+
@filename = '/tmp/pages/exists.html.erb'
|
16
|
+
|
17
|
+
FileUtils.mkdir(File.dirname(@filename))
|
18
|
+
File.open(@filename, 'w') do |file|
|
19
|
+
file << "hello <%= 'world' %>"
|
20
|
+
end
|
21
|
+
assert File.exists?(@filename)
|
22
|
+
|
23
|
+
get :show, :id => 'exists'
|
24
|
+
end
|
25
|
+
|
26
|
+
should_respond_with :success
|
27
|
+
should_render_template 'exists'
|
28
|
+
|
29
|
+
teardown do
|
30
|
+
begin
|
31
|
+
FileUtils.rm(@filename)
|
32
|
+
FileUtils.rmdir(File.dirname(@filename))
|
33
|
+
rescue StandardError => e
|
34
|
+
puts "Error while removing files: #{e}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "on GET to /pages/invalid" do
|
40
|
+
setup { get :show, :id => "invalid" }
|
41
|
+
should_respond_with :missing
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
ENV['RAILS_ENV'] = 'test'
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'active_support'
|
5
|
+
require 'active_support/test_case'
|
6
|
+
require 'action_controller'
|
7
|
+
require 'test_help'
|
8
|
+
require 'high_voltage'
|
9
|
+
|
10
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'app', 'controllers')
|
11
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'app', 'models')
|
12
|
+
|
13
|
+
require 'shoulda'
|
14
|
+
require 'shoulda/rails'
|
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: title_estuary
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Rosen
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-09-
|
12
|
+
date: 2009-09-03 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -27,6 +27,7 @@ files:
|
|
27
27
|
- Rakefile
|
28
28
|
- VERSION
|
29
29
|
- lib/title_estuary.rb
|
30
|
+
- lib/title_estuary/high_voltage_support.rb
|
30
31
|
- lib/title_estuary/inherited_resources_support.rb
|
31
32
|
- tasks/doc.task
|
32
33
|
- tasks/gem.task
|
@@ -67,10 +68,20 @@ summary: Easy, internationalized page titles
|
|
67
68
|
test_files:
|
68
69
|
- test/default_titles_test.rb
|
69
70
|
- test/dynamic_page_title_test.rb
|
71
|
+
- test/high_voltage_integration_test.rb
|
70
72
|
- test/inherited_resources_integration_test.rb
|
71
73
|
- test/interpolated_page_titles_test.rb
|
72
74
|
- test/rails_integration_test.rb
|
73
75
|
- test/shoulda_macros/page_title_macros.rb
|
74
76
|
- test/simple_custom_titles_test.rb
|
75
77
|
- test/test_helper.rb
|
78
|
+
- test/vendor/high_voltage/app/controllers/high_voltage/pages_controller.rb
|
79
|
+
- test/vendor/high_voltage/config/high_voltage_routes.rb
|
80
|
+
- test/vendor/high_voltage/init.rb
|
81
|
+
- test/vendor/high_voltage/install.rb
|
82
|
+
- test/vendor/high_voltage/lib/high_voltage/extensions/routes.rb
|
83
|
+
- test/vendor/high_voltage/lib/high_voltage.rb
|
84
|
+
- test/vendor/high_voltage/test/pages_controller_test.rb
|
85
|
+
- test/vendor/high_voltage/test/test_helper.rb
|
86
|
+
- test/vendor/high_voltage/uninstall.rb
|
76
87
|
- test/village_model_and_controller.rb
|