Sha256: 2f36ce8d6efb3e98ae2659b1acc6f6fe94d4d3462a0540621b791cc06d7dd192

Contents?: true

Size: 1.69 KB

Versions: 7

Compression:

Stored size: 1.69 KB

Contents

# -*- coding: utf-8 -*-
require 'tdiary'
require 'rack/builder'
require 'tdiary/application/configuration'
require 'tdiary/rack'

# FIXME too dirty hack :-<
class CGI
	def env_table_rack
		$RACK_ENV
	end

	alias :env_table_orig :env_table
	alias :env_table :env_table_rack
end

module TDiary
	class Application
		class << self
			def configure(&block)
				instance_eval &block
			end

			def config
				@config ||= Configuration.new
			end
		end

		def initialize( base_dir = '/' )
			@app = ::Rack::Builder.app {
				map base_dir do
					Application.config.builder_procs.each do |builder_proc|
						instance_eval &builder_proc
					end
				end
			}
		end

		def call( env )
			@app.call( env )
		end
	end

	Application.configure do
		config.builder do
			map Application.config.path[:index] do
				use TDiary::Rack::HtmlAnchor
				use TDiary::Rack::Static, "public"
				use TDiary::Rack::ValidRequestPath
				run TDiary::Dispatcher.index
			end

			map Application.config.path[:update] do
				instance_eval &Application.config.authenticate_proc
				run TDiary::Dispatcher.update
			end

			map Application.config.path[:assets] do
				environment = Sprockets::Environment.new
				TDiary::Extensions::constants.map {|extension|
					TDiary::Extensions::const_get( extension ).assets_path
				}.flatten.uniq.each {|assets_path|
					environment.append_path assets_path
				}

				if Application.config.assets_precompile
					require 'tdiary/rack/assets/precompile'
					use TDiary::Rack::Assets::Precompile, environment
				end

				run environment
			end
		end

		config.authenticate TDiary::Rack::Auth::Basic, '.htpasswd'
	end
end

# Local Variables:
# mode: ruby
# indent-tabs-mode: t
# tab-width: 3
# ruby-indent-level: 3
# End:

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
tdiary-4.1.0 lib/tdiary/application.rb
tdiary-4.1.0.20141126 lib/tdiary/application.rb
tdiary-4.0.5.1 tdiary/application.rb
tdiary-4.0.5 tdiary/application.rb
tdiary-4.0.4 tdiary/application.rb
tdiary-4.0.3 tdiary/application.rb
tdiary-4.0.2.20140201 tdiary/application.rb