simple_pages 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +70 -0
- data/Rakefile +24 -0
- data/lib/simple_pages/version.rb +3 -0
- data/lib/simple_pages.rb +42 -0
- data/spec/controllers/i18n_simple_pages_controller_spec.rb +52 -0
- data/spec/controllers/simple_pages_controller_spec.rb +37 -0
- data/spec/controllers/simple_pages_controller_with_special_characters_spec.rb +35 -0
- data/spec/dummy/Rakefile +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/i18n_simple_pages_controller.rb +3 -0
- data/spec/dummy/app/controllers/simple_pages_controller.rb +11 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/i18n_simple_pages/contact.html.erb +0 -0
- data/spec/dummy/app/views/i18n_simple_pages/not_found.html.erb +0 -0
- data/spec/dummy/app/views/i18n_simple_pages/pt/contato.html.erb +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/simple_pages/not_found.html.erb +0 -0
- data/spec/dummy/app/views/simple_pages/plus.html.erb +1 -0
- data/spec/dummy/app/views/simple_pages/sao_paulo_ribeirao.html.erb +0 -0
- data/spec/dummy/app/views/simple_pages/show.html.erb +1 -0
- data/spec/dummy/app/views/simple_pages/testing.html.erb +0 -0
- data/spec/dummy/app/views/simple_pages/testing_testing.html.erb +0 -0
- data/spec/dummy/config/application.rb +16 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/environment.rb +2 -0
- data/spec/dummy/config/environments/test.rb +17 -0
- data/spec/dummy/config/initializers/secret_token.rb +1 -0
- data/spec/dummy/config/initializers/session_store.rb +1 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +7 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/config.ru +2 -0
- data/spec/dummy/log/test.log +2052 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/spec_helper.rb +24 -0
- metadata +189 -0
data/README.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# Simple Pages
|
2
|
+
|
3
|
+
A dummy plugin made for easy static page maintenance.
|
4
|
+
|
5
|
+
|
6
|
+
## Example
|
7
|
+
|
8
|
+
Include the SimplePages into a PagesController:
|
9
|
+
|
10
|
+
class PagesController
|
11
|
+
include SimplePages
|
12
|
+
end
|
13
|
+
|
14
|
+
Then add into your routes the PagesController route:
|
15
|
+
|
16
|
+
ActionController::Routing::Routes.draw do |map|
|
17
|
+
...
|
18
|
+
map.resources :pages
|
19
|
+
...
|
20
|
+
end
|
21
|
+
|
22
|
+
Now create the folder pages into your views folder and put there the templates you wish to render out. Remember to add a show.html.erb as the default template:
|
23
|
+
|
24
|
+
+ app
|
25
|
+
|- views
|
26
|
+
|- pages
|
27
|
+
|- show.html.erb
|
28
|
+
|- about_us.html.erb
|
29
|
+
|
30
|
+
So you can access the views getting:
|
31
|
+
|
32
|
+
http://localhost:3000/pages/about-us
|
33
|
+
|
34
|
+
## Improving
|
35
|
+
|
36
|
+
Let's say you want to put the PagesController as a default route and get this behavior:
|
37
|
+
|
38
|
+
http://localhost:3000/about-us
|
39
|
+
|
40
|
+
You can get it changing the routes to:
|
41
|
+
|
42
|
+
ActionController::Routing::Routes.draw do |map|
|
43
|
+
...
|
44
|
+
map.connect ':id', :controller => 'show', :action => 'show'
|
45
|
+
end
|
46
|
+
|
47
|
+
## Acknowledgment
|
48
|
+
|
49
|
+
fnando's has_permalink plugin where I got the [permalink method](http://github.com/fnando/has_permalink/blob/master/lib/permalink/string_ext.rb).
|
50
|
+
|
51
|
+
Copyright (c) 2009 [Bruno Azisaka Maciel], released under the MIT license
|
52
|
+
|
53
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
54
|
+
a copy of this software and associated documentation files (the
|
55
|
+
"Software"), to deal in the Software without restriction, including
|
56
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
57
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
58
|
+
permit persons to whom the Software is furnished to do so, subject to
|
59
|
+
the following conditions:
|
60
|
+
|
61
|
+
The above copyright notice and this permission notice shall be
|
62
|
+
included in all copies or substantial portions of the Software.
|
63
|
+
|
64
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
65
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
66
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
67
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
68
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
69
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
70
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
|
8
|
+
Bundler::GemHelper.install_tasks
|
9
|
+
|
10
|
+
begin
|
11
|
+
require 'rdoc/task'
|
12
|
+
rescue LoadError
|
13
|
+
require 'rdoc/rdoc'
|
14
|
+
require 'rake/rdoctask'
|
15
|
+
RDoc::Task = Rake::RDocTask
|
16
|
+
end
|
17
|
+
|
18
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
19
|
+
rdoc.rdoc_dir = 'rdoc'
|
20
|
+
rdoc.title = 'SimplePages'
|
21
|
+
rdoc.options << '--line-numbers'
|
22
|
+
rdoc.rdoc_files.include('README.md')
|
23
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
24
|
+
end
|
data/lib/simple_pages.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
module SimplePages
|
2
|
+
def self.included(base)
|
3
|
+
base.send :include, InstanceMethods
|
4
|
+
end
|
5
|
+
|
6
|
+
module InstanceMethods
|
7
|
+
def show
|
8
|
+
respond_to?(page_action) ? executes_page_action : render_page_template
|
9
|
+
end
|
10
|
+
|
11
|
+
protected
|
12
|
+
def page_action
|
13
|
+
@page_action ||= page_permalink params[:id]
|
14
|
+
end
|
15
|
+
|
16
|
+
def executes_page_action
|
17
|
+
send page_action
|
18
|
+
render page_template_path
|
19
|
+
rescue ActionView::MissingTemplate
|
20
|
+
render 'show'
|
21
|
+
end
|
22
|
+
|
23
|
+
def render_page_template
|
24
|
+
render page_template_path
|
25
|
+
rescue ActionView::MissingTemplate
|
26
|
+
render 'not_found', :status => 404
|
27
|
+
end
|
28
|
+
|
29
|
+
def page_template_path
|
30
|
+
[controller_name, page_locale, page_action].compact * "/"
|
31
|
+
end
|
32
|
+
|
33
|
+
def page_locale
|
34
|
+
return I18n.locale = params[:locale] if params[:locale]
|
35
|
+
return I18n.locale if I18n.locale != I18n.default_locale
|
36
|
+
end
|
37
|
+
|
38
|
+
def page_permalink(string)
|
39
|
+
URI.unescape(string).parameterize.underscore
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe I18nSimplePagesController do
|
6
|
+
render_views
|
7
|
+
|
8
|
+
describe "template rendering" do
|
9
|
+
describe "contact page" do
|
10
|
+
before { get :show, :id => "contact" }
|
11
|
+
|
12
|
+
it { should render_template "contact" }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "página de contato" do
|
16
|
+
context "when the locale param is defined" do
|
17
|
+
before { get :show, :id => "contato", :locale => "pt" }
|
18
|
+
|
19
|
+
it { should render_template "i18n_simple_pages/pt/contato" }
|
20
|
+
|
21
|
+
it "should define the locale" do
|
22
|
+
I18n.locale.should == :pt
|
23
|
+
end
|
24
|
+
|
25
|
+
after { I18n.locale = I18n.default_locale }
|
26
|
+
end
|
27
|
+
|
28
|
+
context "when the locale param is not defined" do
|
29
|
+
before { get :show, :id => "contato" }
|
30
|
+
|
31
|
+
it { should render_template "not_found" }
|
32
|
+
end
|
33
|
+
|
34
|
+
context "when the locale is defined" do
|
35
|
+
before do
|
36
|
+
I18n.locale = "pt"
|
37
|
+
get :show, :id => "contato"
|
38
|
+
end
|
39
|
+
|
40
|
+
it { should render_template "i18n_simple_pages/pt/contato" }
|
41
|
+
|
42
|
+
after { I18n.locale = I18n.default_locale }
|
43
|
+
end
|
44
|
+
|
45
|
+
context "when the locale param is not defined" do
|
46
|
+
before { get :show, :id => "contato" }
|
47
|
+
|
48
|
+
it { should render_template "not_found" }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe SimplePagesController do
|
6
|
+
render_views
|
7
|
+
|
8
|
+
context "when the template doesn't exist" do
|
9
|
+
before { get :show, :id => 'nothing' }
|
10
|
+
|
11
|
+
it { should render_template 'not_found' }
|
12
|
+
it { response.should be_not_found }
|
13
|
+
end
|
14
|
+
|
15
|
+
context "when the template exists" do
|
16
|
+
before { get :show, :id => 'testing' }
|
17
|
+
|
18
|
+
it { should render_template 'testing' }
|
19
|
+
it { response.should be_success }
|
20
|
+
end
|
21
|
+
|
22
|
+
context "when the template and action exist" do
|
23
|
+
before { get :show, :id => 'plus' }
|
24
|
+
|
25
|
+
it { should render_template 'plus' }
|
26
|
+
it { response.should be_success }
|
27
|
+
it { response.body.should =~ /1/ }
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when the action exists but not the template" do
|
31
|
+
before { get :show, :id => 'minus' }
|
32
|
+
|
33
|
+
it { should render_template 'show' }
|
34
|
+
it { response.should be_success }
|
35
|
+
it { response.body.should =~ /\-1/ }
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe SimplePagesController, "using special characters like" do
|
6
|
+
context "\"testing-testing\"" do
|
7
|
+
before { get :show, :id => 'testing-testing' }
|
8
|
+
|
9
|
+
it { should render_template 'testing_testing' }
|
10
|
+
end
|
11
|
+
|
12
|
+
context "\"são-paulo-ribeirão\"" do
|
13
|
+
before { get :show, :id => 'são-paulo-ribeirão' }
|
14
|
+
|
15
|
+
it { should render_template 'sao_paulo_ribeirao' }
|
16
|
+
end
|
17
|
+
|
18
|
+
context "\"testing-testing\"" do
|
19
|
+
before { get :show, :id => 'testing-testing' }
|
20
|
+
|
21
|
+
it { should render_template 'testing_testing' }
|
22
|
+
end
|
23
|
+
|
24
|
+
context "\"são-paulo_ribeirão\"" do
|
25
|
+
before { get :show, :id => 'são-paulo_ribeirão' }
|
26
|
+
|
27
|
+
it { should render_template 'sao_paulo_ribeirao' }
|
28
|
+
end
|
29
|
+
|
30
|
+
context "\"são-paulo ribeirão\"" do
|
31
|
+
before { get :show, :id => 'são-paulo%20ribeirão' }
|
32
|
+
|
33
|
+
it { should render_template 'sao_paulo_ribeirao' }
|
34
|
+
end
|
35
|
+
end
|
data/spec/dummy/Rakefile
ADDED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= @total %>
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= @total %>
|
File without changes
|
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require "action_controller/railtie"
|
4
|
+
require "rails/test_unit/railtie"
|
5
|
+
|
6
|
+
Bundler.require(*Rails.groups)
|
7
|
+
require "simple_pages"
|
8
|
+
|
9
|
+
module Dummy
|
10
|
+
class Application < Rails::Application
|
11
|
+
config.encoding = "utf-8"
|
12
|
+
config.assets.enabled = true
|
13
|
+
config.assets.version = '1.0'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
config.cache_classes = true
|
3
|
+
|
4
|
+
config.serve_static_assets = true
|
5
|
+
config.static_cache_control = "public, max-age=3600"
|
6
|
+
|
7
|
+
config.whiny_nils = true
|
8
|
+
|
9
|
+
config.consider_all_requests_local = true
|
10
|
+
config.action_controller.perform_caching = false
|
11
|
+
|
12
|
+
config.action_dispatch.show_exceptions = false
|
13
|
+
|
14
|
+
config.action_controller.allow_forgery_protection = false
|
15
|
+
|
16
|
+
config.active_support.deprecation = :stderr
|
17
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Dummy::Application.config.secret_token = '9b6732ba44fd8625c7eadcac4c16c3e09ddf8e9b8df9e8dfb5e3da5bad77ce424324e8cf132c5cb723302dba28697fd88111895610ca82d3f13d9131a5570eb0'
|
@@ -0,0 +1 @@
|
|
1
|
+
Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
|