One of the most annoying things inside Sublime Text 2 is the sidebar. There are 2 things that bug me the most.

1) When you create a new file, it doesn’t ask you the file name. It simple creates a file and then you have to save to give it a name.
2) You can’t duplicate a file.

Both of these problems are solved by using the SideBarEnhancements package by titoBouzout. It’s available for install using Package Control.

SideBarEnhancements Features

There are a few features that SideBarEnhancements gives you.

New File Creation

When you create a new file, it will immediately ask you for a file name. And don’t worry, if you want to just create a new file without saving, Cmd+N still works fine.

New File in Current Directory

When you’re working on a file and would like to create a new file in the same directory, just hit Ctrl+T. Very nice!

Duplicate Files & Folders

You can now duplicate a file or an entire folder simply by right clicking on a item in the sidebar and clicking Duplicate.

Copy Content as ‘data:uri base64′

Embedding images into your CSS saves http requests, which can make your app/site feel much faster, though it might have a larger css file. The problem I had was not having a convenient way to turn images into base64 data. Now I do, thanks to SideBarEnhancements. Just click on an image file, click “Copy as Text > Content as Data URI”. Now go to the css and paste. Done.

Other Features

  • Move files and folders
  • Open files with separate applications
  • Cut & Paste Files/Folders

{ 0 comments }

New Rails App Setup

by Melvin on February 1, 2012

I’m just using this post to note down what I usually do when setting up a new project, mostly as a reference page.

rails new appname
cd appname
git init .
rm public/index.html
rm app/assets/images/rails.png
git add .
git commit -m "Generated new app. Removed index.html and rails.png"
lime .

‘lime .’ opens up the project inside Sublime Text 2.

Add the following to Gemfile:

gem 'haml'
# gem 'devise'
# gem "cancan"
# gem 'stripe'
# gem 'launchy'
# gem 'carrierwave'
# gem 'rmagick'

gem 'rspec-rails'

group :test do
  gem "factory_girl_rails"
  gem "capybara"
  gem "capybara-webkit"
  gem "guard-rspec"
  gem 'growl'
  gem "ruby_gntp"
  gem 'database_cleaner'
  gem 'shoulda-matchers'
  gem 'shoulda-context'
end

group :production do
  gem 'pg'
end

You’ll notice a number of the gems above are commented out. That’s because they are gems I use frequently but I don’t want to add them at the beginning of the project. Also, I add the pg because most of my apps are deployed on Heroku and POSTgres is the database of choice on Heroku.

Next I run:

bundle install
rails g rspec:install
guard init rspec
mkdir spec/support spec/requests spec/models
rm -rf test

Next, I open up spec/spec_helper.rb and make it match the following:

ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rspec'
Capybara.javascript_driver = :webkit

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

RSpec.configure do |config|
  config.include Factory::Syntax::Methods
  config.mock_with :rspec
  config.infer_base_class_for_anonymous_controllers = false
  config.use_transactional_fixtures = false

  config.before(:suite) do
    DatabaseCleaner.strategy = :truncation
  end 

  config.before(:each) do
    DatabaseCleaner.start
  end

  config.after(:each) do
    DatabaseCleaner.clean
  end
end

After this, I create /spec/factories.rb file with this:

FactoryGirl.define do
#   sequence :email do |n|
#     "email#{n}@example.com"
#   end

#   factory :user do
#     email { Factory.next(:email) }
#     password "password"
#     password_confirmation "password"
#     association :account
#   end
end

It’s mostly commented out to give me a quick example so I can remember the syntax easily. At this point I commit the changes:

git add .
git commit -m "Added factory_girl_rails, capybara, capybara-webkit, guard-rspec, growl_notify, database_cleaner, shoulda-matchers, shoulda-context and haml gems. Generated rspec setup files, added a factories.rb and updated spec_helper with capybara and databaase_cleaner settings."

{ 0 comments }

Using Helpers Inside Controllers

January 2, 2012

Helpers are view related code. They don’t really belong inside a controller. That’s why by default, Rails doesn’t allow you to utilize it inside controllers. It does however give you the option do so if you want to using an object it calls view_context. Here’s how it might work: flash[:notice] = “Blah blah blah #{ view_context.link_to(“sign [...]

Read the full article →

Eliminating Whitespace In Haml

December 29, 2011

HTML is a very forgiving language. Extra whitespace almost never matters. However, there are a few small cases where a single space can make a difference and it isn’t obvious how you can fix that in HAML. For example, let’s say you write the following code: = link_to “please register”, new_account_path = “.” This will [...]

Read the full article →

How to Set Up Postgres SQL with OSX Lion

December 22, 2011

It’s generally a good idea to keep your development environment close to what your production environment will be. One of the best ways to deploy a Rails app without dealing with much of the server mumbo jumbo is to use Heroku.com, which gives us a pretty straight forward ‘git push’ approach to deploying. Heroku uses [...]

Read the full article →

Super Ruby on Rails

November 26, 2011

I’ve seen the keyword super used in Rails and Ruby methods used a number of different places… but I never really understand what it did… until today, I decided to dig a bit and get a better grasp of it. As it turns out, super is a clever little way of calling the method you’re [...]

Read the full article →

Introducing Rails Experiments

October 11, 2011

I’ve found that the fastest way to building something complex is to build it in parts separately. This allows you to test, find bugs and refactor quickly. Rails Experiments is going to be an outlet for sharing and recording how I solve problems while building Ruby on Rails applications. Rant, troll, provide helpful advice, offer [...]

Read the full article →