@@ -2,12 +2,6 @@ Encoding.default_external = "UTF-8" if defined?(Encoding)
2
2
require 'json'
3
3
require 'bundler/gem_tasks'
4
4
5
- # returns the source filename for a given JSON build file
6
- # (e.g., "ui.core.jquery.json" returns "core.js")
7
- def source_file_for_build_file ( build_file )
8
- "#{ build_file . sub ( 'ui.' , '' ) . sub ( '.jquery.json' , '' ) } .js"
9
- end
10
-
11
5
# returns the source filename for a named file in the 'dependencies'
12
6
# array of a JSON build file
13
7
# (e.g., if the JSON build file contains
22
16
#
23
17
# The only exception is "jquery", which doesn't follow the
24
18
# same naming conventions so it's a special case.
25
- def source_file_for_dependency_entry ( dep_entry )
19
+ def source_file_for_dependency_entry ( caller , dep_entry )
26
20
return "jquery.js" if dep_entry == 'jquery'
27
21
28
- "#{ dep_entry . sub 'ui.' , '' } .js"
22
+ p = Pathname . new caller
23
+ parent_path = p . parent
24
+ parent_path . join ( dep_entry ) . to_s
29
25
end
30
26
31
27
# return a Hash of dependency info, whose keys are jquery-ui
32
28
# source files and values are Arrays containing the source files
33
29
# they depend on
34
30
def map_dependencies
35
31
dependencies = { }
36
- Dir . glob ( "jquery-ui/*.jquery.json" ) . each do |build_file |
37
- build_info = JSON . parse ( File . read build_file )
38
- source_file_name = source_file_for_build_file ( File . basename ( build_file ) )
32
+ Dir . glob ( "jquery-ui/ui/**/*.js" ) . each do |path |
33
+ basename = File . basename path
34
+ file = File . read path
35
+
36
+ matchdata = file . match ( /define\( .*\[ [\S \s ]+\] \, factory \) ;/m )
37
+
38
+ matchdata ||= file . match ( /define\( .*\[ [\S \s ]+\] (\, factory )?.*\) ;/m )
39
+
40
+ next if matchdata . nil?
41
+
42
+ deps_str = matchdata [ 0 ]
39
43
40
- deps = build_info [ 'dependencies' ] . keys
44
+ deps = deps_str . match ( /\[ [\s \S ]*\] / ) [ 0 ]
45
+
46
+ deps = deps . gsub ( /\/ \/ .+\s / , "" )
47
+
48
+ deps = deps . gsub ( /[\r \n \t \" \[ \] \s ]/ , "" )
49
+
50
+ deps_paths = deps . split ( ',' )
41
51
42
52
# None of jquery.ui files should depend on jquery.js,
43
53
# so we remove 'jquery' from the list of dependencies for all files
44
- deps . reject! { |d | d == "jquery" }
54
+ deps_paths . reject! { |d | d == "jquery" }
45
55
46
- deps . map! { |d | source_file_for_dependency_entry d }
56
+ deps_paths . map! { |d | d + '.js' }
47
57
48
- dependencies [ source_file_name ] = deps
58
+ deps_paths . map! { |d | source_file_for_dependency_entry path , d }
59
+
60
+ dependencies [ basename ] = deps_paths
49
61
end
50
62
dependencies
51
63
end
@@ -70,7 +82,7 @@ def get_js_dependencies(basename)
70
82
end
71
83
# Make sure we do not package assets with broken dependencies
72
84
dependencies . each do |dep |
73
- unless File . exist? ( "jquery-ui/ui/ #{ dep } " )
85
+ unless File . exist? ( "#{ dep } " )
74
86
fail "#{ basename } : missing #{ dep } "
75
87
end
76
88
end
@@ -107,13 +119,18 @@ task :javascripts => :submodule do
107
119
target_dir = "app/assets/javascripts"
108
120
target_ui_dir = "#{ target_dir } /jquery-ui"
109
121
mkdir_p target_ui_dir
122
+ mkdir_p target_ui_dir + '/effects'
123
+ mkdir_p target_ui_dir + '/widgets'
124
+ mkdir_p target_ui_dir + '/i18n'
110
125
111
- Dir . glob ( "jquery-ui/ui/*.js" ) . each do |path |
126
+ Dir . glob ( "jquery-ui/ui/**/* .js" ) . each do |path |
112
127
basename = File . basename ( path )
128
+ clean_path = path . gsub ( '/ui' , '' )
113
129
dep_modules = get_js_dependencies ( basename ) . map ( &method ( :remove_js_extension ) )
114
- File . open ( "#{ target_ui_dir } /#{ basename } " , "w" ) do |out |
130
+ File . open ( "#{ target_dir } /#{ clean_path } " , "w" ) do |out |
115
131
dep_modules . each do |mod |
116
- out . write ( "//= require jquery-ui/#{ mod } \n " )
132
+ mod . gsub! ( '/ui' , '' )
133
+ out . write ( "//= require #{ mod } \n " )
117
134
end
118
135
out . write ( "\n " ) unless dep_modules . empty?
119
136
source_code = File . read ( path )
@@ -127,7 +144,7 @@ task :javascripts => :submodule do
127
144
# https://github.com/joliss/jquery-ui-rails/issues/9
128
145
Dir . glob ( "jquery-ui/ui/i18n/*.js" ) . each do |path |
129
146
basename = File . basename ( path )
130
- File . open ( "#{ target_ui_dir } /#{ basename } " , "w" ) do |out |
147
+ File . open ( "#{ target_ui_dir } /i18n/ #{ basename } " , "w" ) do |out |
131
148
source_code = File . read ( path )
132
149
source_code . gsub! ( '@VERSION' , version )
133
150
protect_copyright_notice ( source_code )
@@ -136,15 +153,23 @@ task :javascripts => :submodule do
136
153
end
137
154
138
155
File . open ( "#{ target_ui_dir } /effect.all.js" , "w" ) do |out |
139
- Dir . glob ( "jquery-ui/ui/effect *.js" ) . sort . each do |path |
140
- asset_name = remove_js_extension ( File . basename ( path ) )
141
- out . write ( "//= require jquery-ui/ #{ asset_name } \n " )
156
+ Dir . glob ( "jquery-ui/ui/effects/ *.js" ) . sort . each do |path |
157
+ clean_path = path . gsub ( '/ui' , '' )
158
+ out . write ( "//= require #{ clean_path } \n " )
142
159
end
143
160
end
144
161
File . open ( "#{ target_dir } /jquery-ui.js" , "w" ) do |out |
145
162
Dir . glob ( "jquery-ui/ui/*.js" ) . sort . each do |path |
146
- asset_name = remove_js_extension ( File . basename ( path ) )
147
- out . write ( "//= require jquery-ui/#{ asset_name } \n " )
163
+ clean_path = path . gsub ( '/ui' , '' )
164
+ out . write ( "//= require #{ clean_path } \n " )
165
+ end
166
+ Dir . glob ( "jquery-ui/ui/effects/*.js" ) . sort . each do |path |
167
+ clean_path = path . gsub ( '/ui' , '' )
168
+ out . write ( "//= require #{ clean_path } \n " )
169
+ end
170
+ Dir . glob ( "jquery-ui/ui/widgets/*.js" ) . sort . each do |path |
171
+ clean_path = path . gsub ( '/ui' , '' )
172
+ out . write ( "//= require #{ clean_path } \n " )
148
173
end
149
174
end
150
175
end
0 commit comments