jeremyboles-smart-asset-helper 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -26,8 +26,8 @@ class AssetManager
26
26
  end
27
27
 
28
28
  # Automaticly add assets based the controller/action params, if they exsist
29
- def auto_add(asset_type, request_params)
30
- files = self.auto_find(asset_type, request_params)
29
+ def auto_add(asset_type, response)
30
+ files = self.auto_find(asset_type, response)
31
31
  self.add(asset_type, files)
32
32
  end
33
33
 
@@ -43,7 +43,7 @@ class AssetManager
43
43
  files
44
44
  end
45
45
 
46
- def required_with_extra(asset_type, extra, auto, request_params = nil)
46
+ def required_with_extra(asset_type, extra, auto, response = nil)
47
47
  files = []
48
48
  self.required(asset_type).each do |file|
49
49
  path = "#{file}-#{extra}"
@@ -51,22 +51,26 @@ class AssetManager
51
51
  file_path = "#{ASSET_DIR[asset_type]}/#{asset_path}"
52
52
  files << path if File.exists?(file_path)
53
53
  end
54
- files += auto_find(asset_type, request_params, extra) if auto
54
+ files += auto_find(asset_type, response, extra) if auto
55
55
  files
56
56
  end
57
57
 
58
58
  protected
59
59
 
60
- def auto_find(asset_type, request_params, extra = '')
60
+ def auto_find(asset_type, response, extra = '')
61
61
  extra = '-' + extra unless extra.blank?
62
- files, prefix = [], ''
63
- (request_params[:controller] + '/' + request_params[:action]).split('/').each do |path|
64
- path = prefix + path
65
- asset_path = "#{path}#{extra}.#{asset_type}"
66
- file_path = "#{ASSET_DIR[asset_type]}/#{asset_path}"
62
+ files = []
63
+ possible_assets_for_response(response).each do |asset|
64
+ prefix = ''
65
+ (asset).split('/').each do |path|
66
+ path = prefix + path.gsub(/^_/, '').dasherize
67
+ RAILS_DEFAULT_LOGGER.debug(path)
68
+ asset_path = "#{path}#{extra}.#{asset_type}"
69
+ file_path = "#{ASSET_DIR[asset_type]}/#{asset_path}"
67
70
 
68
- files << path + extra if File.exists?(file_path)
69
- prefix = path + '/'
71
+ files << path + extra if File.exists?(file_path)
72
+ prefix = path + '/'
73
+ end
70
74
  end
71
75
  files
72
76
  end
@@ -83,6 +87,19 @@ protected
83
87
  end.flatten
84
88
  end
85
89
 
90
+ def possible_assets_for_response(response)
91
+ assets = [
92
+ response.template.template,
93
+ response.template.instance_variable_get(:@_first_render),
94
+ response.template.instance_variable_get(:@_memoized__pick_partial_template).try(:map, &:second)
95
+ ].flatten.compact
96
+
97
+ assets.map do |t|
98
+ RAILS_DEFAULT_LOGGER.debug(t)
99
+ t.relative_path.gsub('.' + t.format.to_s, '').gsub('.' + t.extension.to_s, '').gsub('app/', '').gsub('views/', '')
100
+ end
101
+ end
102
+
86
103
  # Processes the shortcuts
87
104
  def process_shortcuts(asset_type, files)
88
105
  files.flatten.map do |file|
@@ -22,7 +22,7 @@ module SmartAssetHelper
22
22
  options = extract_options(args)
23
23
  assets = include_assets(:js, args, options)
24
24
  javascript = javascript_include_tag(*assets)
25
- javascript += ie_assets(:js, args, options[:auto], params) if options[:ie]
25
+ javascript += ie_assets(:js, args, options[:auto], response) if options[:ie]
26
26
  javascript.gsub("\n", '')
27
27
  end
28
28
 
@@ -31,7 +31,7 @@ module SmartAssetHelper
31
31
  options = extract_options(args)
32
32
  assets = include_assets(:css, args, options)
33
33
  stylesheets = stylesheet_link_tag(*assets)
34
- stylesheets += ie_assets(:css, args, options[:auto], params) if options[:ie]
34
+ stylesheets += ie_assets(:css, args, options[:auto], response) if options[:ie]
35
35
  stylesheets.gsub("\n", '')
36
36
  end
37
37
 
@@ -58,10 +58,10 @@ private
58
58
  options || {}
59
59
  end
60
60
 
61
- def ie_assets(asset_type, args, auto, request_params)
61
+ def ie_assets(asset_type, args, auto, request_response)
62
62
  ie_assets = ''
63
63
  %w{ 6 7 8 }.each do |v|
64
- assets = @_asset_manager.required_with_extra(asset_type, "ie#{v}", auto, request_params)
64
+ assets = @_asset_manager.required_with_extra(asset_type, "ie#{v}", auto, request_response)
65
65
 
66
66
  unless assets.blank?
67
67
  assets = case asset_type
@@ -77,7 +77,7 @@ private
77
77
 
78
78
  def include_assets(asset_type, args, options)
79
79
  @_asset_manager.append(asset_type, args) unless args.empty?
80
- @_asset_manager.auto_add(asset_type, params) if options[:auto]
80
+ @_asset_manager.auto_add(asset_type, response) if options[:auto]
81
81
  @_asset_manager.required(asset_type)
82
82
  end
83
83
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jeremyboles-smart-asset-helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Boles
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-20 00:00:00 -07:00
12
+ date: 2009-05-26 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency