-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathRakefile
184 lines (146 loc) · 5.44 KB
/
Rakefile
1
2
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
require "bundler/gem_tasks"
datatables_dir = "DataTablesSrc"
extensions = %w(AutoFill Buttons ColReorder FixedColumns FixedHeader KeyTable Responsive RowReorder Scroller Select RowGroup)
frameworks = %w(regular bootstrap bootstrap4 foundation jqueryui material semanticui uikit)
namespace :images do
desc "Delete images directory"
task :clean do
tgt_dir = "app/assets/media/datatables/"
rm_rf tgt_dir
end
desc "Copy images from #{datatables_dir}/media/images/"
task :copy do
tgt_dir = "app/assets/images/datatables/"
mkdir_p tgt_dir
Dir.glob("#{datatables_dir}/images/*.png") do |src_file|
cp src_file, tgt_dir
end
end
desc "Setup image assets"
task setup: [:clean, :copy]
end
namespace :javascripts do
desc "Cleaning javascripts directory"
task :clean do
rm_rf "app/assets/javascripts/datatables"
end
desc "Copy main #{datatables_dir}/js/"
task :copy do
src_file = "https://raw.githubusercontent.com/DataTables/DataTables/master/media/js/jquery.dataTables.js"
tgt_dir = "app/assets/javascripts/datatables/"
mkdir_p tgt_dir
Dir.chdir tgt_dir do
%x(wget #{src_file})
end
end
desc "Copy integration #{datatables_dir}/js/"
task :copy do
src_dir = "#{datatables_dir}/js/integration/."
tgt_dir = "app/assets/javascripts/datatables/"
mkdir_p tgt_dir
cp_r src_dir, tgt_dir
end
desc "Copy #{datatables_dir}/extensions/*/js"
task :copy_extensions do
extensions.each do |ext|
src_dir = "#{datatables_dir}/extensions/#{ext}/js/."
tgt_dir = "app/assets/javascripts/datatables/extensions/#{ext}/"
mkdir_p tgt_dir
cp_r src_dir, tgt_dir
end
end
desc "Setup javascript assets"
task setup: [:clean, :copy, :copy_extensions]
end
namespace :stylesheets do
desc "Cleaning stylesheets directory"
task :clean do
rm_rf "app/assets/stylesheets/datatables"
end
desc "Copy #{datatables_dir}/css/"
task :copy do
src_dir = "#{datatables_dir}/css/."
tgt_dir = "app/assets/stylesheets/datatables/"
mkdir_p tgt_dir
cp_r src_dir, tgt_dir
end
desc "Copy #{datatables_dir}/extensions/*/css"
task :copy_extensions do
extensions.each do |ext|
src_dir = "#{datatables_dir}/extensions/#{ext}/css/."
tgt_dir = "app/assets/stylesheets/datatables/extensions/#{ext}/"
mkdir_p tgt_dir
cp_r src_dir, tgt_dir
end
end
desc "Setup stylesheet assets"
task setup: [:clean, :copy, :copy_extensions]
end
desc "Remove minified file .min"
task :cleanup do
Dir.glob('app/assets/**/*.min.*').each do |file|
rm file
end
end
desc "Fix image URLs in stylesheets"
task :fix_urls do
puts "fix assets path"
Dir.glob('app/assets/stylesheets/datatables/*.scss').each do |file|
puts file
content = File.read(file)
fixed_content = content.gsub(/url\(\'\.\.\/images\/([A-Za-z_]*.png)\'\)/, 'image-url("datatables/\1")')
File.open(file, "w") { |f| f.puts fixed_content}
end
end
task :templates do
templates_dir = "lib/generators/jquery/datatables/templates"
rm_rf templates_dir
mkdir_p templates_dir
stylesheets = Dir.glob('app/assets/stylesheets/**/*')
javascripts = Dir.glob('app/assets/javascripts/**/*')
frameworks.each do |framework|
tgt_css_file = "#{templates_dir}/#{framework}.scss.tt"
tgt_js_file = "#{templates_dir}/#{framework}.js.tt"
javascripts.each do |file|
file_name = file.gsub("app/assets/javascripts/", "")
puts file_name
if file_name.match(/jquery\./)
File.open(tgt_js_file, "a") { |f| f.puts "//= require #{file_name.gsub('.js', '')}"}
File.open(tgt_js_file, "a") { |f| f.puts "// optional change to '//=' enable)" }
end
end
javascripts.each do |file|
file_name = file.gsub("app/assets/javascripts/", "")
puts file_name
next if frameworks.any? { |s| file_name.match(/#{Regexp.escape(s)}/) } or file_name.match(/jquery/)
File.open(tgt_js_file, "a") { |f| f.puts "// require #{file_name.gsub('.js', '')}"} if file_name.match(/dataTables/)
end
case framework
when "bootstrap", "bootstrap4", "foundation", "jqueryui", "material", "semanticui", "uikit"
stylesheets.each do |file|
file_name = file.gsub("app/assets/stylesheets/", "")
puts file_name
File.open(tgt_css_file, "a") { |f| f.puts "//@import '#{file_name.gsub('.css', '')}';"} if file_name.match(/#{Regexp.escape(framework)}\./)
end
javascripts.each do |file|
file_name = file.gsub("app/assets/javascripts/", "")
puts file_name
File.open(tgt_js_file, "a") { |f| f.puts "// require #{file_name.gsub('.js', '')}"} if file_name.match(/#{Regexp.escape(framework)}\./)
end
else
#core first]
stylesheets.each do |file|
file_name = file.gsub("app/assets/stylesheets/", "")
File.open(tgt_css_file, "a") { |f| f.puts "//@import '#{file_name.gsub('.css', '')}';"} if file_name.match(/jquery\./)
end
#plugins
stylesheets.each do |file|
file_name = file.gsub("app/assets/stylesheets/", "")
next if frameworks.any? { |s| file_name.match(/#{Regexp.escape(s)}/) } or file_name.match(/jquery/)
File.open(tgt_css_file, "a") { |f| f.puts "//@import '#{file_name.gsub('.css', '')}';"} if file_name.match(/dataTables/)
end
end
end
end
desc "Setup or update assets files"
task setup: ["images:setup", "javascripts:setup", "stylesheets:setup"]