www 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +15 -21
 - data/VERSION +1 -1
 - data/example/app.rb +5 -18
 - data/example/foo.haml +2 -5
 - data/example/layout.haml +7 -0
 - data/lib/www/base.rb +7 -11
 - data/lib/www/view.rb +18 -3
 - data/spec/views/foo.haml +1 -1
 - data/spec/views/layout.haml +3 -0
 - data/spec/www_spec.rb +9 -2
 - metadata +4 -2
 
    
        data/README.md
    CHANGED
    
    | 
         @@ -11,43 +11,37 @@ app.rb 
     | 
|
| 
       11 
11 
     | 
    
         
             
                # encoding: utf-8
         
     | 
| 
       12 
12 
     | 
    
         
             
                require 'www'
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
                class  
     | 
| 
       15 
     | 
    
         
            -
                  before do
         
     | 
| 
       16 
     | 
    
         
            -
                    # do something
         
     | 
| 
       17 
     | 
    
         
            -
                  end
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
      
 14 
     | 
    
         
            +
                class App < Www::Base
         
     | 
| 
       19 
15 
     | 
    
         
             
                  get '/'
         
     | 
| 
       20 
     | 
    
         
            -
                  def index
         
     | 
| 
       21 
     | 
    
         
            -
                     
     | 
| 
      
 16 
     | 
    
         
            +
                  def index(params)
         
     | 
| 
      
 17 
     | 
    
         
            +
                    params
         
     | 
| 
       22 
18 
     | 
    
         
             
                  end
         
     | 
| 
       23 
19 
     | 
    
         | 
| 
       24 
20 
     | 
    
         
             
                  get '/foo'
         
     | 
| 
       25 
     | 
    
         
            -
                  def foo 
     | 
| 
       26 
     | 
    
         
            -
                    haml :title => 'foo'
         
     | 
| 
       27 
     | 
    
         
            -
                  end
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
                  get '/regexp/?(.*)' # ex: /regexp/foo
         
     | 
| 
       30 
     | 
    
         
            -
                  def regexp(arg, params)
         
     | 
| 
       31 
     | 
    
         
            -
                    "#{arg} - #{params.inspect}"
         
     | 
| 
      
 21 
     | 
    
         
            +
                  def foo
         
     | 
| 
      
 22 
     | 
    
         
            +
                    haml :title => 'foo', :body => 'bar'
         
     | 
| 
       32 
23 
     | 
    
         
             
                  end
         
     | 
| 
       33 
24 
     | 
    
         | 
| 
       34 
25 
     | 
    
         
             
                  get '/(\d{4})/(\d{2})/(\d{2})' # ex: /2009/10/10
         
     | 
| 
       35 
26 
     | 
    
         
             
                  def entry(year, month, date)
         
     | 
| 
       36 
27 
     | 
    
         
             
                    [year, month, date]
         
     | 
| 
       37 
28 
     | 
    
         
             
                  end
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
                  def helper
         
     | 
| 
       40 
     | 
    
         
            -
                    'bar'
         
     | 
| 
       41 
     | 
    
         
            -
                  end
         
     | 
| 
       42 
29 
     | 
    
         
             
                end
         
     | 
| 
       43 
30 
     | 
    
         | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
      
 31 
     | 
    
         
            +
            foo.haml
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                %h2= title
         
     | 
| 
      
 34 
     | 
    
         
            +
                %p= body
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
            example.haml (as template)
         
     | 
| 
       45 
37 
     | 
    
         | 
| 
       46 
38 
     | 
    
         
             
                !!!
         
     | 
| 
       47 
39 
     | 
    
         
             
                %html
         
     | 
| 
      
 40 
     | 
    
         
            +
                  %head
         
     | 
| 
      
 41 
     | 
    
         
            +
                    %title= 'www-example'
         
     | 
| 
       48 
42 
     | 
    
         
             
                  %body
         
     | 
| 
       49 
     | 
    
         
            -
                    %h1 
     | 
| 
       50 
     | 
    
         
            -
                     
     | 
| 
      
 43 
     | 
    
         
            +
                    %h1 www-example
         
     | 
| 
      
 44 
     | 
    
         
            +
                    != yield
         
     | 
| 
       51 
45 
     | 
    
         | 
| 
       52 
46 
     | 
    
         
             
            config.ru
         
     | 
| 
       53 
47 
     | 
    
         | 
    
        data/VERSION
    CHANGED
    
    | 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            0.0. 
     | 
| 
      
 1 
     | 
    
         
            +
            0.0.4
         
     | 
    
        data/example/app.rb
    CHANGED
    
    | 
         @@ -1,32 +1,19 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # encoding: utf-8
         
     | 
| 
       2 
2 
     | 
    
         
             
            require 'www'
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
            class  
     | 
| 
       5 
     | 
    
         
            -
              before do
         
     | 
| 
       6 
     | 
    
         
            -
                # do something
         
     | 
| 
       7 
     | 
    
         
            -
              end
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
      
 4 
     | 
    
         
            +
            class App < Www::Base
         
     | 
| 
       9 
5 
     | 
    
         
             
              get '/'
         
     | 
| 
       10 
     | 
    
         
            -
              def index
         
     | 
| 
       11 
     | 
    
         
            -
                 
     | 
| 
      
 6 
     | 
    
         
            +
              def index(params)
         
     | 
| 
      
 7 
     | 
    
         
            +
                params
         
     | 
| 
       12 
8 
     | 
    
         
             
              end
         
     | 
| 
       13 
9 
     | 
    
         | 
| 
       14 
10 
     | 
    
         
             
              get '/foo'
         
     | 
| 
       15 
     | 
    
         
            -
              def foo 
     | 
| 
       16 
     | 
    
         
            -
                haml :title => 'foo'
         
     | 
| 
       17 
     | 
    
         
            -
              end
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
              get '/regexp/?(.*)' # ex: /regexp/foo
         
     | 
| 
       20 
     | 
    
         
            -
              def regexp(arg, params)
         
     | 
| 
       21 
     | 
    
         
            -
                "#{arg} - #{params.inspect}"
         
     | 
| 
      
 11 
     | 
    
         
            +
              def foo
         
     | 
| 
      
 12 
     | 
    
         
            +
                haml :title => 'foo', :body => 'bar'
         
     | 
| 
       22 
13 
     | 
    
         
             
              end
         
     | 
| 
       23 
14 
     | 
    
         | 
| 
       24 
15 
     | 
    
         
             
              get '/(\d{4})/(\d{2})/(\d{2})' # ex: /2009/10/10
         
     | 
| 
       25 
16 
     | 
    
         
             
              def entry(year, month, date)
         
     | 
| 
       26 
17 
     | 
    
         
             
                [year, month, date]
         
     | 
| 
       27 
18 
     | 
    
         
             
              end
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
              def helper
         
     | 
| 
       30 
     | 
    
         
            -
                'bar'
         
     | 
| 
       31 
     | 
    
         
            -
              end
         
     | 
| 
       32 
19 
     | 
    
         
             
            end
         
     | 
    
        data/example/foo.haml
    CHANGED
    
    
    
        data/example/layout.haml
    ADDED
    
    
    
        data/lib/www/base.rb
    CHANGED
    
    | 
         @@ -4,15 +4,12 @@ module Www 
     | 
|
| 
       4 
4 
     | 
    
         
             
                include View
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
                class << self
         
     | 
| 
       7 
     | 
    
         
            -
                  @@current_route = nil
         
     | 
| 
       8 
     | 
    
         
            -
                  @@routes = []
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
7 
     | 
    
         
             
                  def routes
         
     | 
| 
       11 
     | 
    
         
            -
                    @@routes
         
     | 
| 
      
 8 
     | 
    
         
            +
                    @@routes ||= []
         
     | 
| 
       12 
9 
     | 
    
         
             
                  end
         
     | 
| 
       13 
10 
     | 
    
         | 
| 
       14 
11 
     | 
    
         
             
                  def route(pattern, methods = [:get])
         
     | 
| 
       15 
     | 
    
         
            -
                     
     | 
| 
      
 12 
     | 
    
         
            +
                    @current_route = Route.new(pattern, methods, self)
         
     | 
| 
       16 
13 
     | 
    
         
             
                  end
         
     | 
| 
       17 
14 
     | 
    
         
             
                  alias_method :_, :route
         
     | 
| 
       18 
15 
     | 
    
         | 
| 
         @@ -30,10 +27,10 @@ module Www 
     | 
|
| 
       30 
27 
     | 
    
         
             
                  end
         
     | 
| 
       31 
28 
     | 
    
         | 
| 
       32 
29 
     | 
    
         
             
                  def method_added(name)
         
     | 
| 
       33 
     | 
    
         
            -
                    return unless  
     | 
| 
       34 
     | 
    
         
            -
                     
     | 
| 
       35 
     | 
    
         
            -
                     
     | 
| 
       36 
     | 
    
         
            -
                     
     | 
| 
      
 30 
     | 
    
         
            +
                    return unless @current_route
         
     | 
| 
      
 31 
     | 
    
         
            +
                    @current_route.name = name
         
     | 
| 
      
 32 
     | 
    
         
            +
                    routes << @current_route
         
     | 
| 
      
 33 
     | 
    
         
            +
                    @current_route = nil
         
     | 
| 
       37 
34 
     | 
    
         | 
| 
       38 
35 
     | 
    
         
             
                    class_eval do
         
     | 
| 
       39 
36 
     | 
    
         
             
                      alias_method :"www_#{name}", name
         
     | 
| 
         @@ -57,7 +54,7 @@ module Www 
     | 
|
| 
       57 
54 
     | 
    
         
             
                  end
         
     | 
| 
       58 
55 
     | 
    
         | 
| 
       59 
56 
     | 
    
         
             
                  def find_route(path, request_method)
         
     | 
| 
       60 
     | 
    
         
            -
                    [ 
     | 
| 
      
 57 
     | 
    
         
            +
                    [routes.detect { |route|
         
     | 
| 
       61 
58 
     | 
    
         
             
                        path.match(route.pattern) && route.request_methods.include?(request_method.downcase.to_sym) }, $~]
         
     | 
| 
       62 
59 
     | 
    
         
             
                  end
         
     | 
| 
       63 
60 
     | 
    
         | 
| 
         @@ -81,7 +78,6 @@ module Www 
     | 
|
| 
       81 
78 
     | 
    
         
             
                end
         
     | 
| 
       82 
79 
     | 
    
         | 
| 
       83 
80 
     | 
    
         
             
                def initialize(request = nil)
         
     | 
| 
       84 
     | 
    
         
            -
                  # TODO: @_ で始まるようにした方がいいかもしれない
         
     | 
| 
       85 
81 
     | 
    
         
             
                  @request = request
         
     | 
| 
       86 
82 
     | 
    
         
             
                  @response = Rack::Response.new
         
     | 
| 
       87 
83 
     | 
    
         
             
                end
         
     | 
    
        data/lib/www/view.rb
    CHANGED
    
    | 
         @@ -8,6 +8,14 @@ module Www 
     | 
|
| 
       8 
8 
     | 
    
         
             
                end
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
                module ClassMethods
         
     | 
| 
      
 11 
     | 
    
         
            +
                  def layout(layout)
         
     | 
| 
      
 12 
     | 
    
         
            +
                    @layout = layout
         
     | 
| 
      
 13 
     | 
    
         
            +
                  end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                  def layout_path
         
     | 
| 
      
 16 
     | 
    
         
            +
                    @layout || 'layout'
         
     | 
| 
      
 17 
     | 
    
         
            +
                  end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
       11 
19 
     | 
    
         
             
                  def view_dir(dir)
         
     | 
| 
       12 
20 
     | 
    
         
             
                    @view_dir = dir
         
     | 
| 
       13 
21 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -26,9 +34,16 @@ module Www 
     | 
|
| 
       26 
34 
     | 
    
         
             
                def render(type, *args)
         
     | 
| 
       27 
35 
     | 
    
         
             
                  name = args[0].is_a?(String) ? args.shift : @route_name
         
     | 
| 
       28 
36 
     | 
    
         
             
                  values = args[0]
         
     | 
| 
       29 
     | 
    
         
            -
                   
     | 
| 
       30 
     | 
    
         
            -
                   
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
      
 37 
     | 
    
         
            +
                  view_path = File.join(self.class.view_dir_path, "#{name}.#{type}")
         
     | 
| 
      
 38 
     | 
    
         
            +
                  layout_path = "#{self.class.layout_path}.#{type}"
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                  if File.exists?(layout_path)
         
     | 
| 
      
 41 
     | 
    
         
            +
                    Tilt.new(layout_path).render self, values do
         
     | 
| 
      
 42 
     | 
    
         
            +
                      Tilt.new(view_path).render self, values
         
     | 
| 
      
 43 
     | 
    
         
            +
                    end
         
     | 
| 
      
 44 
     | 
    
         
            +
                  else
         
     | 
| 
      
 45 
     | 
    
         
            +
                    Tilt.new(view_path).render self, values
         
     | 
| 
      
 46 
     | 
    
         
            +
                  end
         
     | 
| 
       32 
47 
     | 
    
         
             
                end
         
     | 
| 
       33 
48 
     | 
    
         
             
              end
         
     | 
| 
       34 
49 
     | 
    
         
             
            end
         
     | 
    
        data/spec/views/foo.haml
    CHANGED
    
    | 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            =  
     | 
| 
      
 1 
     | 
    
         
            +
            = foo
         
     | 
    
        data/spec/www_spec.rb
    CHANGED
    
    | 
         @@ -1,5 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            class Foo < Www::Base
         
     | 
| 
       2 
2 
     | 
    
         
             
              view_dir 'spec/views'
         
     | 
| 
      
 3 
     | 
    
         
            +
              layout 'spec/views/layout'
         
     | 
| 
       3 
4 
     | 
    
         | 
| 
       4 
5 
     | 
    
         
             
              before {}
         
     | 
| 
       5 
6 
     | 
    
         
             
              before(:foo, :index) {}
         
     | 
| 
         @@ -11,7 +12,7 @@ class Foo < Www::Base 
     | 
|
| 
       11 
12 
     | 
    
         | 
| 
       12 
13 
     | 
    
         
             
              get '/foo'
         
     | 
| 
       13 
14 
     | 
    
         
             
              def foo(params)
         
     | 
| 
       14 
     | 
    
         
            -
                haml : 
     | 
| 
      
 15 
     | 
    
         
            +
                haml :foo => params['foo']
         
     | 
| 
       15 
16 
     | 
    
         
             
              end
         
     | 
| 
       16 
17 
     | 
    
         | 
| 
       17 
18 
     | 
    
         
             
              get '/regexp/?(.*)'
         
     | 
| 
         @@ -45,7 +46,13 @@ describe "Www" do 
     | 
|
| 
       45 
46 
     | 
    
         | 
| 
       46 
47 
     | 
    
         
             
              it 'should call foo as "/foo" with params' do
         
     | 
| 
       47 
48 
     | 
    
         
             
                params = {'foo' => 'bar'}
         
     | 
| 
       48 
     | 
    
         
            -
                get('/foo', params).body. 
     | 
| 
      
 49 
     | 
    
         
            +
                get('/foo', params).body.should == <<-EOS
         
     | 
| 
      
 50 
     | 
    
         
            +
            <html>
         
     | 
| 
      
 51 
     | 
    
         
            +
              <body>
         
     | 
| 
      
 52 
     | 
    
         
            +
                bar
         
     | 
| 
      
 53 
     | 
    
         
            +
              </body>
         
     | 
| 
      
 54 
     | 
    
         
            +
            </html>
         
     | 
| 
      
 55 
     | 
    
         
            +
                EOS
         
     | 
| 
       49 
56 
     | 
    
         
             
              end
         
     | 
| 
       50 
57 
     | 
    
         | 
| 
       51 
58 
     | 
    
         
             
              it 'should call regexp as "/regexp/..."' do
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version 
     | 
|
| 
       5 
5 
     | 
    
         
             
              segments: 
         
     | 
| 
       6 
6 
     | 
    
         
             
              - 0
         
     | 
| 
       7 
7 
     | 
    
         
             
              - 0
         
     | 
| 
       8 
     | 
    
         
            -
              -  
     | 
| 
       9 
     | 
    
         
            -
              version: 0.0. 
     | 
| 
      
 8 
     | 
    
         
            +
              - 4
         
     | 
| 
      
 9 
     | 
    
         
            +
              version: 0.0.4
         
     | 
| 
       10 
10 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       11 
11 
     | 
    
         
             
            authors: 
         
     | 
| 
       12 
12 
     | 
    
         
             
            - jugyo
         
     | 
| 
         @@ -83,6 +83,7 @@ files: 
     | 
|
| 
       83 
83 
     | 
    
         
             
            - example/app.rb
         
     | 
| 
       84 
84 
     | 
    
         
             
            - example/config.ru
         
     | 
| 
       85 
85 
     | 
    
         
             
            - example/foo.haml
         
     | 
| 
      
 86 
     | 
    
         
            +
            - example/layout.haml
         
     | 
| 
       86 
87 
     | 
    
         
             
            - lib/www.rb
         
     | 
| 
       87 
88 
     | 
    
         
             
            - lib/www/app.rb
         
     | 
| 
       88 
89 
     | 
    
         
             
            - lib/www/base.rb
         
     | 
| 
         @@ -90,6 +91,7 @@ files: 
     | 
|
| 
       90 
91 
     | 
    
         
             
            - lib/www/view.rb
         
     | 
| 
       91 
92 
     | 
    
         
             
            - spec/spec_helper.rb
         
     | 
| 
       92 
93 
     | 
    
         
             
            - spec/views/foo.haml
         
     | 
| 
      
 94 
     | 
    
         
            +
            - spec/views/layout.haml
         
     | 
| 
       93 
95 
     | 
    
         
             
            - spec/www_spec.rb
         
     | 
| 
       94 
96 
     | 
    
         
             
            has_rdoc: true
         
     | 
| 
       95 
97 
     | 
    
         
             
            homepage: http://github.com/jugyo/www
         
     |