apex 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: 21cb76724c8c45f09e6aa71f2e7aed589a2df7f2
4
- data.tar.gz: 65ad0a407f2791fd0b32444c524a03aaa83ed00b
3
+ metadata.gz: 5ce8882c6a877b50d8b2fbbe8db5469d03d6b657
4
+ data.tar.gz: a815007e4186159f5ce2afb1e26a9b8dd37b9fb6
5
5
  SHA512:
6
- metadata.gz: 1383749d17d3528be127fa53b50afa40442f96f381aba948355e639cb0c11614392e33af2823d618162fa78007604828589249702b3996ff5ac88f61500a7f9b
7
- data.tar.gz: 3487874a158f9343bd67802b7ca3f102fd43f92ef4537e7fd4aa0c5af8576cec2bdc2b3175287a31148338aef24f0e454ad56273f3a568379b13f8808cefa25b
6
+ metadata.gz: f8903362700a01513fdcca170ee89109ccb8f401e8340f5898bd96eac3cf4b45144425774ca09210738365003678420b580d449f6ebfda0829321acf0c9b3ec6
7
+ data.tar.gz: a4aa2357797d5ce7e404928c6fdb5a39abe4eeaf9061f9dbd999e3c586cef82cdee30da8c4d681852ad716640692b0da323acbc5ea87384f49d83c91b75c67c1
data/README.md CHANGED
@@ -1,24 +1,54 @@
1
1
  # apex
2
2
 
3
- TODO: Write a gem description
3
+ Apex is a RubyMotion web framework for OS X. It uses
4
+ GCDWebServer under the hood and provides a Sinatra-like
5
+ router and DSL.
4
6
 
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- gem 'apex'
7
+ Apex is currently experimental and in development. I'd
8
+ love to have help; feel free get in touch [on Twitter](http://twitter.com/jamonholmgren).
10
9
 
11
- And then execute:
12
-
13
- $ bundle
10
+ ## Installation
14
11
 
15
- Or install it yourself as:
12
+ ```ruby
13
+ # In Gemfile:
14
+ gem 'apex'
16
15
 
17
- $ gem install apex
16
+ # In Terminal:
17
+ bundle install
18
+ rake pod:install
19
+ ```
18
20
 
19
21
  ## Usage
20
22
 
21
- TODO: Write usage instructions here
23
+ ```ruby
24
+ class AppDelegate < Apex::Server
25
+ port 8080 # defaults to 8080
26
+
27
+ layout do
28
+ "<html>" +
29
+ "<head><title>Apex</title></head>" +
30
+ "<body>" +
31
+ content +
32
+ "</body>" +
33
+ "</html>"
34
+ end
35
+
36
+ get "/" do |r|
37
+ "<h1>Apex is running. Response: #{r}</h1>" +
38
+ "<p><a href='/about'>About Apex</a></p>"
39
+ end
40
+
41
+ get "/about" do |r|
42
+ "<h1>About Apex</h1>" +
43
+ "<p><a href='/'>Home</a></p>"
44
+ end
45
+
46
+ post "/some_post" do |request|
47
+ request.headers["User-Agent"]
48
+ end
49
+
50
+ end
51
+ ```
22
52
 
23
53
  ## Contributing
24
54
 
@@ -3,8 +3,12 @@
3
3
  unless defined?(Motion::Project::Config)
4
4
  raise "This file must be required within a RubyMotion project Rakefile."
5
5
  end
6
+ require 'motion-cocoapods'
6
7
 
7
8
  lib_dir_path = File.dirname(File.expand_path(__FILE__))
8
9
  Motion::Project::App.setup do |app|
9
- app.files.unshift(Dir.glob(File.join(lib_dir_path, "project/**/*.rb")))
10
+ app.files.unshift(Dir.glob(File.join(lib_dir_path, "apex/**/*.rb")))
11
+ app.pods do
12
+ pod "GCDWebServer", "~> 2.4"
13
+ end
10
14
  end
@@ -1,4 +1,3 @@
1
- class Apex
2
-
1
+ module Apex
3
2
  end
4
3
 
@@ -0,0 +1,10 @@
1
+ module Apex
2
+ module DelegateInterface
3
+
4
+ def applicationDidFinishLaunching(notification)
5
+ on_launch
6
+ true
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,43 @@
1
+ module Apex
2
+ class Request
3
+ attr_accessor :raw
4
+
5
+ def initialize(raw)
6
+ @raw = raw
7
+ end
8
+
9
+ def body?
10
+ raw.hasBody
11
+ end
12
+
13
+ def content_type
14
+ raw.contentType
15
+ end
16
+
17
+ def headers
18
+ raw.headers
19
+ end
20
+
21
+ def content_length
22
+ raw.contentLength
23
+ end
24
+ alias_method :length, :content_length
25
+
26
+ def query
27
+ raw.query
28
+ end
29
+
30
+ def path
31
+ raw.path
32
+ end
33
+
34
+ def url
35
+ raw.URL
36
+ end
37
+
38
+ def url_string
39
+ url.absoluteString
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,9 @@
1
+ module Apex
2
+ class Response
3
+
4
+ def initialize
5
+ # placeholder
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,100 @@
1
+ module Apex
2
+ class Server
3
+ include DelegateInterface
4
+
5
+ def on_launch
6
+ add_static_handler
7
+ add_app_handlers
8
+ start
9
+ end
10
+
11
+ def server
12
+ @server ||= GCDWebServer.new
13
+ end
14
+
15
+ def routes
16
+ self.class.routes
17
+ end
18
+
19
+ def layouts
20
+ self.class.layouts
21
+ end
22
+
23
+ def add_app_handlers
24
+ [ :get, :post, :put, :patch, :delete ].each do |verb|
25
+ self.server.addDefaultHandlerForMethod(verb.to_s.upcase,
26
+ requestClass: GCDWebServerRequest,
27
+ processBlock: -> (raw_request) {
28
+ layout = false
29
+ request = Request.new(raw_request)
30
+ if response_block = self.routes[verb][request.path][:handler] rescue nil
31
+ request_args = [request].first(response_block.arity)
32
+ response = response_block.call(*request_args)
33
+ layout = self.routes[verb][request.path][:layout]
34
+ else
35
+ response = "<h1>404 not found</h1>"
36
+ end
37
+ GCDWebServerDataResponse.responseWithHTML apply_layout(response, layout)
38
+ }
39
+ )
40
+ end
41
+ end
42
+
43
+ def apply_layout(response, name)
44
+ layouts[name] ? layouts[name].call.to_s.gsub(self.class.content(:main), response) : response
45
+ end
46
+
47
+ def add_static_handler
48
+ public_path = NSBundle.mainBundle.pathForResource("assets", ofType:nil)
49
+ self.server.addGETHandlerForBasePath("/", directoryPath:public_path, indexFilename:nil, cacheAge:3600, allowRangeRequests:false)
50
+ end
51
+
52
+ def start
53
+ server.runWithPort self.class.port, bonjourName: nil
54
+ end
55
+
56
+ # Class methods *************************
57
+
58
+ def self.get(path, args={}, &block)
59
+ routes[:get][path] = { handler: block, layout: args[:layout] }
60
+ end
61
+
62
+ def self.post(path, args={}, &block)
63
+ routes[:post][path] = { handler: block, layout: args[:layout] }
64
+ end
65
+
66
+ def self.put(path, args={}, &block)
67
+ routes[:put][path] = { handler: block, layout: args[:layout] }
68
+ end
69
+
70
+ def self.patch(path, args={}, &block)
71
+ routes[:patch][path] = { handler: block, layout: args[:layout] }
72
+ end
73
+
74
+ def self.delete(path, args={}, &block)
75
+ routes[:delete][path] = { handler: block, layout: args[:layout] }
76
+ end
77
+
78
+ def self.routes
79
+ @routes ||= { get: {}, post: {}, put: {}, patch: {}, delete: {} }
80
+ end
81
+
82
+ def self.layouts
83
+ @layouts ||= {}
84
+ end
85
+
86
+ def self.port(port_number=nil)
87
+ @port = port_number if port_number
88
+ @port || 8080
89
+ end
90
+
91
+ def self.layout(name=:main, &block)
92
+ layouts[name] = block
93
+ end
94
+
95
+ def self.content(name=:main)
96
+ "%CONTENT-#{name}%"
97
+ end
98
+
99
+ end
100
+ end
@@ -0,0 +1,3 @@
1
+ module Apex
2
+ VERSION = "0.0.2" unless defined?(Apex::VERSION)
3
+ end
@@ -0,0 +1,9 @@
1
+ describe "Application 'apex'" do
2
+ before do
3
+ @app = NSApplication.sharedApplication
4
+ end
5
+
6
+ it "has one window" do
7
+ @app.windows.size.should == 1
8
+ end
9
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apex
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
  - Jamon Holmgren
@@ -10,21 +10,77 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2014-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: motion-cocoapods
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.5.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.5.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: webstub
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: motion-stump
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: motion-redgreen
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.1'
13
69
  - !ruby/object:Gem::Dependency
14
70
  name: rake
15
71
  requirement: !ruby/object:Gem::Requirement
16
72
  requirements:
17
73
  - - ">="
18
74
  - !ruby/object:Gem::Version
19
- version: '0'
75
+ version: '10.0'
20
76
  type: :development
21
77
  prerelease: false
22
78
  version_requirements: !ruby/object:Gem::Requirement
23
79
  requirements:
24
80
  - - ">="
25
81
  - !ruby/object:Gem::Version
26
- version: '0'
27
- description: Initial build
82
+ version: '10.0'
83
+ description: 'Apex: the RubyMotion web framework for OS X.'
28
84
  email:
29
85
  - jamon@clearsightstudio.com
30
86
  executables: []
@@ -34,9 +90,15 @@ files:
34
90
  - README.md
35
91
  - lib/apex.rb
36
92
  - lib/apex/apex.rb
37
- homepage: ''
93
+ - lib/apex/cocoa/delegate_interface.rb
94
+ - lib/apex/request.rb
95
+ - lib/apex/response.rb
96
+ - lib/apex/server.rb
97
+ - lib/apex/version.rb
98
+ - spec/main_spec.rb
99
+ homepage: https://github.com/clearsightstudio/apex
38
100
  licenses:
39
- - ''
101
+ - MIT
40
102
  metadata: {}
41
103
  post_install_message:
42
104
  rdoc_options: []
@@ -57,5 +119,7 @@ rubyforge_project:
57
119
  rubygems_version: 2.2.2
58
120
  signing_key:
59
121
  specification_version: 4
60
- summary: Initial build is initial.
61
- test_files: []
122
+ summary: Apex is a RubyMotion web framework for OS X. It uses GCDWebServer under the
123
+ hood and provides a Sinatra-like router and DSL.
124
+ test_files:
125
+ - spec/main_spec.rb