Class: Raylayers::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/raylayers/install/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#build_openlayersObject



32
33
34
35
36
37
38
# File 'lib/generators/raylayers/install/install_generator.rb', line 32

def build_openlayers
  say_status("building", "OpenLayers (#{options.version})", :green)
  # TODO: ruby script?
  Dir.chdir("tmp/OpenLayers-#{options.version}/build"){ system("python build.py 1> /dev/null")}
rescue
  say_status("error", "could not build OpenLayers", :red)
end

#download_openlayersObject



10
11
12
13
14
15
16
# File 'lib/generators/raylayers/install/install_generator.rb', line 10

def download_openlayers
  @tmp_file = "tmp/OpenLayers-#{options.version}.zip"
  say_status("fetching", "OpenLayers (#{options.version})", :green)
  get "http://openlayers.org/download/OpenLayers-#{options.version}.zip",  @tmp_file
rescue OpenURI::HTTPError
  say_status("error", "could not find OpenLayers ({options.version})", :red)
end

#install_openlayersObject



40
41
42
43
44
45
46
47
48
# File 'lib/generators/raylayers/install/install_generator.rb', line 40

def install_openlayers
  say_status("installing", "OpenLayers (#{options.version})", :green)
  FileUtils.mkdir_p("public/openlayers/")
  FileUtils.cp("tmp/OpenLayers-#{options.version}/build/OpenLayers.js", "public/openlayers/OpenLayers.js")
  FileUtils.cp_r("tmp/OpenLayers-#{options.version}/theme", "public/openlayers/theme")
  FileUtils.cp_r("tmp/OpenLayers-#{options.version}/img", "public/openlayers/img")
rescue
  say_status("error", "could not install OpenLayers", :red)
end

#readyObject



56
57
58
59
60
61
62
# File 'lib/generators/raylayers/install/install_generator.rb', line 56

def ready
  msg = "\n\nOpenLayers #{options.version} is ready to use\n"
  msg += "HAML => = javascript_include_tag '/openlayers/OpenLayers.js'\n"
  msg += "HTML => <script src='/openlayers/OpenLayers.js' type='text/javascript'></script>\n"
  msg += "RequireJS => require (['/openlayers/OpenLayers.js']);\n\n"
  say (msg)
end

#remove_tmp_filesObject



50
51
52
53
54
# File 'lib/generators/raylayers/install/install_generator.rb', line 50

def remove_tmp_files
  say_status("clean", "Removing temp files", :green)
  FileUtils.rm_f(@tmp_file)
  FileUtils.rm_rf("tmp/OpenLayers-#{options.version}")
end

#unpack_openlayersObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/generators/raylayers/install/install_generator.rb', line 18

def unpack_openlayers
  say_status("unpacking", @tmp_file, :green)
  Zip::ZipFile.open(@tmp_file) do |zip|
    zip.each do |file|
      file_path = File.join("tmp/", file.to_s)
      directory = file_path[0, file_path.rindex("/") + 1] 
      FileUtils.mkdir_p(directory) unless File.directory?(directory)
      zip.extract(file, file_path) unless File.exists? file_path
    end
  end
rescue
  say_status("error", "could not unpack #{@tmp_file}", :red)
end