forked from RadPad/swagger-ui_rails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
46 lines (35 loc) · 1.45 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
require "fileutils"
require "bundler/gem_tasks"
desc "Syncronize Swagger UI"
task :sync_swagger_ui do
source = File.join File.dirname(__FILE__), "swagger-ui-src", "dist"
destination = File.join File.dirname(__FILE__), "app", "assets"
js_destination = File.join destination, "javascripts", "swagger-ui"
idx = File.join js_destination, "index.js"
File.read(idx).each_line do | line |
if line =~ /require (.*)/
file = "#{source}/#{$1.strip}"
# hack to make throbber.gif available on asset pipeline
if $1.strip =~ /swagger-ui\.js/
contents = File.read file
File.open "#{file.gsub(source, js_destination)}.erb", "w" do | f |
f << contents.gsub("src='images/throbber.gif'", "src='<%= asset_path(\"throbber.gif\") %>'")
end
else
FileUtils.cp_r file, file.gsub(source, js_destination), verbose: true
end
end
end
oauth_source = File.join source, "lib", "swagger-oauth.js"
oauth_dest = js_destination.gsub "swagger-ui-src", "swagger-oauth.js"
FileUtils.cp_r oauth_source, oauth_dest, verbose: true
css_destination = File.join destination, "stylesheets", "swagger-ui"
css_source = File.join source, "css"
idx = File.join css_destination, "index.css"
File.read(idx).each_line do | line |
if line =~ /require (.*)\.css/
file = "#{css_source}/#{$1.strip}.css"
FileUtils.cp_r file, file.gsub(css_source, css_destination), verbose: true
end
end
end