staticman 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +74 -0
- data/Rakefile +1 -0
- data/lib/generators/staticman/config_generator.rb +16 -0
- data/lib/generators/staticman/templates/config.rb +14 -0
- data/lib/staticman.rb +38 -0
- data/lib/staticman/configurable.rb +40 -0
- data/lib/staticman/controller.rb +40 -0
- data/lib/staticman/performer.rb +41 -0
- data/lib/staticman/railtie.rb +13 -0
- data/lib/staticman/request.rb +23 -0
- data/lib/staticman/tasks.rake +25 -0
- data/lib/staticman/version.rb +3 -0
- data/lib/staticman/view_silencer.rb +8 -0
- data/spec/controller_spec.rb +43 -0
- data/spec/performer_spec.rb +95 -0
- data/spec/rails_app/app/helpers/application_helper.rb +5 -0
- data/spec/rails_app/app/helpers/welcome_helper.rb +5 -0
- data/spec/rails_app/app/views/errors.html.erb +7 -0
- data/spec/rails_app/app/views/layouts/application.html.erb +11 -0
- data/spec/rails_app/app/views/layouts/welcome.html.erb +11 -0
- data/spec/rails_app/app/views/no_methods.html.erb +5 -0
- data/spec/rails_app/app/views/welcome.html.erb +10 -0
- data/spec/rails_app/config/staticman.rb +14 -0
- data/spec/rails_app/public/index.html +0 -0
- data/spec/rails_app/rails_app.rb +54 -0
- data/spec/request_spec.rb +18 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/tasks_spec.rb +37 -0
- data/staticman.gemspec +29 -0
- metadata +228 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 terut
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Staticman
|
2
|
+
|
3
|
+
Staticman build static pages, e.g. errors, about, contact, and it's very easy, fast, programable.
|
4
|
+
Rending with proxy inherited rails controller.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'staticman'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install staticman
|
19
|
+
|
20
|
+
## Setup
|
21
|
+
|
22
|
+
Create `staticman.rb` as config in `config` directory.
|
23
|
+
|
24
|
+
$ rails g staticman:build
|
25
|
+
|
26
|
+
Next, setting config with `staticman.rb`.
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
Staticman.configure do |config|
|
30
|
+
config.static_pages = [
|
31
|
+
{ file: 'statics/about', layout: 'application' },
|
32
|
+
{ file: 'statics/404', layout: 'application' }
|
33
|
+
]
|
34
|
+
# config.static_dir = 'public'
|
35
|
+
config.host = 'staticman.github.com'
|
36
|
+
# config.controller_context_class = nil
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
The following is config parameters means.
|
41
|
+
|
42
|
+
- `static_pages` - rendering pages, default is `[]`.
|
43
|
+
- `static_dir` - output directory for html, default is `public`.
|
44
|
+
- `host` - resolve domain, default is `example.com`.
|
45
|
+
- `controller_context_class` - using controller as proxy, default is `ApplicationController`.
|
46
|
+
|
47
|
+
## Usage
|
48
|
+
|
49
|
+
So easy how to use, you only execute two commands of `build` and `destroy`.
|
50
|
+
|
51
|
+
First, add static pages in directory specified.
|
52
|
+
you can write static pages the same as other views, include `helper_method`, `*_helper`.
|
53
|
+
|
54
|
+
$ vim app/view/statics/about.html.erb[haml, etc...]
|
55
|
+
|
56
|
+
Create static pages.
|
57
|
+
|
58
|
+
$ rake staticman:build
|
59
|
+
|
60
|
+
And delete.
|
61
|
+
|
62
|
+
$ rake staticman:destroy
|
63
|
+
|
64
|
+
## Contributing
|
65
|
+
|
66
|
+
1. Fork it
|
67
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
68
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
69
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
70
|
+
5. Create new Pull Request
|
71
|
+
|
72
|
+
## Copyright
|
73
|
+
|
74
|
+
Copyright (c) 2012 terut. See MIT LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Staticman
|
2
|
+
module Generators
|
3
|
+
class ConfigGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
5
|
+
|
6
|
+
desc <<DESC
|
7
|
+
Description:
|
8
|
+
Copies Staticman configuration file to your application's config directory.
|
9
|
+
DESC
|
10
|
+
|
11
|
+
def copy_config_file
|
12
|
+
template 'config.rb', 'config/staticman.rb'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
Staticman.configure do |config|
|
2
|
+
## static_pages - rendering pages
|
3
|
+
## static_dir - output directory for html
|
4
|
+
## host - resolve domain
|
5
|
+
## controller_context_class - using controller as proxy, default is ApplicationController
|
6
|
+
|
7
|
+
# config.static_pages = [
|
8
|
+
# { file: 'statics/about', layout: 'application' },
|
9
|
+
# { file: 'statics/404', layout: 'application' }
|
10
|
+
# ]
|
11
|
+
# config.static_dir = 'public'
|
12
|
+
# config.host = 'example.com'
|
13
|
+
# config.controller_context_class = nil
|
14
|
+
end
|
data/lib/staticman.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# Load Rails/Railtie
|
2
|
+
begin
|
3
|
+
require 'rails'
|
4
|
+
require 'action_controller/railtie'
|
5
|
+
rescue LoadError
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
$stderr.puts <<-EOC if !defined?(Rails)
|
10
|
+
warning: no framework detected.
|
11
|
+
|
12
|
+
Your Gemfile might not be configured properly.
|
13
|
+
----- e.g. -----
|
14
|
+
Rails:
|
15
|
+
gem 'staticman'
|
16
|
+
|
17
|
+
EOC
|
18
|
+
|
19
|
+
require "staticman/version"
|
20
|
+
require 'staticman/configurable'
|
21
|
+
require 'staticman/view_silencer'
|
22
|
+
require 'staticman/controller'
|
23
|
+
require 'staticman/request'
|
24
|
+
require 'staticman/performer'
|
25
|
+
|
26
|
+
if defined?(Rails)
|
27
|
+
require 'staticman/railtie'
|
28
|
+
end
|
29
|
+
|
30
|
+
module Staticman
|
31
|
+
include Configurable
|
32
|
+
|
33
|
+
class << self
|
34
|
+
def root
|
35
|
+
@root ||= File.expand_path '../..', __FILE__
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module Staticman
|
4
|
+
module Configurable
|
5
|
+
class Configuration
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
@@defaults = {
|
9
|
+
static_pages: [],
|
10
|
+
static_dir: 'public',
|
11
|
+
host: 'example.com',
|
12
|
+
controller_context_class: nil
|
13
|
+
}
|
14
|
+
|
15
|
+
def self.defaults
|
16
|
+
@@defaults
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
@@defaults.each_pair { |k,v| __send__("#{k}=", v) }
|
21
|
+
end
|
22
|
+
|
23
|
+
attr_accessor *(@@defaults.keys)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.included(base)
|
27
|
+
base.extend ClassMethods
|
28
|
+
end
|
29
|
+
|
30
|
+
module ClassMethods
|
31
|
+
def config
|
32
|
+
Configuration.instance
|
33
|
+
end
|
34
|
+
|
35
|
+
def configure
|
36
|
+
yield config
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'pry'
|
3
|
+
module Staticman
|
4
|
+
module ProxyController
|
5
|
+
def self.included(base)
|
6
|
+
base.extend ClassMethods
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def controller_context_class
|
11
|
+
@controller_context_class ||= begin
|
12
|
+
klass_name = :"Staticman#{controller_base_class.name}"
|
13
|
+
if Object.const_defined?(klass_name)
|
14
|
+
klass = Object.const_get(klass_name)
|
15
|
+
else
|
16
|
+
klass = Class.new(controller_base_class) do
|
17
|
+
#include Rails.application.routes.url_helpers
|
18
|
+
#include Rails.application.routes.mounted_helpers
|
19
|
+
end
|
20
|
+
Object.const_set(klass_name, klass)
|
21
|
+
end
|
22
|
+
klass
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def controller_base_class
|
27
|
+
klass = Staticman.config.controller_context_class
|
28
|
+
klass ? klass : ApplicationController
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def controller_context_class
|
33
|
+
@_controller_context_class ||= self.class.controller_context_class
|
34
|
+
end
|
35
|
+
|
36
|
+
def controller_context
|
37
|
+
controller_context_class.new
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Staticman
|
2
|
+
class Performer
|
3
|
+
include ProxyController
|
4
|
+
include ProxyRequest
|
5
|
+
|
6
|
+
attr_reader :proxy
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@proxy = controller_context
|
10
|
+
@proxy.request = request_context
|
11
|
+
|
12
|
+
ActiveSupport.run_load_hooks(:staticman_performer, @proxy)
|
13
|
+
end
|
14
|
+
|
15
|
+
def build(*args, &block)
|
16
|
+
raw = render(*args, &block)
|
17
|
+
option = args.first
|
18
|
+
path = file_path(option[:file])
|
19
|
+
open(path, "w") { |f| f.write raw }
|
20
|
+
end
|
21
|
+
|
22
|
+
def render(*args, &block)
|
23
|
+
@proxy.render_to_string(*args, &block)
|
24
|
+
end
|
25
|
+
|
26
|
+
def file_path(path)
|
27
|
+
name = filename(path)
|
28
|
+
Rails.root.join(Staticman.config.static_dir, "#{name}.html")
|
29
|
+
end
|
30
|
+
|
31
|
+
def destroy(file)
|
32
|
+
File.delete file_path(file)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
def filename(path)
|
37
|
+
return path unless path.include?("/")
|
38
|
+
path.split("/").last
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Staticman
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
initializer 'staticman' do |app|
|
4
|
+
ActiveSupport.on_load(:staticman_performer) do |proxy|
|
5
|
+
proxy.view_context.class.send :include, ViewSilencer
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
rake_tasks do
|
10
|
+
load 'staticman/tasks.rake'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Staticman
|
2
|
+
module ProxyRequest
|
3
|
+
def self.included(base)
|
4
|
+
base.extend ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def request_context_class
|
9
|
+
@request_context_class ||= Class.new(ActionDispatch::TestRequest)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def request_context_class
|
14
|
+
@_request_context_class ||= self.class.request_context_class
|
15
|
+
end
|
16
|
+
|
17
|
+
def request_context
|
18
|
+
request = request_context_class.new
|
19
|
+
request.host = Staticman.config.host
|
20
|
+
request
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
namespace :staticman do
|
2
|
+
desc "Write static page in public"
|
3
|
+
task :build => :environment do
|
4
|
+
require Rails.root.join('config/staticman')
|
5
|
+
|
6
|
+
pages = Staticman.config.static_pages
|
7
|
+
|
8
|
+
pages.each do |page|
|
9
|
+
proxy = Staticman::Performer.new
|
10
|
+
proxy.build page
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "Destory static page in public"
|
15
|
+
task :destroy => :environment do
|
16
|
+
require Rails.root.join('config/staticman')
|
17
|
+
|
18
|
+
pages = Staticman.config.static_pages
|
19
|
+
|
20
|
+
pages.each do |page|
|
21
|
+
proxy = Staticman::Performer.new
|
22
|
+
proxy.destroy page[:file]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
include Staticman
|
4
|
+
class ProxyControllerTest
|
5
|
+
include ProxyController
|
6
|
+
end
|
7
|
+
|
8
|
+
describe ProxyController do
|
9
|
+
describe '#controller_context' do
|
10
|
+
context 'inherited ApplicationController' do
|
11
|
+
let(:controller) { ProxyControllerTest.new.controller_context }
|
12
|
+
let(:view) { controller.view_context }
|
13
|
+
|
14
|
+
it { controller.should be_kind_of ApplicationController }
|
15
|
+
it { view.should respond_to(:signed_in?)}
|
16
|
+
it { view.should respond_to(:current_user) }
|
17
|
+
it { view.should_not respond_to(:welcome) }
|
18
|
+
it { view.should_not respond_to(:welcome?) }
|
19
|
+
it { view.should respond_to(:copyright_helper) }
|
20
|
+
it { view.should respond_to(:welcome_helper) }
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'config of controller_context_class has WelcomeController' do
|
24
|
+
before do
|
25
|
+
Staticman.configure do |config|
|
26
|
+
config.controller_context_class = WelcomeController
|
27
|
+
end
|
28
|
+
ProxyControllerTest.instance_variable_set(:@controller_context_class, nil)
|
29
|
+
end
|
30
|
+
let(:controller) { ProxyControllerTest.new.controller_context }
|
31
|
+
let(:view) { controller.view_context }
|
32
|
+
|
33
|
+
it { controller.should be_kind_of WelcomeController }
|
34
|
+
it { view.should respond_to(:signed_in?)}
|
35
|
+
it { view.should respond_to(:current_user) }
|
36
|
+
it { view.should respond_to(:welcome) }
|
37
|
+
it { view.should respond_to(:welcome?) }
|
38
|
+
it { view.should respond_to(:copyright_helper) }
|
39
|
+
it { view.should respond_to(:welcome_helper) }
|
40
|
+
it { view.should respond_to(:welcome_helper) }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'pry'
|
4
|
+
|
5
|
+
include Staticman
|
6
|
+
|
7
|
+
describe 'Performer' do
|
8
|
+
|
9
|
+
shared_examples_for 'render raw' do
|
10
|
+
it { raw.should include('<p>404 Not Found</p>') }
|
11
|
+
it { raw.should include('<h1><a href="/">Hello World</a></h1>') }
|
12
|
+
it { raw.should include('<p>singied_in?</p>') }
|
13
|
+
it { raw.should include('<p>copyright_helper</p>') }
|
14
|
+
it { raw.should include('<p>staticman</p>') }
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'view_context extend ViewSilencer moudle' do
|
18
|
+
let(:view) { Performer.new.proxy.view_context }
|
19
|
+
|
20
|
+
it { view.should be_kind_of ViewSilencer }
|
21
|
+
it { view.should respond_to(:method_missing) }
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'rendering static page' do
|
25
|
+
before do
|
26
|
+
@proxy = Performer.new
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:raw) { @proxy.render file: 'errors', layout: 'application' }
|
30
|
+
it { raw.should include('<title>application</title>') }
|
31
|
+
it { raw.should include('<p><a href="http://example.com/">back</a></p>') }
|
32
|
+
it_behaves_like 'render raw'
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'rendering with config changing' do
|
36
|
+
before do
|
37
|
+
Staticman.configure do |config|
|
38
|
+
config.host = 'example.net'
|
39
|
+
end
|
40
|
+
|
41
|
+
@proxy = Performer.new
|
42
|
+
end
|
43
|
+
|
44
|
+
let(:raw) { @proxy.render file: 'errors', layout: 'application' }
|
45
|
+
it { raw.should include('<p><a href="http://example.net/">back</a></p>') }
|
46
|
+
|
47
|
+
after do
|
48
|
+
Staticman.configure do |config|
|
49
|
+
config.host = 'example.com'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'write static page' do
|
55
|
+
before do
|
56
|
+
@proxy = Performer.new
|
57
|
+
@proxy.build file: 'errors', layout: 'application'
|
58
|
+
end
|
59
|
+
|
60
|
+
let(:raw) { File.read(@proxy.file_path('errors')) }
|
61
|
+
it { File.should exist(@proxy.file_path('errors')) }
|
62
|
+
it { raw.should include('<title>application</title>') }
|
63
|
+
it { raw.should include('<p><a href="http://example.com/">back</a></p>') }
|
64
|
+
it_behaves_like 'render raw'
|
65
|
+
|
66
|
+
after do
|
67
|
+
@proxy.destroy('errors')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'rendering with inherited WelcomeController' do
|
72
|
+
before do
|
73
|
+
Staticman.configure do |config|
|
74
|
+
config.controller_context_class = WelcomeController
|
75
|
+
end
|
76
|
+
@proxy = Performer.new
|
77
|
+
end
|
78
|
+
|
79
|
+
let(:raw) { @proxy.render file: 'welcome', layout: 'welcome' }
|
80
|
+
it { raw.should include('<title>welcome</title>') }
|
81
|
+
it { raw.should include('<p>welcome</p>') }
|
82
|
+
it_behaves_like 'render raw'
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'rendering with undefined method' do
|
86
|
+
before do
|
87
|
+
@proxy = Performer.new
|
88
|
+
end
|
89
|
+
|
90
|
+
let(:raw) { @proxy.render file: 'no_methods' }
|
91
|
+
it { raw.should include('<p>no methods</p>') }
|
92
|
+
it { raw.should_not include('<p>no_methods?</p>') }
|
93
|
+
it { capture(:stdout) { @proxy.render file: 'no_methods' }.should include('Silence no method error') }
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
Staticman.configure do |config|
|
2
|
+
## static_pages - rendering pages
|
3
|
+
## static_dir - output directory for html
|
4
|
+
## host - resolve domain
|
5
|
+
## controller_context_class - using controller as proxy, default is ApplicationController
|
6
|
+
|
7
|
+
config.static_pages = [
|
8
|
+
{ file: 'errors', layout: 'application' },
|
9
|
+
{ file: 'welcome', layout: 'welcome' }
|
10
|
+
]
|
11
|
+
config.static_dir = 'public'
|
12
|
+
config.host = 'example.net'
|
13
|
+
config.controller_context_class = WelcomeController
|
14
|
+
end
|
File without changes
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'action_controller/railtie'
|
2
|
+
require 'action_view/railtie'
|
3
|
+
|
4
|
+
# config
|
5
|
+
app = Class.new(Rails::Application)
|
6
|
+
app.config.secret_token = '3b7cd727ee24e8444053437c36cc66c4'
|
7
|
+
app.config.session_store :cookie_store, :key => '_myapp_session'
|
8
|
+
app.config.active_support.deprecation = :log
|
9
|
+
# TODO if helpers path change, spec raise load error. Search rails code, after.
|
10
|
+
#app.config.paths['app/views'] = 'views'
|
11
|
+
#app.config.paths['app/helpers'] = 'helpers'
|
12
|
+
|
13
|
+
# Rais.root
|
14
|
+
app.config.root = File.dirname(__FILE__)
|
15
|
+
|
16
|
+
Rails.backtrace_cleaner.remove_silencers!
|
17
|
+
app.initialize!
|
18
|
+
|
19
|
+
# routes
|
20
|
+
app.routes.draw do
|
21
|
+
root to: "welcome#index"
|
22
|
+
end
|
23
|
+
|
24
|
+
User = Struct.new("User", :name)
|
25
|
+
|
26
|
+
# controllers
|
27
|
+
class ApplicationController < ActionController::Base
|
28
|
+
helper_method :current_user, :signed_in?
|
29
|
+
|
30
|
+
private
|
31
|
+
def signed_in?
|
32
|
+
true
|
33
|
+
end
|
34
|
+
|
35
|
+
def current_user
|
36
|
+
@current_user ||= User.new('staticman')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class WelcomeController < ApplicationController
|
41
|
+
helper_method :welcome?, :welcome
|
42
|
+
|
43
|
+
private
|
44
|
+
def welcome?
|
45
|
+
true
|
46
|
+
end
|
47
|
+
|
48
|
+
def welcome
|
49
|
+
"welcome"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# helpers
|
54
|
+
# Object.const_set(:ApplicationHelper, Module.new)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
include Staticman
|
5
|
+
|
6
|
+
class ProxyRequestTest
|
7
|
+
include ProxyRequest
|
8
|
+
end
|
9
|
+
|
10
|
+
describe ProxyRequest do
|
11
|
+
describe '#request_context' do
|
12
|
+
context 'host is config value' do
|
13
|
+
let(:request) { ProxyRequestTest.new.request_context }
|
14
|
+
it { request.should be_kind_of ActionDispatch::TestRequest }
|
15
|
+
it { request.host.should be_eql 'example.com' }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
#$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rails'
|
6
|
+
rescue LoadError
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'bundler/setup'
|
10
|
+
Bundler.require
|
11
|
+
|
12
|
+
if defined? Rails
|
13
|
+
require 'rails_app/rails_app'
|
14
|
+
#require 'rspec/rails'
|
15
|
+
end
|
16
|
+
|
17
|
+
# Requires supporting files with custom matchers and macros, etc,
|
18
|
+
# in ./support/ and its subdirectories.
|
19
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
20
|
+
|
21
|
+
RSpec.configure do |config|
|
22
|
+
# config.mock_with :rr
|
23
|
+
end
|
data/spec/tasks_spec.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'rake'
|
4
|
+
|
5
|
+
describe 'Tasks' do
|
6
|
+
before(:all) do
|
7
|
+
@rake = Rake::Application.new
|
8
|
+
Rake.application = @rake
|
9
|
+
Rake.application.rake_require('tasks', ["#{Staticman.root}/lib/staticman/"])
|
10
|
+
Rake::Task.define_task(:environment)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'staticman:build' do
|
14
|
+
before do
|
15
|
+
@rake['staticman:build'].execute
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:errors_file_path) { "#{Rails.root}/public/errors.html" }
|
19
|
+
let(:welcome_file_path) { "#{Rails.root}/public/welcome.html" }
|
20
|
+
it { File.should exist(errors_file_path) }
|
21
|
+
it { File.should exist(welcome_file_path) }
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'staticman:destroy' do
|
25
|
+
before do
|
26
|
+
@rake['staticman:build'].execute
|
27
|
+
@rake['staticman:destroy'].execute
|
28
|
+
end
|
29
|
+
|
30
|
+
let(:errors_file_path) { "#{Rails.root}/public/errors.html" }
|
31
|
+
let(:welcome_file_path) { "#{Rails.root}/public/welcome.html" }
|
32
|
+
let(:index_file_path) { "#{Rails.root}/public/index.html" }
|
33
|
+
it { File.should_not exist(errors_file_path) }
|
34
|
+
it { File.should_not exist(welcome_file_path) }
|
35
|
+
it { File.should exist(index_file_path) }
|
36
|
+
end
|
37
|
+
end
|
data/staticman.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'staticman/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "staticman"
|
8
|
+
gem.version = Staticman::VERSION
|
9
|
+
gem.authors = ["terut"]
|
10
|
+
gem.email = ["terut.dev+github@gmail.com"]
|
11
|
+
gem.description = %q{Staticman build static pages, e.g. errors, about, contact, and it's very easy, fast, programable}
|
12
|
+
gem.summary = %q{A builder for static pages with template engine}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
%w{ actionpack activesupport railties }.each do |g|
|
21
|
+
gem.add_dependency g, ['>= 3.2.0']
|
22
|
+
end
|
23
|
+
|
24
|
+
gem.add_development_dependency 'bundler', ['>= 1.0.0']
|
25
|
+
gem.add_development_dependency 'rake', ['>= 0']
|
26
|
+
gem.add_development_dependency 'tzinfo', ['>= 0']
|
27
|
+
gem.add_development_dependency 'rspec', ['>= 0']
|
28
|
+
gem.add_development_dependency 'pry', ['>= 0']
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,228 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: staticman
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- terut
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: actionpack
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.2.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.2.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: activesupport
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 3.2.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 3.2.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: railties
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 3.2.0
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.2.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: bundler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.0.0
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.0.0
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rake
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: tzinfo
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rspec
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: pry
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
description: Staticman build static pages, e.g. errors, about, contact, and it's very
|
143
|
+
easy, fast, programable
|
144
|
+
email:
|
145
|
+
- terut.dev+github@gmail.com
|
146
|
+
executables: []
|
147
|
+
extensions: []
|
148
|
+
extra_rdoc_files: []
|
149
|
+
files:
|
150
|
+
- .gitignore
|
151
|
+
- .rspec
|
152
|
+
- Gemfile
|
153
|
+
- LICENSE.txt
|
154
|
+
- README.md
|
155
|
+
- Rakefile
|
156
|
+
- lib/generators/staticman/config_generator.rb
|
157
|
+
- lib/generators/staticman/templates/config.rb
|
158
|
+
- lib/staticman.rb
|
159
|
+
- lib/staticman/configurable.rb
|
160
|
+
- lib/staticman/controller.rb
|
161
|
+
- lib/staticman/performer.rb
|
162
|
+
- lib/staticman/railtie.rb
|
163
|
+
- lib/staticman/request.rb
|
164
|
+
- lib/staticman/tasks.rake
|
165
|
+
- lib/staticman/version.rb
|
166
|
+
- lib/staticman/view_silencer.rb
|
167
|
+
- spec/controller_spec.rb
|
168
|
+
- spec/performer_spec.rb
|
169
|
+
- spec/rails_app/app/helpers/application_helper.rb
|
170
|
+
- spec/rails_app/app/helpers/welcome_helper.rb
|
171
|
+
- spec/rails_app/app/views/errors.html.erb
|
172
|
+
- spec/rails_app/app/views/layouts/application.html.erb
|
173
|
+
- spec/rails_app/app/views/layouts/welcome.html.erb
|
174
|
+
- spec/rails_app/app/views/no_methods.html.erb
|
175
|
+
- spec/rails_app/app/views/welcome.html.erb
|
176
|
+
- spec/rails_app/config/staticman.rb
|
177
|
+
- spec/rails_app/public/index.html
|
178
|
+
- spec/rails_app/rails_app.rb
|
179
|
+
- spec/request_spec.rb
|
180
|
+
- spec/spec_helper.rb
|
181
|
+
- spec/tasks_spec.rb
|
182
|
+
- staticman.gemspec
|
183
|
+
homepage: ''
|
184
|
+
licenses: []
|
185
|
+
post_install_message:
|
186
|
+
rdoc_options: []
|
187
|
+
require_paths:
|
188
|
+
- lib
|
189
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
190
|
+
none: false
|
191
|
+
requirements:
|
192
|
+
- - ! '>='
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
segments:
|
196
|
+
- 0
|
197
|
+
hash: 1949611760368093083
|
198
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
199
|
+
none: false
|
200
|
+
requirements:
|
201
|
+
- - ! '>='
|
202
|
+
- !ruby/object:Gem::Version
|
203
|
+
version: '0'
|
204
|
+
segments:
|
205
|
+
- 0
|
206
|
+
hash: 1949611760368093083
|
207
|
+
requirements: []
|
208
|
+
rubyforge_project:
|
209
|
+
rubygems_version: 1.8.23
|
210
|
+
signing_key:
|
211
|
+
specification_version: 3
|
212
|
+
summary: A builder for static pages with template engine
|
213
|
+
test_files:
|
214
|
+
- spec/controller_spec.rb
|
215
|
+
- spec/performer_spec.rb
|
216
|
+
- spec/rails_app/app/helpers/application_helper.rb
|
217
|
+
- spec/rails_app/app/helpers/welcome_helper.rb
|
218
|
+
- spec/rails_app/app/views/errors.html.erb
|
219
|
+
- spec/rails_app/app/views/layouts/application.html.erb
|
220
|
+
- spec/rails_app/app/views/layouts/welcome.html.erb
|
221
|
+
- spec/rails_app/app/views/no_methods.html.erb
|
222
|
+
- spec/rails_app/app/views/welcome.html.erb
|
223
|
+
- spec/rails_app/config/staticman.rb
|
224
|
+
- spec/rails_app/public/index.html
|
225
|
+
- spec/rails_app/rails_app.rb
|
226
|
+
- spec/request_spec.rb
|
227
|
+
- spec/spec_helper.rb
|
228
|
+
- spec/tasks_spec.rb
|