Class: Raylayers::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Raylayers::Generators::InstallGenerator
- Defined in:
- lib/generators/raylayers/install/install_generator.rb
Instance Method Summary collapse
- #build_openlayers ⇒ Object
- #download_openlayers ⇒ Object
- #install_openlayers ⇒ Object
- #ready ⇒ Object
- #remove_tmp_files ⇒ Object
- #unpack_openlayers ⇒ Object
Instance Method Details
#build_openlayers ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/generators/raylayers/install/install_generator.rb', line 32 def build_openlayers say_status("building", "OpenLayers (#{.version})", :green) # TODO: ruby script? Dir.chdir("tmp/OpenLayers-#{.version}/build"){ system("python build.py 1> /dev/null")} rescue say_status("error", "could not build OpenLayers", :red) end |
#download_openlayers ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/generators/raylayers/install/install_generator.rb', line 10 def download_openlayers @tmp_file = "tmp/OpenLayers-#{.version}.zip" say_status("fetching", "OpenLayers (#{.version})", :green) get "http://openlayers.org/download/OpenLayers-#{.version}.zip", @tmp_file rescue OpenURI::HTTPError say_status("error", "could not find OpenLayers ({options.version})", :red) end |
#install_openlayers ⇒ Object
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 (#{.version})", :green) FileUtils.mkdir_p("public/openlayers/") FileUtils.cp("tmp/OpenLayers-#{.version}/build/OpenLayers.js", "public/openlayers/OpenLayers.js") FileUtils.cp_r("tmp/OpenLayers-#{.version}/theme", "public/openlayers/theme") FileUtils.cp_r("tmp/OpenLayers-#{.version}/img", "public/openlayers/img") rescue say_status("error", "could not install OpenLayers", :red) end |
#ready ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/generators/raylayers/install/install_generator.rb', line 56 def ready msg = "\n\nOpenLayers #{.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_files ⇒ Object
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-#{.version}") end |
#unpack_openlayers ⇒ Object
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 |