florida 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c4e3f79bac70546f93c6961b8ebc01146570e476
4
- data.tar.gz: b63f76fe741118e18a1a233d3f9e96926b27cdd6
3
+ metadata.gz: 790c8e349e5160cb793028d3231fb10a6feacf60
4
+ data.tar.gz: 135a9d5d0842e18a075222f737cafd4566922ee8
5
5
  SHA512:
6
- metadata.gz: c9a50576fc162a882dc32392829ae073599a734e8427dcccb4e04311507ed1773bcbc489d8b8aecf40974491a69e6e0068c4ac3074876b8b0e17827943c00d56
7
- data.tar.gz: c2f3b17140279dfc329e3734e1bea0ea1ace2c410cd476b1f7a68eb2cdcb9772783a8e49456b63a9c9c619d8719031068d498642eb93c86088edc50f59e09e0a
6
+ metadata.gz: 57e5331ce69da69f4adb1d379686a9a123f7bc3529c46ed8a61f5c0c22e69aadab9fb4cd57aa0a92ed717973d6ccf21540f1ee6de64b9e1c692f76385ac1e600
7
+ data.tar.gz: 7efbe79e64e0c6baab155022514940c75741d642e37de888fc4783a34eb071fe1e38ead6762876af86bc7a292ce1a5563d97b27b04add8410c05a34d1ca13e03
data/.gitignore CHANGED
@@ -11,4 +11,5 @@
11
11
  *.so
12
12
  *.o
13
13
  *.a
14
+ *.swp
14
15
  mkmf.log
data/Gemfile CHANGED
@@ -3,4 +3,11 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in florida.gemspec
4
4
  gemspec
5
5
 
6
+ # Server / Engine
7
+ gem 'rack'
6
8
  gem 'sinatra'
9
+
10
+ # for Testing
11
+ gem 'rspec'
12
+ gem 'guard-rspec'
13
+ gem 'rack-test'
data/Guardfile ADDED
@@ -0,0 +1,33 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ # Note: The cmd option is now required due to the increasing number of ways
5
+ # rspec may be run, below are examples of the most common uses.
6
+ # * bundler: 'bundle exec rspec'
7
+ # * bundler binstubs: 'bin/rspec'
8
+ # * spring: 'bin/rsspec' (This will use spring if running and you have
9
+ # installed the spring binstubs per the docs)
10
+ # * zeus: 'zeus rspec' (requires the server to be started separetly)
11
+ # * 'just' rspec: 'rspec'
12
+ guard :rspec, cmd: 'bundle exec rspec' do
13
+ watch(%r{^spec/.+_spec\.rb$})
14
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
15
+ watch('spec/spec_helper.rb') { "spec" }
16
+
17
+ # Rails example
18
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
19
+ watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
20
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
21
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
22
+ watch('config/routes.rb') { "spec/routing" }
23
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
24
+ watch('spec/rails_helper.rb') { "spec" }
25
+
26
+ # Capybara features specs
27
+ watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
28
+
29
+ # Turnip features and steps
30
+ watch(%r{^spec/acceptance/(.+)\.feature$})
31
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
32
+ end
33
+
data/README.md CHANGED
@@ -25,13 +25,17 @@ write application ruby script.
25
25
  ```ruby
26
26
  require 'florida'
27
27
 
28
- class MyApplication < Florida::Application
29
- get '/' do
28
+ class HomeController < Florida::Controller::Base
29
+ def index
30
30
  'Hello Florida!!'
31
31
  end
32
32
  end
33
33
 
34
- MyApplication.run
34
+ class MyApplication < Florida::Application::Base
35
+ routings do
36
+ path "/", to: HomeController
37
+ end
38
+ end
35
39
  ```
36
40
 
37
41
  and script execute in ruby.
data/lib/florida.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'florida/version'
2
2
  require 'florida/application'
3
+ require 'florida/sinatra_server'
3
4
 
4
5
  module Florida; end
@@ -1,9 +1 @@
1
- require 'sinatra'
2
-
3
- module Florida
4
- class Application < Sinatra::Base
5
- def self.run(port: 4567)
6
- Rack::Server.start(app: new, Port: port)
7
- end
8
- end
9
- end
1
+ require 'florida/application/base'
@@ -0,0 +1,11 @@
1
+ module Florida::Application; end
2
+ require 'florida/router'
3
+ require 'florida/controller/base'
4
+
5
+ module Florida
6
+ module Application
7
+ class Base
8
+ extend Florida::Router
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ module Florida
2
+ module Controller
3
+ class Base
4
+ def initialize(sinatra_app = nil)
5
+ @sinatra_app = sinatra_app
6
+ end
7
+
8
+ def params
9
+ @sinatra_app.params
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ module Florida::Router
2
+ def path(path, options = {})
3
+ @routings ||= {}
4
+ @routings[path] = options
5
+ end
6
+
7
+ def routings(&block)
8
+ if block_given?
9
+ block.call
10
+ else
11
+ @routings
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,34 @@
1
+ require 'sinatra'
2
+ require 'rack'
3
+
4
+ class Florida::SinatraServer; end
5
+ require 'florida/sinatra_server/router'
6
+
7
+ module Florida
8
+ class SinatraServer
9
+ attr_reader :sinatra_app
10
+
11
+ def initialize(app, params = {})
12
+ @sinatra_app = Class.new(Sinatra::Base)
13
+ @params = params
14
+ setup(app)
15
+ end
16
+
17
+ def application
18
+ @sinatra_app
19
+ end
20
+
21
+ def run
22
+ Rack::Server.start(app: @sinatra_app.new, Port: @params[:port] || 4567)
23
+ end
24
+
25
+ def self.run(app, params = {})
26
+ self.new(app, params).run
27
+ end
28
+
29
+ private
30
+ def setup(app)
31
+ Router.setup(app, @sinatra_app)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,42 @@
1
+ class Florida::SinatraServer::Router
2
+ def initialize(app, sinatra)
3
+ @app = app
4
+ @sinatra = sinatra
5
+ end
6
+
7
+ def self.setup(app, sinatra)
8
+ self.new(app, sinatra).routing!
9
+ end
10
+
11
+ def routing!
12
+ @app.routings.each do |path, data|
13
+ setup_routing(path, data)
14
+ end
15
+ end
16
+
17
+ private
18
+ def setup_routing(path, params)
19
+ controller_class = params[:to]
20
+ controller = controller_class.new
21
+
22
+ if controller.respond_to? :index
23
+ @sinatra.get self.class.index_routing_matcher(path) do
24
+ controller_class.new(self).index
25
+ end
26
+ end
27
+
28
+ if controller.respond_to? :show
29
+ @sinatra.get(self.class.show_routing_matcher(path)) do
30
+ controller_class.new(self).show(self.params[:captures].first)
31
+ end
32
+ end
33
+ end
34
+
35
+ def self.index_routing_matcher(path)
36
+ %r{\A#{path}(\.[\w]+)?/?\z}
37
+ end
38
+
39
+ def self.show_routing_matcher(path)
40
+ %r{\A#{path}/(\w+)(\.[\w]+)?/?\z}
41
+ end
42
+ end
@@ -1,3 +1,3 @@
1
1
  module Florida
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,64 @@
1
+ require 'florida'
2
+
3
+ ENV['RACK_ENV'] = 'test'
4
+ require 'rack/test'
5
+
6
+ describe Florida do
7
+ describe "Application" do
8
+ include Rack::Test::Methods
9
+
10
+ let!(:example_application) do
11
+ class HomeController < Florida::Controller::Base
12
+ def index
13
+ 'Hello Florida!!'
14
+ end
15
+ end
16
+
17
+ class ExampleController < Florida::Controller::Base
18
+ def index
19
+ 'This is example index page.'
20
+ end
21
+
22
+ def show(id)
23
+ "This is example of #{id}"
24
+ end
25
+ end
26
+
27
+ class MyApplication < Florida::Application::Base
28
+ routings do
29
+ path "/", to: HomeController
30
+ path "/examples", to: ExampleController
31
+ end
32
+ end
33
+ MyApplication
34
+ end
35
+
36
+ def app
37
+ Florida::SinatraServer.new(example_application).application
38
+ end
39
+
40
+ describe "access to /" do
41
+ before do
42
+ get '/'
43
+ end
44
+ it { expect(last_response).to be_ok }
45
+ it { expect(last_response.body).to eq 'Hello Florida!!' }
46
+ end
47
+
48
+ describe "access to /examples" do
49
+ before do
50
+ get '/examples'
51
+ end
52
+ it { expect(last_response).to be_ok }
53
+ it { expect(last_response.body).to eq 'This is example index page.' }
54
+ end
55
+
56
+ describe "access to /examples/1" do
57
+ before do
58
+ get '/examples/1'
59
+ end
60
+ it { expect(last_response).to be_ok }
61
+ it { expect(last_response.body).to eq 'This is example of 1' }
62
+ end
63
+ end
64
+ end
@@ -1,10 +1,20 @@
1
1
  $:.unshift File.expand_path('../lib/', File.dirname(__FILE__))
2
2
  require 'florida'
3
3
 
4
- class MyApplication < Florida::Application
5
- get '/' do
6
- 'Hello Florida!!'
4
+ class HomeController < Florida::Controller::Base
5
+ def index
6
+ 'Hello Index!!'
7
+ end
8
+
9
+ def show(id)
10
+ "This page is #{id}"
11
+ end
12
+ end
13
+
14
+ class MyApplication < Florida::Application::Base
15
+ routings do
16
+ path "/home", to: HomeController
7
17
  end
8
18
  end
9
19
 
10
- MyApplication.run
20
+ Florida::SinatraServer.run(MyApplication)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: florida
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - myun2
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-17 00:00:00.000000000 Z
11
+ date: 2014-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -61,13 +61,20 @@ extra_rdoc_files: []
61
61
  files:
62
62
  - .gitignore
63
63
  - Gemfile
64
+ - Guardfile
64
65
  - LICENSE.txt
65
66
  - README.md
66
67
  - Rakefile
67
68
  - florida.gemspec
68
69
  - lib/florida.rb
69
70
  - lib/florida/application.rb
71
+ - lib/florida/application/base.rb
72
+ - lib/florida/controller/base.rb
73
+ - lib/florida/router.rb
74
+ - lib/florida/sinatra_server.rb
75
+ - lib/florida/sinatra_server/router.rb
70
76
  - lib/florida/version.rb
77
+ - spec/florida/request_spec.rb
71
78
  - test/application_test.rb
72
79
  homepage: ''
73
80
  licenses:
@@ -94,4 +101,5 @@ signing_key:
94
101
  specification_version: 4
95
102
  summary: Sinatra Based web Application framework.
96
103
  test_files:
104
+ - spec/florida/request_spec.rb
97
105
  - test/application_test.rb