Class: TDiary::Dispatcher::IndexMain
- Inherits:
-
Object
- Object
- TDiary::Dispatcher::IndexMain
- Defined in:
- lib/tdiary/dispatcher/index_main.rb
Instance Attribute Summary collapse
-
#cgi ⇒ Object
readonly
Returns the value of attribute cgi.
-
#conf ⇒ Object
readonly
Returns the value of attribute conf.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#tdiary ⇒ Object
readonly
Returns the value of attribute tdiary.
Class Method Summary collapse
Instance Method Summary collapse
- #create_tdiary ⇒ Object
-
#initialize(request) ⇒ IndexMain
constructor
A new instance of IndexMain.
- #run ⇒ Object
Constructor Details
#initialize(request) ⇒ IndexMain
10 11 12 13 14 15 |
# File 'lib/tdiary/dispatcher/index_main.rb', line 10 def initialize( request ) @request = request @cgi = request.cgi_compat @conf = TDiary::Configuration::new( request ) @params = request.params end |
Instance Attribute Details
#cgi ⇒ Object (readonly)
Returns the value of attribute cgi.
8 9 10 |
# File 'lib/tdiary/dispatcher/index_main.rb', line 8 def cgi @cgi end |
#conf ⇒ Object (readonly)
Returns the value of attribute conf.
8 9 10 |
# File 'lib/tdiary/dispatcher/index_main.rb', line 8 def conf @conf end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
8 9 10 |
# File 'lib/tdiary/dispatcher/index_main.rb', line 8 def params @params end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
8 9 10 |
# File 'lib/tdiary/dispatcher/index_main.rb', line 8 def request @request end |
#tdiary ⇒ Object (readonly)
Returns the value of attribute tdiary.
8 9 10 |
# File 'lib/tdiary/dispatcher/index_main.rb', line 8 def tdiary @tdiary end |
Class Method Details
.run(request) ⇒ Object
4 5 6 |
# File 'lib/tdiary/dispatcher/index_main.rb', line 4 def self.run( request ) new( request ).run end |
Instance Method Details
#create_tdiary ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/tdiary/dispatcher/index_main.rb', line 60 def create_tdiary begin if params['comment'] tdiary = TDiary::TDiaryComment::new( request, "day.rhtml", conf ) elsif params['plugin'] tdiary = TDiary::TDiaryPluginView::new( request, '', conf ) elsif (date = params['date']) if /^\d{8}-\d+$/ =~ date tdiary = TDiary::TDiaryLatest::new( request, "latest.rhtml", conf ) elsif /^\d{8}$/ =~ date tdiary = TDiary::TDiaryDay::new( request, "day.rhtml", conf ) elsif /^\d{6}$/ =~ date tdiary = TDiary::TDiaryMonth::new( request, "month.rhtml", conf ) elsif /^\d{4}$/ =~ date tdiary = TDiary::TDiaryNYear::new( request, "month.rhtml", conf ) end elsif params['category'] tdiary = TDiary::TDiaryCategoryView::new( request, "category.rhtml", conf ) elsif params['q'] tdiary = TDiary::TDiarySearch::new( request, "search.rhtml", conf ) else tdiary = TDiary::TDiaryLatest::new( request, "latest.rhtml", conf ) end rescue TDiary::PermissionError raise rescue TDiary::TDiaryError end ( tdiary ? tdiary : TDiary::TDiaryLatest::new( request, "latest.rhtml", conf ) ) end |
#run ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/tdiary/dispatcher/index_main.rb', line 17 def run begin @tdiary = create_tdiary begin status = 200 head = { 'content-type' => 'text/html; charset=UTF-8', 'vary' => 'User-Agent' } body = '' head['last-modified'] = tdiary.last_modified.httpdate if request.head? head['cache-control'] = 'no-cache' return TDiary::Response.new( '', 200, head ) else require 'openssl' body = tdiary.eval_rhtml head['etag'] = %Q["#{OpenSSL::Digest::SHA256.hexdigest( body )}"] if request.env['HTTP_IF_NONE_MATCH'] == head['etag'] and request.get? then status = 304 else head['content-length'] = body.bytesize.to_s end head['cache-control'] = 'no-cache' res = TDiary::Response.new( body, status, head ) res.set_header('Set-Cookie', tdiary..map(&:to_s)) if tdiary && tdiary..size > 0 res end rescue TDiary::NotFound body = %Q[ <h1>404 Not Found</h1> <div>#{' ' * 500}</div>] TDiary::Response.new( body, 404, { 'content-type' => 'text/html' } ) end rescue TDiary::ForceRedirect res = TDiary::Response.new( '', 303, { 'location' => $!.path } ) res.set_header('Set-Cookie', tdiary..map(&:to_s)) if tdiary && tdiary..size > 0 res end end |