blue_sparks 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README.md +130 -0
- data/app/controllers/blue_sparks/pages_controller.rb +47 -0
- data/config/routes.rb +3 -0
- data/lib/blue_sparks.rb +3 -0
- data/lib/blue_sparks/engine.rb +6 -0
- metadata +61 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2010 Cody Krieger
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
BlueSparks
|
2
|
+
============
|
3
|
+
|
4
|
+
Epic static page rendering controller with support for nested pages.
|
5
|
+
Heavily inspired by [thoughtbot's high_voltage](/thoughtbot/high_voltage).
|
6
|
+
|
7
|
+
Static pages?
|
8
|
+
-------------
|
9
|
+
|
10
|
+
Yeah, like "About us", "Directions", marketing pages, etc.
|
11
|
+
|
12
|
+
Installation
|
13
|
+
------------
|
14
|
+
|
15
|
+
% gem install blue_sparks
|
16
|
+
|
17
|
+
Include in your Gemfile:
|
18
|
+
|
19
|
+
gem "blue_sparks"
|
20
|
+
|
21
|
+
Sorry, folks, Rails 3 only.
|
22
|
+
|
23
|
+
Usage
|
24
|
+
-----
|
25
|
+
|
26
|
+
Write your static pages and put them in the RAILS_ROOT/app/views/pages directory.
|
27
|
+
|
28
|
+
% mkdir app/views/pages
|
29
|
+
% touch app/views/pages/about.html.erb
|
30
|
+
|
31
|
+
<!--
|
32
|
+
After putting something interesting there, you can link to it from anywhere in your app with:
|
33
|
+
|
34
|
+
link_to "About", page_path("about")
|
35
|
+
|
36
|
+
This will also work, if you like the more explicit style:
|
37
|
+
|
38
|
+
link_to "About", page_path(:id => "about")
|
39
|
+
-->
|
40
|
+
|
41
|
+
Bam.
|
42
|
+
|
43
|
+
Routes
|
44
|
+
------
|
45
|
+
|
46
|
+
By default, the static page routes will be like /pages/:id (where :id is the view filename).
|
47
|
+
|
48
|
+
If you want to route to a static page in another location (for example, a homepage), do this:
|
49
|
+
|
50
|
+
match 'pages/home' => 'blue_sparks/pages#show', :id => 'home'
|
51
|
+
|
52
|
+
In that case, you'd need an app/views/pages/home.html.erb file.
|
53
|
+
|
54
|
+
Generally speaking, you need to route to the 'show' action with an :id param of the view filename.
|
55
|
+
|
56
|
+
You can route the root url to a high voltage page like this:
|
57
|
+
|
58
|
+
root :to => 'blue_sparks/pages#show', :id => 'home'
|
59
|
+
|
60
|
+
Which will render a homepage from app/views/pages/home.html.erb
|
61
|
+
|
62
|
+
Override
|
63
|
+
--------
|
64
|
+
|
65
|
+
Most common reasons to override?
|
66
|
+
|
67
|
+
* You need authentication around the pages to make sure a user is signed in.
|
68
|
+
* You need to render different layouts for different pages.
|
69
|
+
|
70
|
+
Create a PagesController of your own:
|
71
|
+
|
72
|
+
$ rails generate controller pages
|
73
|
+
|
74
|
+
Override the default route:
|
75
|
+
|
76
|
+
# in config/routes.rb
|
77
|
+
resources :pages
|
78
|
+
|
79
|
+
Then modify it to subclass from High Voltage, adding whatever you need:
|
80
|
+
|
81
|
+
class PagesController < BlueSparks::PagesController
|
82
|
+
before_filter :authenticate
|
83
|
+
layout :layout_for_page
|
84
|
+
|
85
|
+
protected
|
86
|
+
def layout_for_page
|
87
|
+
case params[:id]
|
88
|
+
when 'home'
|
89
|
+
'home'
|
90
|
+
else
|
91
|
+
'application'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
Testing
|
97
|
+
-------
|
98
|
+
|
99
|
+
Just a suggestion, but you can test your pages using Shoulda pretty easily:
|
100
|
+
|
101
|
+
class PagesControllerTest < ActionController::TestCase
|
102
|
+
tests PagesController
|
103
|
+
|
104
|
+
%w(earn_money screencast about contact).each do |page|
|
105
|
+
context "on GET to /#{page}" do
|
106
|
+
setup { get :show, :slug => page }
|
107
|
+
|
108
|
+
should_respond_with :success
|
109
|
+
should_render_template page
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
If you're not using a custom PagesController be sure to test <code>BlueSparks::PagesController</code> instead.
|
115
|
+
|
116
|
+
Enjoy!
|
117
|
+
|
118
|
+
Credits
|
119
|
+
-------
|
120
|
+
|
121
|
+

|
122
|
+
|
123
|
+
for their awesome high_voltage gem.
|
124
|
+
|
125
|
+
The names and logos for thoughtbot are trademarks of thoughtbot, inc.
|
126
|
+
|
127
|
+
License
|
128
|
+
-------
|
129
|
+
|
130
|
+
BlueSparks is Copyright © 2011 Cody Krieger. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class BlueSparks::PagesController < ApplicationController
|
2
|
+
|
3
|
+
unloadable
|
4
|
+
|
5
|
+
rescue_from ActionView::MissingTemplate do |exception|
|
6
|
+
if exception.message =~ %r{Missing template pages/}
|
7
|
+
raise ActionController::RoutingError, "No such page: #{params[:slug]}"
|
8
|
+
else
|
9
|
+
raise exception
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def show
|
14
|
+
begin
|
15
|
+
render :template => current_page
|
16
|
+
rescue
|
17
|
+
raise $! unless $!.kind_of? ActionView::MissingTemplate
|
18
|
+
|
19
|
+
render :template => "#{current_page}/index"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def subnav
|
24
|
+
# magic method to render a given folder's subnav partial
|
25
|
+
begin
|
26
|
+
subnav = render :partial => "#{current_page}/menu", :layout => "menu_template"
|
27
|
+
subnav.first unless subnav.nil?
|
28
|
+
rescue
|
29
|
+
begin
|
30
|
+
subnav = render :partial => "#{page_root}/menu", :layout => "menu_template"
|
31
|
+
rescue
|
32
|
+
end
|
33
|
+
end
|
34
|
+
subnav.first unless subnav.nil?
|
35
|
+
end
|
36
|
+
|
37
|
+
protected
|
38
|
+
|
39
|
+
def current_page
|
40
|
+
"pages/#{params[:slug].to_s.downcase}"
|
41
|
+
end
|
42
|
+
|
43
|
+
def page_root
|
44
|
+
"pages/#{params[:slug].to_s.downcase.gsub /^([^\/]+)(\/.+)+$/, '\1'}"
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
data/config/routes.rb
ADDED
data/lib/blue_sparks.rb
ADDED
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: blue_sparks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Cody Krieger
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-04-25 00:00:00 -04:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: Fire in the disco. Fire in the ... taco bell.
|
18
|
+
email: cody@codykrieger.com
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files: []
|
24
|
+
|
25
|
+
files:
|
26
|
+
- MIT-LICENSE
|
27
|
+
- README.md
|
28
|
+
- app/controllers/blue_sparks/pages_controller.rb
|
29
|
+
- config/routes.rb
|
30
|
+
- lib/blue_sparks/engine.rb
|
31
|
+
- lib/blue_sparks.rb
|
32
|
+
has_rdoc: true
|
33
|
+
homepage: https://github.com/codykrieger/blue_sparks
|
34
|
+
licenses: []
|
35
|
+
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options: []
|
38
|
+
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
requirements: []
|
54
|
+
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 1.6.2
|
57
|
+
signing_key:
|
58
|
+
specification_version: 3
|
59
|
+
summary: Epic static page rendering controller with support for nested pages.
|
60
|
+
test_files: []
|
61
|
+
|