Sha256: 937935f12323cbfe900e826382fba775c95bb73b603d20b63a184d3b47d984d1

Contents?: true

Size: 1.23 KB

Versions: 15

Compression:

Stored size: 1.23 KB

Contents

require 'erb'

module Sprite
  module Styles
    # renders css rules from template
    class TemplatedCssGenerator
      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|
          f.puts "/* Generated by the sprite gem */"
          sprite_files.each do |sprite_file|
            @builder.images.each do |image|
              if "#{image['name']}.#{image['format']}" == sprite_file[0]
                erb_path = @builder.send :style_template_source_path, image
                erb_template = ERB.new(File.read(erb_path))
                sprites = sprite_file[1]
                sprites.each do |sprite|
                  name = sprite[:name]
                  width = sprite[:width]
                  height = sprite[:height]
                  left = sprite[:x]
                  top = sprite[:y]
                  image_path = ImageWriter.new(@builder.config).image_output_path(image['name'], image['format'])
                  f.puts erb_template.result(binding)
                end
              end
            end
          end
        end
      end

      def extension
        "css"
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
sprite-0.3.0 lib/sprite/styles/templated_css_generator.rb
sprite-0.2.7 lib/sprite/styles/templated_css_generator.rb
amikula-sprite-0.1.13 lib/sprite/styles/templated_css_generator.rb
sprite-0.2.6 lib/sprite/styles/templated_css_generator.rb
amikula-sprite-0.1.12 lib/sprite/styles/templated_css_generator.rb
sprite-0.2.5 lib/sprite/styles/templated_css_generator.rb
sprite-0.2.4 lib/sprite/styles/templated_css_generator.rb
sprite-0.2.2 lib/sprite/styles/templated_css_generator.rb
sprite-0.2.1 lib/sprite/styles/templated_css_generator.rb
sprite-0.2.0 lib/sprite/styles/templated_css_generator.rb
amikula-sprite-0.1.11 lib/sprite/styles/templated_css_generator.rb
amikula-sprite-0.1.10 lib/sprite/styles/templated_css_generator.rb
amikula-sprite-0.1.9 lib/sprite/styles/templated_css_generator.rb
amikula-sprite-0.1.8.1 lib/sprite/styles/templated_css_generator.rb
amikula-sprite-0.1.8 lib/sprite/styles/templated_css_generator.rb