happy 0.1.0.pre15 → 0.1.0.pre16

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -98,26 +98,14 @@ Controllers are the magic behind Happy; they're essentially **re-useable, self-c
98
98
 
99
99
  ### More Happy Features
100
100
 
101
- In addition to its fun and flexible approach to writing web applications, Happy boasts the following features, and more:
101
+ In addition to its fun and flexible approach to writing web applications, Happy boasts the following features, among others:
102
102
 
103
- * Run-time permission management provided by [Allowance](https://github.com/hmans/allowance).
103
+ * Optional run-time permission management provided by [Allowance](https://github.com/hmans/allowance).
104
104
  * A set of Happy Controllers making you super-productive, from serving static files to minifying JavaScript assets or even serving complete RESTful resources.
105
105
  * A set of view helpers including [simple_form](https://github.com/plataformatec/simple_form) inspired forms on auto-pilot, with full support for translations and localization through [I18n](https://github.com/svenfuchs/i18n).
106
106
  * Happy _loves_ Rack. You can mount Rack Middleware as well as pass control to another Rack application, just like that. Or use Happy Controllers from within other applications -- they're just Rack apps. And, of course, serve your Happy application through any Rack-compliant Rack server.
107
107
 
108
108
 
109
- ### Happy is Opinionated Software
110
-
111
- Happy is opinionated software. Its design and functionality follow a certain set of opinions, a few of which are:
112
-
113
- * **The core framework should be very simple**. As described above, the entire framework revolves around two important classes (Happy::Controller and Happy::Context). Everything that's not directly related to the core framework should be provided by additional gems. (For example, anything that is view helper related has been moved to the [HappyHelpers](https://github.com/hmans/happy-helpers) gem, and the permission management code has been extracted to the [Allowance](https://github.com/hmans/allowance) gem.) Happy isn't trying to be a kitchen sink framework.
114
- * **Full-stack is boring**. Sure, it's nice if your framework of choice is holding your hands almost every step you go, but it's when you get to that point where you want to do something _differently_ from what your framework provides to you that you'll start hitting walls. For example, Happy doesn't generate data layer code for you; you're expected (and free to) simply use any ORM (or whatever) you desire, if any. For example, adding [Mongoid](http://mongoid.org/) to your Happy project is just two lines of code. Don't worry, we'll provide recipes; you don't need generators for that kind of stuff.
115
- * **Routing sucks**. Pretty much all other Ruby web application frameworks go to great lengths to map incoming requests to code through regular expressions (or DSLs allowing you to specify routes that are then compiled to regular expressions behind the scenes.) It's a very fast, but somewhat inflexible approach.
116
- * **Objects are awesome**. Frameworks like Rails are, technically speaking, object-oriented, but really only use classes mostly as containers for code. Requests are mapped (through the aforementioned routes) to controller classes, which are then instantiated and passed control to. It works, but it's also really boring. Objects are fun! Happy uses the request URL as a roadmap through your application's object graph. It allows you to think of your application as a nested tree of _things_.
117
-
118
- If you find that you agree with these, you're going to _love_ building Happy web applications.
119
-
120
-
121
109
  ## Current Status
122
110
 
123
111
  Happy is being extracted from a web application that I've been working on. I'm trying to get a first, hopefully somewhat stable release out of the door some time during June 2012.
@@ -39,24 +39,11 @@ module Happy
39
39
  end
40
40
  end
41
41
 
42
- def get(*args, &blk)
43
- args.last.is_a?(Hash) ? args.last.merge(:method => :get) : args.push(:method => :get)
44
- path(*args, &blk)
45
- end
46
-
47
- def post(*args, &blk)
48
- args.last.is_a?(Hash) ? args.last.merge(:method => :post) : args.push(:method => :post)
49
- path(*args, &blk)
50
- end
51
-
52
- def put(*args, &blk)
53
- args.last.is_a?(Hash) ? args.last.merge(:method => :put) : args.push(:method => :put)
54
- path(*args, &blk)
55
- end
56
-
57
- def delete(*args, &blk)
58
- args.last.is_a?(Hash) ? args.last.merge(:method => :delete) : args.push(:method => :delete)
59
- path(*args, &blk)
42
+ [:get, :post, :put, :delete].each do |method|
43
+ define_method(method) do |*args, &blk|
44
+ args.last.is_a?(Hash) ? args.last.merge(:method => method) : args.push(:method => method)
45
+ path(*args, &blk)
46
+ end
60
47
  end
61
48
  end
62
49
  end
@@ -0,0 +1,37 @@
1
+ require 'happy/extras/permissions'
2
+
3
+ module Happy
4
+ module Extras
5
+ class Scriptable < Happy::Controller
6
+ def route
7
+ Happy::Context.class_eval(load_script 'context.rb')
8
+ run_script 'permissions.rb'
9
+ run_script 'route.rb'
10
+ end
11
+
12
+ def run_script(name)
13
+ instance_exec &get_proc_for_script(name)
14
+ end
15
+
16
+ def get_proc_for_script(name)
17
+ if reload_script?(name)
18
+ procs[name] = eval "lambda { %s }" % load_script(name)
19
+ end
20
+ procs[name]
21
+ end
22
+
23
+ def reload_script?(name)
24
+ !procs[name] || Happy.env.development?
25
+ end
26
+
27
+ def load_script(name)
28
+ file_name = File.expand_path(File.join(options[:directory], name))
29
+ File.read(file_name)
30
+ end
31
+
32
+ def procs
33
+ @procs ||= {}
34
+ end
35
+ end
36
+ end
37
+ end
data/lib/happy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Happy
2
- VERSION = "0.1.0.pre15"
2
+ VERSION = "0.1.0.pre16"
3
3
  end
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.pre15
4
+ version: 0.1.0.pre16
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-06-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &70267629187180 !ruby/object:Gem::Requirement
16
+ requirement: &70251874709220 !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: *70267629187180
24
+ version_requirements: *70251874709220
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rack
27
- requirement: &70267629185900 !ruby/object:Gem::Requirement
27
+ requirement: &70251874706120 !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: *70267629185900
35
+ version_requirements: *70251874706120
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: happy-helpers
38
- requirement: &70267629184380 !ruby/object:Gem::Requirement
38
+ requirement: &70251874722540 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.1.0.pre9
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70267629184380
46
+ version_requirements: *70251874722540
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: allowance
49
- requirement: &70267629199080 !ruby/object:Gem::Requirement
49
+ requirement: &70251874720680 !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: *70267629199080
57
+ version_requirements: *70251874720680
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: happy-cli
60
- requirement: &70267629195280 !ruby/object:Gem::Requirement
60
+ requirement: &70251874719340 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 0.1.0.pre1
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70267629195280
68
+ version_requirements: *70251874719340
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
- requirement: &70267629191760 !ruby/object:Gem::Requirement
71
+ requirement: &70251874718000 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70267629191760
79
+ version_requirements: *70251874718000
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rspec
82
- requirement: &70267629213020 !ruby/object:Gem::Requirement
82
+ requirement: &70251874735320 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '2.8'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70267629213020
90
+ version_requirements: *70251874735320
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rspec-html-matchers
93
- requirement: &70267629211400 !ruby/object:Gem::Requirement
93
+ requirement: &70251874732880 !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: *70267629211400
101
+ version_requirements: *70251874732880
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: rack-test
104
- requirement: &70267629210420 !ruby/object:Gem::Requirement
104
+ requirement: &70251874731140 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *70267629210420
112
+ version_requirements: *70251874731140
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: watchr
115
- requirement: &70267629209340 !ruby/object:Gem::Requirement
115
+ requirement: &70251874727440 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,7 +120,7 @@ dependencies:
120
120
  version: '0'
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *70267629209340
123
+ version_requirements: *70251874727440
124
124
  description: A happy little toolkit for writing web applications.
125
125
  email:
126
126
  - hendrik@mans.de
@@ -147,9 +147,9 @@ files:
147
147
  - lib/happy/controller/routing.rb
148
148
  - lib/happy/extras/permissions.rb
149
149
  - lib/happy/extras/resources.rb
150
+ - lib/happy/extras/scriptable.rb
150
151
  - lib/happy/extras/static.rb
151
152
  - lib/happy/request.rb
152
- - lib/happy/utils/app_spawner.rb
153
153
  - lib/happy/version.rb
154
154
  - spec/controller/actions_spec.rb
155
155
  - spec/controller/routing_spec.rb
@@ -1,35 +0,0 @@
1
- module Happy
2
- module Utils
3
- # SMELL: this should be a controller, spawning another controller.
4
- class AppSpawner
5
- attr_reader :options
6
-
7
- def initialize(options = {})
8
- @app = nil
9
- @options = {
10
- :scripts => './app/*.rb'
11
- }.merge(options)
12
- end
13
-
14
- def call(env)
15
- app.call(env)
16
- end
17
-
18
- def app
19
- @app = reload_app? ? load_app : @app
20
- end
21
-
22
- def load_app
23
- Happy::Controller.build.tap do |klass|
24
- Dir[options[:scripts]].each do |file|
25
- klass.instance_eval File.read(file)
26
- end
27
- end
28
- end
29
-
30
- def reload_app?
31
- !Happy.env.production? || @app.nil?
32
- end
33
- end
34
- end
35
- end