Module: ExtJS::Theme::Effects

Defined in:
lib/extjs-theme/effects.rb

Class Method Summary collapse

Class Method Details

.each_image(path) ⇒ Object

Iterate all theme images

Parameters:

  • path (String)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/extjs-theme/effects.rb', line 27

def self.each_image(path)
  Dir["#{path}/*/"].each do |dir|
    Dir[dir+'/*.gif'].each do |filename|
      yield(Magick::ImageList.new(filename))
    end
    Dir[dir+'/*.png'].each do |filename|
      yield(Magick::ImageList.new(filename))
    end
  end
  # Now transform any images left in the base /images/default directory (excluding s.gif)
  Dir["#{path}/*.*"].reject {|f| f.match('s.gif')}.each do |filename|
    yield(Magick::ImageList.new(filename))
  end
end

.modulate(ext_dir, theme_dir, hue = 1.0, saturation = 1.0, lightness = 1.0) ⇒ Object

performs hsv transformation on Ext theme images and save to Sass theme dir.

Parameters:

  • name (String)

    Theme name

  • ext_dir (String)

    path to Ext directory relative to public/javascripts

  • hue (Float) (defaults to: 1.0)
  • saturation (Float) (defaults to: 1.0)
  • lightneess (Float)


12
13
14
15
16
17
18
19
# File 'lib/extjs-theme/effects.rb', line 12

def self.modulate(ext_dir, theme_dir, hue=1.0, saturation=1.0, lightness=1.0)
  each_image("#{ext_dir}/resources/images/default") {|img|
    write_image(img.modulate(lightness, saturation, hue), theme_dir)
  }
  # update hue in defines.sass
  defines = File.read("#{theme_dir}/defines.sass")
  File.open("#{theme_dir}/defines.sass", "w+") {|f| f << defines.gsub(/hue\s?=.*/, "hue = #{(hue-1)*180}") }
end

.write_image(img, dest) ⇒ Object

Write transformed RMagick::Image to theme directory

Parameters:

  • img (RMagick::Image)
  • dest (String)

    Theme directory



47
48
49
50
51
52
53
54
55
# File 'lib/extjs-theme/effects.rb', line 47

def self.write_image(img, dest)
  # Get filename and directory
  m = /\/default\/(.*)\/(.*)\.(.*)$/.match(img.filename) || /\/default\/(.*)\.(.*)$/.match(img.filename)
  #m = /\/(.*)\/(.*)\.(.*)$/.match(img.filename) || /\/(.*)\.(.*)$/.match(img.filename)
  outfile = (m.captures.length == 3) ? "#{dest}/images/#{m[1]}#{m[2]}.#{m[3]}" : "#{dest}/images/#{m[1]}.#{m[2]}"

  puts " - #{outfile}"
  img.write(outfile)
end