freddie 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - jruby-19mode # JRuby in 1.9 mode
6
+ - rbx-19mode
7
+ script: bundle exec rake
@@ -19,6 +19,7 @@ Gem::Specification.new do |gem|
19
19
  gem.add_dependency 'activesupport', '~> 3.2.3'
20
20
  gem.add_dependency 'tilt', '~> 1.3.3'
21
21
 
22
+ gem.add_development_dependency 'rake'
22
23
  gem.add_development_dependency 'rack-test'
23
24
  gem.add_development_dependency 'minitest-reporters'
24
25
  end
@@ -14,7 +14,5 @@ module Freddie
14
14
  end
15
15
 
16
16
  def Freddie(&block)
17
- app = Class.new(Freddie::Application)
18
- app.block = block
19
- app
17
+ Freddie::Application.new(&block)
20
18
  end
@@ -1,13 +1,7 @@
1
1
  module Freddie
2
2
  class Application < Handlers::Base
3
- class << self
4
- def block=(block)
5
- @@block = block
6
- end
7
- end
8
-
9
3
  def perform
10
- instance_exec &@@block if @@block
4
+ perform_freddie_block
11
5
  end
12
6
  end
13
7
  end
@@ -4,7 +4,7 @@ module Freddie
4
4
  # Base class for all handlers.
5
5
  #
6
6
  class Base
7
- attr_reader :block, :env
7
+ attr_reader :block, :env, :args
8
8
 
9
9
  class << self
10
10
  def call(env)
@@ -20,7 +20,7 @@ module Freddie
20
20
  def call(env)
21
21
  @env = env
22
22
  before_perform
23
- perform(*@args)
23
+ perform
24
24
  after_perform
25
25
  response
26
26
  end
@@ -61,6 +61,17 @@ module Freddie
61
61
  env['freddie.finished']
62
62
  end
63
63
 
64
+ def perform_freddie_block
65
+ if block
66
+ # cater for different DSL styles
67
+ if block.arity == 1
68
+ block.call(self)
69
+ else
70
+ instance_exec &block
71
+ end
72
+ end
73
+ end
74
+
64
75
  def method_missing(name, *args, &block)
65
76
  klass_name = "Freddie::Handlers::#{name.to_s.classify}"
66
77
 
@@ -84,23 +95,16 @@ module Freddie
84
95
  end
85
96
 
86
97
  class Path < Base
87
- def perform(path)
98
+ def perform
99
+ path = args.shift
100
+
88
101
  if match_data = self.class.path_to_regexp(path).match(context.path.first)
89
102
  # write parameter matches into params
90
103
  match_data.names.each { |k| params[k] = match_data[k] }
91
104
 
92
105
  # execute block
93
106
  el = context.path.shift
94
-
95
- if block
96
- # cater for different DSL styles
97
- if block.arity == 1
98
- block.call(self)
99
- else
100
- instance_exec &block
101
- end
102
- end
103
-
107
+ perform_freddie_block
104
108
  context.path.unshift(el)
105
109
  end
106
110
  end
@@ -116,25 +120,31 @@ module Freddie
116
120
  class Render < Base
117
121
  include Endpoint
118
122
 
119
- def perform(data)
120
- response.body << data
123
+ def perform
124
+ response.body << args.shift
121
125
  end
122
126
  end
123
127
 
124
128
  class Template < Base
125
129
  include Endpoint
126
130
 
127
- def perform(name, variables = {})
128
- html = Tilt.new("views/%s" % name).render(self, variables)
131
+ def perform
132
+ name = args.shift
133
+ variables = args.shift || {}
134
+
135
+ html = Tilt.new("views/%s" % name).render(context, variables)
129
136
  if env['freddie.layout'].present?
130
- html = Tilt.new("views/#{env['freddie.layout']}").render(self) { html }
137
+ html = Tilt.new("views/#{env['freddie.layout']}").render(context) { html }
131
138
  end
132
139
  response.body << html
133
140
  end
134
141
  end
135
142
 
136
143
  class Resource < Base
137
- def perform(name, options = {})
144
+ def perform
145
+ name = args.shift
146
+ options = args.shift || {}
147
+
138
148
  options = {
139
149
  name: name.to_s,
140
150
  singular_name: name.to_s.singularize,
@@ -143,9 +153,21 @@ module Freddie
143
153
  }.merge(options)
144
154
 
145
155
  path(options[:name]) do |n|
156
+ n.path('new') do
157
+ n.template "#{options[:plural_name]}/new.html.haml",
158
+ options[:singular_name] => options[:klass].new
159
+ end
160
+
146
161
  n.path(:id) do |n|
162
+ resource = options[:klass].find(params[:id])
163
+
164
+ n.path('edit') do |n|
165
+ n.template "#{options[:plural_name]}/edit.html.haml",
166
+ options[:singular_name] => resource
167
+ end
168
+
147
169
  n.template "#{options[:plural_name]}/show.html.haml",
148
- options[:singular_name] => options[:klass].find(params[:id])
170
+ options[:singular_name] => resource
149
171
  end
150
172
 
151
173
  n.template "#{options[:plural_name]}/index.html.haml",
@@ -157,8 +179,8 @@ module Freddie
157
179
  class RedirectTo < Base
158
180
  include Endpoint
159
181
 
160
- def perform(destination)
161
- response.headers['Location'] = destination
182
+ def perform
183
+ response.headers['Location'] = args.shift
162
184
  response.status = 302
163
185
  end
164
186
  end
@@ -166,7 +188,8 @@ module Freddie
166
188
  class Run < Base
167
189
  include Endpoint
168
190
 
169
- def perform(app)
191
+ def perform
192
+ app = args.shift
170
193
  context.response = Rack::Response.new(app.call(env))
171
194
  end
172
195
  end
@@ -174,7 +197,9 @@ module Freddie
174
197
  class Stylesheet < Base
175
198
  include Endpoint
176
199
 
177
- def perform(name)
200
+ def perform
201
+ name = args.shift
202
+
178
203
  response.headers['Content-type'] = 'text/css'
179
204
  layout nil
180
205
  template name
@@ -184,7 +209,8 @@ module Freddie
184
209
  class SendFile < Base
185
210
  include Endpoint
186
211
 
187
- def perform(name)
212
+ def perform
213
+ name = args.shift
188
214
  response.body << File.read(name)
189
215
  end
190
216
  end
@@ -192,16 +218,19 @@ module Freddie
192
218
  class Javascript < Base
193
219
  include Endpoint
194
220
 
195
- def perform(name)
196
- response.headers['Content-type'] = 'text/javascript'
221
+ def perform
222
+ name = args.shift
197
223
 
224
+ response.headers['Content-type'] = 'text/javascript'
198
225
  # insert crazy javascript packing code here... :)
199
226
  response.body << File.read("views/#{name}")
200
227
  end
201
228
  end
202
229
 
203
230
  class OmniAuth < Base
204
- def perform(options = {})
231
+ def perform
232
+ options = args.shift || {}
233
+
205
234
  options = {
206
235
  session_key: :omniauth_user,
207
236
  redirect_to: '/'
@@ -1,3 +1,3 @@
1
1
  module Freddie
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: freddie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
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-05-06 00:00:00.000000000 Z
12
+ date: 2012-05-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
16
- requirement: &70194826049540 !ruby/object:Gem::Requirement
16
+ requirement: &70124346343220 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.4.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70194826049540
24
+ version_requirements: *70124346343220
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activesupport
27
- requirement: &70194826048660 !ruby/object:Gem::Requirement
27
+ requirement: &70124346341560 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 3.2.3
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70194826048660
35
+ version_requirements: *70124346341560
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: tilt
38
- requirement: &70194826047820 !ruby/object:Gem::Requirement
38
+ requirement: &70124346340540 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,21 @@ dependencies:
43
43
  version: 1.3.3
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70194826047820
46
+ version_requirements: *70124346340540
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: &70124346339580 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70124346339580
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: rack-test
49
- requirement: &70194826047100 !ruby/object:Gem::Requirement
60
+ requirement: &70124346338260 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ! '>='
@@ -54,10 +65,10 @@ dependencies:
54
65
  version: '0'
55
66
  type: :development
56
67
  prerelease: false
57
- version_requirements: *70194826047100
68
+ version_requirements: *70124346338260
58
69
  - !ruby/object:Gem::Dependency
59
70
  name: minitest-reporters
60
- requirement: &70194826046180 !ruby/object:Gem::Requirement
71
+ requirement: &70124355046360 !ruby/object:Gem::Requirement
61
72
  none: false
62
73
  requirements:
63
74
  - - ! '>='
@@ -65,7 +76,7 @@ dependencies:
65
76
  version: '0'
66
77
  type: :development
67
78
  prerelease: false
68
- version_requirements: *70194826046180
79
+ version_requirements: *70124355046360
69
80
  description: Expressive, Rack-loving web application DSL.
70
81
  email:
71
82
  - hendrik@mans.de
@@ -74,6 +85,7 @@ extensions: []
74
85
  extra_rdoc_files: []
75
86
  files:
76
87
  - .gitignore
88
+ - .travis.yml
77
89
  - .yardopt
78
90
  - Gemfile
79
91
  - LICENSE