www 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 jugyo
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,79 @@
1
+ WWW
2
+ ====
3
+
4
+ World Wide Web
5
+
6
+ Usage
7
+ ----
8
+
9
+ app.rb
10
+
11
+ # encoding: utf-8
12
+ require 'www'
13
+
14
+ class Foo < Www
15
+ before do
16
+ # do something
17
+ end
18
+
19
+ get '/'
20
+ def index
21
+ "index"
22
+ end
23
+
24
+ get '/foo'
25
+ def foo(params)
26
+ params
27
+ end
28
+
29
+ get %r{/regexp/?(.*)} # ex: /regexp/foo
30
+ def regexp(arg, params)
31
+ "#{arg} - #{params.inspect}"
32
+ end
33
+
34
+ get %r{/(\d{4})/(\d{2})/(\d{2})} # ex: /2009/10/10
35
+ def entry(year, month, date)
36
+ [year, month, date]
37
+ end
38
+ end
39
+
40
+ config.ru
41
+
42
+ require 'app'
43
+ run Www
44
+
45
+ rackup
46
+
47
+ % rackup config.ru
48
+
49
+ TODO
50
+ ----
51
+
52
+ * handle static files
53
+ * view
54
+ * redirect
55
+ * template
56
+ * layout
57
+ * url helper
58
+ * namespace
59
+
60
+ Run Examples
61
+ ----
62
+
63
+ shotgun -Ilib example/config.ru
64
+
65
+ Note on Patches/Pull Requests
66
+ ----
67
+
68
+ * Fork the project.
69
+ * Make your feature addition or bug fix.
70
+ * Add tests for it. This is important so I don't break it in a
71
+ future version unintentionally.
72
+ * Commit, do not mess with rakefile, version, or history.
73
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
74
+ * Send me a pull request. Bonus points for topic branches.
75
+
76
+ Copyright
77
+ ----
78
+
79
+ Copyright (c) 2010 jugyo. See LICENSE for details.
@@ -0,0 +1,44 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "www"
8
+ gem.summary = %Q{World Wide Web}
9
+ gem.description = %Q{A World Wide Web Application Framework}
10
+ gem.email = "jugyo.org@gmail.com"
11
+ gem.homepage = "http://github.com/jugyo/www"
12
+ gem.authors = ["jugyo"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'spec/rake/spectask'
22
+ Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ spec.libs << 'lib' << 'spec'
24
+ spec.spec_files = FileList['spec/**/*_spec.rb']
25
+ end
26
+
27
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
+ spec.rcov = true
31
+ end
32
+
33
+ task :spec => :check_dependencies
34
+
35
+ task :default => :spec
36
+
37
+ begin
38
+ require 'yard'
39
+ YARD::Rake::YardocTask.new
40
+ rescue LoadError
41
+ task :yardoc do
42
+ abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
43
+ end
44
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+ require 'www'
3
+
4
+ class Foo < Www
5
+ before do
6
+ # do something
7
+ end
8
+
9
+ get '/'
10
+ def index
11
+ "index"
12
+ end
13
+
14
+ get '/foo'
15
+ def foo(params)
16
+ params
17
+ end
18
+
19
+ get %r{/regexp/?(.*)} # ex: /regexp/foo
20
+ def regexp(arg, params)
21
+ "#{arg} - #{params.inspect}"
22
+ end
23
+
24
+ get %r{/(\d{4})/(\d{2})/(\d{2})} # ex: /2009/10/10
25
+ def entry(year, month, date)
26
+ [year, month, date]
27
+ end
28
+ end
@@ -0,0 +1,4 @@
1
+ # encoding: utf-8
2
+ $:.unshift File.dirname(__FILE__)
3
+ require 'app'
4
+ run Www
@@ -0,0 +1,79 @@
1
+ # encoding: utf-8
2
+ require 'www/route'
3
+
4
+ class Www
5
+ @@current_route = nil
6
+ @@routes = []
7
+
8
+ class << self
9
+ def routes
10
+ @@routes
11
+ end
12
+
13
+ def route(pattern, methods = [:get])
14
+ @@current_route = Route.new(pattern, methods, self)
15
+ end
16
+ alias_method :_, :route
17
+
18
+ def get(pattern) _(pattern, :get) end
19
+ def post(pattern) _(pattern, :post) end
20
+ def put(pattern) _(pattern, :put) end
21
+ def delete(pattern) _(pattern, :delete) end
22
+
23
+ def before(&block)
24
+ @before_block = block
25
+ end
26
+
27
+ def before_block
28
+ @before_block
29
+ end
30
+
31
+ def method_added(name)
32
+ return unless @@current_route
33
+ @@current_route.name = name
34
+ @@routes << @@current_route
35
+ @@current_route = nil
36
+
37
+ class_eval do
38
+ alias_method :"www_#{name}", name
39
+ define_method name do |*args|
40
+ instance_eval(&self.class.before_block)
41
+ body = send(:"www_#{name}", *args) || ''
42
+ body = body.inspect unless body.is_a?(String)
43
+ [@response.status, @response.header, [body].flatten]
44
+ end
45
+ end
46
+ end
47
+
48
+ def error(code)
49
+ [code, {"Content-Type" => "text/html"}, []]
50
+ end
51
+
52
+ def find_route(path, request_method)
53
+ [@@routes.detect { |route|
54
+ route.pattern =~ path && route.request_methods.include?(request_method) }, $~]
55
+ end
56
+
57
+ def call(env)
58
+ request = Rack::Request.new(env)
59
+ route, match = find_route(request.path_info, request.request_method)
60
+ if route
61
+ handler = route.clazz.new(request)
62
+ args = match[1..-1]
63
+ args << request.params
64
+ # adjust args
65
+ arity = handler.method(:"www_#{route.name}").arity
66
+ args = arity == 0 ? [] : args[0..(arity-1)]
67
+ puts "#{route.clazz}##{route.name}(#{args.map{|i| "'#{i}'"}.join(', ')})" # TODO: use logger
68
+ handler.send(route.name, *args)
69
+ else
70
+ error 404
71
+ end
72
+ end
73
+ end
74
+
75
+ def initialize(request = nil)
76
+ @request = request
77
+ @response = Rack::Response.new
78
+ end
79
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+ class Www
3
+ class Route
4
+ attr_accessor :pattern, :request_methods, :name, :clazz
5
+ def initialize(pattern, request_methods, clazz)
6
+ case pattern
7
+ when Regexp then @pattern = /^#{pattern}$/
8
+ when String then @pattern = /^#{Regexp.quote(pattern)}$/
9
+ else
10
+ raise 'pattern must be Regexp or String'
11
+ end
12
+ @request_methods = [request_methods].flatten.map { |m| m.to_s.upcase }
13
+ @clazz = clazz
14
+ end
15
+
16
+ def to_s
17
+ inspect
18
+ end
19
+
20
+ def inspect
21
+ "#<#{self.class}: #{pattern}, [#{request_methods.join(',')}] => #{clazz}##{name} >"
22
+ end
23
+ end
24
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'www'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Www" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: www
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ version: 0.0.2
10
+ platform: ruby
11
+ authors:
12
+ - jugyo
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-10-14 00:00:00 +09:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 1
30
+ - 2
31
+ - 9
32
+ version: 1.2.9
33
+ type: :development
34
+ version_requirements: *id001
35
+ description: A World Wide Web Application Framework
36
+ email: jugyo.org@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.md
44
+ files:
45
+ - .document
46
+ - LICENSE
47
+ - README.md
48
+ - Rakefile
49
+ - VERSION
50
+ - example/app.rb
51
+ - example/config.ru
52
+ - lib/www.rb
53
+ - lib/www/route.rb
54
+ - spec/spec.opts
55
+ - spec/spec_helper.rb
56
+ - spec/www_spec.rb
57
+ has_rdoc: true
58
+ homepage: http://github.com/jugyo/www
59
+ licenses: []
60
+
61
+ post_install_message:
62
+ rdoc_options:
63
+ - --charset=UTF-8
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ requirements: []
83
+
84
+ rubyforge_project:
85
+ rubygems_version: 1.3.7
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: World Wide Web
89
+ test_files:
90
+ - spec/spec_helper.rb
91
+ - spec/www_spec.rb