My Ruby Cookbook: #1 Textile Convertor
#!/usr/bin/env ruby
# Used to generate a HTML-ized file from a textile marked up file
#
require 'rubygems'
require 'redcloth'
ARGV.each { |file|
a = File.open(file, "r")
lines = a.readlines
a.close
contents = Array.new()
lines.each { |line|
contents << line
}
html_file = File.new(file +".html", "w")
html_file.puts(RedCloth.new(contents.join()).to_html)
html_file.close
}
Eric Davis
2005, how did you do?
2006 is just around the corner now. It is time to start reviewing this past year to learn from what happened.
Some questions you might ask yourself:
- How was 2005?
- Did I get anything done?
- Did you work on small stuff or did you work on something important?
- What did you do to make the world better?
I will be posting some of my personal review in later days.
Good luck to everyone in 2006, it is time to have an impact on the world.
Eric Davis
Free Culture
If you have not read Lawrence Lessig’s speech, now is the time to. I has been a real eye opener for me and has made me realize that Free Software and OSS is more than just low-cost, high quality code….
It is a way of life
Closed source and proprietary anything defeats competition. For a business this is good but as a society this is terrible. What is to become of us if all the means of innovation are destroyed?
Personally, I have learned more from reading and using Free Software than anything in my $30,000 college term. So I ask myself, and everyone around to please do what they can to stop this evil plague that is covering our society. Don’t know how? Start Here with the EFF, I know I am.
Eric Davis
Once again, a new theme
Well you might notice that I once again have a new theme up. This one is called subtleTheme and is by Thomas Aylott.
I adjusted the width of the content area a bit and had to patch the code a bit for trunk but it works pretty good, and looks great.
The patch is in
views/articles/read.rhtml line:22
<%= article_html(@article) %>
Eric Davis
Using Migrations to Insert Content
Migrations have made “Rails”:http://www.rubyonrails.org development so much easier by being able to code our SQL “data definations”:http://en.wikipedia.org/wiki/DataDefinitionLanguage in “Ruby”:http://www.ruby-lang.org. You can also use migrations to code in some data too.
To do this you just access the models as you would in any other “Rails”:http://www.rubyonrails.org file. For example, if you want to add to rows to “Typo’s”:http://typo.leetsoft.com Setting Table you could use this migration.
class MyNewSettings < ActiveRecord::Migration
def self.up
Setting.create(:name => 'new_setting_toggle', :value => 0)
Setting.create(:name => 'new_setting_url', :value => 'http://www.foo.com')
end
def self.down
Setting.find(:first, :conditions => [ "name IN (?)", 'new_setting_toggle' ] ).destroy
Setting.find(:first, :conditions => [ "name IN (?)", 'new_setting_url' ]).destroy
end
end
This would insert a two new rows into Setting with the names and values above. It would also be able to be rolled back using the self.down method.
A great practical example of this would be to initialize the database with some starting values, or even to insert some demo data. The only thing you need to watchout for is that since migrations are sequential, if you have this migration the it will have to be ran if make a migration after it. A workaround is to generate the migration and move the migration file out of db/migrations/. Then you can create a Rake task to run the migration if the user needs demo data (but you will need to fuss with the schema_info table)
Eric Davis