resin 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,8 @@ require 'rubygems'
2
2
  require 'sinatra/base'
3
3
  require 'haml'
4
4
 
5
+ require File.expand_path(File.dirname(__FILE__) + '/helpers.rb')
6
+
5
7
  AMBER_PATH = File.expand_path('../../../../amber', __FILE__)
6
8
 
7
9
  module Resin
@@ -18,38 +20,10 @@ module Resin
18
20
  class Server < Sinatra::Base
19
21
  set :dump_errors, true
20
22
  set :port, ENV['PORT'] || 4567
21
- set :views, File.expand_path('../views', __FILE__)
22
-
23
23
  set :views, [File.join(Dir.pwd, 'views'), File.expand_path('../views', __FILE__)]
24
24
 
25
25
  helpers do
26
- def find_template(views, name, engine, &block)
27
- Array(views).each do |view|
28
- super(view, name, engine, &block)
29
- end
30
- end
31
-
32
- def embed_amber
33
- return <<-END
34
- <script type="text/javascript" src="/js/amber.js"></script>
35
- <script type="text/javascript">
36
- loadAmber({
37
- files : [#{javascript_files}],
38
- ready : function() { }
39
- });
40
- </script>
41
- END
42
- end
43
- end
44
-
45
- def javascript_files
46
- files = []
47
- Dir.glob("#{Dir.pwd}/js/*.js") do |filename|
48
- unless filename.include? 'deploy'
49
- files << "\"#{File.basename(filename)}\""
50
- end
51
- end
52
- files.join(',')
26
+ include Resin::Helpers
53
27
  end
54
28
 
55
29
  get '/' do
@@ -64,32 +38,6 @@ module Resin
64
38
  end
65
39
  end
66
40
 
67
- def load_resource(prefix, filename)
68
- # A file in our working directory will take precedence over the
69
- # Amber-bundled files. This should allow custom Kernel-Objects.js files
70
- # for example.
71
- local_file = File.join(Dir.pwd, "#{prefix}/", filename)
72
- amber_file = File.join(AMBER_PATH, "/#{prefix}/", filename)
73
-
74
- if File.exists? local_file
75
- File.open(local_file, 'r').read
76
- elsif File.exists? amber_file
77
- File.open(amber_file, 'r').read
78
- else
79
- nil
80
- end
81
- end
82
-
83
- def content_type_for_ext(filename)
84
- if File.extname(filename) == '.js'
85
- content_type 'application/javascript'
86
- elsif File.extname(filename) == '.css'
87
- content_type 'text/css'
88
- else
89
- content_type 'text/plain'
90
- end
91
- end
92
-
93
41
  ['js', 'css', 'images'].each do |path|
94
42
  get "/#{path}/*" do |filename|
95
43
  content_type_for_ext filename
@@ -0,0 +1,64 @@
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
+ if filename.include? 'deploy'
13
+ files << "\"#{File.basename(filename)}\""
14
+ end
15
+ end
16
+ end
17
+ files.join(',')
18
+ end
19
+
20
+ def find_template(views, name, engine, &block)
21
+ Array(views).each do |view|
22
+ super(view, name, engine, &block)
23
+ end
24
+ end
25
+
26
+ def embed_amber
27
+ return <<-END
28
+ <script type="text/javascript" src="/js/amber.js"></script>
29
+ <script type="text/javascript">
30
+ loadAmber({
31
+ files : [#{javascript_files}],
32
+ ready : function() { }
33
+ });
34
+ </script>
35
+ END
36
+ end
37
+
38
+ def load_resource(prefix, filename)
39
+ # A file in our working directory will take precedence over the
40
+ # Amber-bundled files. This should allow custom Kernel-Objects.js files
41
+ # for example.
42
+ local_file = File.join(Dir.pwd, "#{prefix}/", filename)
43
+ amber_file = File.join(AMBER_PATH, "/#{prefix}/", filename)
44
+
45
+ if File.exists? local_file
46
+ File.open(local_file, 'r').read
47
+ elsif File.exists? amber_file
48
+ File.open(amber_file, 'r').read
49
+ else
50
+ nil
51
+ end
52
+ end
53
+
54
+ def content_type_for_ext(filename)
55
+ if File.extname(filename) == '.js'
56
+ content_type 'application/javascript'
57
+ elsif File.extname(filename) == '.css'
58
+ content_type 'text/css'
59
+ else
60
+ content_type 'text/plain'
61
+ end
62
+ end
63
+ end
64
+ end
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.3
4
+ version: 0.0.4
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-02-27 00:00:00.000000000 Z
12
+ date: 2012-03-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
- requirement: &7592780 !ruby/object:Gem::Requirement
16
+ requirement: &7592760 !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: *7592780
24
+ version_requirements: *7592760
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &7592380 !ruby/object:Gem::Requirement
27
+ requirement: &7592360 !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: *7592380
35
+ version_requirements: *7592360
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: shotgun
38
- requirement: &7591920 !ruby/object:Gem::Requirement
38
+ requirement: &7591900 !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: *7591920
46
+ version_requirements: *7591900
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &7591480 !ruby/object:Gem::Requirement
49
+ requirement: &7591440 !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: *7591480
57
+ version_requirements: *7591440
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rack-test
60
- requirement: &7591040 !ruby/object:Gem::Requirement
60
+ requirement: &7591020 !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: *7591040
68
+ version_requirements: *7591020
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: thin
71
- requirement: &7590620 !ruby/object:Gem::Requirement
71
+ requirement: &7590600 !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: *7590620
79
+ version_requirements: *7590600
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: haml
82
- requirement: &7590200 !ruby/object:Gem::Requirement
82
+ requirement: &7590180 !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: *7590200
90
+ version_requirements: *7590180
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: sinatra
93
- requirement: &7589760 !ruby/object:Gem::Requirement
93
+ requirement: &7589740 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: '0'
99
99
  type: :runtime
100
100
  prerelease: false
101
- version_requirements: *7589760
101
+ version_requirements: *7589740
102
102
  description:
103
103
  email: tyler@linux.com
104
104
  executables:
@@ -108,6 +108,7 @@ extra_rdoc_files:
108
108
  - README.markdown
109
109
  files:
110
110
  - bin/runresin
111
+ - lib/resin/app/helpers.rb
111
112
  - lib/resin/app/app.rb
112
113
  - lib/resin.rb
113
114
  - lib/resin/app/views/index.haml