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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63b1452839cdb15777d8d767e8dff58ede69bb3b
4
- data.tar.gz: 9b8268c0c7a3942236422bd5f5951471318b7efd
3
+ metadata.gz: 136a1fe8daa9d56878c52c4f163c8c239175c653
4
+ data.tar.gz: f0d9c08d08a5704974e8213784a980eef575c13d
5
5
  SHA512:
6
- metadata.gz: c047961b47f989f7ef39f3bf7c4d72f1e0cfb830efa28963cd8770da2256bac745591b0d1a5980d555ddf6fcae4a88826c2edb2af2709084a8f0ef36a46b31c5
7
- data.tar.gz: 146c960f8bcf3543ed2c5df17fcd176f0dd2f6edf3a507bc79a258af7eb3a6c67a8bccb4a75751f531c101355c37e4bef21b86e4b083db7706c8e66376c998fe
6
+ metadata.gz: 16a7c767c5ca38bb4ca51acaad755e55329f0463a4e68767ddb43065558a393be2b60b88662ae93c5a51240e3def2e21f20ee4ced64dccfc70f52aefa8a98829
7
+ data.tar.gz: 56ece8c3455c6a572f7b24becc90d3b071f89170c1fe084c1bc844b2114f9a5f6fa215b05ccf09d5cf8e81d49247c40ab1877aba1ed50cb48fa45e6e4524b965
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_pages (0.0.1)
4
+ rails_pages (0.0.2)
5
5
  rails (~> 4.0.0)
6
6
 
7
7
  GEM
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
- resources :pages,
3
- :module => :rails_pages,
4
- :only => :show,
5
- :format => false,
6
- :constraints => { :id => /.+?/ }
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
@@ -1,3 +1,3 @@
1
1
  module RailsPages
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
data/lib/rails_pages.rb CHANGED
@@ -1 +1,2 @@
1
+ require 'rails_pages/configuration'
1
2
  require 'rails_pages/engine' if defined?(Rails)
@@ -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
@@ -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.1
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-06 00:00:00.000000000 Z
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