roda-cj 1.0.4 → 1.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3718202aa5175a67126539e0d6f4ff22eff2a194
4
- data.tar.gz: d2aa31f52413970c3c9442ca77c75cba0ec9f9f2
3
+ metadata.gz: af3da6c6a5dbecc79ec993e9393115ae8862e8b6
4
+ data.tar.gz: 4238915430382a9d43ccfba59f890229c3388d6a
5
5
  SHA512:
6
- metadata.gz: bde6d4389d7c8c98626512de3e497f9df24d185ecea0c26e6cb3d49934758296730254461fb473b2e795415d119fc31c6d9cf44a6efc136da1151f72b29cf176
7
- data.tar.gz: e45591c85df7a82cb5a6ad487bbf75fce44f124e423b2a301f7a9ff9796e8eeb67085261829e5983be5e6e491858ec8a76be28ff016ec31e5faec6f250538fbd
6
+ metadata.gz: 0a259997417cb792ac317890812d0d549bb6e4003eed49385b420de352a77c182854db078929d3dd2968c2179af289ab32625f56afd9e136445a5f45f6b0b5e7
7
+ data.tar.gz: 158e74929dd3bfbe8ef333b01f7e16567724222cb613c34351105ef8667178f7dd948aa03190edbde3e9b6c1a6a937deff8537723e4f660be61e232768e1d000
@@ -1,5 +1,6 @@
1
1
  require "tilt"
2
- require 'open-uri'
2
+ require 'net/http'
3
+ require 'uri'
3
4
 
4
5
  class Roda
5
6
  module RodaPlugins
@@ -53,7 +54,7 @@ class Roda
53
54
 
54
55
  # Generates a unique id, this is used to keep concat/compiled files
55
56
  # from caching in the browser when they are generated
56
- def assets_unique_id type
57
+ def assets_unique_id(type)
57
58
  if unique_id = instance_variable_get("@#{type}")
58
59
  unique_id
59
60
  else
@@ -83,11 +84,13 @@ class Roda
83
84
 
84
85
  private
85
86
 
86
- def compile_process_files files, type, folder
87
+ def compile_process_files(files, type, folder)
87
88
  require 'yuicompressor'
88
89
 
89
- r = new
90
+ # start app instance
91
+ app = new
90
92
 
93
+ # content to render to file
91
94
  content = ''
92
95
 
93
96
  files.each do |file|
@@ -95,7 +98,7 @@ class Roda
95
98
  file = "#{folder}/#{file}"
96
99
  end
97
100
 
98
- content += r.read_asset_file file, type
101
+ content += app.read_asset_file file, type
99
102
  end
100
103
 
101
104
  path = assets_opts[:compiled_path] \
@@ -150,6 +153,7 @@ class Roda
150
153
  end
151
154
 
152
155
  def render_asset(file, type)
156
+ # convert back url safe to period
153
157
  file.gsub!(/(\$2E|%242E)/, '.')
154
158
 
155
159
  if !assets_opts[:compiled] && !assets_opts[:concat]
@@ -177,7 +181,7 @@ class Roda
177
181
  end
178
182
  end
179
183
 
180
- def read_asset_file file, type
184
+ def read_asset_file(file, type)
181
185
  folder = assets_opts[:"#{type}_folder"]
182
186
 
183
187
  # If there is no file it must be a remote file request.
@@ -187,31 +191,29 @@ class Roda
187
191
  file = env['SCRIPT_NAME'].gsub(/^\/#{route}\/#{folder}\//, '')
188
192
  end
189
193
 
194
+ # If it's not a url or parent direct append the full path
190
195
  if !file[/^\.\//] && !file[/^http/]
191
- path = assets_opts[:path] + '/' + folder + "/#{file}"
192
- else
193
- path = file
196
+ file = assets_opts[:path] + '/' + folder + "/#{file}"
194
197
  end
195
198
 
199
+ # set the current engine
196
200
  engine = assets_opts[:"#{type}_engine"]
197
201
 
198
- # render via tilt
199
- if File.exists? "#{path}.#{engine}"
200
- render path: "#{path}.#{engine}"
201
- # read file directly
202
- elsif File.exists? "#{path}.#{type}"
203
- File.read "#{path}.#{type}"
204
- # grab remote file content
202
+ if File.exists? "#{file}.#{engine}"
203
+ # render via tilt
204
+ render path: "#{file}.#{engine}"
205
+ elsif File.exists? "#{file}.#{type}"
206
+ # read file directly
207
+ File.read "#{file}.#{type}"
205
208
  elsif file[/^http/]
206
- open(file).read
207
- # as a last attempt lets see if the file can be rendered by tilt
208
- # otherwise load the file directly
209
- elsif File.exists? path
210
- begin
211
- render path: path
212
- rescue
213
- File.read path
214
- end
209
+ # grab remote file content
210
+ Net::HTTP.get(URI.parse(file))
211
+ elsif File.exists?(file) && !file[/\.#{type}$/]
212
+ # Render via tilt if the type isn't css or js
213
+ render path: file
214
+ else
215
+ # if it is css/js read the file directly
216
+ File.read file
215
217
  end
216
218
  end
217
219
 
@@ -229,13 +231,13 @@ class Roda
229
231
 
230
232
  # CSS tag template
231
233
  # <link rel="stylesheet" href="theme.css">
232
- def css_assets_tag attrs
234
+ def css_assets_tag(attrs)
233
235
  "<link rel=\"stylesheet\" #{attrs} />"
234
236
  end
235
237
 
236
238
  # JS tag template
237
239
  # <script src="scriptfile.js"></script>
238
- def js_assets_tag attrs
240
+ def js_assets_tag(attrs)
239
241
  "<script type=\"text/javascript\" #{attrs}></script>"
240
242
  end
241
243
  end
@@ -1,3 +1,3 @@
1
1
  class Roda
2
- RodaVersion = '1.0.4'.freeze
2
+ RodaVersion = '1.0.5'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roda-cj
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-27 00:00:00.000000000 Z
11
+ date: 2014-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack