Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

merge tdiary-request

  • Loading branch information...
commit 1738964873d58bac736ec2b30f685c766ffc669c 1 parent 99ee5eb
@hsbt hsbt authored
View
3  ChangeLog
@@ -30,6 +30,9 @@
2011-07-05 TADA Tadashi <t@tdtds.jp>
* saved preferences in ajax.
+2011-07-03 SHIBATA Hiroshi <shibata.hiroshi@gmail.com>
+ * merge tdiary-request. use Rack like interface when cgi mode.
+
2011-06-25 TADA Tadashi <t@tdtds.jp>
* plugin/image.rb, js/image.js: using jQuery to insert image tags. #54
* plugin/image.rb: fixed encoding error on ruby 1.9.
View
1  Rakefile
@@ -3,7 +3,6 @@
require File.expand_path('../tdiary/environment', __FILE__)
require 'rake'
require 'rake/clean'
-require 'rake/testtask'
require 'rspec/core/rake_task'
CLEAN.include(
View
2  config.ru
@@ -1,5 +1,5 @@
$:.unshift( File::dirname( __FILE__ ).untaint )
-require 'tdiary/tdiary_application'
+require 'tdiary/application'
use Rack::Reloader
use Rack::Static, :urls => ["/theme"], :root => "."
View
5 index.rb
@@ -20,7 +20,7 @@
org_path = File::dirname( __FILE__ ).untaint
end
$:.unshift( org_path ) unless $:.include?( org_path )
- require 'tdiary/dispatcher'
+ require 'tdiary'
encoding_error = {}
cgi = CGI::new(:accept_charset => "UTF-8") do |name, value|
@@ -32,7 +32,8 @@
@cgi = CGI::new(:accept_charset => 'shift_jis')
@cgi.params = cgi.params
end
- status, headers, body = TDiary::Dispatcher.index.dispatch_cgi( @cgi )
+ request = TDiary::Request.new( ENV, @cgi )
+ status, headers, body = TDiary::Dispatcher.index.dispatch_cgi( request, @cgi )
headers['type'] = headers.delete('Content-Type')
TDiary::Dispatcher.send_headers( status, headers )
TDiary::Dispatcher.send_body( body )
View
2  spec/acceptance_helper.rb
@@ -1,5 +1,4 @@
require 'spec_helper'
-require 'tdiary/tdiary_application'
Dir["#{File.dirname(__FILE__)}/acceptance/support/**/*.rb"].each {|f| require f}
@@ -32,6 +31,7 @@
Capybara.app_host = 'http://localhost:19292'
RSpec.configuration.filter_run_excluding :mechanize => true
else
+ require 'tdiary/application'
Capybara.default_driver = :rack_test
Capybara.app = Rack::Builder.new do
map '/' do
View
16 tdiary.rb
@@ -22,6 +22,7 @@
require 'erb'
end
require 'tdiary/compatible'
+require 'tdiary/request_extension'
require 'tdiary/core_ext'
#
@@ -30,12 +31,15 @@
module TDiary
PATH = File::dirname( __FILE__ ).untaint
- autoload :Config, 'tdiary/config'
- autoload :Plugin, 'tdiary/plugin'
- autoload :Comment, 'tdiary/comment'
- autoload :CommentManager, 'tdiary/comment_manager'
- autoload :RefererManager, 'tdiary/referer_manager'
- autoload :Filter, 'tdiary/filter'
+ autoload :Config, 'tdiary/config'
+ autoload :Plugin, 'tdiary/plugin'
+ autoload :Comment, 'tdiary/comment'
+ autoload :CommentManager, 'tdiary/comment_manager'
+ autoload :RefererManager, 'tdiary/referer_manager'
+ autoload :Filter, 'tdiary/filter'
+ autoload :Dispatcher, 'tdiary/dispatcher'
+ autoload :Request, 'tdiary/request'
+ autoload :Response, 'tdiary/response'
#
# module DiaryBase
View
35 tdiary/tdiary_application.rb → tdiary/application.rb
@@ -2,10 +2,7 @@
require File.expand_path('../environment', __FILE__)
Bundler.require :default if defined?(Bundler)
-require 'rack/request'
-require 'rack/response'
-
-require 'tdiary/dispatcher'
+require 'tdiary'
# FIXME too dirty hack :-<
class CGI
@@ -24,11 +21,25 @@ def initialize( target )
end
def call( env )
- adopt_rack_request_to_plain_old_tdiary_style( env )
- dispatch_request
+ req = adopt_rack_request_to_plain_old_tdiary_style( env )
+ dispatch_request( req )
end
private
+ def adopt_rack_request_to_plain_old_tdiary_style( env )
+ req = TDiary::Request.new( env )
+ req.params # fill params to tdiary_request
+ $RACK_ENV = req.env
+ env["rack.input"].rewind
+ fake_stdin_as_params
+ req
+ end
+
+ def dispatch_request( request )
+ dispatcher = TDiary::Dispatcher.__send__( @target )
+ dispatcher.dispatch_cgi( request )
+ end
+
def fake_stdin_as_params
stdin_spy = StringIO.new( "" )
# FIXME dirty hack
@@ -38,18 +49,6 @@ def fake_stdin_as_params
end
$stdin = stdin_spy
end
-
- def adopt_rack_request_to_plain_old_tdiary_style( env )
- req = Rack::Request.new( env )
- $RACK_ENV = req.env
- env["rack.input"].rewind
- fake_stdin_as_params
- end
-
- def dispatch_request
- dispatcher = TDiary::Dispatcher.__send__( @target )
- dispatcher.dispatch_cgi( CGI.new )
- end
end
end
View
49 tdiary/config.rb
@@ -5,26 +5,11 @@
#
module TDiary
class Config
- def initialize(cgi)
- @cgi = cgi
- load
-
- instance_variables.each do |v|
- v = v.to_s.sub( /@/, '' )
- instance_eval( <<-SRC
- def #{v}
- @#{v}
- end
- def #{v}=(p)
- @#{v} = p
- end
- SRC
- )
- end
-
- bot = ["bot", "spider", "antenna", "crawler", "moget", "slurp"]
- bot += @options['bot'] || []
- @bot = Regexp::new( "(#{bot.uniq.join( '|' )})", true )
+ def initialize( cgi, request = nil )
+ @cgi, @request = cgi, request
+ configure_attrs
+ configure_bot_pattern
+ setup_attr_accessor_to_all_ivars
end
# saving to tdiary.conf in @data_path
@@ -94,8 +79,8 @@ def base_url_auto
end
private
- # loading tdiary.conf in current directory(index.rb or update.rb path)
- def load
+ # loading tdiary.conf in current directory
+ def configure_attrs
@secure = true unless @secure
@options = {}
@@ -219,6 +204,26 @@ def load_cgi_conf
end
private
+ def setup_attr_accessor_to_all_ivars
+ instance_variables.each do |ivar_sym|
+ v = ivar_sym.to_s.sub( /@/, '' )
+ instance_eval( <<-SRC
+ def #{v}
+ @#{v}
+ end
+ def #{v}=(p)
+ @#{v} = p
+ end
+ SRC
+ )
+ end
+ end
+
+ def configure_bot_pattern
+ bot = ["bot", "spider", "antenna", "crawler", "moget", "slurp"]
+ bot += @options['bot'] || []
+ @bot = Regexp::new( "(#{bot.uniq.join( '|' )})", true )
+ end
def method_missing( *m )
if m.length == 1 then
View
10 tdiary/core_ext.rb
@@ -27,18 +27,12 @@ def make_link
enhanced CGI class
=end
class CGI
+ include TDiary::RequestExtension
+
def valid?( param, idx = 0 )
self.params[param] and self.params[param][idx] and self.params[param][idx].length > 0
end
- def mobile_agent?
- self.user_agent =~ %r[(DoCoMo|J-PHONE|Vodafone|MOT-|UP\.Browser|DDIPOCKET|ASTEL|PDXGW|Palmscape|Xiino|sharp pda browser|Windows CE|L-mode|WILLCOM|SoftBank|Semulator|Vemulator|J-EMULATOR|emobile|mixi-mobile-converter)]i
- end
-
- def smartphone?
- self.user_agent =~ /iPhone|iPod|Opera Mini|Android.*Mobile|NetFront|PSP/
- end
-
def https?
return false if env_table['HTTPS'].nil? or /off/i =~ env_table['HTTPS']
true
View
25 tdiary/dispatcher.rb
@@ -1,8 +1,5 @@
# -*- coding: utf-8; -*-
-
require 'stringio'
-require 'tdiary'
-require 'tdiary/tdiary_response'
module TDiary
class Dispatcher
@@ -19,17 +16,11 @@ def initialize( target )
@target = TARGET[target]
end
- def dispatch_cgi( cgi = CGI.new, raw_result = StringIO.new, dummy_stderr = StringIO.new )
- stdout_orig = $stdout; stderr_orig = $stderr
- begin
- $stdout = raw_result; $stderr = dummy_stderr
- result = @target.run( cgi )
- result.headers.reject!{|k,v| k.to_s.downcase == "status" }
- result.to_a
- ensure
- $stdout = stdout_orig
- $stderr = stderr_orig
- end
+ # FIXME rename method name to more suitable one.
+ def dispatch_cgi( request, cgi = CGI.new )
+ result = @target.run( request, cgi )
+ result.headers.reject!{|k,v| k.to_s.downcase == "status" }
+ result.to_a
end
class << self
@@ -56,8 +47,10 @@ def send_body( body )
end
# FIXME temporary method during (scratch) refactoring
- def extract_status_for_legacy_tdiary( status_str )
- return 200 unless status_str
+ def extract_status_for_legacy_tdiary( head )
+ status_str = head.delete('status')
+ return 200 if !status_str || status_str.empty?
+
if m = status_str.match(/(\d+)\s(.+)\Z/)
m[1].to_i
else
View
88 tdiary/dispatcher/index_main.rb
@@ -1,40 +1,24 @@
# -*- coding: utf-8; -*-
module TDiary
- class Dispatcher
+ class Dispatcher
class IndexMain
- def self.run( cgi )
+ def self.run( request, cgi )
+ new( request, cgi ).run
+ end
+
+ attr_reader :request, :cgi, :conf, :tdiary, :params
+
+ def initialize( request, cgi )
+ @request = request
+ @cgi = cgi
+ @conf = TDiary::Config::new( cgi, request )
+ @params = request.params
+ end
+
+ def run
begin
- @cgi = cgi
- conf = TDiary::Config::new(@cgi)
- tdiary = nil
status = nil
-
- begin
- if @cgi.valid?( 'comment' ) then
- tdiary = TDiary::TDiaryComment::new( @cgi, "day.rhtml", conf )
- elsif @cgi.valid?( 'date' )
- date = @cgi.params['date'][0]
- if /^\d{8}-\d+$/ =~ date then
- tdiary = TDiary::TDiaryLatest::new( @cgi, "latest.rhtml", conf )
- elsif /^\d{8}$/ =~ date then
- tdiary = TDiary::TDiaryDay::new( @cgi, "day.rhtml", conf )
- elsif /^\d{6}$/ =~ date then
- tdiary = TDiary::TDiaryMonth::new( @cgi, "month.rhtml", conf )
- elsif /^\d{4}$/ =~ date then
- tdiary = TDiary::TDiaryNYear::new( @cgi, "month.rhtml", conf )
- end
- elsif @cgi.valid?( 'category' )
- tdiary = TDiary::TDiaryCategoryView::new( @cgi, "category.rhtml", conf )
- elsif @cgi.valid?( 'q' )
- tdiary = TDiary::TDiarySearch::new( @cgi, "search.rhtml", conf )
- else
- tdiary = TDiary::TDiaryLatest::new( @cgi, "latest.rhtml", conf )
- end
- rescue TDiary::PermissionError
- raise
- rescue TDiary::TDiaryError
- end
- tdiary = TDiary::TDiaryLatest::new( @cgi, "latest.rhtml", conf ) if not tdiary
+ @tdiary = create_tdiary
begin
head = {
@@ -45,12 +29,12 @@ def self.run( cgi )
body = ''
head['Last-Modified'] = CGI::rfc1123_date( tdiary.last_modified )
- if /HEAD/i =~ @cgi.request_method then
+ if request.head?
head['Pragma'] = 'no-cache'
head['Cache-Control'] = 'no-cache'
return TDiary::Response.new( '', 200, head )
else
- if @cgi.mobile_agent? then
+ if request.mobile_agent?
body = conf.to_mobile( tdiary.eval_rhtml( 'i.' ) )
head['charset'] = conf.mobile_encoding
head['Content-Length'] = body.bytesize.to_s
@@ -58,7 +42,7 @@ def self.run( cgi )
require 'digest/md5'
body = tdiary.eval_rhtml
head['ETag'] = %Q["#{Digest::MD5.hexdigest( body )}"]
- if ENV['HTTP_IF_NONE_MATCH'] == head['ETag'] and /^GET$/i =~ @cgi.request_method then
+ if ENV['HTTP_IF_NONE_MATCH'] == head['ETag'] and request.get? then
status = CGI::HTTP_STATUS['NOT_MODIFIED']
body = ''
else
@@ -70,7 +54,7 @@ def self.run( cgi )
head['X-Frame-Options'] = conf.x_frame_options if conf.x_frame_options
end
head['cookie'] = tdiary.cookies if tdiary.cookies.size > 0
- TDiary::Response.new( body, ::TDiary::Dispatcher.extract_status_for_legacy_tdiary( status ), head )
+ TDiary::Response.new( body, ::TDiary::Dispatcher.extract_status_for_legacy_tdiary( head ), head )
end
rescue TDiary::NotFound
body = %Q[
@@ -83,7 +67,6 @@ def self.run( cgi )
#'Location' => $!.path
'Content-Type' => 'text/html',
}
- head['cookie'] = tdiary.cookies if tdiary && tdiary.cookies.size > 0
body = %Q[
<html>
<head>
@@ -92,12 +75,41 @@ def self.run( cgi )
</head>
<body>Wait or <a href="#{$!.path}">Click here!</a></body>
</html>]
+ head['cookie'] = tdiary.cookies if tdiary && tdiary.cookies.size > 0
# TODO return code should be 302? (current behaviour returns 200)
TDiary::Response.new( body, 200, head )
end
end
+
+ def create_tdiary
+ begin
+ if params['comment']
+ tdiary = TDiary::TDiaryComment::new( cgi, "day.rhtml", conf )
+ elsif (date = params['date'])
+ if /^\d{8}-\d+$/ =~ date
+ tdiary = TDiary::TDiaryLatest::new( cgi, "latest.rhtml", conf )
+ elsif /^\d{8}$/ =~ date
+ tdiary = TDiary::TDiaryDay::new( cgi, "day.rhtml", conf )
+ elsif /^\d{6}$/ =~ date
+ tdiary = TDiary::TDiaryMonth::new( cgi, "month.rhtml", conf )
+ elsif /^\d{4}$/ =~ date
+ tdiary = TDiary::TDiaryNYear::new( cgi, "month.rhtml", conf )
+ end
+ elsif params['category']
+ tdiary = TDiary::TDiaryCategoryView::new( cgi, "category.rhtml", conf )
+ elsif params['q']
+ tdiary = TDiary::TDiarySearch::new( cgi, "search.rhtml", conf )
+ else
+ tdiary = TDiary::TDiaryLatest::new( cgi, "latest.rhtml", conf )
+ end
+ rescue TDiary::PermissionError
+ raise
+ rescue TDiary::TDiaryError
+ end
+ ( tdiary ? tdiary : TDiary::TDiaryLatest::new( cgi, "latest.rhtml", conf ) )
+ end
end
- end
+ end
end
# Local Variables:
View
85 tdiary/dispatcher/update_main.rb
@@ -1,43 +1,27 @@
# -*- coding: utf-8; -*-
module TDiary
- class Dispatcher
+ class Dispatcher
class UpdateMain
- def self.run( cgi )
+ def self.run( request, cgi )
+ new( request, cgi ).run
+ end
+
+ attr_reader :request, :cgi, :conf, :tdiary, :params
+
+ def initialize( request, cgi )
+ @request = request
@cgi = cgi
- conf = TDiary::Config::new(@cgi)
- tdiary = nil
- begin
- if @cgi.valid?( 'append' )
- tdiary = TDiary::TDiaryAppend::new( @cgi, 'show.rhtml', conf )
- elsif @cgi.valid?( 'edit' )
- tdiary = TDiary::TDiaryEdit::new( @cgi, 'update.rhtml', conf )
- elsif @cgi.valid?( 'replace' )
- tdiary = TDiary::TDiaryReplace::new( @cgi, 'show.rhtml', conf )
- elsif @cgi.valid?( 'appendpreview' ) or @cgi.valid?( 'replacepreview' )
- tdiary = TDiary::TDiaryPreview::new( @cgi, 'preview.rhtml', conf )
- elsif @cgi.valid?( 'plugin' )
- tdiary = TDiary::TDiaryFormPlugin::new( @cgi, 'update.rhtml', conf )
- elsif @cgi.valid?( 'comment' )
- tdiary = TDiary::TDiaryShowComment::new( @cgi, 'update.rhtml', conf )
- elsif @cgi.valid?( 'saveconf' )
- tdiary = TDiary::TDiarySaveConf::new( @cgi, 'conf.rhtml', conf )
- elsif @cgi.valid?( 'conf' )
- tdiary = TDiary::TDiaryConf::new( @cgi, 'conf.rhtml', conf )
- elsif @cgi.valid?( 'referer' )
- tdiary = TDiary::TDiaryConf::new( @cgi, 'referer.rhtml', conf )
- else
- tdiary = TDiary::TDiaryForm::new( @cgi, 'update.rhtml', conf )
- end
- rescue TDiary::TDiaryError
- tdiary = TDiary::TDiaryForm::new( @cgi, 'update.rhtml', conf )
- end
+ @conf = TDiary::Config::new( cgi, request )
+ @params = request.params
+ end
+ def run
+ @tdiary = create_tdiary
begin
- head = body = ''
- if @cgi.mobile_agent? then
+ head = {}; body = ''
+ if request.mobile_agent?
body = conf.to_mobile( tdiary.eval_rhtml( 'i.' ) )
head = {
- 'status' => '200 OK',
'Content-Type' => 'text/html',
'charset' => conf.mobile_encoding,
'Content-Length' => body.bytesize.to_s,
@@ -46,21 +30,19 @@ def self.run( cgi )
else
body = tdiary.eval_rhtml
head = {
- 'status' => '200 OK',
'Content-Type' => 'text/html',
'charset' => conf.encoding,
'Content-Length' => body.bytesize.to_s,
'Vary' => 'User-Agent'
}
end
- body = ( /HEAD/i !~ @cgi.request_method ? body : '' )
+ body = ( request.head? ? '' : body )
TDiary::Response.new( body, 200, head )
rescue TDiary::ForceRedirect
head = {
#'Location' => $!.path
'Content-Type' => 'text/html',
}
- head['cookie'] = tdiary.cookies if tdiary.cookies.size > 0
body = %Q[
<html>
<head>
@@ -69,12 +51,43 @@ def self.run( cgi )
</head>
<body>Wait or <a href="#{$!.path}">Click here!</a></body>
</html>]
+ head['cookie'] = tdiary.cookies if tdiary.cookies.size > 0
# TODO return code should be 302? (current behaviour returns 200)
TDiary::Response.new( body, 200, head )
end
end
+
+ private
+ def create_tdiary
+ begin
+ if params['append']
+ tdiary = TDiary::TDiaryAppend::new( cgi, 'show.rhtml', conf )
+ elsif params['edit']
+ tdiary = TDiary::TDiaryEdit::new( cgi, 'update.rhtml', conf )
+ elsif params['replace']
+ tdiary = TDiary::TDiaryReplace::new( cgi, 'show.rhtml', conf )
+ elsif params['appendpreview'] or params['replacepreview']
+ tdiary = TDiary::TDiaryPreview::new( cgi, 'preview.rhtml', conf )
+ elsif params['plugin']
+ tdiary = TDiary::TDiaryFormPlugin::new( cgi, 'update.rhtml', conf )
+ elsif params['comment']
+ tdiary = TDiary::TDiaryShowComment::new( cgi, 'update.rhtml', conf )
+ elsif params['saveconf']
+ tdiary = TDiary::TDiarySaveConf::new( cgi, 'conf.rhtml', conf )
+ elsif params['conf']
+ tdiary = TDiary::TDiaryConf::new( cgi, 'conf.rhtml', conf )
+ elsif params['referer']
+ tdiary = TDiary::TDiaryConf::new( cgi, 'referer.rhtml', conf )
+ else
+ tdiary = TDiary::TDiaryForm::new( cgi, 'update.rhtml', conf )
+ end
+ rescue TDiary::TDiaryError
+ tdiary = TDiary::TDiaryForm::new( cgi, 'update.rhtml', conf )
+ end
+ tdiary
+ end
end
- end
+ end
end
# Local Variables:
View
213 tdiary/request.rb
@@ -0,0 +1,213 @@
+# -*- coding: utf-8 -*-
+# stolen from okkez http://github.com/hiki/hiki/blob/rack/hiki/request.rb
+module TDiary
+ if Object.const_defined?( :Rack )
+ Request = ::Rack::Request
+ class ::Rack::Request
+ alias remote_addr ip
+ end
+ Request.class_eval { include RequestExtension }
+ else
+ raise RuntimeError, 'Do not use CGI class!' if Object.const_defined?( :Rack )
+ # CGI を Rack::Request っぽいインターフェイスに変換する
+ class Request
+ include RequestExtension
+
+ attr_reader :env, :cgi
+ def initialize( env, cgi = CGI.new )
+ @cgi = cgi
+ @env = env
+ end
+
+ def params
+ return @params if @params
+ @params = { }
+ @cgi.params.each{|k, v|
+ v = v.uniq
+ case v.size
+ when 0
+ @params[k] = nil
+ when 1
+ @params[k] = v[0]
+ else
+ @params[k] = v
+ end
+ }
+ @params
+ end
+
+ def []( key )
+ params[key.to_s]
+ end
+
+ def []=( key, val )
+ params[key.to_s] = val
+ end
+
+ def request_method
+ @env['REQUEST_METHOD']
+ end
+
+ def header( header )
+ @cgi.header( header )
+ end
+
+ def get?
+ request_method == 'GET'
+ end
+
+ def head?
+ request_method == 'HEAD'
+ end
+
+ def post?
+ request_method == 'POST'
+ end
+
+ def put?
+ request_method == 'PUT'
+ end
+
+ def delete?
+ request_method == 'DELETE'
+ end
+
+ def xhr?
+ raise NameError, 'not implemented : xhr?'
+ end
+
+ def accept_encoding
+ raise NameError, 'not implemented : accept_encoding'
+ end
+
+ def body
+ raise NameError, 'not implemented : body'
+ end
+
+ def content_charset
+ @env['CONTENT_CHARSET']
+ end
+
+ def content_length
+ @env['CONTENT_LENGTH']
+ end
+
+ def content_type
+ @env['CONTENT_TYPE']
+ end
+
+ def remote_addr
+ @env['REMOTE_ADDR']
+ end
+
+ def cookies
+ return @cookies if @cookies
+ @cookies = { }
+ @cgi.cookies.each{|k, v|
+ case v.size
+ when 0
+ @cookies[k] = nil
+ when 1
+ @cookies[k] = v[0]
+ else
+ @cookies[k] = v
+ end
+ }
+ @cookies
+ end
+
+ def form_data?
+ raise NameError, 'not implemented : form_data?'
+ end
+
+ def fullpath
+ raise NameError, 'not implemented : fullpath'
+ end
+
+ def host
+ # Remove port number.from Rack::Response
+ ( @env["HTTP_HOST"] || @env["SERVER_NAME"] ).gsub( /:\d+\z/, '' )
+ end
+
+ def ip
+ raise NameError, 'not implemented : ip'
+ end
+
+ def media_type
+ raise NameError, 'not implemented : madia_type'
+ end
+
+ def media_type_params
+ raise NameError, 'not implemented : media_type_params'
+ end
+
+ def openid_request
+ raise NameError, 'not implemented : openid_request'
+ end
+
+ def openid_response
+ raise NameError, 'not implemented : openid_response'
+ end
+
+ def parseable_data?
+ raise NameError, 'not implemented : parseable_data?'
+ end
+
+ def path
+ raise NameError, 'not implemented : path'
+ end
+
+ def path_info
+ @env['PATH_INFO'].to_s
+ end
+
+ def path_info=( s )
+ raise NameError, 'not implemented : path_info='
+ end
+
+ def port
+ raise NameError, 'not implemented : port'
+ end
+
+ def query_string
+ raise NameError, 'not implemented : query_string'
+ end
+
+ def referer
+ raise NameError, 'not implemented : referer'
+ end
+ alias referrer referer
+
+ def schema
+ raise NameError, 'not implemented : schema'
+ end
+
+ def script_name
+ @env['SCRIPT_NAME']
+ end
+
+ def session_options
+ raise NameError, 'not implemented : session_options'
+ end
+
+ def url
+ raise NameError, 'not implemented : url'
+ end
+
+ def user_agent
+ @cgi.user_agent
+ end
+
+ def values_at( *keys )
+ raise NameError, 'not implemented : values_at'
+ end
+ end
+ end
+end
+
+# Local Variables:
+# mode: ruby
+# indent-tabs-mode: t
+# tab-width: 3
+# ruby-indent-level: 3
+# End:
View
19 tdiary/request_extension.rb
@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+module TDiary
+ module RequestExtension
+ def mobile_agent?
+ self.user_agent =~ %r[(DoCoMo|J-PHONE|Vodafone|MOT-|UP\.Browser|DDIPOCKET|ASTEL|PDXGW|Palmscape|Xiino|sharp pda browser|Windows CE|L-mode|WILLCOM|SoftBank|Semulator|Vemulator|J-EMULATOR|emobile|mixi-mobile-converter)]i
+ end
+
+ def smartphone?
+ self.user_agent =~ /iPhone|iPod|Opera Mini|Android.*Mobile|NetFront|PSP/
+ end
+ end
+end
+
+# Local Variables:
+# mode: ruby
+# indent-tabs-mode: t
+# tab-width: 3
+# ruby-indent-level: 3
+# End:
View
3  tdiary/tdiary_response.rb → tdiary/response.rb
@@ -13,9 +13,10 @@ def initialize(body = [], status = 200, headers = {}, &block)
yield self if block_given?
end
- def to_a
+ def finish
[status, headers, body]
end
+ alias to_a finish
end
end
end
View
5 update.rb
@@ -20,10 +20,11 @@
org_path = File::dirname( __FILE__ ).untaint
end
$:.unshift( org_path ) unless $:.include?( org_path )
- require 'tdiary/dispatcher'
+ require 'tdiary'
@cgi = CGI.new
- status, headers, body = TDiary::Dispatcher.update.dispatch_cgi( @cgi )
+ request = TDiary::Request.new( ENV, @cgi )
+ status, headers, body = TDiary::Dispatcher.update.dispatch_cgi( request, @cgi )
headers['type'] = headers.delete('Content-Type')
TDiary::Dispatcher.send_headers( status, headers )
TDiary::Dispatcher.send_body( body )
Please sign in to comment.
Something went wrong with that request. Please try again.