Class: JqueryUiThemes::GoogleCDN

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/jquery-ui-themes/google_cdn.rb

Class Method Summary collapse

Class Method Details

.download(theme, version) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/jquery-ui-themes/google_cdn.rb', line 12

def download(theme, version)
  version ||= JqueryUiThemes::JQUERYUI_VERSION

  initial_path = FileUtils.pwd

  path = "/#{version}/themes/#{theme}/jquery-ui.css"

  css = get(path)

  if css.success?
    FileUtils.mkdir_p(File.expand_path("./vendor/assets/stylesheets/jquery-ui/#{version}/"))
    FileUtils.mkdir_p(File.expand_path("./vendor/assets/images/jquery-ui/#{version}/#{theme}/"))

    # Store the css file
    File.open(File.expand_path("./vendor/assets/stylesheets/jquery-ui/#{version}/#{theme}.css.scss"), "w") do |file|
      content = css.gsub(/0pxdow=0px/, '0px') # Weird Google CDN bug
      content = content.gsub(/url\(['"]?images\/([^'"]+)['"]?\)/, 'url(image-path("jquery-ui/' + version + '/' + theme + '/\1"))')
      file.puts(content)
    end

    dest_path = File.expand_path("./vendor/assets/images/jquery-ui/#{version}/#{theme}/")

    FileUtils.cd(dest_path)

    # Store the images
    css.to_s.scan(/images\/.*\.png|\.gif/).each do |path|
      check_path = File.expand_path("./#{path.split('/')[1]}")

      unless File.exists?(File.expand_path(check_path))
        `wget http://ajax.googleapis.com/ajax/libs/jqueryui/#{version}/themes/#{theme}/#{path}`
      end
    end

    FileUtils.cd(initial_path)
  else
    puts "Failed to download the css: #{path}"
  end

  css
end

.download_all(version) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/jquery-ui-themes/google_cdn.rb', line 53

def download_all(version)
  version ||= JqueryUiThemes::JQUERYUI_VERSION

  themes.each do |theme|
    self.download(theme, version)
  end
end