ignition 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/ignition/pages_controller.rb +22 -0
- data/config/routes.rb +8 -0
- data/lib/ignition.rb +5 -0
- data/lib/ignition/config.rb +12 -0
- data/lib/ignition/engine.rb +30 -0
- data/lib/ignition/routing.rb +25 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/controllers/time_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +16 -0
- data/test/dummy/config/boot.rb +13 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/test.rb +35 -0
- data/test/dummy/config/initializers/secret_token.rb +2 -0
- data/test/dummy/config/initializers/session_store.rb +2 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/routing_test.rb +39 -0
- data/test/test_helper.rb +5 -0
- data/test/url_helpers_test.rb +13 -0
- metadata +93 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
module Ignition
|
2
|
+
class PagesController < ApplicationController
|
3
|
+
layout Rails.application.config.ignition.layout
|
4
|
+
|
5
|
+
case Rails.application.config.ignition.cache
|
6
|
+
when :page then
|
7
|
+
caches_page :show
|
8
|
+
when :page_without_layout then
|
9
|
+
caches_action :show, :layout => false
|
10
|
+
when :none then
|
11
|
+
# do nothing
|
12
|
+
else
|
13
|
+
raise "Invalid caching method: #{Rails.application.config.ignition.cache}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def show
|
17
|
+
id = params[:id]
|
18
|
+
render :template => "#{Rails.application.config.ignition.view_prefix}/#{id}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
data/config/routes.rb
ADDED
data/lib/ignition.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'ignition/config'
|
2
|
+
require 'rails'
|
3
|
+
|
4
|
+
module Ignition
|
5
|
+
class Engine < Rails::Engine
|
6
|
+
config.ignition = Ignition::Configuration.new
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
# this hack allows URLs to be generated correctly if the engine is mounted at /
|
11
|
+
class ActionDispatch::Routing::Mapper
|
12
|
+
private
|
13
|
+
def define_generate_prefix(app, name)
|
14
|
+
return unless app.respond_to?(:routes) && app.routes.respond_to?(:define_mounted_helper)
|
15
|
+
|
16
|
+
_route = @set.named_routes.routes[name.to_sym]
|
17
|
+
_routes = @set
|
18
|
+
app.routes.define_mounted_helper(name)
|
19
|
+
app.routes.class_eval do
|
20
|
+
define_method :_generate_prefix do |options|
|
21
|
+
prefix_options = options.slice(*_route.segment_keys)
|
22
|
+
# we must actually delete prefix segment keys to avoid passing them to next url_for
|
23
|
+
_route.segment_keys.each { |k| options.delete(k) }
|
24
|
+
prefix = _routes.url_helpers.send("#{name}_path", prefix_options)
|
25
|
+
return prefix == '/' ? '' : prefix
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Ignition
|
2
|
+
class PageExistsConstraint
|
3
|
+
def self.matches?(request)
|
4
|
+
id = request.symbolized_path_parameters[:id]
|
5
|
+
return exists_and_valid?(id)
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
def self.exists_and_valid?(id)
|
10
|
+
view_prefix = Rails.application.config.ignition.view_prefix
|
11
|
+
|
12
|
+
Rails.application.config.paths['app/views'].each do |path|
|
13
|
+
base = File.expand_path(view_prefix, File.expand_path(path, Rails.root))
|
14
|
+
file = File.expand_path(id, base)
|
15
|
+
return false if not file.starts_with? base
|
16
|
+
|
17
|
+
templates = Dir.glob("#{file}.*")
|
18
|
+
return true if not templates.empty?
|
19
|
+
end
|
20
|
+
|
21
|
+
return false
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require 'action_controller/railtie'
|
4
|
+
require File.expand_path('../../../../lib/ignition', __FILE__)
|
5
|
+
|
6
|
+
# If you have a Gemfile, require the gems listed there, including any gems
|
7
|
+
# you've limited to :test, :development, or :production.
|
8
|
+
Bundler.require(:default, Rails.env) if defined?(Bundler)
|
9
|
+
|
10
|
+
module Dummy
|
11
|
+
class Application < Rails::Application
|
12
|
+
config.encoding = "utf-8"
|
13
|
+
config.filter_parameters += [:password]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
# Set up gems listed in the Gemfile.
|
4
|
+
gemfile = File.expand_path('../../Gemfile', __FILE__)
|
5
|
+
begin
|
6
|
+
ENV['BUNDLE_GEMFILE'] = gemfile
|
7
|
+
require 'bundler'
|
8
|
+
Bundler.setup
|
9
|
+
rescue Bundler::GemNotFound => e
|
10
|
+
STDERR.puts e.message
|
11
|
+
STDERR.puts "Try running `bundle install`."
|
12
|
+
exit!
|
13
|
+
end if File.exist?(gemfile)
|
@@ -0,0 +1,35 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
3
|
+
|
4
|
+
# The test environment is used exclusively to run your application's
|
5
|
+
# test suite. You never need to work with it otherwise. Remember that
|
6
|
+
# your test database is "scratch space" for the test suite and is wiped
|
7
|
+
# and recreated between test runs. Don't rely on the data there!
|
8
|
+
config.cache_classes = true
|
9
|
+
|
10
|
+
# Log error messages when you accidentally call methods on nil.
|
11
|
+
config.whiny_nils = true
|
12
|
+
|
13
|
+
# Show full error reports and disable caching
|
14
|
+
config.consider_all_requests_local = true
|
15
|
+
config.action_controller.perform_caching = false
|
16
|
+
|
17
|
+
# Raise exceptions instead of rendering exception templates
|
18
|
+
config.action_dispatch.show_exceptions = false
|
19
|
+
|
20
|
+
# Disable request forgery protection in test environment
|
21
|
+
config.action_controller.allow_forgery_protection = false
|
22
|
+
|
23
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
24
|
+
# The :test delivery method accumulates sent emails in the
|
25
|
+
# ActionMailer::Base.deliveries array.
|
26
|
+
# config.action_mailer.delivery_method = :test
|
27
|
+
|
28
|
+
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
29
|
+
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
30
|
+
# like if you have constraints or database-specific column types
|
31
|
+
# config.active_record.schema_format = :sql
|
32
|
+
|
33
|
+
# Print deprecation notices to the stderr
|
34
|
+
config.active_support.deprecation = :stderr
|
35
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Ignition
|
4
|
+
class RoutingTest < ActionController::IntegrationTest
|
5
|
+
test 'top-level page' do
|
6
|
+
get 'hello'
|
7
|
+
|
8
|
+
assert_response :success
|
9
|
+
assert_template 'pages/hello'
|
10
|
+
end
|
11
|
+
|
12
|
+
test 'nested page' do
|
13
|
+
get 'nested/page'
|
14
|
+
|
15
|
+
assert_response :success
|
16
|
+
assert_template 'pages/nested/page'
|
17
|
+
end
|
18
|
+
|
19
|
+
test '404 errors' do
|
20
|
+
assert_raises ActionController::RoutingError do
|
21
|
+
get 'non-existant'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
test 'directory access restricted' do
|
26
|
+
assert_raises ActionController::RoutingError do
|
27
|
+
get '../layouts/application'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
test 'route cascades' do
|
32
|
+
get 'time'
|
33
|
+
|
34
|
+
assert_response :success
|
35
|
+
assert_template 'time/now'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Ignition
|
4
|
+
class UrlHelpersTest < ActionView::TestCase
|
5
|
+
include Rails.application.routes.mounted_helpers
|
6
|
+
|
7
|
+
test 'url helpers' do
|
8
|
+
assert_equal '/hello', ignition_engine.page_path('hello')
|
9
|
+
assert_equal '/nested/page', ignition_engine.page_path('nested/page')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ignition
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Graham Edgecombe
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-05-21 00:00:00.000000000 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rails
|
17
|
+
requirement: &16026420 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.0.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *16026420
|
26
|
+
description: An engine for Rails 3 applications which allows easy management and caching
|
27
|
+
of static pages.
|
28
|
+
email: grahamedgecombe@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- app/controllers/ignition/pages_controller.rb
|
34
|
+
- config/routes.rb
|
35
|
+
- lib/ignition/config.rb
|
36
|
+
- lib/ignition/engine.rb
|
37
|
+
- lib/ignition/routing.rb
|
38
|
+
- lib/ignition.rb
|
39
|
+
- test/routing_test.rb
|
40
|
+
- test/url_helpers_test.rb
|
41
|
+
- test/dummy/config/initializers/session_store.rb
|
42
|
+
- test/dummy/config/initializers/secret_token.rb
|
43
|
+
- test/dummy/config/environment.rb
|
44
|
+
- test/dummy/config/boot.rb
|
45
|
+
- test/dummy/config/environments/test.rb
|
46
|
+
- test/dummy/config/application.rb
|
47
|
+
- test/dummy/config/routes.rb
|
48
|
+
- test/dummy/app/helpers/application_helper.rb
|
49
|
+
- test/dummy/app/controllers/application_controller.rb
|
50
|
+
- test/dummy/app/controllers/time_controller.rb
|
51
|
+
- test/test_helper.rb
|
52
|
+
- test/dummy/config.ru
|
53
|
+
has_rdoc: true
|
54
|
+
homepage: http://grahamedgecombe.com/projects/ignition
|
55
|
+
licenses:
|
56
|
+
- MIT
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 1.9.2
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.6.2
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: Static pages for Rails 3.
|
79
|
+
test_files:
|
80
|
+
- test/routing_test.rb
|
81
|
+
- test/url_helpers_test.rb
|
82
|
+
- test/dummy/config/initializers/session_store.rb
|
83
|
+
- test/dummy/config/initializers/secret_token.rb
|
84
|
+
- test/dummy/config/environment.rb
|
85
|
+
- test/dummy/config/boot.rb
|
86
|
+
- test/dummy/config/environments/test.rb
|
87
|
+
- test/dummy/config/application.rb
|
88
|
+
- test/dummy/config/routes.rb
|
89
|
+
- test/dummy/app/helpers/application_helper.rb
|
90
|
+
- test/dummy/app/controllers/application_controller.rb
|
91
|
+
- test/dummy/app/controllers/time_controller.rb
|
92
|
+
- test/test_helper.rb
|
93
|
+
- test/dummy/config.ru
|