@@ -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 )
26
- return "jquery.js" if dep_entry == 'jquery'
27
-
28
- " #{ dep_entry . sub 'ui.' , '' } .js"
19
+ def source_file_for_dependency_entry ( caller , dep_entry )
20
+ p = Pathname . new caller
21
+ parent_path = p . parent
22
+ parent_path . join ( dep_entry + ' .js' ) . to_s
29
23
end
30
24
31
25
# return a Hash of dependency info, whose keys are jquery-ui
32
26
# source files and values are Arrays containing the source files
33
27
# they depend on
34
28
def map_dependencies
35
29
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 ) )
30
+ Dir . glob ( "jquery-ui/ui/**/*.js" ) . each do |path |
31
+ basename = File . basename path
32
+ file = File . read path
33
+
34
+ matchdata = file . match ( /define\( \s *\[ \s *([\" \. \/ \, \w \s -\: ]+)\] /m )
35
+
36
+ next if matchdata . nil?
37
+
38
+ deps = matchdata [ 1 ]
39
39
40
- deps = build_info [ 'dependencies' ] . keys
40
+ # remove lines with comments
41
+ deps = deps . gsub ( /\/ \/ .+\s / , "" )
42
+
43
+ # remove all non-path symbols
44
+ deps = deps . gsub ( /[\r \n \t \" \[ \] \s ]/ , "" )
45
+
46
+ deps_paths = deps . split ( ',' )
47
+
48
+ deps_paths . map! ( &method ( :remove_js_extension ) )
41
49
42
50
# None of jquery.ui files should depend on jquery.js,
43
51
# so we remove 'jquery' from the list of dependencies for all files
44
- deps . reject! { |d | d == "jquery" }
52
+ deps_paths . reject! { |d | d == "jquery" }
45
53
46
- deps . map! { |d | source_file_for_dependency_entry d }
54
+ deps_paths . map! { |d | source_file_for_dependency_entry path , d }
47
55
48
- dependencies [ source_file_name ] = deps
56
+ dependencies [ basename ] = deps_paths
49
57
end
50
58
dependencies
51
59
end
@@ -70,7 +78,7 @@ def get_js_dependencies(basename)
70
78
end
71
79
# Make sure we do not package assets with broken dependencies
72
80
dependencies . each do |dep |
73
- unless File . exist? ( "jquery-ui/ui/ #{ dep } " )
81
+ unless File . exist? ( "#{ dep } " )
74
82
fail "#{ basename } : missing #{ dep } "
75
83
end
76
84
end
@@ -107,13 +115,18 @@ task :javascripts => :submodule do
107
115
target_dir = "app/assets/javascripts"
108
116
target_ui_dir = "#{ target_dir } /jquery-ui"
109
117
mkdir_p target_ui_dir
118
+ mkdir_p target_ui_dir + '/effects'
119
+ mkdir_p target_ui_dir + '/widgets'
120
+ mkdir_p target_ui_dir + '/i18n'
110
121
111
- Dir . glob ( "jquery-ui/ui/*.js" ) . each do |path |
122
+ Dir . glob ( "jquery-ui/ui/**/* .js" ) . each do |path |
112
123
basename = File . basename ( path )
124
+ clean_path = path . gsub ( '/ui' , '' )
113
125
dep_modules = get_js_dependencies ( basename ) . map ( &method ( :remove_js_extension ) )
114
- File . open ( "#{ target_ui_dir } /#{ basename } " , "w" ) do |out |
126
+ File . open ( "#{ target_dir } /#{ clean_path } " , "w" ) do |out |
115
127
dep_modules . each do |mod |
116
- out . write ( "//= require jquery-ui/#{ mod } \n " )
128
+ mod . gsub! ( '/ui' , '' )
129
+ out . write ( "//= require #{ mod } \n " )
117
130
end
118
131
out . write ( "\n " ) unless dep_modules . empty?
119
132
source_code = File . read ( path )
@@ -127,7 +140,7 @@ task :javascripts => :submodule do
127
140
# https://github.com/joliss/jquery-ui-rails/issues/9
128
141
Dir . glob ( "jquery-ui/ui/i18n/*.js" ) . each do |path |
129
142
basename = File . basename ( path )
130
- File . open ( "#{ target_ui_dir } /#{ basename } " , "w" ) do |out |
143
+ File . open ( "#{ target_ui_dir } /i18n/ #{ basename } " , "w" ) do |out |
131
144
source_code = File . read ( path )
132
145
source_code . gsub! ( '@VERSION' , version )
133
146
protect_copyright_notice ( source_code )
@@ -136,15 +149,23 @@ task :javascripts => :submodule do
136
149
end
137
150
138
151
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 " )
152
+ Dir . glob ( "jquery-ui/ui/effects/ *.js" ) . sort . each do |path |
153
+ clean_path = remove_js_extension ( path ) . gsub ( '/ui' , '' )
154
+ out . write ( "//= require #{ clean_path } \n " )
142
155
end
143
156
end
144
157
File . open ( "#{ target_dir } /jquery-ui.js" , "w" ) do |out |
145
158
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 " )
159
+ clean_path = remove_js_extension ( path ) . gsub ( '/ui' , '' )
160
+ out . write ( "//= require #{ clean_path } \n " )
161
+ end
162
+ Dir . glob ( "jquery-ui/ui/effects/*.js" ) . sort . each do |path |
163
+ clean_path = remove_js_extension ( path ) . gsub ( '/ui' , '' )
164
+ out . write ( "//= require #{ clean_path } \n " )
165
+ end
166
+ Dir . glob ( "jquery-ui/ui/widgets/*.js" ) . sort . each do |path |
167
+ clean_path = remove_js_extension ( path ) . gsub ( '/ui' , '' )
168
+ out . write ( "//= require #{ clean_path } \n " )
148
169
end
149
170
end
150
171
end
0 commit comments