Sha256: 43cd1d20f870bf458d69933f7fccd1d37472c01cccc653ac3d810416cecef5d4
Contents?: true
Size: 828 Bytes
Versions: 1
Compression:
Stored size: 828 Bytes
Contents
# CSSHTTPRequest Ruby Encoder # # Author: Cameron Walters <cameron@nb.io> # License: Apache License 2.0 <http://www.apache.org/licenses/LICENSE-2.0.html> # Copyright (c) 2008, Cameron Walters require "erb" class CSSHTTPRequest PREFIX = "data:,".freeze LENGTH = (2000 - PREFIX.size).freeze # Internet Explorer 2KB URI limit def self.encode(str) quoted = ERB::Util.url_encode(str) slice_num = 0 last_start = 0 chunks = (quoted.length.to_f / LENGTH).ceil STDERR << chunks output = "" chunks.times do |n| finish = last_start + LENGTH output += "#c%d{background:url(%s%s);}\n" % [slice_num, PREFIX, quoted[last_start...finish]] slice_num += 1 last_start = finish end output end end if __FILE__ == $PROGRAM_NAME puts CSSHTTPRequest.encode(STDIN.read) end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
nbio-csshttprequest-1.0.2 | lib/csshttprequest.rb |