jeremyboles-smart-asset-helper 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/asset_manager.rb CHANGED
@@ -27,15 +27,7 @@ class AssetManager
27
27
 
28
28
  # Automaticly add assets based the controller/action params, if they exsist
29
29
  def auto_add(asset_type, request_params)
30
- files, prefix = [], ''
31
- (request_params[:controller] + '/' + request_params[:action]).split('/').each do |path|
32
- path = prefix + path
33
- asset_path = "#{path}.#{asset_type}"
34
- file_path = "#{ASSET_DIR[asset_type]}/#{asset_path}"
35
-
36
- files << path if File.exists?(file_path)
37
- prefix = path + '/'
38
- end
30
+ files = self.auto_find(asset_type, request_params)
39
31
  self.add(asset_type, files)
40
32
  end
41
33
 
@@ -51,7 +43,7 @@ class AssetManager
51
43
  files
52
44
  end
53
45
 
54
- def required_with_extra(asset_type, extra)
46
+ def required_with_extra(asset_type, extra, auto, request_params = nil)
55
47
  files = []
56
48
  self.required(asset_type).each do |file|
57
49
  path = "#{file}-#{extra}"
@@ -59,11 +51,26 @@ class AssetManager
59
51
  file_path = "#{ASSET_DIR[asset_type]}/#{asset_path}"
60
52
  files << path if File.exists?(file_path)
61
53
  end
54
+ files += self.auto_find(asset_type, request_params) if auto
62
55
  files
63
56
  end
64
57
 
65
58
  private
66
59
 
60
+ def auto_find(asset_type, request_params, extra = '')
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}"
67
+
68
+ files << path if File.exists?(file_path)
69
+ prefix = path + '/'
70
+ end
71
+ files
72
+ end
73
+
67
74
  # Extracts the required files, unique and honoring denied assets
68
75
  def extract(asset_type)
69
76
  seen_files = @denied[asset_type].flatten
@@ -2,6 +2,10 @@ require 'asset_manager'
2
2
 
3
3
  module SmartAssetHelper
4
4
 
5
+ def conditional_comment(text, version)
6
+ "<!--[if IE #{version}]>#{text}<![endif]-->"
7
+ end
8
+
5
9
  # Prevent a javscript file from being required
6
10
  def deny_javascript(*javascripts)
7
11
  @_asset_manager.deny(:js, javascripts)
@@ -24,7 +28,7 @@ module SmartAssetHelper
24
28
  def include_stylesheets(*args)
25
29
  options = extract_options(args)
26
30
  stylesheets = stylesheet_link_tag(*include_assets(:css, args, options))
27
- stylesheets += ie_assets(:css, args) if options[:ie]
31
+ stylesheets += ie_assets(:css, args, options[:auto], params) if options[:ie]
28
32
  stylesheets.gsub("\n", '')
29
33
  end
30
34
 
@@ -45,20 +49,16 @@ module SmartAssetHelper
45
49
  end
46
50
 
47
51
  private
48
-
49
- def conditional_comment(text, version)
50
- "<!--[if IE #{version}]>#{text}<![endif]-->"
51
- end
52
52
 
53
53
  def extract_options(args)
54
54
  options = args.delete(args.last) if args.last.is_a?(Hash)
55
55
  options || {}
56
56
  end
57
57
 
58
- def ie_assets(asset_type, args)
58
+ def ie_assets(asset_type, args, auto)
59
59
  ie_assets = ''
60
60
  %w{ 6 7 8 }.each do |v|
61
- assets = @_asset_manager.required_with_extra(asset_type, "ie#{v}")
61
+ assets = @_asset_manager.required_with_extra(asset_type, "ie#{v}", auto)
62
62
 
63
63
  unless assets.blank?
64
64
  assets = case asset_type
data/rails/init.rb CHANGED
@@ -1 +1,2 @@
1
- require 'smart_asset_helper'
1
+ require 'smart_asset_helper'
2
+ require 'smarter_asset_tag_helper'
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.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Boles