Showing posts with label Ruby. Show all posts
Showing posts with label Ruby. Show all posts
November 20, 2009
Ruby and Rake to Deploy ASP.NET and SQL II
In a follow-up to my article from yesterday. It seems that starting last night the website that I am pointing too went down. I am posting a link to the ruby file here with all credit to derek who wrote it up. The details of what he did are on his site and I hope it comes back up soon.
November 19, 2009
Ruby and Rake to Deploy ASP.NET and SQL
I currently use NAnt and some powershell to deploy most of my web applications in our environment. I was curious if I could do this with Ruby. I came across this informative article here that discusses how to use Rake and Ruby to do deployments for ASP.NET and also how to do SQL compares. Very interesting!
November 11, 2009
Ruby Part II
Yup, Ruby really does rock. I am starting to read up on Rails and what it can do. I question why I have been working with C# for so long :) Anyone else see the light when they started working with Rails?
November 10, 2009
October 19, 2009
Combine & Minimize JavaScript using Ruby
AC shared with me this great way of combining many .js files to one big file. I am not sure if all the code was his or if some he found, so credit to whoever helped out with this. This is really a great and easy way to do this, and you can run this on a postscript or even from NAnt if you wanted. In order to use it, you will first need to download and install some software:
For the code below, I need to download jslint.js, jsmin.js, pack.js, and packer.js and store them in the same folder as well.
You then have a batch file with has just one word: rake. You run this batch file (which is in the same directory as your rake file explained below)
Now, the code is all in one little Rakefile:
- Java
- Ruby (http://rubyinstaller.rubyforge.org/wiki/wiki.pl)
- RubyGems (http://rubyforge.org/frs/?group_id=126 & unzip to lcoation)
- command line > gem install rake
- command line > gem install rio
- command line > ruby.exe c:\rubygems-1.3.1\setup.rb
For the code below, I need to download jslint.js, jsmin.js, pack.js, and packer.js and store them in the same folder as well.
You then have a batch file with has just one word: rake. You run this batch file (which is in the same directory as your rake file explained below)
Now, the code is all in one little Rakefile:
require 'rio'Thanks AC for this.
$rhino_compile_enabled = false
$minify_enabled = true
$jslint_enabled = false
$output_dir = "out"
puts "Starting..."
def get_files
files = []
files << as_is("http://yui.yahooapis.com/combo?2.5.2/build/yahoo-dom-event/yahoo-dom-event.js")
files << as_is("http://yui.yahooapis.com/combo?2.5.2/build/yahoo-dom-event/yahoo-dom-event.js&2.5.2/build/container/container-min.js&2.5.2/build/cookie/cookie-beta-min.js&2.5.2/build/json/json-min.js&2.5.2/build/element/element-beta-min.js&2.5.2/build/datasource/datasource-beta-min.js&2.5.2/build/connection/connection-min.js&2.5.2/build/charts/charts-experimental-min.js")
files << minify("../WebApp/js/diag.js")
files << as_is("../WebApp/js/jquery-1.3.1.min.js")
#add more files here
end
def as_is(file_path)
task file_path do
end
file_path
end
def minify(file_path)
mkdir_if_not_exist "#{$output_dir}/min"
min_path = get_min_path(file_path)
file min_path => file_path do
do_jslint file_path
do_minify file_path, min_path
end
min_path
end
def do_minify(file_path, min_path)
if $minify_enabled
`java -cp build/js.jar org.mozilla.javascript.tools.shell.Main build/min.js #{file_path} #{min_path}`
else
rio(min_path) < rio(file_path)
end
end
def do_jslint(file_path)
return unless $jslint_enabled
puts "jslint #{file_path}"
mkdir_if_not_exist "#{$output_dir}/tmp"
mkdir_if_not_exist "#{$output_dir}/jslint_errors"
tmp = "#{$output_dir}/tmp/jslint.tmp.js"
rio(tmp) < rio('jslint-options.js')
rio(tmp) << rio(file_path)
errors = `java -cp build/js.jar org.mozilla.javascript.tools.shell.Main build/jslint.js #{tmp}`
unless /jslint: No problems found/.match(errors)
rio("#{$output_dir}/jslint_errors/#{File.basename(file_path)}.err") < errors
end
end
def get_min_path(file_path)
"#{$output_dir}/min/" + File.basename(file_path) + ".min"
end
def mkdir_if_not_exist(dir_name)
Dir.mkdir dir_name unless File.exist? dir_name
end
def do_rhino_compile(file_path)
return unless $rhino_compile_enabled
puts "Rhino compiling..."
`java -cp build/js.jar org.mozilla.javascript.tools.jsc.Main #{file_path}`
puts "Rhino compilation done."
end
def get_combined_path
"#{$output_dir}/combined.js"
end
task :combine => get_files do
mkdir_if_not_exist "#{$output_dir}"
combined = get_combined_path
rio(combined) < "
/*
* Combined JavaScript.
* #{Time.now}
*/
"
get_files.each do |file_path|
puts "Combining: #{file_path}"
rio(combined) << "
/************************************************************************
* Source: #{file_path}
************************************************************************/
"
rio(combined) << rio(file_path)
puts 'next...'
end
end
task :rhino_compile do
do_rhino_compile get_combined_path
end
task :copy_combined do
rio("../WebApp/Combined/combined.js") < rio(get_combined_path)
end
task :default => [:combine, :copy_combined]
July 4, 2009
Ruby Wrapper for LogParser
Since we are on the topic of logparser, I happened to come across this today. The project description:
" Ruby Log Parser is a wrapper around Microsoft's Log Parser tool freely available for Windows. This wrapper enables a SQL statement to be passed to the LogParser executable and the results returned via an array or hash for further processing in Ruby. "
Very cool!
" Ruby Log Parser is a wrapper around Microsoft's Log Parser tool freely available for Windows. This wrapper enables a SQL statement to be passed to the LogParser executable and the results returned via an array or hash for further processing in Ruby. "
Very cool!
May 31, 2009
Replace macro fields with Ruby
OK, now let's do it in Ruby. This requires a values.rb folder (like our values.ps1 folder in powershell):
require 'erb'
require 'rio'
module MacroConfig
def self.generate
mkdir_if_not_exist 'configs'
Dir.glob('templates/*').each do |template_file|
template = ''
rio(template_file) > template
config = ERB.new(template).result(get_values)
config_file = 'configs/' + File.basename(template_file)
rio(config_file) < script =" ''">> script
script << "\n"
end
eval script
binding
end
def self.get_values
read_values(['../values.rb', 'values.rb'])
end
def self.mkdir_if_not_exist(dir_name)
Dir.mkdir dir_name unless File.exist? dir_name
end
end
Subscribe to:
Posts (Atom)