utils.rb (2726B)
1 module ExtJS4 2 module SassExtensions 3 module Functions 4 module Utils 5 def parsebox(list, n) 6 assert_type n, :Number 7 if !n.int? 8 raise ArgumentError.new("List index #{n} must be an integer") 9 elsif n.to_i < 1 10 raise ArgumentError.new("List index #{n} must be greater than or equal to 1") 11 elsif n.to_i > 4 12 raise ArgumentError.new("A box string can't contain more then 4") 13 end 14 15 new_list = list.clone.to_a 16 size = new_list.size 17 18 if n.to_i >= size 19 if size == 1 20 new_list[1] = new_list[0] 21 new_list[2] = new_list[0] 22 new_list[3] = new_list[0] 23 elsif size == 2 24 new_list[2] = new_list[0] 25 new_list[3] = new_list[1] 26 elsif size == 3 27 new_list[3] = new_list[1] 28 end 29 end 30 31 new_list.to_a[n.to_i - 1] 32 end 33 34 def parseint(value) 35 Sass::Script::Number.new(value.to_i) 36 end 37 38 # Returns a background-image property for a specified images for the theme 39 def theme_image(theme, path, without_url = false, relative = false) 40 path = path.value 41 theme = theme.value 42 without_url = (without_url.class == FalseClass) ? without_url : without_url.value 43 44 relative_path = "../images/" 45 46 if relative 47 if relative.class == Sass::Script::String 48 relative_path = relative.value 49 relative = true 50 elsif relative.class == FalseClass || relative.class == TrueClass 51 relative = relative 52 else 53 relative = relative.value 54 end 55 else 56 relative = false 57 end 58 59 if relative 60 images_path = relative_path 61 else 62 images_path = File.join($ext_path, 'themes', 'images', theme) 63 image_path = File.join(images_path, path) 64 end 65 66 if !without_url 67 url = "url('#{image_path}')" 68 else 69 url = "#{image_path}" 70 end 71 72 Sass::Script::String.new(url) 73 end 74 75 def theme_image_exists(path) 76 result = false 77 78 where_to_look = path.value.gsub('../../resources', 'resources') 79 80 if where_to_look && FileTest.exists?("#{where_to_look}") 81 result = true 82 end 83 84 return Sass::Script::Bool.new(result) 85 end 86 end 87 end 88 end 89 end 90 91 module Sass::Script::Functions 92 include ExtJS4::SassExtensions::Functions::Utils 93 end