Skip to content

Commit b3c48ef

Browse files
joenoonchriseppstein
authored andcommitted
adding asset-data-url sass helper
1 parent cc6f3fd commit b3c48ef

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

README.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ The [list of supported options](http://sass-lang.com/docs/yardoc/file.SASS_REFER
5959
For example: `image_url("rails.png")` becomes `url(/assets/rails.png)` and
6060
`image_path("rails.png")` becomes `"/assets/rails.png"`.
6161

62+
* `asset_data_url($relative-asset-path)` - Returns url reference to the Base64-encoded asset at the specified path.
63+
For example: `asset-data-url("rails.png")` becomes `url(data:image/png;base64,iVBORw0K...)`
6264

6365
## Running Tests
6466

lib/sass/rails/helpers.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ module Sass
22
module Rails
33
module Helpers
44

5+
def asset_data_url(path)
6+
data = context_asset_data_uri(path.value)
7+
Sass::Script::String.new(%Q{url(#{data})})
8+
end
9+
510
def asset_path(asset, kind)
611
Sass::Script::String.new(public_path(asset.value, kind.value), true)
712
end
@@ -25,6 +30,10 @@ def #{asset_class}_url(asset)
2530
def public_path(asset, kind)
2631
options[:custom][:resolver].public_path(asset, kind.pluralize)
2732
end
33+
34+
def context_asset_data_uri(path)
35+
options[:custom][:resolver].context.asset_data_uri(path)
36+
end
2837
end
2938
end
3039
end

0 commit comments

Comments
 (0)