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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ef0c43dfae0fce8f9706fcc3135952f4c4c8e1c1
4
- data.tar.gz: 1a39f101d0fe888ef661e84c04a7d84ac4175c4a
3
+ metadata.gz: 82bc5755ca9c2513786f46e4cc522771af004199
4
+ data.tar.gz: 60d535e47177d591f0dee474cba3b0b532468ab4
5
5
  SHA512:
6
- metadata.gz: 3e03dc08260093192b81fb81dfae6df988f3ca8e92d38f17851df018783d02bdb1bebdd1ecf0362fe4c32c0434af26655152c45acc1f011d6cf27885b2a24e83
7
- data.tar.gz: 97247809a96b58c7f47a6ed5a6526159012f052b21eb6ec35089caed48967b82a2183ae11538cfb7b9d924d9ac8194147f2a746f057a8aa326f8a53474d40b9e
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 template: "layouts/#{layout}"
9
+ render options
9
10
  end
10
11
 
11
12
  def javascripts(&block)
@@ -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(::ActionDispatch::Static, ::ActionDispatch::Static, "#{root}/public")
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: "/assets/#{name}",
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 = File.join(destination, asset_root)
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
- path = if Cyborg.production?
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}
@@ -1,3 +1,3 @@
1
1
  module Cyborg
2
- VERSION = "0.4.11"
2
+ VERSION = "0.5.0"
3
3
  end
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.11
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: 2016-09-22 00:00:00.000000000 Z
11
+ date: 2017-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sass