cyborg 0.4.11 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cyborg/helpers/layout_helpers.rb +2 -1
- data/lib/cyborg/middleware.rb +27 -0
- data/lib/cyborg/plugin.rb +24 -14
- data/lib/cyborg/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82bc5755ca9c2513786f46e4cc522771af004199
|
4
|
+
data.tar.gz: 60d535e47177d591f0dee474cba3b0b532468ab4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d18429cc529df9ae3551625f8d77aed1708acbf57429b091b74e2e32d272a59ad4b11559abedc89c95a95e5885c3e8f7ad62b3077150afa3259e6fd62234f3a9
|
7
|
+
data.tar.gz: b943de6964048a25deaa5bcd5adc3a702d8e8b0f3c1c1392ddfa19d288f1d0e09ce70da281a43c8b827870e30b4f34e01ce4542892d40bb00952ff86a67b4c5f
|
@@ -4,8 +4,9 @@ module Cyborg
|
|
4
4
|
def render_layout(*args, &block)
|
5
5
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
6
6
|
layout = args.first || 'default'
|
7
|
+
options[:template] = "layouts/#{layout}"
|
7
8
|
yield if block_given?
|
8
|
-
render
|
9
|
+
render options
|
9
10
|
end
|
10
11
|
|
11
12
|
def javascripts(&block)
|
data/lib/cyborg/middleware.rb
CHANGED
@@ -15,4 +15,31 @@ module Cyborg
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
18
|
+
class StaticAssets
|
19
|
+
def initialize(app, path, index: 'index', headers: {}, engine_name: nil)
|
20
|
+
@app = app
|
21
|
+
@engine_name = engine_name
|
22
|
+
@file_handler = ActionDispatch::FileHandler.new(path, index: index, headers: headers)
|
23
|
+
end
|
24
|
+
|
25
|
+
def call(env)
|
26
|
+
req = Rack::Request.new env
|
27
|
+
prefix = File.join Application.config.assets.prefix, @engine_name
|
28
|
+
|
29
|
+
if req.get? || req.head?
|
30
|
+
path = req.path_info.chomp('/'.freeze)
|
31
|
+
|
32
|
+
if path.start_with? prefix
|
33
|
+
path = path.remove /\A#{prefix}\//
|
34
|
+
|
35
|
+
if match = @file_handler.match?(path)
|
36
|
+
req.path_info = match
|
37
|
+
return @file_handler.serve(req)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
@app.call(req.env)
|
43
|
+
end
|
44
|
+
end
|
18
45
|
end
|
data/lib/cyborg/plugin.rb
CHANGED
@@ -34,8 +34,12 @@ module Cyborg
|
|
34
34
|
|
35
35
|
engine_name Cyborg.plugin.name
|
36
36
|
|
37
|
+
require 'cyborg/middleware'
|
38
|
+
|
39
|
+
prefix = Rails.application.config.assets.prefix
|
40
|
+
|
37
41
|
initializer "#{name}.static_assets" do |app|
|
38
|
-
app.middleware.insert_before
|
42
|
+
app.middleware.insert_before ::ActionDispatch::Static, Cyborg::StaticAssets, "#{root}/public", engine_name: Cyborg.plugin.name
|
39
43
|
app.middleware.insert_before ::ActionDispatch::Static, Rack::Deflater
|
40
44
|
end
|
41
45
|
end)
|
@@ -82,10 +86,19 @@ module Cyborg
|
|
82
86
|
assets(options).map(&:watch)
|
83
87
|
end
|
84
88
|
|
89
|
+
def asset_root
|
90
|
+
asset_prefix = Rails.application.config.assets.prefix || '/assets'
|
91
|
+
File.join asset_prefix, name
|
92
|
+
end
|
93
|
+
|
94
|
+
def production_asset_root
|
95
|
+
@production_asset_root || asset_root
|
96
|
+
end
|
97
|
+
|
85
98
|
def config(options)
|
99
|
+
|
86
100
|
options = {
|
87
|
-
production_asset_root:
|
88
|
-
asset_root: "/assets/#{name}",
|
101
|
+
production_asset_root: nil,
|
89
102
|
destination: "public/",
|
90
103
|
root: @gem.full_gem_path,
|
91
104
|
version: @gem.version.to_s,
|
@@ -98,7 +111,7 @@ module Cyborg
|
|
98
111
|
}.merge(options)
|
99
112
|
|
100
113
|
options.each do |k,v|
|
101
|
-
set_instance(k.to_s,v)
|
114
|
+
set_instance(k.to_s,v)
|
102
115
|
end
|
103
116
|
end
|
104
117
|
|
@@ -110,17 +123,19 @@ module Cyborg
|
|
110
123
|
end
|
111
124
|
|
112
125
|
def asset_path(file=nil)
|
113
|
-
dest =
|
126
|
+
dest = destination
|
114
127
|
dest = File.join(dest, file) if file
|
115
128
|
dest
|
116
129
|
end
|
117
130
|
|
118
131
|
def asset_url(file=nil)
|
119
|
-
|
132
|
+
|
133
|
+
path = if Cyborg.production?
|
120
134
|
production_asset_root
|
121
135
|
else
|
122
136
|
asset_root
|
123
137
|
end
|
138
|
+
|
124
139
|
path = File.join(path, file) if file
|
125
140
|
path
|
126
141
|
end
|
@@ -130,23 +145,18 @@ module Cyborg
|
|
130
145
|
def asset_ext(klass)
|
131
146
|
klass.name.split('::').last.downcase
|
132
147
|
end
|
133
|
-
|
148
|
+
|
134
149
|
# Find files based on class type and
|
135
150
|
# return an array of Classes for each file
|
136
151
|
def add_files(klass)
|
137
152
|
ext = asset_ext klass
|
138
|
-
find_files(ext).map do |path|
|
153
|
+
find_files(ext).map do |path|
|
139
154
|
klass.new(self, path)
|
140
155
|
end
|
141
156
|
end
|
142
157
|
|
143
|
-
def glob(asset_ext)
|
144
|
-
|
145
|
-
end
|
146
|
-
|
147
158
|
# Find files by class type and extension
|
148
159
|
def find_files(ext)
|
149
|
-
|
150
160
|
files = Dir[File.join(paths[ext.to_sym], asset_glob(ext))]
|
151
161
|
|
152
162
|
# Filter out partials
|
@@ -162,10 +172,10 @@ module Cyborg
|
|
162
172
|
end
|
163
173
|
end
|
164
174
|
|
165
|
-
|
166
175
|
# Convert configuration into instance variables
|
167
176
|
def set_instance(name, value)
|
168
177
|
instance_variable_set("@#{name}", value)
|
178
|
+
|
169
179
|
instance_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
170
180
|
def #{name}
|
171
181
|
@#{name}
|
data/lib/cyborg/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cyborg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Mathis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sass
|