Created
March 23, 2009 21:51
-
-
Save osteele/83809 to your computer and use it in GitHub Desktop.
Rails template to install the OpenLaszlo plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This application template for Rails >= 2.3 installs the OpenLaszlo | |
# plugin and its dependencies. It offers to download the OpenLaszlo | |
# SDK and set the OPENLASZLO_HOME environment variable, and it updates | |
# .gitignore. | |
# | |
# To create a new Rails app: | |
# rails webapp -m http://gist.github.com/83809.txt | |
# | |
# To upgrade an existing app: | |
# rake rails:template LOCATION=http://gist.github.com/83809.txt | |
# | |
# To create a new Rails app, or upgrade an existing one, *and* create | |
# a starter applet name myapp that's served from /home/applet, do one of: | |
# # To create a new application | |
# generate=myapp/home/applet rails webapp -m http://gist.github.com/83809.txt | |
# # To upgrade an existing one | |
# generate=myapp/home/applet rake rails:template LOCATION=http://gist.github.com/83809.txt | |
# | |
# Install OpenLaszlo SDK | |
# | |
def download_sdk | |
ol_version = '4.2.0.2' | |
platform_suffix = case RUBY_PLATFORM | |
when /darwin/ then '-osx-dev-install.dmg' | |
when /win/ then '-windows-dev-install.exe' | |
else '-unix.tar.gz' | |
end | |
ol_download_url = "http://download.openlaszlo.org/#{ol_version}/openlaszlo-#{ol_version}#{platform_suffix}" | |
ol_download_dir = 'tmp' | |
ol_basename = File.basename(ol_download_url) | |
ol_download_path = File.join(ol_download_dir, ol_basename) | |
run "mkdir -p #{ol_download_dir}" | |
puts "curl -L #{ol_download_url} > #{ol_download_path}" | |
msgs << "Downloaded #{File.basename(ol_basename)} to tmp" | |
msgs << "Now follow the install instructions from http://www.openlaszlo.org/lps4.2/docs/installation/install-instructions.html." | |
msgs << "When you're done, you can delete #{ol_download_path}." | |
end | |
def openlaszlo_path_is_right?(path=ENV['OPENLASZLO_HOME']) | |
return path && | |
File.exists?(probefile = File.join(path, 'README.txt')) && | |
open(probefile).read =~ /Laszlo/ | |
end | |
msgs = [] | |
needs_download, needs_path = false, false | |
case | |
when ! ENV['OPENLASZLO_HOME'] | |
if yes?("OPENLASZLO_HOME is not set. Have you installed the OpenLaszlo SDK?") | |
while true | |
unless yes?("Shall I edit your ~/.bashrc to set OPENLASZLO_HOME?") | |
needs_path = true | |
break | |
end | |
path = ask("What is the path to the OpenLaszlo SDK?") | |
unless openlaszlo_path_is_right?(path) | |
puts "Sorry, that doesn't seem to be right." | |
next | |
end | |
run "echo export OPENLASZLO_SDK=\\\"#{path}\\\" >> ~/.bashrc" | |
msgs << "Execute the following line before you continue:" | |
msgs << " export OPENLASZLO_SDK=\"#{path}\"" | |
break | |
end | |
elsif yes?("Shall I download it?") | |
download_sdk | |
needs_path = true | |
else | |
needs_download = true | |
end | |
when ! openlaszlo_path_is_right? | |
puts "OPENLASZLO_HOME is set, but not to the location of the OpenLaszlo SDK." | |
if no?("Have you installed the OpenLaszlo SDK?") | |
if yes?("Shall I download it?") | |
download_sdk | |
needs_path = true | |
else | |
needs_download = true | |
end | |
else | |
needs_path = true | |
end | |
end | |
if needs_download | |
msgs << "Please download the OpenLaszlo SDK from http://www.openlaszlo.org/download, and set OPENLASZLO_HOME to point to its installed location." | |
elsif needs_path | |
msgs << "Please set OPENLASZLO_HOME to point to the installed location OpenLaszlo SDK." | |
end | |
# | |
# Gem | |
# | |
gem 'ropenlaszlo', :lib => 'openlaszlo', :version => '>= 0.6.3' | |
rake("gems:install", :sudo => true) | |
# | |
# Plugin | |
# | |
plugin 'openlaszlo-plugin', :git => 'git://github.com/osteele/openlaszlo-plugin.git' | |
if ENV['generate'] | |
components = %w[applet home applet] | |
ENV['generate'].split('/').each_with_index do |component, i| | |
components[i] = component if i < components.length | |
end | |
appname, controller, action = components | |
generate("applet", appname, controller, action) | |
else | |
msgs << "To create an applet name myapp, that's served at /home/view, execute:" | |
msgs << " script/generate applet myapp home view" | |
end | |
# | |
# .gitignore | |
# | |
if File.exists?('.git') or true | |
require 'shellwords' | |
run "touch .gitignore" | |
for pattern in [ | |
'# openlaszlo_plugin', | |
'/public/expressInstall.swf', | |
'/public/javascripts/swfobject.js', | |
'/public/applets/', | |
'*.lzx.lzr=*.swf'] | |
run "echo #{Shellwords.escape(pattern)} >> .gitignore" | |
end | |
end | |
# | |
# Finally | |
# | |
if msgs.any? | |
puts | |
msgs.each do |line| puts line end | |
puts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment