-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
plugin 機構で config.ru を操作 #315
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
805f64c
TDiary::Application has self routing logic (move from config.ru)
machu 45f1ac9
Rack::Builder.app creates the rack app only once
machu 055271f
add Static middleware to serve static file
machu fdca5b0
add Application::Configuration class
machu c560b88
Merge branch 'master' into routing
machu 2425536
Merge branch 'master' into routing
machu 9cdff91
implement builder interface to add routing and middlewares from plugin
machu 40f130c
base_dir can not accept an empty path
machu 2f2bc47
use autoload to load TDiary::Rack middleware
machu b8194ad
rename tDiary application extensions
machu 41b7eac
construct self routing via config.builder
machu 88c63b9
implement authenticate interface to change auth middleware
machu abbecd7
specify the sprokets gem in gemspec
machu 8868d9b
gemspec dependency doesn't load library automatically
machu a9941ab
require sprokets also in acceptance helper
machu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,7 @@ | ||
$:.unshift( File::dirname( __FILE__ ).untaint ) | ||
require 'tdiary/environment' | ||
require 'tdiary/application' | ||
|
||
require 'tdiary' | ||
require 'tdiary/rack/html_anchor' | ||
require 'tdiary/rack/valid_request_path' | ||
require 'tdiary/rack/auth/basic' | ||
require 'omniauth' | ||
require 'tdiary/rack/auth/omniauth' | ||
|
||
use Rack::Reloader unless ENV['RACK_ENV'] == 'production' | ||
|
||
base_dir = '' | ||
|
||
# OmniAuth settings | ||
use Rack::Session::Pool, :expire_after => 2592000 | ||
use OmniAuth::Builder do | ||
configure {|conf| conf.path_prefix = "#{base_dir}/auth" } | ||
# provider :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET'] | ||
# provider :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET'] | ||
end | ||
map "#{base_dir}/auth" do | ||
run TDiary::Rack::Auth::OmniAuth::CallbackHandler.new | ||
end | ||
|
||
map "#{base_dir}/update.rb" do | ||
# Basic Auth | ||
use TDiary::Rack::Auth::Basic, '.htpasswd' | ||
|
||
# OAuth | ||
# use TDiary::Rack::Auth::OmniAuth, :twitter do |auth| | ||
# auth.info.nickname == 'your_twitter_screen_name' | ||
# end | ||
|
||
run TDiary::Application.new(:update) | ||
end | ||
|
||
map "#{base_dir}/assets" do | ||
environment = Sprockets::Environment.new | ||
%w(js theme).each {|path| environment.append_path File.join(TDiary.root, path) } | ||
|
||
# FIXME: dirty hack, it should create TDiary::Server::Config.assets_path | ||
TDiary::Contrib::Assets.setup(environment) if defined?(TDiary::Contrib) | ||
|
||
# if you need to auto compilation for CoffeeScript | ||
# require 'tdiary/rack/assets/precompile' | ||
# use TDiary::Rack::Assets::Precompile, environment | ||
|
||
run environment | ||
end | ||
|
||
map "#{base_dir}/" do | ||
use TDiary::Rack::HtmlAnchor | ||
run Rack::Cascade.new([ | ||
Rack::File.new("./public/"), | ||
TDiary::Rack::ValidRequestPath.new(TDiary::Application.new(:index)) | ||
]) | ||
end | ||
|
||
# Local Variables: | ||
# mode: ruby | ||
# indent-tabs-mode: t | ||
# tab-width: 3 | ||
# ruby-indent-level: 3 | ||
# End: | ||
use ::Rack::Reloader unless ENV['RACK_ENV'] == 'production' | ||
base_dir = '/' | ||
run TDiary::Application.new( base_dir ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'spec_helper' | ||
require 'rack/test' | ||
require 'tdiary/rack/static' | ||
|
||
describe TDiary::Rack::Static do | ||
include Rack::Test::Methods | ||
|
||
describe "reserve static files" do | ||
let(:app) { TDiary::Rack::Static.new( | ||
lambda{|env| [500, {}, ['Internal Server Error']]}, 'doc')} | ||
|
||
it 'should return the file in static directory' do | ||
get '/README.md' | ||
last_response.should be_ok | ||
end | ||
|
||
it 'should run the app if file is not exist' do | ||
get '/index.rb' | ||
last_response.status.should be 500 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module TDiary | ||
class Application | ||
class Configuration | ||
attr_accessor :assets_paths, :assets_precompile, :plugin_paths, :path, :builder_procs, :authenticate_proc | ||
|
||
def initialize | ||
@assets_paths = [] | ||
# if you need to auto compilation for CoffeeScript | ||
@assets_precompile = false; | ||
@plugin_paths = [] | ||
@path = { | ||
index: '/', | ||
update: '/update.rb', | ||
assets: '/assets' | ||
} | ||
@builder_procs = [] | ||
@authenticate_proc = proc { } | ||
end | ||
|
||
def builder(&block) | ||
@builder_procs << block | ||
end | ||
|
||
def authenticate(middleware, *params, &block) | ||
@authenticate_proc = proc { use middleware, *params, &block } | ||
end | ||
end | ||
end | ||
end | ||
|
||
# Local Variables: | ||
# mode: ruby | ||
# indent-tabs-mode: t | ||
# tab-width: 3 | ||
# ruby-indent-level: 3 | ||
# End: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# -*- coding: utf-8 -*- | ||
require 'tdiary/application' | ||
require 'tdiary/rack/auth/omniauth' | ||
|
||
TDiary::Application.configure do | ||
config.builder do | ||
use ::Rack::Session::Pool, :expire_after => 2592000 | ||
use OmniAuth::Builder do | ||
configure {|conf| conf.path_prefix = "/auth" } | ||
provider :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET'] | ||
provider :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET'] | ||
end | ||
|
||
map('/auth') do | ||
run TDiary::Rack::Auth::OmniAuth::CallbackHandler.new | ||
end | ||
end | ||
|
||
config.authenticate TDiary::Rack::Auth::OmniAuth, :twitter do |auth| | ||
# TODO: an user can setting | ||
auth.info.nickname == 'your_twitter_screen_name' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これは cool ですねえ