Skip to content

Commit 1962b09

Browse files
committed
assets pipline
1 parent 7bb9e59 commit 1962b09

File tree

4 files changed

+38
-17
lines changed

4 files changed

+38
-17
lines changed

app/assets/stylesheets/group-buttons.css.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@
7171
.start {
7272
display: inline-block;
7373
padding-left: 13px;
74-
background: url(<%= asset_path('play-icon.png') %>) no-repeat 0 -35px;
74+
background: url(<%= asset_data_uri('play-icon.png') %>) no-repeat 0 -35px;
7575
}
7676

7777
.stop {
7878
display: inline-block;
7979
padding-left: 13px;
80-
background: url(<%= asset_path('stop-icon.png') %>) no-repeat 0 5px;
80+
background: url(<%= asset_data_uri('stop-icon.png') %>) no-repeat 0 5px;
8181
}

app/assets/stylesheets/library.css.erb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ a:hover, a:active {
4646

4747
.success {
4848
padding-right: 15px;
49-
background: url(<%= asset_path('success.png') %>) no-repeat 100% 50%;
49+
background: url(<%= asset_data_uri('success.png') %>) no-repeat 100% 50%;
5050
}
5151

5252
.failure {
5353
padding-right: 15px;
54-
background: url(<%= asset_path('failure.png') %>) no-repeat 100% 50%;
54+
background: url(<%= asset_data_uri('failure.png') %>) no-repeat 100% 50%;
5555
}
5656

5757
.notice {
@@ -62,7 +62,7 @@ a:hover, a:active {
6262
display: inline-block;
6363
margin-right: 5px;
6464
margin-left: -17px;
65-
/* background: url(<%= asset_path('success.png') %>) no-repeat 0 0; */
65+
/* background: url(<%= asset_data_uri('success.png') %>) no-repeat 0 0; */
6666
}
6767

6868
.error {
@@ -73,16 +73,16 @@ a:hover, a:active {
7373
display: inline-block;
7474
margin-right: 5px;
7575
margin-left: -17px;
76-
background: url(<%= asset_path('failure.png') %>) no-repeat 0 0;
76+
background: url(<%= asset_data_uri('failure.png') %>) no-repeat 0 0;
7777
}
7878

7979
.arrow-down {
8080
padding-right: 15px;
81-
background: url(<%= asset_path('arrow-down.png') %>) no-repeat 100% 50%;
81+
background: url(<%= asset_data_uri('arrow-down.png') %>) no-repeat 100% 50%;
8282
}
8383

8484
.arrow-down.rotate {
85-
background: url(<%= asset_path('arrow-up.png') %>) no-repeat 100% 50%;
85+
background: url(<%= asset_data_uri('arrow-up.png') %>) no-repeat 100% 50%;
8686
}
8787

8888
code {
@@ -156,7 +156,7 @@ code {
156156
font: 12px arial, sans-serif;
157157
vertical-align: middle;
158158
border: 1px solid #bbb;
159-
background: #fff url(<%= asset_path('date.png') %>) no-repeat 9px 50%;
159+
background: #fff url(<%= asset_data_uri('date.png') %>) no-repeat 9px 50%;
160160
border-radius: 3px;
161161
box-shadow: 0 1px 2px #e6e6e6 inset, 0 1px 0 #fff;
162162
}
@@ -230,7 +230,7 @@ li.message_tab {
230230

231231
a[target="_blank"] {
232232
display: inline-block;
233-
background: url(<%= asset_path('external.png') %>) no-repeat 0 3px;
233+
background: url(<%= asset_data_uri('external.png') %>) no-repeat 0 3px;
234234
padding-left: 17px;
235235
}
236236

lib/mongodb_logger/server/sprokets.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'base64'
2+
require 'rack/utils'
13
require 'sprockets'
24

35
module MongodbLogger
@@ -6,6 +8,13 @@ module AssetHelpers
68
def asset_path(source)
79
"/assets/#{Assets.instance.find_asset(source).digest_path}" unless Assets.instance.find_asset(source).nil?
810
end
11+
def asset_data_uri(source)
12+
unless Assets.instance.find_asset(source).nil?
13+
asset = Assets.instance.find_asset(source)
14+
base64 = Base64.encode64(asset.to_s).gsub(/\s+/, "")
15+
"data:#{asset.content_type};base64,#{Rack::Utils.escape(base64)}"
16+
end
17+
end
918
end
1019

1120
class Assets < Sprockets::Environment

lib/tasks/mongodb_logger.rake

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,37 @@ require 'mongodb_logger/server/sprokets'
22
namespace :mongodb_logger do
33
namespace :assets do
44
desc 'compile assets'
5-
task :compile => [:compile_js, :compile_css] do
5+
task :compile, [:output_dir] => [:compile_js, :compile_css, :compile_imgs] do
66
end
77

88
desc 'compile javascript assets'
99
task :compile_js, [:output_dir] => :environment do |t, args|
1010
return (raise "Specify output dir for assets") if args.output_dir.nil?
11-
sprockets = MongodbLogger::Assets.instance
12-
asset = sprockets['mongodb_logger.js']
13-
asset.write_to(output_dir)
11+
sprockets = MongodbLogger::Assets.instance
12+
asset_name = 'mongodb_logger.js'
13+
asset = sprockets[asset_name]
14+
asset.write_to(File.join(args.output_dir, sprockets.find_asset(asset_name).digest_path))
1415
puts "successfully compiled js assets"
1516
end
1617

1718
desc 'compile css assets'
1819
task :compile_css, [:output_dir] => :environment do |t, args|
1920
return (raise "Specify output dir for assets") if args.output_dir.nil?
20-
sprockets = MongodbLogger::Assets.instance
21-
asset = sprockets['mongodb_logger.css']
22-
asset.write_to(output_dir)
21+
sprockets = MongodbLogger::Assets.instance
22+
asset_name = 'mongodb_logger.css'
23+
asset = sprockets[asset_name]
24+
asset.write_to(File.join(args.output_dir, sprockets.find_asset(asset_name).digest_path))
2325
puts "successfully compiled css assets"
2426
end
27+
28+
desc 'compile images assets'
29+
task :compile_imgs, [:output_dir] => :environment do |t, args|
30+
return (raise "Specify output dir for assets") if args.output_dir.nil?
31+
sprockets = MongodbLogger::Assets.instance
32+
asset_name = 'logo.png'
33+
asset = sprockets[asset_name]
34+
asset.write_to(File.join(args.output_dir, sprockets.find_asset(asset_name).digest_path))
35+
puts "successfully compiled images assets"
36+
end
2537
end
2638
end

0 commit comments

Comments
 (0)