Sha256: 4e1cd8dc2c47fa5f42338572962a0af7c97d3824b226afdc4b74d122dd4fac2f
Contents?: true
Size: 1.83 KB
Versions: 1
Compression:
Stored size: 1.83 KB
Contents
module RailsSprite class StylesheetGenerator def self.generate options={} css_class_prefix = options[:css_class_prefix] css_class_shared = options[:css_class_shared] css_extend = options[:css_extend] image_scope_name = options[:image_scope_name] file_infos = options[:file_infos] stylesheet_to = options[:stylesheet_to] result = {} styles = [] file_infos.each do |file_info| style = {} style[:width] = "#{file_info[:width]}px" style[:height] = "#{file_info[:height]}px" style[:x] = "#{file_info[:x]}px" style[:y] = "#{file_info[:y]}px" style[:class] = "#{css_class_prefix}#{file_info[:file_purename]}" styles << style end result[:styles] = styles result[:image_scope_name] = image_scope_name result[:css_class_shared] = css_class_shared css_filt_content = case css_extend when '.css.scss.erb', '.scss.erb' composite_css_scss_erb(result) else end system "mkdir -p #{::File.dirname(stylesheet_to)}" ::File.open(stylesheet_to, 'w') do |file| file.write( css_filt_content ) end result end def self.composite_css_scss_erb result styles = [] styles << <<-END_CSS .#{result[:css_class_shared]} { background-image: url(<%= image_path("#{result[:image_scope_name]}") %>); background-repeat: no-repeat; } END_CSS result[:styles].each do |style| styles << <<-END_CSS .#{style[:class]} { background-position: #{style[:x]} -#{style[:y]}; } END_CSS # .#{style[:class]} { # background: url(<%= image_path("#{result[:image_scope_name]}") %>) #{style[:x]} -#{style[:y]} no-repeat; # } end styles.join("\n") end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rails-sprite-0.0.4 | lib/rails_sprite/stylesheet_generator.rb |