rails_mini 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ log
2
+ pkg/*
3
+ .DS_Store
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'http://rubygems.org'
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,133 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rails_mini (0.0.1)
5
+ minitest
6
+ racksh
7
+ rails (= 3.1)
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ actionmailer (3.1.0)
13
+ actionpack (= 3.1.0)
14
+ mail (~> 2.3.0)
15
+ actionpack (3.1.0)
16
+ activemodel (= 3.1.0)
17
+ activesupport (= 3.1.0)
18
+ builder (~> 3.0.0)
19
+ erubis (~> 2.7.0)
20
+ i18n (~> 0.6)
21
+ rack (~> 1.3.2)
22
+ rack-cache (~> 1.0.3)
23
+ rack-mount (~> 0.8.2)
24
+ rack-test (~> 0.6.1)
25
+ sprockets (~> 2.0.0)
26
+ activemodel (3.1.0)
27
+ activesupport (= 3.1.0)
28
+ bcrypt-ruby (~> 3.0.0)
29
+ builder (~> 3.0.0)
30
+ i18n (~> 0.6)
31
+ activerecord (3.1.0)
32
+ activemodel (= 3.1.0)
33
+ activesupport (= 3.1.0)
34
+ arel (~> 2.2.1)
35
+ tzinfo (~> 0.3.29)
36
+ activeresource (3.1.0)
37
+ activemodel (= 3.1.0)
38
+ activesupport (= 3.1.0)
39
+ activesupport (3.1.0)
40
+ multi_json (~> 1.0)
41
+ arel (2.2.1)
42
+ awesome_print (0.4.0)
43
+ bcrypt-ruby (3.0.1)
44
+ builder (3.0.0)
45
+ coderay (0.9.8)
46
+ diff-lcs (1.1.3)
47
+ erubis (2.7.0)
48
+ hike (1.2.1)
49
+ i18n (0.6.0)
50
+ json (1.6.1)
51
+ mail (2.3.0)
52
+ i18n (>= 0.4.0)
53
+ mime-types (~> 1.16)
54
+ treetop (~> 1.4.8)
55
+ method_source (0.6.6)
56
+ ruby_parser (~> 2.0.5)
57
+ mime-types (1.17.2)
58
+ minitest (2.7.0)
59
+ multi_json (1.0.3)
60
+ polyglot (0.3.3)
61
+ pry (0.9.6.2)
62
+ coderay (~> 0.9.8)
63
+ method_source (~> 0.6.5)
64
+ ruby_parser (~> 2.0.5)
65
+ slop (~> 2.1.0)
66
+ rack (1.3.5)
67
+ rack-cache (1.0.3)
68
+ rack (>= 0.4)
69
+ rack-mount (0.8.3)
70
+ rack (>= 1.0.0)
71
+ rack-ssl (1.3.2)
72
+ rack
73
+ rack-test (0.6.1)
74
+ rack (>= 1.0)
75
+ racksh (0.9.9)
76
+ rack (>= 1.0)
77
+ rack-test (>= 0.5)
78
+ rails (3.1.0)
79
+ actionmailer (= 3.1.0)
80
+ actionpack (= 3.1.0)
81
+ activerecord (= 3.1.0)
82
+ activeresource (= 3.1.0)
83
+ activesupport (= 3.1.0)
84
+ bundler (~> 1.0)
85
+ railties (= 3.1.0)
86
+ railties (3.1.0)
87
+ actionpack (= 3.1.0)
88
+ activesupport (= 3.1.0)
89
+ rack-ssl (~> 1.3.2)
90
+ rake (>= 0.8.7)
91
+ rdoc (~> 3.4)
92
+ thor (~> 0.14.6)
93
+ rake (0.9.2.2)
94
+ rdoc (3.11)
95
+ json (~> 1.4)
96
+ rspec (2.7.0)
97
+ rspec-core (~> 2.7.0)
98
+ rspec-expectations (~> 2.7.0)
99
+ rspec-mocks (~> 2.7.0)
100
+ rspec-core (2.7.1)
101
+ rspec-expectations (2.7.0)
102
+ diff-lcs (~> 1.1.2)
103
+ rspec-mocks (2.7.0)
104
+ rspec-rails (2.7.0)
105
+ actionpack (~> 3.0)
106
+ activesupport (~> 3.0)
107
+ railties (~> 3.0)
108
+ rspec (~> 2.7.0)
109
+ ruby_parser (2.0.6)
110
+ sexp_processor (~> 3.0)
111
+ sexp_processor (3.0.7)
112
+ slop (2.1.0)
113
+ sprockets (2.0.3)
114
+ hike (~> 1.2)
115
+ rack (~> 1.0)
116
+ tilt (~> 1.1, != 1.3.0)
117
+ thor (0.14.6)
118
+ tilt (1.3.3)
119
+ treetop (1.4.10)
120
+ polyglot
121
+ polyglot (>= 0.3.1)
122
+ tzinfo (0.3.31)
123
+
124
+ PLATFORMS
125
+ ruby
126
+
127
+ DEPENDENCIES
128
+ awesome_print
129
+ pry
130
+ rails_mini!
131
+ rspec
132
+ rspec-core
133
+ rspec-rails
data/README.md ADDED
@@ -0,0 +1,76 @@
1
+ ## About
2
+ Simple Web DSL built with rails
3
+
4
+ Sometimes rails feels over powering, luckily rails is quite modular. This gem provides sane defaults, with a simple, familiar and handy DSL
5
+
6
+ [rails_mini](http://github.com/gmarik/mini-rails) is a single-file-rails-app project
7
+
8
+ ## Getting Started
9
+
10
+
11
+ ## Example
12
+ ```ruby
13
+ App = Rails.app do
14
+ class PingController < ActionController::Base
15
+ def ping
16
+ render text: 'pong'
17
+ end
18
+ end
19
+
20
+ config.secret_token = '!*#&$' * 31
21
+
22
+ get '/ping', :to => 'ping#ping'
23
+ match '/pang', :to => Apple
24
+ match '/pzng', :to => ->(hash) { [200,{'content-type' => 'text/html'},["Hello, World!"]] }
25
+ match '/pung' do
26
+ render text: "Hello, World!"
27
+ end
28
+
29
+ get '/pxng' do
30
+ render text: "Hello, World!"
31
+ end
32
+
33
+ get '/ptng' do
34
+ render text: "Hello, World!"
35
+ end
36
+
37
+ post '/ptng' do
38
+ render text: "POST Hello, World!"
39
+ end
40
+ end
41
+ ```
42
+
43
+ ## Todo
44
+
45
+ [x] Better defaults
46
+ [/] Sinatra DSL
47
+ [X] block dsl in router
48
+ [X] block dsl behaviours like controller action
49
+ [X] render
50
+ [X] redirect
51
+ [ ] ....
52
+ [ ] jsonp helpers?
53
+ [ ] short helpers
54
+ (jsonp,404,text,haml etc.)
55
+ lets provide these as controller helpers, so they become backwards compatible
56
+ [ ] Guides
57
+ [ ] Example App, 1 branch per refactor
58
+ [ ] Encourage fast tests
59
+ [ ] Routing stuff
60
+ [ ] Single Controller per routing context
61
+ [ ] expose callbacks, helper methods...
62
+
63
+ ## Future
64
+
65
+ [ ] Async
66
+ [ ] long connections
67
+ [ ] large non-blocking fileuploads
68
+
69
+ ## Example Ideas
70
+
71
+ ...
72
+
73
+ ## Inspiration
74
+
75
+ - sinatra
76
+ - astaire
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require './lib/rails_mini'
2
+ require 'rake'
3
+ require 'bundler/gem_tasks'
4
+
5
+ require 'rspec/core/rake_task'
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task :default => :spec
10
+ RailsMini::App.load_tasks
data/config.ru ADDED
@@ -0,0 +1,22 @@
1
+ require './lib/rails_mini'
2
+
3
+ app = Rails.mini do
4
+
5
+ config.secret_token = '!*#&$' * 31
6
+
7
+ get '/' do
8
+ render(<<-ERB)
9
+ Holla
10
+ ERB
11
+ end
12
+
13
+ get '/hello' do
14
+ render text: "Hello #{params[:who]}!"
15
+ end
16
+
17
+ get '/ping' do
18
+ render json: {'ping' => 'pong'}
19
+ end
20
+ end
21
+
22
+ run app
@@ -0,0 +1,22 @@
1
+ module RailsMini::Ext
2
+ module RouterMappings
3
+ def config
4
+ RailsMini::App.config
5
+ end
6
+
7
+ def match(path,options=nil,&blk)
8
+ if blk
9
+ options ||= {}
10
+
11
+ controller = Class.new(ActionController::Base)
12
+
13
+ controller.send(:define_method,path.to_sym,blk)
14
+
15
+ options[:to] ||= controller.action(path.to_sym)
16
+ end
17
+ super(path,options)
18
+ end
19
+ end
20
+ end
21
+
22
+ ActionDispatch::Routing::Mapper.send(:include, RailsMini::Ext::RouterMappings)
@@ -0,0 +1,3 @@
1
+ class RailsMini
2
+ VERSION = "0.0.1"
3
+ end
data/lib/rails_mini.rb ADDED
@@ -0,0 +1,22 @@
1
+ require 'rails'
2
+ require 'action_controller/railtie'
3
+ require './lib/rails_mini/version'
4
+
5
+ class RailsMini
6
+ class App < Rails::Application;end
7
+
8
+ def initialize(&blk)
9
+ App.routes.draw &blk
10
+ @app = App
11
+ end
12
+
13
+ def call(env)
14
+ @app.call(env)
15
+ end
16
+ end
17
+
18
+ require 'rails_mini/ext'
19
+
20
+ def Rails.mini(&blk)
21
+ RailsMini.new(&blk)
22
+ end
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "rails_mini/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rails_mini"
7
+ s.version = RailsMini::VERSION
8
+ s.authors = ["gmarik","Stefan Penner"]
9
+ s.email = ["gmarik@gmail.com","stefan.penner@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Simple Web DSL built with rails}
12
+ s.description = %q{Sometimes rails feels over powering, luckily rails is quite modular. This gem provides sane defaults, with a simple, familiar and handy DSL}
13
+
14
+ s.rubyforge_project = "rails_mini"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_runtime_dependency 'rails', '3.1'
23
+ s.add_runtime_dependency 'racksh'
24
+ s.add_runtime_dependency 'minitest'
25
+
26
+ s.add_development_dependency 'awesome_print'
27
+ s.add_development_dependency 'pry'
28
+ s.add_development_dependency 'rspec'
29
+ s.add_development_dependency 'rspec-core'
30
+ s.add_development_dependency 'rspec-rails'
31
+ end
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+ require 'rails_mini'
3
+
4
+ module Apple
5
+ extend self
6
+ def call(env)
7
+ [200,{'content-type' => 'text/html'},["Hello, World!"]]
8
+ end
9
+ end
10
+
11
+ App = Rails.mini do
12
+
13
+ class PingController < ActionController::Base
14
+ def ping
15
+ render text: 'pong'
16
+ end
17
+ end
18
+
19
+ config.secret_token = '!*#&$' * 31
20
+
21
+ get '/ping', :to => 'ping#ping'
22
+ match '/rack_apple', :to => Apple
23
+ match '/lambda', :to => ->(hash) { [200,{'content-type' => 'text/html'},["Hello, World!"]] }
24
+
25
+ match '/match_with_block' do
26
+ render text: "match with block"
27
+ end
28
+
29
+ get '/get_with_block' do
30
+ render text: "get with block"
31
+ end
32
+
33
+ put '/ping' do
34
+ render text: "Put ping?"
35
+ end
36
+
37
+ post '/ping' do
38
+ render json: {'ping' => 'pong'}
39
+ end
40
+ end
41
+
42
+ describe App do
43
+ include Rack::Test::Methods
44
+ def app
45
+ @app ||= App
46
+ end
47
+
48
+ describe 'get' do
49
+ it "test_ping_pong" do
50
+ get '/ping'
51
+ last_response.should be_ok
52
+ last_response.body.should == 'pong'
53
+ end
54
+
55
+ it 'test rack app' do
56
+ get '/rack_apple'
57
+ last_response.should be_ok
58
+ last_response.body.should == 'Hello, World!'
59
+ end
60
+
61
+ it 'test_lambda_rack_app' do
62
+ get '/lambda'
63
+ last_response.should be_ok
64
+ last_response.body.should == 'Hello, World!'
65
+ end
66
+
67
+ it 'match_with_block' do
68
+ get '/match_with_block'
69
+ last_response.should be_ok
70
+ last_response.body.should == 'match with block'
71
+ end
72
+
73
+ it 'test get with block' do
74
+ get '/get_with_block'
75
+ last_response.should be_ok
76
+ last_response.body.should == 'get with block'
77
+ end
78
+
79
+ it 'accepts put and renders' do
80
+ put '/ping'
81
+ last_response.should be_ok
82
+ last_response.body.should == 'Put ping?'
83
+ end
84
+
85
+ it 'accepts posts and renders json' do
86
+ post '/ping'
87
+ last_response.should be_ok
88
+ last_response.body.should == %Q[{"ping":"pong"}]
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,3 @@
1
+ require 'rails_mini'
2
+ require 'rspec'
3
+ require 'rack/test'
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_mini
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - gmarik
9
+ - Stefan Penner
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-01-26 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rails
17
+ requirement: &2152717620 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - =
21
+ - !ruby/object:Gem::Version
22
+ version: '3.1'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *2152717620
26
+ - !ruby/object:Gem::Dependency
27
+ name: racksh
28
+ requirement: &2152717200 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *2152717200
37
+ - !ruby/object:Gem::Dependency
38
+ name: minitest
39
+ requirement: &2152716740 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: *2152716740
48
+ - !ruby/object:Gem::Dependency
49
+ name: awesome_print
50
+ requirement: &2152716320 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *2152716320
59
+ - !ruby/object:Gem::Dependency
60
+ name: pry
61
+ requirement: &2152715900 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *2152715900
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec
72
+ requirement: &2152715480 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: *2152715480
81
+ - !ruby/object:Gem::Dependency
82
+ name: rspec-core
83
+ requirement: &2152715060 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: *2152715060
92
+ - !ruby/object:Gem::Dependency
93
+ name: rspec-rails
94
+ requirement: &2152714640 !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ type: :development
101
+ prerelease: false
102
+ version_requirements: *2152714640
103
+ description: Sometimes rails feels over powering, luckily rails is quite modular.
104
+ This gem provides sane defaults, with a simple, familiar and handy DSL
105
+ email:
106
+ - gmarik@gmail.com
107
+ - stefan.penner@gmail.com
108
+ executables: []
109
+ extensions: []
110
+ extra_rdoc_files: []
111
+ files:
112
+ - .gitignore
113
+ - .rvmrc
114
+ - Gemfile
115
+ - Gemfile.lock
116
+ - README.md
117
+ - Rakefile
118
+ - config.ru
119
+ - lib/rails_mini.rb
120
+ - lib/rails_mini/ext.rb
121
+ - lib/rails_mini/version.rb
122
+ - rails_mini.gemspec
123
+ - spec/router_mapping_spec.rb
124
+ - spec/spec_helper.rb
125
+ homepage: ''
126
+ licenses: []
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ! '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project: rails_mini
145
+ rubygems_version: 1.8.10
146
+ signing_key:
147
+ specification_version: 3
148
+ summary: Simple Web DSL built with rails
149
+ test_files:
150
+ - spec/router_mapping_spec.rb
151
+ - spec/spec_helper.rb