resin 0.0.8 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/runresin +2 -2
- data/lib/resin/{app/app.rb → app.rb} +15 -2
- data/lib/resin/helpers.rb +167 -0
- data/lib/resin/{app/views → views}/index.haml +0 -0
- metadata +34 -23
- data/lib/resin/app/helpers.rb +0 -77
data/bin/runresin
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
begin
|
4
|
-
require 'resin/app
|
4
|
+
require 'resin/app'
|
5
5
|
rescue LoadError => e
|
6
6
|
require 'rubygems'
|
7
7
|
path = File.expand_path '../../lib', __FILE__
|
8
8
|
$:.unshift(path) if File.directory?(path) && !$:.include?(path)
|
9
|
-
require 'resin/app
|
9
|
+
require 'resin/app'
|
10
10
|
end
|
11
11
|
|
12
12
|
Resin::Server.run!
|
@@ -4,7 +4,7 @@ require 'haml'
|
|
4
4
|
|
5
5
|
require File.expand_path(File.dirname(__FILE__) + '/helpers.rb')
|
6
6
|
|
7
|
-
AMBER_PATH = File.expand_path('
|
7
|
+
AMBER_PATH = File.expand_path('../../../amber', __FILE__)
|
8
8
|
|
9
9
|
module Resin
|
10
10
|
def env
|
@@ -42,9 +42,14 @@ module Resin
|
|
42
42
|
get "/#{path}/*" do |filename|
|
43
43
|
content_type_for_ext filename
|
44
44
|
data = load_resource(path, filename)
|
45
|
+
if data.nil? and path == 'js'
|
46
|
+
data = load_drop_resource(filename)
|
47
|
+
end
|
48
|
+
|
45
49
|
if data.nil?
|
46
50
|
halt 404, 'Not found'
|
47
51
|
end
|
52
|
+
|
48
53
|
data
|
49
54
|
end
|
50
55
|
end
|
@@ -61,7 +66,15 @@ module Resin
|
|
61
66
|
if filename.end_with? '.js'
|
62
67
|
directory = '/js/'
|
63
68
|
end
|
64
|
-
|
69
|
+
|
70
|
+
root_dir = Dir.pwd
|
71
|
+
|
72
|
+
if drops_filemap[filename]
|
73
|
+
drop_name = drops_filemap[filename]
|
74
|
+
root_dir = drops_map[drop_name]
|
75
|
+
end
|
76
|
+
|
77
|
+
path = File.join(root_dir, directory, filename)
|
65
78
|
puts ">> Commiting changes to #{path}"
|
66
79
|
File.open(path, 'w') do |fd|
|
67
80
|
request.body.each do |line|
|
@@ -0,0 +1,167 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'json'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module Resin
|
6
|
+
module Helpers
|
7
|
+
def self.append_js_file(filename, to_array)
|
8
|
+
filename = File.basename(filename)
|
9
|
+
|
10
|
+
if Resin.development?
|
11
|
+
unless filename.include? 'deploy'
|
12
|
+
to_array << filename
|
13
|
+
end
|
14
|
+
return
|
15
|
+
end
|
16
|
+
|
17
|
+
if (filename.include? 'deploy') && !(filename.include? '-Tests')
|
18
|
+
to_array << filename
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def javascript_files
|
23
|
+
files = []
|
24
|
+
|
25
|
+
# First our project's files take precedence
|
26
|
+
Dir.glob("#{Dir.pwd}/js/*.js") do |filename|
|
27
|
+
Resin::Helpers.append_js_file(filename, files)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Then our drops get loaded
|
31
|
+
drops.each do |drop|
|
32
|
+
unless drop[:meta]
|
33
|
+
next
|
34
|
+
end
|
35
|
+
|
36
|
+
if drop[:js]
|
37
|
+
drop[:js].each do |filename|
|
38
|
+
Resin::Helpers.append_js_file(filename, files)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
files
|
44
|
+
end
|
45
|
+
|
46
|
+
def find_template(views, name, engine, &block)
|
47
|
+
Array(views).each do |view|
|
48
|
+
super(view, name, engine, &block)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def embed_amber(options={})
|
53
|
+
deploy_line = ''
|
54
|
+
unless Resin.development?
|
55
|
+
deploy_line = "deploy: true,"
|
56
|
+
end
|
57
|
+
|
58
|
+
on_ready_function = options[:on_ready] || ''
|
59
|
+
|
60
|
+
return <<-END
|
61
|
+
<script type="text/javascript" src="/js/amber.js"></script>
|
62
|
+
<script type="text/javascript">
|
63
|
+
loadAmber({
|
64
|
+
#{deploy_line}
|
65
|
+
files : #{JSON.dump(javascript_files)},
|
66
|
+
prefix : 'js',
|
67
|
+
ready : function() { #{on_ready_function} }
|
68
|
+
});
|
69
|
+
</script>
|
70
|
+
END
|
71
|
+
end
|
72
|
+
|
73
|
+
def load_resource(prefix, filename)
|
74
|
+
# A file in our working directory will take precedence over the
|
75
|
+
# Amber-bundled files. This should allow custom Kernel-Objects.js files
|
76
|
+
# for example.
|
77
|
+
local_file = File.join(Dir.pwd, "#{prefix}/", filename)
|
78
|
+
amber_file = File.join(AMBER_PATH, "/#{prefix}/", filename)
|
79
|
+
|
80
|
+
if File.exists? local_file
|
81
|
+
File.open(local_file, 'r').read
|
82
|
+
elsif File.exists? amber_file
|
83
|
+
File.open(amber_file, 'r').read
|
84
|
+
else
|
85
|
+
nil
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def load_drop_resource(filename)
|
90
|
+
drops.each do |drop|
|
91
|
+
if drop.nil? or drop.empty? or drop[:js].empty?
|
92
|
+
next
|
93
|
+
end
|
94
|
+
|
95
|
+
drop[:js].each do |drop_filepath|
|
96
|
+
drop_filename = File.basename(drop_filepath)
|
97
|
+
if filename == drop_filename
|
98
|
+
return File.open(drop_filepath).read
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
nil
|
103
|
+
end
|
104
|
+
|
105
|
+
def content_type_for_ext(filename)
|
106
|
+
if File.extname(filename) == '.js'
|
107
|
+
content_type 'application/javascript'
|
108
|
+
elsif File.extname(filename) == '.css'
|
109
|
+
content_type 'text/css'
|
110
|
+
else
|
111
|
+
content_type 'text/plain'
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def load_drop_file(filepath)
|
116
|
+
YAML::load(File.open(filepath).read)
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.flush_drops
|
120
|
+
@@drops = nil
|
121
|
+
@@drops_map = {}
|
122
|
+
@@drops_filemap = {}
|
123
|
+
end
|
124
|
+
|
125
|
+
def drops_map
|
126
|
+
@@drops_map
|
127
|
+
end
|
128
|
+
|
129
|
+
def drops_filemap
|
130
|
+
@@drops_filemap
|
131
|
+
end
|
132
|
+
|
133
|
+
def drops
|
134
|
+
@@drops ||= begin
|
135
|
+
@@drops_map ||= {}
|
136
|
+
@@drops_filemap ||= {}
|
137
|
+
drops_path = File.join(Dir.pwd, 'drops')
|
138
|
+
loaded = []
|
139
|
+
Dir.glob("#{drops_path}/*/drop.yml") do |filename|
|
140
|
+
drop = load_drop_file(filename)
|
141
|
+
if drop.nil? or drop.empty?
|
142
|
+
next
|
143
|
+
end
|
144
|
+
drop_dir = File.dirname(filename)
|
145
|
+
name = drop['drop']['name']
|
146
|
+
puts ">>> Loading Resin Drop: #{name}"
|
147
|
+
|
148
|
+
data = {:meta => drop['drop'],
|
149
|
+
:js => Dir[File.join(drop_dir, 'js', '*.js')],
|
150
|
+
:st => Dir[File.join(drop_dir, 'st', '*.st')]
|
151
|
+
}
|
152
|
+
loaded << data
|
153
|
+
|
154
|
+
@@drops_map[name] = drop_dir
|
155
|
+
|
156
|
+
data[:js].each do |js|
|
157
|
+
@@drops_filemap[File.basename(js)] = name
|
158
|
+
end
|
159
|
+
data[:st].each do |st|
|
160
|
+
@@drops_filemap[File.basename(st)] = name
|
161
|
+
end
|
162
|
+
end
|
163
|
+
loaded
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
16
|
-
requirement: &
|
16
|
+
requirement: &3285240 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.0.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *3285240
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &3284540 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *3284540
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: shotgun
|
38
|
-
requirement: &
|
38
|
+
requirement: &3283740 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *3283740
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &3283020 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *3283020
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rack-test
|
60
|
-
requirement: &
|
60
|
+
requirement: &3282340 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *3282340
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: thin
|
71
|
-
requirement: &
|
71
|
+
requirement: &3298000 !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: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *3298000
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: haml
|
82
|
-
requirement: &
|
82
|
+
requirement: &3297320 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :runtime
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *3297320
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: sinatra
|
93
|
-
requirement: &
|
93
|
+
requirement: &3296460 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,7 +98,18 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :runtime
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *3296460
|
102
|
+
- !ruby/object:Gem::Dependency
|
103
|
+
name: json
|
104
|
+
requirement: &3295300 !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :runtime
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: *3295300
|
102
113
|
description:
|
103
114
|
email: tyler@linux.com
|
104
115
|
executables:
|
@@ -108,10 +119,10 @@ extra_rdoc_files:
|
|
108
119
|
- README.markdown
|
109
120
|
files:
|
110
121
|
- bin/runresin
|
111
|
-
- lib/resin/
|
112
|
-
- lib/resin/app
|
122
|
+
- lib/resin/helpers.rb
|
123
|
+
- lib/resin/app.rb
|
113
124
|
- lib/resin.rb
|
114
|
-
- lib/resin/
|
125
|
+
- lib/resin/views/index.haml
|
115
126
|
- amber/css/amber-normalize.css
|
116
127
|
- amber/css/amber.css
|
117
128
|
- amber/css/style.css
|
@@ -207,7 +218,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
207
218
|
version: '0'
|
208
219
|
segments:
|
209
220
|
- 0
|
210
|
-
hash:
|
221
|
+
hash: 2600024671058263064
|
211
222
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
212
223
|
none: false
|
213
224
|
requirements:
|
@@ -216,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
216
227
|
version: '0'
|
217
228
|
segments:
|
218
229
|
- 0
|
219
|
-
hash:
|
230
|
+
hash: 2600024671058263064
|
220
231
|
requirements: []
|
221
232
|
rubyforge_project:
|
222
233
|
rubygems_version: 1.8.10
|
data/lib/resin/app/helpers.rb
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
|
2
|
-
module Resin
|
3
|
-
module Helpers
|
4
|
-
def javascript_files
|
5
|
-
files = []
|
6
|
-
Dir.glob("#{Dir.pwd}/js/*.js") do |filename|
|
7
|
-
if Resin.development?
|
8
|
-
unless filename.include? 'deploy'
|
9
|
-
files << "\"#{File.basename(filename)}\""
|
10
|
-
end
|
11
|
-
else
|
12
|
-
unless filename.include? 'deploy'
|
13
|
-
next
|
14
|
-
end
|
15
|
-
|
16
|
-
unless filename.include? '-Tests'
|
17
|
-
files << "\"#{File.basename(filename)}\""
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
files.join(',')
|
22
|
-
end
|
23
|
-
|
24
|
-
def find_template(views, name, engine, &block)
|
25
|
-
Array(views).each do |view|
|
26
|
-
super(view, name, engine, &block)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def embed_amber(options={})
|
31
|
-
deploy_line = ''
|
32
|
-
unless Resin.development?
|
33
|
-
deploy_line = "deploy: true,"
|
34
|
-
end
|
35
|
-
|
36
|
-
on_ready_function = options[:on_ready] || ''
|
37
|
-
|
38
|
-
return <<-END
|
39
|
-
<script type="text/javascript" src="/js/amber.js"></script>
|
40
|
-
<script type="text/javascript">
|
41
|
-
loadAmber({
|
42
|
-
#{deploy_line}
|
43
|
-
files : [#{javascript_files}],
|
44
|
-
prefix : 'js',
|
45
|
-
ready : function() { #{on_ready_function} }
|
46
|
-
});
|
47
|
-
</script>
|
48
|
-
END
|
49
|
-
end
|
50
|
-
|
51
|
-
def load_resource(prefix, filename)
|
52
|
-
# A file in our working directory will take precedence over the
|
53
|
-
# Amber-bundled files. This should allow custom Kernel-Objects.js files
|
54
|
-
# for example.
|
55
|
-
local_file = File.join(Dir.pwd, "#{prefix}/", filename)
|
56
|
-
amber_file = File.join(AMBER_PATH, "/#{prefix}/", filename)
|
57
|
-
|
58
|
-
if File.exists? local_file
|
59
|
-
File.open(local_file, 'r').read
|
60
|
-
elsif File.exists? amber_file
|
61
|
-
File.open(amber_file, 'r').read
|
62
|
-
else
|
63
|
-
nil
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def content_type_for_ext(filename)
|
68
|
-
if File.extname(filename) == '.js'
|
69
|
-
content_type 'application/javascript'
|
70
|
-
elsif File.extname(filename) == '.css'
|
71
|
-
content_type 'text/css'
|
72
|
-
else
|
73
|
-
content_type 'text/plain'
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|