Sha256: 106d8d65a039af680592f78e791acc68df210a9aeb0a923b3ec4197a3c3ce8c3

Contents?: true

Size: 1.11 KB

Versions: 8

Compression:

Stored size: 1.11 KB

Contents

module Sprite
  module Styles
    # renders standard css style rules
    class CssGenerator
      def initialize(builder)
        @builder = builder
      end

      def write(path, sprite_files)
        # write styles to disk
        File.open(File.join(Sprite.root, path), 'w') do |f|
          write_standard_css(f, sprite_files)
        end
      end

      def write_standard_css(f, sprite_files)
        # set up class_name to append to each rule
        sprites_class = @builder.config['sprites_class'] ? ".#{@builder.config['sprites_class']}" : ""

        sprite_files.each do |sprite_file, sprites|
          background_url = @builder.background_url(sprite_file)
          sprites.each do |sprite|
            f.puts "#{sprites_class}.#{sprite[:group]}#{@builder.config['class_separator']}#{sprite[:name]} {"
            f.puts "  background: #{background_url} no-repeat #{sprite[:x]}px #{sprite[:y]}px;"
            f.puts "  width: #{sprite[:width]}px;"
            f.puts "  height: #{sprite[:height]}px;"
            f.puts "}"
          end
        end
      end

      def extension
        "css"
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
sprite-0.3.0 lib/sprite/styles/css_generator.rb
sprite-0.2.7 lib/sprite/styles/css_generator.rb
sprite-0.2.6 lib/sprite/styles/css_generator.rb
sprite-0.2.5 lib/sprite/styles/css_generator.rb
sprite-0.2.4 lib/sprite/styles/css_generator.rb
sprite-0.2.2 lib/sprite/styles/css_generator.rb
sprite-0.2.1 lib/sprite/styles/css_generator.rb
sprite-0.2.0 lib/sprite/styles/css_generator.rb