As a small thank you to the Redcar team for such a great editor and in the spirit of giving a little bit back I’m documenting the process of creating my first plugin.
I really like the idea of the Redcar editor. Its written in Ruby, its possible to write your own plugins what’s not to like? Though I must confess I don’t use it as my day to day editor, I wonder if writing my own plugins will change that.
Let see how easy it is to write a plugin for Redcar.
What’s da big idea
The idea for my first plugin is rather ambitious considering I’ve no idea how to write a plugin. I’d like to replicate some of the functionality of Live Reload – basically refresh a browser web page whenever I save a file in Redcar. This will save me constantly hitting refresh in the browser when working with Backbone.js.
I’m hoping to trap the save event of Redcar and call out to my browser (Chrome) and tell it to refresh the page.
I first followed the install instructions:
All good no problems there (I’m running on a Mac OSX 10.7.1)
I then read the plugin guides I found here:
Setting up a plugin is really easy and well described in the guides listed above. Redcar itself is made up of a bunch of plugin’s so there are no end of great examples to follow in the source code (http://github.com/redcar/redcar)
For trapping the save event I dug into the source code and came across the method project_refresh_task_type which is called on all plugins after a save. To hook into this process my plugin simply defines the method:
This may not be the best place to hook into save, Redcar has the concept of events and that may be a better place to look but for now this is working.
Browser refresh script
RefreshBrowser is a Redcar::Task which I have created to run the browser refresh script.
I managed to find a script to refresh the browser here:
The script uses a keyword to identify which tab to refresh in the browser so I needed this to be saved and configurable somewhere. Luckily Redcar has a storage mechanism built right in.
Redcar’s storage mechanism allows you to easily store configuration data into a yaml file.
@storage ||= Plugin::Storage.new('live_reload_plugin')
Here I am using this mechanism to store the ‘keyword’ used by the RefreshBrowser task. This allows the user to edit the yaml file via the Redcar plugin preferences. It’s also possible to setup a nice edit page but for now this will do.
You can find the source for this plugin here:
Was it easy?
YES! The Redcar team have done a great job and made it incredibly easy to create your own plugins. In a couple of hours I made a useful plugin, useful to me at least. I’ve spent more time fussing over this blog post than developing the plugin.
So what you waiting for? Go give it a try!
It seemed almost impossible to penetrate the fortress that is Sharepoint with only NTLM authentication enabled. Turns out its really easy when you know how.
curl to the rescue!
You can upload files using curl directly into Sharepoint via it’s HTTP PUT interface.
curl --ntlm --user username:password --upload-file myfile.xls https://sharepointserver.com/sites/mysite/myfile.xls
Told you, easy when you know how.
Setup Apache as a Reverse Proxy in front of a standalone Torquebox server.
For this to work Apache must have the mod_proxy module loaded:
Config file: /etc/httpd/conf/httpd.conf
ProxyRequests Off # Switch off forward proxy
ProxyPreserveHost On # Pass host name onto the proxy
ProxyPass /myapp http://localhost:8080/myapp/ # Map url to remote server
ProxyPassReverse /myapp http://localhost:8080/myapp/ # Adjust header sent from remote server to match url
Here we are passing all calls to the /myapp/ url on to the Torquebox server http://localhost:8080/myapp/
In your Torquebox application folder create a file ‘config/torquebox.yml’ which contains a context which matches the Apache reverse proxy url.
To build FubuMVC you need to install ruby, rake etc. Unfortunately for me the firewall at work will not allow me to get the rake gem (I’ve downloaded gems before using the HTTP_PROXY setting before but no luck this time). Any hoose I remember reading Stephen Balkum post on packaging up Rake as an executable. I followed Stephens guide and created a portable rake package which got around my firewall problem but FubuMVC required another gem rubyzip to allow a build.
Adding another gem
Luckily using Stephen’s guide its really easy to add extra gems, you just need to have them installed before you build your exe. So we follow the first part of the process outlined in Stephen’s guide then do the following:
NOTE: In this case we need rubyzip but it could be any old gem.
- Download rubyzip and extract to contents to c:\rubywork\zip
- To install rubyzip, at a command prompt in c:\rubywork\zip, run ..\ruby\bin\ruby install.rb
- Download zlib and extract the zlib1.dll to C:\rubywork\ruby\lib\ruby\1.8\i386-mswin32
- Rename zlib1.dll to zlib.dll (rubyzip required this extra dll other gems may not)
Now continue part two of the process from Stephen’s guide to compile your very own allinoneruby.exe which includes, rake and rubyzip.
You should now have allinoneruby.exe and rake.rb file.
We can now drop these files into to the FubuMVC project under the build support folder:
We need a helper batch file in the root folder of FubuMVC called rake.bat which contains:
@.\build_support\allinoneruby.exe .\build_support\rake.rb %*
This will be called when we run the build.
Run the build already
Drop to the command prompt and cd into the FubuMVC project root and simply type build. You should get something like:
Don’t want to go through all that? You can download my version of portable rake here (I don’t think I’m breaking any licensing agreements here, this is all open source software. If I am let me know and I’ll remove the link)
DISCLAIMER: I offer no guarantees I can only confirm this works on my machine!
One final note
I’ve used this method to build some of the other open source projects out there which use rake (all the cool kids seem to be using rake) and so far I’ve not had any problems. This could be pretty frictionless way to introduce rake to a team of .net developers who don’t want the overhead of installing ruby on their machines. Just add it to a tools folder check it in to source control they’ll never know!
Assuming you have an SQL Server 2005 running reporting services you can run Report builder as a ClickOnce app using the following url:
build_log.xml *.suo *.user _ReSharper* *.resharper bin obj class build
Looking for help on the SAP Portal? HTMLB syntax and lots of other goodies this way…
By the way setting up the server was a lot easier than I thought it would be! Here’s what I did:
I’ve used version 1.0.1:
NOTE: After setup if your server has .Net 1.1 and 2.0 as mine did you may need to change the ccnet website to use .Net 2.0. This can be done through the IIS control panel, get the properties of the ccnet site and change via the ASP.NET tab.
Your server will need the subversion console client on the server to allow CruiseControl to checkout your source.
.Net 2 SDK
To allow us to build .Net 2 projects without the need for Visual Studio we need to download and install .Net 2 SDK onto the server
To use MSBuild with CC.Net we need the logger dll -ThoughtWorks.CruiseControl.MsBuild.dll from:
Download and copy to:
Setup your directory structure:
Using your subversion client checkout source to C:\CI\MyProject\build
Add the project config to ccnet.confg:
<cruisecontrol> <project name="MyProject"> <!-- after a change is detected, wait 10 mins and then kick off the build--> <schedule type="schedule" sleepSeconds="600" /> <!--set the sourcecontrol type to subversion and point to the subversion exe--> <sourcecontrol type="svn"> <executable>C:\Program Files\Subversion\bin\svn.exe</executable> <workingDirectory>C:\CI\MyProject\build</workingDirectory> <trunkUrl>svn://svnserver/MyProject/trunk</trunkUrl> <autoGetSource>true</autoGetSource> <username>myuser</username> <password>mypassword</password> </sourcecontrol> <tasks> <!-- Configure MSBuild to compile the updated files -->c:\ <msbuild> <executable>C:\windows\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe</executable> <workingDirectory>C:\CI\MyProject\build\src\</workingDirectory> <projectFile>MyProject.sln</projectFile> <buildArgs>/noconsolelogger /p:Configuration=Debug</buildArgs> <targets></targets> <timeout>15</timeout> <logger>ThoughtWorks.CruiseControl.MsBuild.XmlLogger,C:\Program Files\CruiseControl.NET\webdashboard\bin\ThoughtWorks.CruiseControl.MsBuild.dll</logger> </msbuild> </tasks> <!--Publishers will be done after the build has completed--> <publishers> <xmllogger> <logDir>C:\CI\MyProject\Logs</logDir> </xmllogger> </publishers> <modificationDelaySeconds>10</modificationDelaySeconds> </project> </cruisecontrol>
You will also want to install the CC Tray monitoring software on your pc:
It will allow you to keep an eye on the server from the comfort of your own pc.
That’s it we’re down!
So you want to backup your repository?
Unfortunately you cannot do a straight backup of your repository as someone may have a file open/locked which will cause problems on restore. So you should do a “hot copy” to prevent any locking issues when the actual backup is made. My “hot copy” is created using the following batch file:
REM Reset hot copy rmdir /S /Q c:\\svnrepos_hotcopy mkdir c:\\svnrepos_hotcopy REM Initiate SVN backup. Use svadmin hotcopy --help for details svnadmin hotcopy c:\\svnrepos c:\\svnrepos_hotcopy --clean-logs
I run this batch file daily as a scheduled task before the actual backup.
This batch file is a modification of the batch file described over at:
Its a good idea to keep your test cases seperate from your production code:
myproject lib/ workomatic.rb test/ test_workomatic.rb
When you have your project setup in this way add the following line to the top of your test cases:
$:.unshift File.join(File.dirname(__FILE__), "..", "lib") require workomatic.rb
Now when you run this test case the workomatic.rb file and all supporting files in the lib folder will be picked up.