public
Rubygem
Description: Rails Plugin - a Ruby way to manage your stylesheets and javascripts. Don't put all your assets in your layout; define what you need where you need them.
Homepage: http://6brand.com
Clone URL: git://github.com/JackDanger/sweet_assets.git
Search Repo:
updated sweet_assets to always prepend default javascripts

git-svn-id: http://svn.6brand.com/projects/plugins/sweet_assets@392 
7491b73d-821b-0410-9297-ad1f6b5b4194
studioda (author)
Fri Feb 15 08:23:15 -0800 2008
commit  e1232281357a247916d2848176c073e0baece93c
tree    0e018546ca00cca87521067382bc6ab45e986349
parent  2b569a2bfc503bb99e841ef3f106dfcb45014997
...
3
4
5
6
7
8
9
10
11
12
13
14
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
17
18
 
 
19
20
21
22
...
40
41
42
43
 
 
 
44
45
46
47
48
...
85
86
87
 
88
89
90
...
114
115
116
 
 
 
117
118
119
...
3
4
5
 
 
 
 
 
 
 
 
 
 
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 
25
26
27
28
29
30
...
48
49
50
 
51
52
53
54
 
55
56
57
...
94
95
96
97
98
99
100
...
124
125
126
127
128
129
130
131
132
0
@@ -3,19 +3,27 @@
0
 require 'action_view/helpers/tag_helper'
0
 
0
 module SweetAssets
0
- def self.included(base)
0
- base.class_eval do
0
- include AssignmentMethods
0
- include ClassMethods
0
- extend SweetAssetsShortcuts
0
- include AppendAssetsAfterRescue
0
- before_filter :initialize_assets_accessor
0
- before_filter :apply_default_styles
0
- before_filter :apply_default_scripts
0
- after_filter :apply_sweet_assets
0
+ PRIMARY_JAVASCRIPTS = [:prototype, :scriptaculous, :builder, :effects, :dragdrop, :controls, :slider, :sound, :application]
0
+
0
+ class << self
0
+
0
+ attr_accessor :use_primary_javascripts
0
+
0
+ def included(base)
0
+ base.class_eval do
0
+ include AssignmentMethods
0
+ include ClassMethods
0
+ extend SweetAssetsShortcuts
0
+ include AppendAssetsAfterRescue
0
+ before_filter :initialize_assets_accessor
0
+ before_filter :apply_default_styles
0
+ before_filter :apply_default_scripts
0
+ after_filter :apply_sweet_assets
0
+ end
0
     end
0
   end
0
-
0
+
0
+
0
   module SweetAssetsShortcuts
0
     def style_like(*assets)
0
       options = assets.extract_options!
0
0
@@ -40,9 +48,10 @@
0
       scripts.each do |script|
0
         script = script.to_s
0
         if 'defaults' == script
0
- script_like :prototype, :scriptaculous, :builder, :effects, :dragdrop, :controls, :slider, :sound, :application
0
+ SweetAssets.use_primary_javascripts = true
0
+ else
0
+ sweet_assets[:javascripts][script.ends_with?('!') ? :bottom : :top] << script.gsub(/!$/, '')
0
         end
0
- sweet_assets[:javascripts][script.ends_with?('!') ? :bottom : :top] << script.gsub(/!$/, '')
0
       end
0
     end
0
     
0
@@ -85,6 +94,7 @@
0
       generator = SweetAssetsGenerator.new(@sweet_assets, self)
0
       response.body.gsub! '<head>', "<head>\n#{generator.tags(:top)}\n" if response.body.respond_to?(:gsub!)
0
       response.body.gsub! '</head>', "\n#{generator.tags(:bottom)}\n</head>" if response.body.respond_to?(:gsub!)
0
+ SweetAssets.use_primary_javascripts = false
0
       @sweet_assets = {}
0
     end
0
     
0
@@ -114,6 +124,9 @@
0
 
0
       def javascript_tags(placement)
0
         files = @assets[:javascripts][placement].dup
0
+ if SweetAssets.use_primary_javascripts
0
+ files = SweetAssets::PRIMARY_JAVASCRIPTS + files
0
+ end
0
         files.uniq!
0
         files.map! {|file| file =~ /\.js$/ ? file : "#{file}.js" }
0
         files = files.select {|file| File.exists?("#{JAVASCRIPTS_DIR}/#{file}") } unless RAILS_ENV.eql?('test')
...
71
72
73
74
75
 
 
76
77
78
79
80
 
 
81
82
83
84
...
96
97
98
99
100
 
 
101
102
103
104
105
 
 
106
107
108
...
71
72
73
 
 
74
75
76
77
78
 
 
79
80
81
82
83
84
...
96
97
98
 
 
99
100
101
102
103
 
 
104
105
106
107
108
0
@@ -71,13 +71,13 @@
0
     assert_no_tag :link, :attributes => {:href => /stylesheets\/home.css/, :rel => 'stylesheet'}
0
     assert_no_tag :link, :attributes => {:href => /stylesheets\/extra.css/, :rel => 'stylesheet'}
0
     assert_no_tag :link, :attributes => {:href => /stylesheets\/users.css/, :rel => 'stylesheet'}
0
- assert_tag :link, :attributes => {:href => /sweet_stylesheets_application,home,extra.css(\?\d*)?/, :rel => 'stylesheet'}
0
- assert_tag :link, :attributes => {:href => /sweet_stylesheets_web,users.css(\?\d*)?/, :rel => 'stylesheet'}
0
+ assert_tag :link, :attributes => {:href => /sweet_stylesheets_application.css,home.css,extra.css(\?\d*)?/, :rel => 'stylesheet'}
0
+ assert_tag :link, :attributes => {:href => /sweet_stylesheets_web.css,users.css(\?\d*)?/, :rel => 'stylesheet'}
0
     # and check the placement
0
     location_of_head = @response.body =~ /<head>/
0
     location_of_title = @response.body =~ /<title>/
0
- location_of_home_extra_css = @response.body =~ /<link href="\/stylesheets\/sweet_stylesheets_application,home,extra.css/
0
- location_of_web_users_css = @response.body =~ /<link href="\/stylesheets\/sweet_stylesheets_web,users.css/
0
+ location_of_home_extra_css = @response.body =~ /<link href="\/stylesheets\/sweet_stylesheets_application.css,home.css,extra.css/
0
+ location_of_web_users_css = @response.body =~ /<link href="\/stylesheets\/sweet_stylesheets_web.css,users.css/
0
     assert location_of_head < location_of_home_extra_css
0
     assert location_of_home_extra_css < location_of_title
0
     assert location_of_title < location_of_web_users_css
0
0
@@ -96,13 +96,13 @@
0
     assert_no_tag :script, :attributes => {:src => /javascripts\/home.js/}
0
     assert_no_tag :script, :attributes => {:src => /javascripts\/extra.js/}
0
     assert_no_tag :script, :attributes => {:src => /javascripts\/users.js/}
0
- assert_tag :script, :attributes => {:src => /sweet_javascripts_home,extra.js(\?\d*)?/}
0
- assert_tag :script, :attributes => {:src => /sweet_javascripts_web,users.js(\?\d*)?/}
0
+ assert_tag :script, :attributes => {:src => /sweet_javascripts_home.js,extra.js(\?\d*)?/}
0
+ assert_tag :script, :attributes => {:src => /sweet_javascripts_web.js,users.js(\?\d*)?/}
0
     # and check the placement
0
     location_of_head = @response.body =~ /<head>/
0
     location_of_title = @response.body =~ /<title>/
0
- location_of_home_extra_js = @response.body =~ /<script src="\/javascripts\/sweet_javascripts_home,extra.js/
0
- location_of_web_users_js = @response.body =~ /<script src="\/javascripts\/sweet_javascripts_web,users.js/
0
+ location_of_home_extra_js = @response.body =~ /<script src="\/javascripts\/sweet_javascripts_home.js,extra.js/
0
+ location_of_web_users_js = @response.body =~ /<script src="\/javascripts\/sweet_javascripts_web.js,users.js/
0
     assert location_of_head < location_of_home_extra_js
0
     assert location_of_home_extra_js < location_of_title
0
     assert location_of_title < location_of_web_users_js

Comments

    No one has commented yet.