public
Description: A Rails plugin to make it easy to use YUI on Rails instead of (or along with, I suppose) Prototype and scriptaculous
Clone URL: git://github.com/rubaidh/yui_on_rails.git
When a JS component that has associated CSS is included, include the CSS 
link too.
mathie (author)
Tue Apr 15 07:17:19 -0700 2008
commit  39669cbdc6d92fed52e41d22a06b0adfa5bdcd36
tree    efb125c62920a56547b1a2e04d9dfd7b24d6444a
parent  f3e16ba8e84db0139b49e840875461b02a50e799
...
20
21
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
24
25
...
87
88
89
 
 
 
90
91
92
 
 
 
 
 
 
 
 
 
93
94
95
...
104
105
106
 
 
 
 
107
108
109
...
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
...
106
107
108
109
110
111
112
 
 
113
114
115
116
117
118
119
120
121
122
123
124
...
133
134
135
136
137
138
139
140
141
142
0
@@ -20,6 +20,25 @@ module ActionView # :nodoc:
0
         JS_COMPONENTS_WITHOUT_DEBUG_VERSION = ["utilities", "yahoo-dom-event", "yuiloader-dom-event"]
0
         JS_COMPONENTS_WITHOUT_MINIFIED_VERSION = ["utilities", "yahoo-dom-event", "yuiloader-dom-event"]
0
 
0
+ JS_COMPONENTS_WITH_CSS = [
0
+ "autocomplete",
0
+ "button",
0
+ "calendar",
0
+ "colorpicker",
0
+ "container",
0
+ "datatable",
0
+ "editor",
0
+ "imagecropper",
0
+ "layout",
0
+ "logger",
0
+ "menu",
0
+ "profilerviewer",
0
+ "resize",
0
+ "tabview",
0
+ "treeview",
0
+ "yuitest"
0
+ ]
0
+
0
         # All the dependencies of each YUI component. This is cribbed from
0
         # playing around with:
0
         #
0
@@ -87,9 +106,19 @@ module ActionView # :nodoc:
0
           paths = yui_js_components_with_dependencies(components).map do |component|
0
             yui_javascript_path(component)
0
           end
0
+ component_stylesheets = components.select do |component|
0
+ JS_COMPONENTS_WITH_CSS.include?(component)
0
+ end
0
 
0
- paths << options
0
- javascript_include_tag(*paths)
0
+ returning [] do |html|
0
+ html << javascript_include_tag(*paths)
0
+ unless component_stylesheets.blank?
0
+ stylesheet_paths = component_stylesheets.map do |component_stylesheet|
0
+ yui_js_stylesheet_path(component_stylesheet)
0
+ end
0
+ html << stylesheet_link_tag(*stylesheet_paths)
0
+ end
0
+ end.join("\n")
0
         end
0
 
0
         def yui_js_components_with_dependencies(components)
0
@@ -104,6 +133,10 @@ module ActionView # :nodoc:
0
           JS_COMPONENT_DEPENDENCIES[component] || []
0
         end
0
 
0
+ def yui_js_stylesheet_path(source)
0
+ compute_public_path(source, "yui/build/#{source}/assets/skins/sam", 'css')
0
+ end
0
+
0
         def yui_stylesheet_path(source, version = nil)
0
           suffix = "-min" if "#{version}" == "min" && !CSS_COMPONENTS_WITHOUT_MINIFIED_VERSION.include?(source)
0
           compute_public_path("#{source}#{suffix}", "yui/build/#{source}", 'css')
...
107
108
109
110
 
 
111
112
113
 
 
 
 
 
 
 
 
 
 
114
115
116
...
158
159
160
 
 
 
 
 
 
 
 
161
162
163
...
107
108
109
 
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
...
169
170
171
172
173
174
175
176
177
178
179
180
181
182
0
@@ -107,10 +107,21 @@ class AssetTagHelperTest < Test::Unit::TestCase
0
       %(<script type="text/javascript" src="/yui/build/menu/menu.js"></script>),
0
       %(<script type="text/javascript" src="/yui/build/element/element-beta.js"></script>),
0
       %(<script type="text/javascript" src="/yui/build/button/button.js"></script>),
0
- %(<script type="text/javascript" src="/yui/build/editor/editor-beta.js"></script>)
0
+ %(<script type="text/javascript" src="/yui/build/editor/editor-beta.js"></script>),
0
+ %(<link href="/yui/build/editor/assets/skins/sam/editor.css" rel="stylesheet" type="text/css" media="screen" />)
0
     ].join("\n"), yui_javascript_include_tag(:editor)
0
   end
0
 
0
+ def test_yui_javascript_include_tag_also_includes_component_stylesheets
0
+ assert_dom_equal [
0
+ %(<script type="text/javascript" src="/yui/build/yahoo/yahoo.js"></script>),
0
+ %(<script type="text/javascript" src="/yui/build/dom/dom.js"></script>),
0
+ %(<script type="text/javascript" src="/yui/build/event/event.js"></script>),
0
+ %(<script type="text/javascript" src="/yui/build/autocomplete/autocomplete.js"></script>),
0
+ %(<link href="/yui/build/autocomplete/assets/skins/sam/autocomplete.css" rel="stylesheet" type="text/css" media="screen" />)
0
+ ].join("\n"), yui_javascript_include_tag(:autocomplete)
0
+ end
0
+
0
   def test_dependencies_for_component
0
     assert_equal [], yui_js_dependencies_for_component("yahoo")
0
     assert_equal ["yahoo"], yui_js_dependencies_for_component("dom")
0
@@ -158,6 +169,14 @@ class AssetTagHelperTest < Test::Unit::TestCase
0
     end
0
   end
0
 
0
+ def test_yui_js_stylesheet_path_generates_correct_paths
0
+ JS_COMPONENTS_WITH_CSS.each do |component|
0
+ path = yui_js_stylesheet_path(component)
0
+ assert_equal "/yui/build/#{component}/assets/skins/sam/#{component}.css", path
0
+ assert_file_exists "#{File.dirname(__FILE__)}/../../resources#{path}"
0
+ end
0
+ end
0
+
0
   private
0
   def assert_file_exists(file)
0
     assert File.exists?(file), "File #{file} does not exist."

Comments

    No one has commented yet.