happy 0.1.0.pre22 → 0.1.0.pre23

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/example/config.ru CHANGED
@@ -17,7 +17,7 @@ class TestApp < Happy::Controller
17
17
  #
18
18
  # This method can be as simple or complex as you like. In this example
19
19
  # application, it wraps around a couple of annotated Happy examples.
20
- # Usually, you'd use the #path? method to specify code to be executed if
20
+ # Usually, you'd use the #path method to specify code to be executed if
21
21
  # a certain path was requested; in this app, we're using a custom #example
22
22
  # method, that does the same thing but also records the example in a hash
23
23
  # so we can generated a "table of contents" in index.erb.
@@ -38,8 +38,8 @@ class TestApp < Happy::Controller
38
38
  end
39
39
 
40
40
  example 'Path parameters' do
41
- path? 'hello' do
42
- path? :name do
41
+ on 'hello' do
42
+ on :name do
43
43
  "Hello, #{params['name']}!"
44
44
  end
45
45
  end
@@ -48,7 +48,7 @@ class TestApp < Happy::Controller
48
48
  end
49
49
 
50
50
  example 'Inline path parameters' do
51
- path? 'hello-:name' do
51
+ on 'hello-:name' do
52
52
  "Hello, #{params['name']}!"
53
53
  end
54
54
 
@@ -59,7 +59,7 @@ class TestApp < Happy::Controller
59
59
  # set up permissions ;-)
60
60
  can.dance!
61
61
 
62
- path? 'dance' do
62
+ on 'dance' do
63
63
  if can.dance?
64
64
  "You can dance."
65
65
  else
@@ -71,18 +71,18 @@ class TestApp < Happy::Controller
71
71
  end
72
72
 
73
73
  example 'Layouts' do
74
- path? 'with-layout' do
74
+ on 'with-layout' do
75
75
  layout 'layout.erb'
76
76
 
77
- path? 'changed-my-mind' do
77
+ on 'changed-my-mind' do
78
78
  layout false
79
79
  "This should render without a layout."
80
80
  end
81
81
 
82
- "This should render with a layout."
82
+ "This should render with a layout. But #{link_to 'this', current_url('changed-my-mind')} shouldn't!"
83
83
  end
84
84
 
85
- "This should render without a layout."
85
+ "This should render without a layout. But #{link_to 'this', current_url('with-layout')} should."
86
86
  end
87
87
 
88
88
  example 'Invoking other controllers' do
@@ -120,7 +120,7 @@ class TestApp < Happy::Controller
120
120
  examples[name] = path_name
121
121
 
122
122
  # Create a path containing the example's code block
123
- path?(path_name, &blk)
123
+ on path_name, &blk
124
124
  end
125
125
  end
126
126
 
@@ -7,7 +7,7 @@ module Happy
7
7
  Regexp.compile('^'+path.gsub(/\)/, ')?').gsub(/\//, '\/').gsub(/\./, '\.').gsub(/:(\w+)/, '(.+)')+'$')
8
8
  end
9
9
 
10
- def path?(*args, &blk)
10
+ def on(*args, &blk)
11
11
  options = (args.pop if args.last.is_a?(Hash)) || {}
12
12
  args = [nil] if args.empty?
13
13
 
@@ -40,9 +40,9 @@ module Happy
40
40
  end
41
41
 
42
42
  [:get, :post, :put, :delete].each do |method|
43
- define_method("#{method}?") do |*args, &blk|
43
+ define_method("on_%s" % method) do |*args, &blk|
44
44
  args.last.is_a?(Hash) ? args.last.merge(:method => method) : args.push(:method => method)
45
- path?(*args, &blk)
45
+ on(*args, &blk)
46
46
  end
47
47
  end
48
48
  end
@@ -95,17 +95,17 @@ module Happy
95
95
  options[:singular_name] ||= options[:class].to_s.tableize.singularize
96
96
  options[:plural_name] ||= options[:class].to_s.tableize.pluralize
97
97
 
98
- path? options[:plural_name] do
99
- get?('new') { do_new }
98
+ path options[:plural_name] do
99
+ get('new') { do_new }
100
100
 
101
- path? :id do
102
- get? { do_show }
103
- post? { do_update }
104
- get?('edit') { do_edit }
101
+ path :id do
102
+ get { do_show }
103
+ post { do_update }
104
+ get('edit') { do_edit }
105
105
  end
106
106
 
107
- post? { do_create }
108
- get? { do_index }
107
+ post { do_create }
108
+ get { do_index }
109
109
  end
110
110
  end
111
111
  end
data/lib/happy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Happy
2
- VERSION = "0.1.0.pre22"
2
+ VERSION = "0.1.0.pre23"
3
3
  end
@@ -6,11 +6,11 @@ module Happy
6
6
 
7
7
  describe '#serve!' do
8
8
  def app
9
- build_controller do
10
- path?('simple') { serve! "Simple response" }
11
- path?('with_headers') { serve! "body { color: red }", :content_type => 'text/css' }
12
- path?('with_status') { serve! "Not Allowed", :status => 401 }
13
- path?('with_layout') { serve! "content", :layout => 'layout.erb' }
9
+ Happy.route do
10
+ on('simple') { serve! "Simple response" }
11
+ on('with_headers') { serve! "body { color: red }", :content_type => 'text/css' }
12
+ on('with_status') { serve! "Not Allowed", :status => 401 }
13
+ on('with_layout') { serve! "content", :layout => 'layout.erb' }
14
14
  end
15
15
  end
16
16
 
@@ -45,7 +45,7 @@ module Happy
45
45
  def app
46
46
  Happy.route do
47
47
  serve! "This should not render"
48
- path? 'test' do
48
+ on 'test' do
49
49
  serve! "But this should render"
50
50
  end
51
51
  end
@@ -58,7 +58,7 @@ module Happy
58
58
  describe '#redirect!' do
59
59
  it "triggers a redirection to the specified URL" do
60
60
  def app
61
- build_controller { redirect! 'http://www.test.com' }
61
+ Happy.route { redirect! 'http://www.test.com' }
62
62
  end
63
63
 
64
64
  get '/'
@@ -68,7 +68,7 @@ module Happy
68
68
 
69
69
  it "sets the provided status code" do
70
70
  def app
71
- build_controller { redirect! 'http://www.test.com', 301 }
71
+ Happy.route { redirect! 'http://www.test.com', 301 }
72
72
  end
73
73
 
74
74
  get '/'
@@ -80,7 +80,7 @@ module Happy
80
80
  Happy.route do
81
81
  redirect! "http://mans.de"
82
82
 
83
- path? 'test' do
83
+ on 'test' do
84
84
  redirect! "http://schnitzelpress.org"
85
85
  end
86
86
  end
@@ -101,7 +101,7 @@ module Happy
101
101
  end
102
102
 
103
103
  def app
104
- build_controller { run InnerController }
104
+ Happy.route { run InnerController }
105
105
  end
106
106
 
107
107
  response_for { get '/' }.body.should == 'awesome!'
@@ -115,7 +115,7 @@ module Happy
115
115
  end
116
116
 
117
117
  def app
118
- build_controller { run SomeRackApp }
118
+ Happy.route { run SomeRackApp }
119
119
  end
120
120
 
121
121
  response_for { get '/' }.body.should == 'racksome!'
@@ -129,7 +129,7 @@ module Happy
129
129
  end
130
130
 
131
131
  def app
132
- build_controller { run SomeClass }
132
+ Happy.route { run SomeClass }
133
133
  end
134
134
 
135
135
  response_for { get '/' }.body.should == 'stringsome!'
@@ -7,11 +7,11 @@ module Happy
7
7
  it "passes on all method calls to a parent if there is one" do
8
8
  class Inner < Controller
9
9
  def route
10
- path? 'one' do
10
+ on 'one' do
11
11
  some_helper
12
12
  end
13
13
 
14
- path? 'two' do
14
+ on 'two' do
15
15
  some_unknown_helper
16
16
  end
17
17
  end
@@ -5,17 +5,17 @@ module Happy
5
5
  describe '#path' do
6
6
  subject do
7
7
  Happy.route do
8
- path?('foo') { serve! 'bar' }
9
- path?('one', 'two') { serve! 'onetwo' }
10
- path?('hello') do
11
- path?(:name) { serve! "Hello #{params['name']}" }
8
+ on('foo') { serve! 'bar' }
9
+ on('one', 'two') { serve! 'onetwo' }
10
+ on('hello') do
11
+ on(:name) { serve! "Hello #{params['name']}" }
12
12
  serve! "Please provide a name."
13
13
  end
14
- path?('number-:num') { serve! "num = #{params['num']}" }
15
- path?('return-value') { 'moo?' }
16
- path?('resource') do
17
- get? { 'GET resource' }
18
- post? { 'POST resource' }
14
+ on('number-:num') { serve! "num = #{params['num']}" }
15
+ on('return-value') { 'moo?' }
16
+ on('resource') do
17
+ on_get { 'GET resource' }
18
+ on_post { 'POST resource' }
19
19
  end
20
20
  serve! "root"
21
21
  end
@@ -62,12 +62,14 @@ module Happy
62
62
  end
63
63
 
64
64
  %w(get post put delete).each do |what|
65
- describe "##{what}?" do
65
+ method_name = "on_%s" % what
66
+
67
+ describe "#%s" % method_name do
66
68
  subject { Controller.new }
67
69
 
68
- it "merely invokes #path? with the :method => :#{what} option" do
69
- subject.should_receive(:path?).with('path', :method => what.to_sym)
70
- subject.send("#{what}?", 'path')
70
+ it "merely invokes #path with the :method => :#{what} option" do
71
+ subject.should_receive(:on).with('path', :method => what.to_sym)
72
+ subject.send(method_name, 'path')
71
73
  end
72
74
  end
73
75
  end
@@ -21,9 +21,9 @@ module Happy
21
21
  describe '#current_url' do
22
22
  it "returns the current URL" do
23
23
  def app
24
- build_controller do
25
- path? 'foo' do
26
- path? 'bar' do
24
+ Happy.route do
25
+ on 'foo' do
26
+ on 'bar' do
27
27
  "My URL is #{current_url}"
28
28
  end
29
29
 
@@ -41,8 +41,8 @@ module Happy
41
41
 
42
42
  it "appends extra paths to the URL if provided" do
43
43
  def app
44
- build_controller do
45
- path? 'foo' do
44
+ Happy.route do
45
+ on 'foo' do
46
46
  current_url('bar', 'moo')
47
47
  end
48
48
  end
@@ -55,16 +55,16 @@ module Happy
55
55
  describe '#root_url' do
56
56
  it "returns the controller's root URL" do
57
57
  def app
58
- root_url_printer = build_controller do
59
- path? 'bar' do
58
+ root_url_printer = Happy.route do
59
+ on 'bar' do
60
60
  "My root URL is still #{root_url}"
61
61
  end
62
62
 
63
63
  "My root URL is #{root_url}"
64
64
  end
65
65
 
66
- build_controller do
67
- path? 'foo' do
66
+ Happy.route do
67
+ on 'foo' do
68
68
  run root_url_printer
69
69
  end
70
70
 
@@ -79,12 +79,12 @@ module Happy
79
79
 
80
80
  it "appends extra paths to the root URL if provided" do
81
81
  def app
82
- some_controller = build_controller do
82
+ some_controller = Happy.route do
83
83
  root_url('bar')
84
84
  end
85
85
 
86
- build_controller do
87
- path? 'foo' do
86
+ Happy.route do
87
+ on 'foo' do
88
88
  run some_controller
89
89
  end
90
90
  end
data/spec/spec_helper.rb CHANGED
@@ -16,10 +16,6 @@ module SpecHelpers
16
16
  yield if block_given?
17
17
  last_response
18
18
  end
19
-
20
- def build_controller(&blk)
21
- Happy.route(&blk)
22
- end
23
19
  end
24
20
 
25
21
  RSpec.configure do |conf|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: happy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre22
4
+ version: 0.1.0.pre23
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-13 00:00:00.000000000 Z
12
+ date: 2012-06-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &70226632793780 !ruby/object:Gem::Requirement
16
+ requirement: &70202609576440 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.1'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70226632793780
24
+ version_requirements: *70202609576440
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rack
27
- requirement: &70226632793280 !ruby/object:Gem::Requirement
27
+ requirement: &70202609575940 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '1.4'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70226632793280
35
+ version_requirements: *70202609575940
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: happy-helpers
38
- requirement: &70226632792820 !ruby/object:Gem::Requirement
38
+ requirement: &70202609575480 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.1.0.pre11
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70226632792820
46
+ version_requirements: *70202609575480
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: allowance
49
- requirement: &70226632792360 !ruby/object:Gem::Requirement
49
+ requirement: &70202609575020 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 0.1.1
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70226632792360
57
+ version_requirements: *70202609575020
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rake
60
- requirement: &70226632791980 !ruby/object:Gem::Requirement
60
+ requirement: &70202609574640 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70226632791980
68
+ version_requirements: *70202609574640
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
- requirement: &70226632791440 !ruby/object:Gem::Requirement
71
+ requirement: &70202475775160 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '2.8'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70226632791440
79
+ version_requirements: *70202475775160
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rspec-html-matchers
82
- requirement: &70226632791020 !ruby/object:Gem::Requirement
82
+ requirement: &70202475774740 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70226632791020
90
+ version_requirements: *70202475774740
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rack-test
93
- requirement: &70226632790560 !ruby/object:Gem::Requirement
93
+ requirement: &70202475774280 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70226632790560
101
+ version_requirements: *70202475774280
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: watchr
104
- requirement: &70226632790140 !ruby/object:Gem::Requirement
104
+ requirement: &70202475773860 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,7 +109,7 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *70226632790140
112
+ version_requirements: *70202475773860
113
113
  description: A happy little toolkit for writing web applications.
114
114
  email:
115
115
  - hendrik@mans.de