Module: Compass::ImgDelivery

Included in:
Sass::Script::Functions
Defined in:
lib/img-delivery/functions.rb

Instance Method Summary collapse

Instance Method Details

#fallback_scss_rule(basename, img_dir) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/img-delivery/functions.rb', line 17

def fallback_scss_rule(basename, img_dir)
    rule = <<-SCSS
      %#{basename.downcase} {
        background-image: url("#{img_dir}/#{basename}.png");
        background-repeat: no-repeat;
      }

    SCSS
end

#mkdir_if_not_exists(file) ⇒ Object



27
28
29
30
31
32
# File 'lib/img-delivery/functions.rb', line 27

def mkdir_if_not_exists(file)
    if !File.exists?(file)
        d = File.dirname(file)
        Dir.mkdir(d) unless Dir.exists?(d)
    end
end

#scss_rule(basename, mime_type, data_uri) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/img-delivery/functions.rb', line 7

def scss_rule(basename, mime_type, data_uri)
    rule = <<-SCSS
      %#{basename.downcase} {
        background-image: url("data:#{mime_type};base64,#{data_uri}");
        background-repeat: no-repeat;
      }

    SCSS
end

#write_file(file, content) ⇒ Object



34
35
36
37
38
39
# File 'lib/img-delivery/functions.rb', line 34

def write_file(file, content)
    File.open(file, 'w') do |f|
        puts "Writing #{file}"
        f.write(content)
    end
end