Git Rocks!!!!
So I have been using Git for a while now and let me say it rocks. I tend to do alot of work while travelling and you don't always have the net so being able to commit code is the greatest thing since slice bread.So if your not using it DO IT!!!!!! click here for Git
p.s we also use Github
Sassing a .Net application - part II
Part 1 of this post I introduced Sass into my current project that is using the ASP.NET MVC framework.
(Which I might add, I'm still using the initial CTP without any trouble and the application is in production. So if your wondering if in preview 4 its ready for production use... stop wondering)
The problem I introduced was changes to sass files required a VS build in order for the rake task to execute and reproduce the css files. This increased the turn around time to around 15 seconds, unacceptable.
The solution I was aiming for was a file system watcher that looked at the sass directory and any changes to my sass files immediately.
I found this filesystemwatcher code that looked pretty easy to implement (im a ruby noob still), so I moved those files to my tools directory and required them in my rakefile.rb
require 'rake'
require File.join(File.dirname(__FILE__), 'tools/haml-2.0.2/lib', 'sass')
require File.join(File.dirname(__FILE__), 'tools/fsw', 'servicestate')
require File.join(File.dirname(__FILE__), 'tools/fsw', 'filesystemwatcher')
As you can see, I've placed the filesystemwatcher files into my tools directory, again allowing the application to only rely on ruby and not obscure plugins.
The next step is to call the sass generation on the various FSW Events (Created, Modified, and Deleted)
desc "Watches sass directory and generates css on save."
task :watch_sass do
_sass2cssAll
css_dir = File.join(File.dirname(__FILE__), 'src/app/mvc/content/css')
sass_dir = File.join(css_dir, 'sass')
watcher = FileSystemWatcher.new()
watcher.addDirectory(sass_dir, "*.sass")
watcher.sleepTime = 1
watcher.start { |status,file|
case status
when FileSystemWatcher::CREATED
_sass2css(file, css_dir)
when FileSystemWatcher::MODIFIED
_sass2css(file, css_dir)
when FileSystemWatcher::DELETED
puts "deleted: #{file}"
end
}
watcher.join() # join to the thread to keep the program alive
end
I refactored my :sass2css task so it calls straight into _sass2cssAll. The reason for this is that invoking the task from within the watcher was causing subsequent changes to not be picked up. I didnt investigate this too much.
I also extracted a method _sass2css so that the watcher only reproduced the css file in question, and not all of them.
Here are the 2 methods I extracted...
def _sass2cssAll
stylesheets_root = File.join(File.dirname(__FILE__), 'src/app/mvc/content/css')
Dir[stylesheets_root + "/sass/*.sass"].each do |source|
_sass2css(source, stylesheets_root)
end
end
def _sass2css(source,stylesheets_root)
target = File.join(stylesheets_root, File.basename(source, ".sass") + ".css")
puts "Sassing #{source} to #{target}"
puts ""
File.open(target, "w") { |f| f.write(Sass::Engine.new(IO.read(source)).render)}
end
All that I need to do now is fire up the watcher when I start development an watch those css files change!!
Sassing a .Net application - part I
I've long been wanting to remove the duplication Im forced into with CSS, and so I decided to get Sass going in my ASP.NET MVC application.
A side benefit of getting sass into my application was getting Rake running to assist. I can now choose between rake or nant for any of my build activities.
So the first step was getting a 'Hello Rake World' task running on my Windows dev machine, just to get all the working parts in place. I installed ruby, and then created a RakeFile.rb in the trunk of my application. The following is my uber complex :hello_world task.
desc "Hello World"
task :hello_world do
puts "Hello Rake World!"
end
Running this at the command line gave me the following output:
The next step was to be able to call Rake tasks from Nant. Im not sure if this is a particulary elegant way to go, but Nant is contolling my build so it made sense for now.
The following Nant target calls the :hello_world rake task:
All im doing here is calling the rake.bat batch file. I am passing it the rakefile that sits in my applications trunk, specifying the hello_world target and setting the working directory to be the ruby bin directory (specified in a Nant property).
Calling that nant target at the command line yielded the following output:
So far so good, I have a nant target that can run in my build process that can call a rake task, time to start doing something useful.
I then installed the haml gem and copied the haml-2.0.2 directory over to my tools folder in my application. I don't mind having a dependency on Rails being installed on a development machine, but dependencies on gems isn't suitable.
I require the sass in my rakefile with the following. Its not necessary to require haml since we only make use of the Sass rendering engine.
require File.join(File.dirname(__FILE__), 'tools/haml-2.0.2/lib', 'sass')
Now with the help of this post I was able to put together a task that converted any .sass file in my css/sass directory to the associated .css file.
desc "Regenerates all sass templates."
task :sass2css do
stylesheets_root = File.join(File.dirname(__FILE__), 'src/app/mvc/content/css')
Dir[stylesheets_root + "/sass/*.sass"].each do |source|
target = File.join(stylesheets_root, File.basename(source, ".sass") + ".css")
puts "Sassing #{source} to #{target}"
puts ""
File.open(target, "w") { |f| f.write(Sass::Engine.new(IO.read(source)).render)}
end
end
All that remained to do was call this task from within my nant file, and I have my css being generated as part of my build. I also called this from my VS build, so when I change my sass files and recompile, the rake task is called and the css files are regenerated.
Now I've actually gone 2 steps forward and 1 step back here. Previously css changes were visible in my site by simply saving the stylesheet and refreshing, but now I have to recompile, which means my feedback cycle for css changes has gone from roughly 1 second to about 15 seconds, and this is unsatisfactory.... But ill address that in part II.
NHaml Colour, now in open source!
Apologies to everyone who was looking for this earlier. I did intend on cleaning up the source a bit, but I'm consumed by too many projects!
So i've pushed up the code for the Visual Studio Haml plugin to github. You can find it at http://github.com/sentiadave/hamleditor/tree/master.
Sydney Agile happenings
The Sydney XP/Agile group has started a series of monthly presentations going through the ins and outs of agile software development. There's a lot of collective experience and wisdom in the group so this should be very enticing for those interested in or practicing Agile development.I'm particularly looking forward to tonight's session on "Everything you know about Agile is probably wrong". I've spoken and dealt with more than one team in the past claiming to do agile software development, without understanding how and why it works.
Details are at http://blog.syxpac.org/2008/06/june-16-meeting-everything-you-know.html, hope to see everyone there!
War on WWW's
I really don't see the point of www's in a domain url. I now declare a war on websites that are not setup correctly. What started this war you ask. Well its simple Harvey Norman was the last straw.I went looking for a phone number so l typed harveynorman.com.au into firefox expecting to see the latest information from them and nothing.
Wondering what l did wrong l noticed i didn't have the www in the url. Thinking that there is no way that would be it l just tried it just to make sure.
To my horror it worked, so l have now declared war on websites that are not setup correctly to handle the url without the www's. It's a simple 10sec job and not doing it does not make sense. What's the point of www?. I will be listing them and should you all know of any please do so here as well
It begins
http://www.harveynorman.com.au/
Resharper Quick Tip #1
This one really annoyed me for a while. When you run unit tests in Resharper, it pops up a tool window. When I'm finished I was previously closing the window with the mouse, and breaking the flow.
If you're in the same boat then i'm happy to say that Shift+Esc is what you've been looking for!
Setting up ssh keys on OS X
Ok, i'm writing this post because I keep forgetting how to do this! The basic idea is that you want to be able to connect to servers via ssh and not have to keep typing a password in!
The following commands will generate your public key, and then add it to the server's collection of allowed public keys:
ssh-keygen -t dsa -N ''
cat ~/.ssh/id_dsa.pub | ssh deploy@myserver.com "cat - >> ~/.ssh/authorized_keys2"
Sentia gets one more
We are proud to announce that Sentia is welcoming aboard a new developer. Andrew Dedman will be joining the team as a .net / Ruby on Rails developer.We would just like to congratulate and wish him all the best during his time here at Sentia.
Capistrano task to sync local comatose pages to production
I'm using the comatose gem as a light-weight cms for an app I'm building. There's always the problem with CMS based sites of having the production site not look like the development site. So here's a capistrano task to pull the production pages down to your local machine.
Enjoy.
desc "Retrieve production comatose pages"
task :get_comatose_pages do
run "cd #{current_path}; rake RAILS_ENV=production comatose:data:export"
system "scp #{user}@#{domain}:#{current_path}/db/comatose-pages.yml db/"
system "rake comatose:data:import"
end
Archive
Tags
- asp.net
- asp.net jquery
- automated tests
- autotest
- business
- capistrano
- client
- databases
- Design
- git
- haml
- inflections
- javascript
- migrations
- mvc.net
- nhibernate
- os x
- partials
- rails
- rake
- rake tasks
- resharper
- rjs
- ruby on rails
- sentia
- ssh
- syxpac agile
- testing
- tools
- Treehouse
- unit tests
- views
- visual studio
- www
