Class: SpriteFactory::Runner
- Inherits:
-
Object
- Object
- SpriteFactory::Runner
- Defined in:
- lib/sprite_factory/runner.rb
Constant Summary collapse
- PSEUDO_CLASS_ORDER =
[nil, ':link', ':visited', ':focus', ':hover', ':active']
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#input ⇒ Object
readonly
—————————————————————————-.
Instance Method Summary collapse
-
#initialize(input, config = {}) ⇒ Runner
constructor
A new instance of Runner.
-
#run!(&block) ⇒ Object
—————————————————————————-.
Constructor Details
#initialize(input, config = {}) ⇒ Runner
Returns a new instance of Runner.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/sprite_factory/runner.rb', line 16 def initialize(input, config = {}) @input = input.to_s[-1] == "/" ? input[0...-1] : input # gracefully ignore trailing slash on input directory name @config = config @config[:style] ||= SpriteFactory.style || :css @config[:layout] ||= SpriteFactory.layout || :horizontal @config[:library] ||= SpriteFactory.library || :rmagick @config[:selector] ||= SpriteFactory.selector || 'img.' @config[:cssurl] ||= SpriteFactory.cssurl @config[:report] ||= SpriteFactory.report @config[:pngcrush] ||= SpriteFactory.pngcrush @config[:nocomments] ||= SpriteFactory. @config[:separator] ||= SpriteFactory.separator || '_' @config[:glob] ||= SpriteFactory.glob || '*' @config[:sanitizer] ||= SpriteFactory.sanitizer @config[:exclude] ||= SpriteFactory.exclude || [] end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
14 15 16 |
# File 'lib/sprite_factory/runner.rb', line 14 def config @config end |
#input ⇒ Object (readonly)
13 14 15 |
# File 'lib/sprite_factory/runner.rb', line 13 def input @input end |
Instance Method Details
#run!(&block) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/sprite_factory/runner.rb', line 35 def run!(&block) raise RuntimeError, "unknown layout #{layout_name}" if !Layout.respond_to?(layout_name) raise RuntimeError, "unknown style #{style_name}" if !Style.respond_to?(style_name) raise RuntimeError, "unknown library #{library_name}" if !Library.respond_to?(library_name) raise RuntimeError, "input must be a single directory" if input.nil? || input.to_s.empty? || !File.directory?(input) raise RuntimeError, "no image files found" if image_files.empty? raise RuntimeError, "no output file specified" if output.to_s.empty? raise RuntimeError, "no output image file specified" if output_image_file.to_s.empty? raise RuntimeError, "no output style file specified" if output_style_file.to_s.empty? raise RuntimeError, "set :width for fixed width, or :hpadding for horizontal padding, but not both." if width && !hpadding.zero? raise RuntimeError, "set :height for fixed height, or :vpadding for vertical padding, but not both." if height && !vpadding.zero? raise RuntimeError, "set :width for fixed width, or :hmargin for horizontal margin, but not both." if width && !hmargin.zero? raise RuntimeError, "set :height for fixed height, or :vmargin for vertical margin, but not both." if height && !hmargin.zero? raise RuntimeError, "The legacy :csspath attribute is no longer supported, please use :cssurl instead (see README)" unless @config[:csspath].nil? images = load_images max = layout_images(images) header = summary(images, max) report(header) css = [] css << style_comment(header) unless # header comment css << style(selector, css_url, images, &block) # generated styles css << IO.read(custom_style_file) if File.exists?(custom_style_file) # custom styles css = css.join("\n") create_sprite(images, max[:width], max[:height]) unless nocss? css_file = File.open(output_style_file, "w+") css_file.puts css css_file.close end if config[:return] == :images images # if caller explicitly asked for detailed images hash instead of generated CSS else css # otherwise, default is to return the generated CSS to caller in string form end end |