rails_pages 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +135 -0
- data/config/routes.rb +7 -5
- data/lib/rails_pages/configuration.rb +21 -0
- data/lib/rails_pages/version.rb +1 -1
- data/lib/rails_pages.rb +1 -0
- data/spec/rails_pages/configuration_spec.rb +21 -0
- data/spec/routing/routes_spec.rb +18 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 136a1fe8daa9d56878c52c4f163c8c239175c653
|
4
|
+
data.tar.gz: f0d9c08d08a5704974e8213784a980eef575c13d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16a7c767c5ca38bb4ca51acaad755e55329f0463a4e68767ddb43065558a393be2b60b88662ae93c5a51240e3def2e21f20ee4ced64dccfc70f52aefa8a98829
|
7
|
+
data.tar.gz: 56ece8c3455c6a572f7b24becc90d3b071f89170c1fe084c1bc844b2114f9a5f6fa215b05ccf09d5cf8e81d49247c40ab1877aba1ed50cb48fa45e6e4524b965
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,141 @@
|
|
2
2
|
|
3
3
|
Static pages on Rails.
|
4
4
|
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```
|
8
|
+
$ gem install rails_pages
|
9
|
+
```
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
# Gemfile
|
13
|
+
gem 'rails_pages'
|
14
|
+
```
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
Note that nested page directory structures are accepted by default.
|
19
|
+
|
20
|
+
Create static pages:
|
21
|
+
|
22
|
+
```
|
23
|
+
$ mkdir app/views/rails_pages
|
24
|
+
$ touch app/views/rails_pages/page.html.erb
|
25
|
+
```
|
26
|
+
|
27
|
+
Visit pages `http://0.0.0.0:3000/pages/page`.
|
28
|
+
|
29
|
+
### Generating resources
|
30
|
+
|
31
|
+
```
|
32
|
+
$ rails generate rails_pages:scaffold products
|
33
|
+
```
|
34
|
+
|
35
|
+
Would generate the following:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
# app/controllers/products_controller.rb
|
39
|
+
class ProductsController < RailsPages::PagesController
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
# spec/controllers/products_controller_spec.rb
|
45
|
+
require 'spec_helper'
|
46
|
+
|
47
|
+
describe ProductsController do
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
# config/routes.rb
|
53
|
+
resources :products,
|
54
|
+
:only => :show,
|
55
|
+
:format => false,
|
56
|
+
:constraints => { :id => /.+?/ }
|
57
|
+
```
|
58
|
+
|
59
|
+
Create static pages:
|
60
|
+
|
61
|
+
```
|
62
|
+
$ mkdir app/views/products
|
63
|
+
$ touch app/views/products/product.html.erb
|
64
|
+
```
|
65
|
+
|
66
|
+
Visit pages `http://0.0.0.0:3000/products/product`.
|
67
|
+
|
68
|
+
## Routing
|
69
|
+
|
70
|
+
Link to pages with [named helpers][named-helpers]:
|
71
|
+
|
72
|
+
[named-helpers]: http://guides.rubyonrails.org/routing.html#overriding-the-named-helpers
|
73
|
+
|
74
|
+
```erb
|
75
|
+
<%= link_to 'Page', page_path('page') %>
|
76
|
+
```
|
77
|
+
|
78
|
+
Define root path:
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
# config/routes.rb
|
82
|
+
root 'pages#show', :id => 'home'
|
83
|
+
```
|
84
|
+
|
85
|
+
Define root-level resource routes:
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
# config/routes.rb
|
89
|
+
get '/:id' => 'pages#show',
|
90
|
+
:as => :page,
|
91
|
+
:format => false,
|
92
|
+
:constraints => { :id => /.+?/ }
|
93
|
+
```
|
94
|
+
|
95
|
+
Exclude specific pages from resource routes:
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
:constraints => { :id => /.+?(?<!home|new|edit)/ }
|
99
|
+
```
|
100
|
+
|
101
|
+
Disable default routes:
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
# config/initializers/rails_pages.rb
|
105
|
+
RailsPages.configure do |config|
|
106
|
+
config.default_routes = false
|
107
|
+
end
|
108
|
+
```
|
109
|
+
|
110
|
+
## Testing
|
111
|
+
|
112
|
+
[Rspec controller][rspec-controller] example:
|
113
|
+
|
114
|
+
[rspec-controller]: https://github.com/rspec/rspec-rails#controller-specs
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
# spec/controllers/products_controller_spec.rb
|
118
|
+
require 'spec_helper'
|
119
|
+
|
120
|
+
describe ProductsController do
|
121
|
+
describe 'GET /products/product' do
|
122
|
+
before { get :show, :id => 'product' }
|
123
|
+
|
124
|
+
it 'responds successfully with an HTTP 200 status code' do
|
125
|
+
expect(response).to be_success
|
126
|
+
expect(response.status).to eq(200)
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'renders requested template' do
|
130
|
+
expect(response).to render_template('product')
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'inherits layout from ApplicationController' do
|
134
|
+
expect(response).to render_template('layouts/application')
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
```
|
139
|
+
|
5
140
|
## License
|
6
141
|
|
7
142
|
This is free and unencumbered software released into the public domain.
|
data/config/routes.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
if RailsPages.configuration.default_routes
|
3
|
+
resources :pages,
|
4
|
+
:module => :rails_pages,
|
5
|
+
:only => :show,
|
6
|
+
:format => false,
|
7
|
+
:constraints => { :id => /.+?/ }
|
8
|
+
end
|
7
9
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module RailsPages
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :default_routes
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@default_routes = true
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class << self
|
11
|
+
attr_accessor :configuration
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.configuration
|
15
|
+
@configuration ||= Configuration.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.configure
|
19
|
+
yield configuration if block_given?
|
20
|
+
end
|
21
|
+
end
|
data/lib/rails_pages/version.rb
CHANGED
data/lib/rails_pages.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RailsPages::Configuration do
|
4
|
+
describe 'default_routes' do
|
5
|
+
context 'enabled' do
|
6
|
+
it 'returns true' do
|
7
|
+
expect(RailsPages.configuration.default_routes).to be_true
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'disabled' do
|
12
|
+
before do
|
13
|
+
RailsPages.configure { |c| c.default_routes = false }
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'returns false' do
|
17
|
+
expect(RailsPages.configuration.default_routes).to be_false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/spec/routing/routes_spec.rb
CHANGED
@@ -73,4 +73,22 @@ describe 'routing' do
|
|
73
73
|
Rails.application.reload_routes!
|
74
74
|
end
|
75
75
|
end
|
76
|
+
|
77
|
+
context 'disabled' do
|
78
|
+
before do
|
79
|
+
RailsPages.configure { |c| c.default_routes = false }
|
80
|
+
end
|
81
|
+
|
82
|
+
describe 'pages' do
|
83
|
+
it "does not route '/:id'" do
|
84
|
+
expect(:get => '/page').not_to be_routable
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe 'nested pages' do
|
89
|
+
it "does not route '/nested/:id'" do
|
90
|
+
expect(:get => '/nested/page').not_to be_routable
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
76
94
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_pages
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Niclas Gelin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -88,6 +88,7 @@ files:
|
|
88
88
|
- lib/generators/rails_pages/scaffold/USAGE
|
89
89
|
- lib/generators/rails_pages/scaffold/scaffold_generator.rb
|
90
90
|
- lib/rails_pages.rb
|
91
|
+
- lib/rails_pages/configuration.rb
|
91
92
|
- lib/rails_pages/engine.rb
|
92
93
|
- lib/rails_pages/version.rb
|
93
94
|
- rails_pages.gemspec
|
@@ -115,6 +116,7 @@ files:
|
|
115
116
|
- spec/integration/controller_generator_spec.rb
|
116
117
|
- spec/integration/resource_route_generator_spec.rb
|
117
118
|
- spec/integration/scaffold_generator_spec.rb
|
119
|
+
- spec/rails_pages/configuration_spec.rb
|
118
120
|
- spec/routing/routes_spec.rb
|
119
121
|
- spec/spec_helper.rb
|
120
122
|
homepage: https://github.com/niclasgelin/rails_pages
|
@@ -166,5 +168,6 @@ test_files:
|
|
166
168
|
- spec/integration/controller_generator_spec.rb
|
167
169
|
- spec/integration/resource_route_generator_spec.rb
|
168
170
|
- spec/integration/scaffold_generator_spec.rb
|
171
|
+
- spec/rails_pages/configuration_spec.rb
|
169
172
|
- spec/routing/routes_spec.rb
|
170
173
|
- spec/spec_helper.rb
|