File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 11.bundle
22vendor /ruby
33public
4+ node_modules /
Original file line number Diff line number Diff line change @@ -12,3 +12,39 @@ desc "Open your default browser with the test page"
1212task :test do
1313 sh ( "open test/index.html" )
1414end
15+
16+ desc "Automatically wrap given locale files in UMD declarations"
17+ task :umd , [ :files ] do |t , args |
18+ def indent ( str )
19+ indented = str . split ( "\n " ) . map do |line |
20+ " #{ line } "
21+ end
22+ indented . join ( "\n " )
23+ end
24+
25+ def wrap_in_umd ( str )
26+ <<~HEREDOC
27+ (function (factory) {
28+ if (typeof define === 'function' && define.amd) {
29+ define(['jquery'], factory);
30+ } else if (typeof module === 'object' && typeof module.exports === 'object') {
31+ factory(require('jquery'));
32+ } else {
33+ factory(jQuery);
34+ }
35+ }(function (jQuery) {
36+ #{ indent ( str ) }
37+ });
38+ HEREDOC
39+ end
40+
41+ matches = Dir . glob ( args [ :files ] )
42+ puts "Pattern did not match any file" if matches . length == 0
43+ matches . each do |file |
44+ input = File . read ( file )
45+ base = Pathname . new ( file ) . basename
46+ output = File . open ( "locales/#{ base } " , "w" )
47+ output . write ( wrap_in_umd ( input ) )
48+ output . close
49+ end
50+ end
You can’t perform that action at this time.
0 commit comments