Pixie

A mini library for generating files. By Chris.

If you've ever had to use Rubigen, then Pixii is for you. Rubigen is waay too complex for what is a really simple problem. Pixii just provides the basics of what you need to generate files and folders.

Install

sudo gem install pixii

or

rip install pixii

Usage

The best way to learn how to use Pixii is to have a look at tyrone's Pixii file:

Pixii.called(:tyrone) do |make, opts|
  make.dir 'features', 'mockups', 'public', 'public/js', 'public/images', 'public/css'

  make.clone 'http://github.com/toolmantim/states.js/raw/master/states.js', 'public/js/states.js'

  make.template 'sinatra.rb.erb', "#{opts.project}.rb"

  make.magic!
end

Lets start off with the first line:

Pixii.called(:tyrone) do |make, opts|

This conjures the Pixii potion. By default the name of a new project is taken form ARGV.first but you can change this by passing in an options hash.

Pixii.called(:tyrone, :project => 'my_project_name', :foo => 'bar') do |make, opts|

To access :foo in the potion you can just call opts.foo.

Next up are the three basic spells, dir, clone and template. dir just makes the directories in the project. clone copies a file from one place to another. You can specify any type of path, including ones on the internet.

Lastly template processes a template. By default it looks for templates in ../templates but you can change this in the options:

Pixii.called(:tyrone, :templates => '../my_other_template_place') do |make, opts|

Pixii only supports ERB processing. In your template you have access to all same variables in opts, plus any more you pass in. For example:

make.template 'sinatra.rb.erb', "#{opts.project}.rb", :foo => 'bar'

and in sinatra.rb.erb:

#!/usr/bin/env ruby

# <%= project.upcase %>
puts 'Lets get a drink at the <%= foo %>'

The last line, make.magic! just carries out the incantation that we've defined above.

Custom Spells

I understand that three spells may not be enough for the more advanced wizards out there so lets run through making our own Pixii spell. How about a spell which clones a Git repository?

class Pixii
  def git_clone(repo, dest)
    step "Cloning #{repo}..." do
      `git clone #{repo} #{inside(:dest,dest)}`
    end
  end
end

Just place that at the top of your script. Pretty simple! The only new thing that you have to get is the step method. That basically just defines a step to run. The "Cloning ..." passed in at the start is just a string describing what you are doing. You don't have to pass anything there and step do is perfectly acceptable.

The inside(:dest, ...) method basically scopes a path to the destination directory. inside can take :dest, :templates or :src.

You can now use git_clone in your potion:

make.git_clone 'git://github.com/chrislloyd/gravtastic.git', 'vendor/gems/gravtastic'

Contributing

Fork the project, submit a pull request and I'll get to it straight away. Or you can just checkout the source by running:

git clone git://github.com/chrislloyd/pixii.git

License

Copyright (c) 2009 Chris Lloyd.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.