orbit-rb 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/orbit/config.rb +18 -2
- data/lib/orbit/controller.rb +35 -1
- data/lib/orbit/loaders/directory_loader.rb +12 -3
- data/lib/orbit/template_binding.rb +34 -0
- data/lib/orbit/version.rb +1 -1
- data/lib/orbit.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3cd05f089c935285ebf82824a8565989a895a677
|
4
|
+
data.tar.gz: 7ce1e6f2482d364fb13195de7331e628ab50d54d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d07f2acee95a2dd0ef99401faaadccfe263dae3fdcca0e290e20c774176f4c4aa7a7392085838a8155d3a567fca202120e53d7bb23c2061258a9507a8f7bb30
|
7
|
+
data.tar.gz: dda7e52d01b2d78f8912134103ba966559938ae66ad9830cd7967384298598d665ba9dfe380708f556da648956fea3e759f37f35aebe2f28077728ee69aede19
|
data/lib/orbit/config.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
require 'rack'
|
2
2
|
require 'rack/protection'
|
3
|
+
require 'logger'
|
3
4
|
|
4
5
|
module Orbit
|
5
6
|
class Config
|
6
7
|
include Singleton
|
7
|
-
attr_accessor :app_path, :
|
8
|
+
attr_accessor :app_path, :rack_logger_class, :logger_class, :log_level,
|
9
|
+
:log_appname, :log_file, :path_class, :request_class,
|
10
|
+
:response_class, :route_class, :router_class, :session_secret
|
8
11
|
|
9
12
|
def initialize
|
10
13
|
instantiate
|
@@ -17,7 +20,11 @@ module Orbit
|
|
17
20
|
@session_secret = 'session_secret'
|
18
21
|
|
19
22
|
# Classes
|
20
|
-
@
|
23
|
+
@rack_logger_class = Rack::Logger
|
24
|
+
@logger_class = Logger
|
25
|
+
@log_level = Logger::DEBUG
|
26
|
+
@log_file = STDOUT
|
27
|
+
@log_appname = 'Orbit App'
|
21
28
|
@path_class = Orbit::Routing::Path
|
22
29
|
@request_class = Orbit::Request
|
23
30
|
@response_class = Orbit::Response
|
@@ -33,6 +40,15 @@ module Orbit
|
|
33
40
|
@instance.logger_class
|
34
41
|
end
|
35
42
|
|
43
|
+
def self.logger
|
44
|
+
@_logger ||= begin
|
45
|
+
logger_class.new(@instance.log_file).tap do |logger|
|
46
|
+
logger.level = @instance.log_level
|
47
|
+
logger.progname = @instance.log_appname
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
36
52
|
def self.path_class
|
37
53
|
@instance.path_class
|
38
54
|
end
|
data/lib/orbit/controller.rb
CHANGED
@@ -7,6 +7,14 @@ module Orbit
|
|
7
7
|
@response = Orbit::Config.response_class.new
|
8
8
|
end
|
9
9
|
|
10
|
+
def self.layout(_layout = nil)
|
11
|
+
if _layout
|
12
|
+
@layout = "#{Dir.pwd}/#{_layout}"
|
13
|
+
else
|
14
|
+
@layout
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
10
18
|
def self.execute_action(request, action)
|
11
19
|
new(request).execute_action(action)
|
12
20
|
end
|
@@ -21,6 +29,22 @@ module Orbit
|
|
21
29
|
end
|
22
30
|
end
|
23
31
|
|
32
|
+
def render(template)
|
33
|
+
root_path = Dir.pwd
|
34
|
+
|
35
|
+
template_location = "#{root_path}/#{template}"
|
36
|
+
|
37
|
+
templates = [template_location, self.class.layout].compact
|
38
|
+
|
39
|
+
templates.inject(nil) do | prev, template |
|
40
|
+
_render(template) { prev }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def locals
|
45
|
+
@_locals ||= TemplateBinding.locals(params)
|
46
|
+
end
|
47
|
+
|
24
48
|
def self.path(path)
|
25
49
|
@base_path ||= superclass != Orbit::Controller ? superclass.base_path : ''
|
26
50
|
@base_path += path
|
@@ -128,7 +152,7 @@ module Orbit
|
|
128
152
|
sep = '_'
|
129
153
|
# Turn unwanted chars into the separator
|
130
154
|
parameterized_string = string.to_s.gsub(/[^a-z0-9\-_]+/i, sep)
|
131
|
-
|
155
|
+
|
132
156
|
re_sep = Regexp.escape(sep)
|
133
157
|
# No more than one of the separator in a row.
|
134
158
|
parameterized_string.gsub!(/#{re_sep}{2,}/, sep)
|
@@ -137,5 +161,15 @@ module Orbit
|
|
137
161
|
|
138
162
|
parameterized_string.downcase
|
139
163
|
end
|
164
|
+
|
165
|
+
def _render(template)
|
166
|
+
file = File.read(template)
|
167
|
+
|
168
|
+
ERB.new(file).result(locals.variables { yield })
|
169
|
+
end
|
170
|
+
|
171
|
+
private_class_method :create_method
|
172
|
+
private_class_method :update_method
|
173
|
+
private_class_method :parameterize
|
140
174
|
end
|
141
175
|
end
|
@@ -4,10 +4,19 @@ module Orbit
|
|
4
4
|
attr_reader :reloader
|
5
5
|
|
6
6
|
def initialize
|
7
|
-
base_path = "#{Dir.pwd}
|
8
|
-
|
7
|
+
base_path = "#{Dir.pwd}"
|
8
|
+
@files = []
|
9
|
+
|
10
|
+
if Orbit::Config.app_path.is_a?(String)
|
11
|
+
@files.push Dir["#{base_path}/#{Orbit::Config.app_path}/**/*.rb"]
|
12
|
+
else
|
13
|
+
Orbit::Config.app_path.each do |path|
|
14
|
+
@files.push Dir["#{base_path}/#{path}/**/*.rb"]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
9
18
|
@retries = 0
|
10
|
-
@files =
|
19
|
+
@files = @files.flatten
|
11
20
|
@reloader = FileReloader.new(files)
|
12
21
|
end
|
13
22
|
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Orbit
|
2
|
+
class TemplateBinding
|
3
|
+
def initialize(hash)
|
4
|
+
@variables = binding
|
5
|
+
|
6
|
+
hash.each do |key, value|
|
7
|
+
@variables.local_variable_set(key.to_sym, value)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.locals(hash)
|
12
|
+
new(hash).locals
|
13
|
+
end
|
14
|
+
|
15
|
+
def locals
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
def variables
|
20
|
+
binding.tap do |bind|
|
21
|
+
@variables.local_variables.each do |var|
|
22
|
+
binding.local_variable_set(var, @variables.local_variable_get(var))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def method_missing(method, *args, &block)
|
28
|
+
if method.to_s[-1] == '='
|
29
|
+
var_name = method.to_s[0..-2].to_sym
|
30
|
+
@variables.local_variable_set(var_name, args.first)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/orbit/version.rb
CHANGED
data/lib/orbit.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: orbit-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Caio Torres
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -112,6 +112,7 @@ files:
|
|
112
112
|
- lib/orbit/routing/pattern.rb
|
113
113
|
- lib/orbit/routing/route.rb
|
114
114
|
- lib/orbit/singleton.rb
|
115
|
+
- lib/orbit/template_binding.rb
|
115
116
|
- lib/orbit/version.rb
|
116
117
|
- orbit.gemspec
|
117
118
|
homepage: https://github.com/efreesen/orbit
|
@@ -135,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
136
|
version: '0'
|
136
137
|
requirements: []
|
137
138
|
rubyforge_project:
|
138
|
-
rubygems_version: 2.4.5
|
139
|
+
rubygems_version: 2.4.5.1
|
139
140
|
signing_key:
|
140
141
|
specification_version: 4
|
141
142
|
summary: Orbit is a Ruby Framework focused on simplicity and flexibility.
|