jorourke-acts_as_static 0.1
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/init.rb +1 -0
- data/lib/acts_as_static.rb +65 -0
- metadata +54 -0
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ActionController::Base.send :include, ActsAsStatic
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module ActsAsStatic
|
2
|
+
|
3
|
+
def self.included(base)
|
4
|
+
base.extend(ClassMethods)
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
# Configuration options are:
|
9
|
+
#
|
10
|
+
# * +root+ - specifies the root directory for static pages
|
11
|
+
# * +template+ - specifies the template for static pages
|
12
|
+
#
|
13
|
+
# Example: <tt>acts_as_static :root => File.join(RAILS_ROOT, "app", "views", "static") }</tt>
|
14
|
+
def acts_as_static(options = {})
|
15
|
+
configuration = { :root => File.join(RAILS_ROOT, "app", "views", "static") }
|
16
|
+
configuration.update(options) if options.is_a?(Hash)
|
17
|
+
|
18
|
+
class_eval <<-EOV
|
19
|
+
include ActsAsStatic::InstanceMethods
|
20
|
+
|
21
|
+
verify :params => :url, :only => :show, :redirect_to => "/"
|
22
|
+
before_filter :ensure_valid, :only => :show
|
23
|
+
|
24
|
+
def acts_as_static_root
|
25
|
+
'#{configuration[:root]}'
|
26
|
+
end
|
27
|
+
|
28
|
+
private :acts_as_static_root
|
29
|
+
EOV
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
module InstanceMethods
|
34
|
+
def show
|
35
|
+
render :template => current_template, :layout => current_layout
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def current_page
|
41
|
+
path = params[:url].join("/")
|
42
|
+
if File.directory?(File.join(acts_as_static_root, path))
|
43
|
+
"#{path}/index.html.erb"
|
44
|
+
else
|
45
|
+
"#{path}.html.erb"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def current_layout
|
50
|
+
"application"
|
51
|
+
end
|
52
|
+
|
53
|
+
def current_template
|
54
|
+
File.join(acts_as_static_root, current_page)
|
55
|
+
end
|
56
|
+
|
57
|
+
def ensure_valid
|
58
|
+
unless File.exists?(File.join(acts_as_static_root, current_page))
|
59
|
+
render :file => File.join(RAILS_ROOT, "public", "404.html"), :status => 404
|
60
|
+
return false
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jorourke-acts_as_static
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.1"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Josh O'Rourke
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-02-23 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Easy static page handling for Rails.
|
17
|
+
email: jorourke23@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- init.rb
|
26
|
+
- lib/acts_as_static.rb
|
27
|
+
has_rdoc: false
|
28
|
+
homepage: http://github.com/jorourke/acts_as_static
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: "0"
|
39
|
+
version:
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "0"
|
45
|
+
version:
|
46
|
+
requirements: []
|
47
|
+
|
48
|
+
rubyforge_project:
|
49
|
+
rubygems_version: 1.2.0
|
50
|
+
signing_key:
|
51
|
+
specification_version: 2
|
52
|
+
summary: Easy static page handling for Rails.
|
53
|
+
test_files: []
|
54
|
+
|