Copying Text from Notepad++ to Microsoft Word

In the middle of doing up some documentation I realised that the formatting and colors aren’t kept when you copy and paste from Notepad++ to Microsoft Word. Luckily Google was able to help out by showing me default plugin that lets you keep all the syntax highlighting etc.

1: Hightlight any of the text you want copied
2: From the menu select Plugins > NppExport > Copy all formats to clipboard
3: Paste into Microsoft Word
Highlight code
Highlight code
Select NppExport
Select NppExport
Paste in Word
Paste in Word

And that’s it – all done!

Truncating a String within a View – Ruby on Rails

Another quick post, just on how to truncate a string within a view. I used the following in order to ensure that my order_item title is never longer than 100 characters:

Title:  100, :seperator => ' ...') %>

 

This will output the title, if it’s longer than 100 characters the string will be shortened to 100 characters (minus the separator’s length). The neat thing about truncate is all the separator functionality is built in – you don’t have to throw any if/else logic in to check whether it’s required or not.

Output:

#Less than 100 characters
Title: lentesque porttitor

#More than 100 characters
Title: lentesque porttitor, velit vel ullamcorper pharetra, augue erat pharetra risus, quis bibendum fel…

Good Luck!

Adding a Link Within a Flash Notice/Message – Ruby on Rails

I came across an instance where I needed to add a link to flash notice tonight. Manually creating a hyperlink seems to work fine, however I was chasing a rubyish way of doing things:

flash[:notice] = "Order created - Click here to pay for it!"

 

Luckily a quick Google revealed the answer:

flash[:notice] = "Order created - Click here to pay for it!".html_safe

 

If you’re using rails 3 make sure you throw in the .html_safe or your link will be appear as plain text. Just a quick screenshot of the end result below:

Anyway, that’s all. Good Luck!