chrislloyd-pixii 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,93 @@
1
+ ![Pixie](http://github.com/chrislloyd/pixii/raw/master/logo.png)
2
+
3
+ <small>A mini library for generating files. By [Chris](http://chrislloyd.com.au).</small>
4
+
5
+
6
+ If you've ever had to use [Rubigen](http://github.com/drnic/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.
7
+
8
+ ## Install
9
+
10
+ sudo gem install pixii
11
+
12
+ or
13
+
14
+ rip install pixii
15
+
16
+ ## Usage
17
+
18
+ The best way to learn how to use Pixii is to have a look at [tyrone's Pixii file](http://github.com/chrislloyd/tyrone/tree/master/bin/tyrone):
19
+
20
+ Pixii.called(:tyrone) do |make, opts|
21
+ make.dir 'features', 'mockups', 'public', 'public/js', 'public/images', 'public/css'
22
+
23
+ make.clone 'http://github.com/toolmantim/states.js/raw/master/states.js', 'public/js/states.js'
24
+
25
+ make.template 'sinatra.rb.erb', "#{opts.project}.rb"
26
+
27
+ make.magic!
28
+ end
29
+
30
+ Lets start off with the first line:
31
+
32
+ Pixii.called(:tyrone) do |make, opts|
33
+
34
+ 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.
35
+
36
+ Pixii.called(:tyrone, :project => 'my_project_name', :foo => 'bar') do |make, opts|
37
+
38
+ To access `:foo` in the potion you can just call `opts.foo`.
39
+
40
+ 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.
41
+
42
+ Lastly `template` processes a template. By default it looks for templates in `../templates` but you can change this in the options:
43
+
44
+ Pixii.called(:tyrone, :templates => '../my_other_template_place') do |make, opts|
45
+
46
+ 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:
47
+
48
+ make.template 'sinatra.rb.erb', "#{opts.project}.rb", :foo => 'bar'
49
+
50
+ and in `sinatra.rb.erb`:
51
+
52
+ #!/usr/bin/env ruby
53
+
54
+ # <%= project.upcase %>
55
+ puts 'Lets get a drink at the <%= foo %>'
56
+
57
+ The last line, `make.magic!` just carries out the incantation that we've defined above.
58
+
59
+
60
+ ## Custom Spells
61
+
62
+ 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?
63
+
64
+ class Pixii
65
+ def git_clone(repo, dest)
66
+ step "Cloning #{repo}..." do
67
+ `git clone #{repo} #{dest}`
68
+ end
69
+ end
70
+ end
71
+
72
+ 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.
73
+
74
+ You can now use this in your potion:
75
+
76
+ make.git_clone 'git://github.com/chrislloyd/gravtastic.git', 'vendor/gems/gravtastic'
77
+
78
+
79
+ ## Contributing
80
+
81
+ Fork the project, submit a pull request and I'll get to it straight away. Or you can just checkout the source by running:
82
+
83
+ git clone git://github.com/chrislloyd/pixii.git
84
+
85
+ ## License
86
+
87
+ Copyright (c) 2009 Chris Lloyd.
88
+
89
+ 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:
90
+
91
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
92
+
93
+ 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.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'mg'
2
+ require 'spec/rake/spectask'
3
+
4
+ MG.new('pixii.gemspec')
5
+
6
+ Spec::Rake::SpecTask.new('spec') do |t|
7
+ t.spec_opts = ['--color']
8
+ t.spec_files = FileList['spec/**/*.rb']
9
+ end
data/deps.rip ADDED
@@ -0,0 +1 @@
1
+ git://github.com/mbleigh/mash.git bb4ed9b62df3a0130e5417a50e545d8c1e0e0014
data/lib/pixii.rb ADDED
@@ -0,0 +1,91 @@
1
+ require 'open-uri'
2
+ require 'fileutils'
3
+ require 'erb'
4
+ require 'uri'
5
+ require 'rubygems'
6
+
7
+ gem 'mash', '>= 0.0.3'
8
+ require 'mash'
9
+
10
+ class Mash
11
+ public :binding
12
+ end
13
+
14
+ class Pixii
15
+
16
+ attr_reader :opts
17
+ attr_accessor :name, :steps
18
+
19
+ def self.called(name, options={:project => ARGV.first, :templates => '../templates'})
20
+ g = new(name, options)
21
+ g.normalize_opts!
22
+ yield g, g.opts
23
+ end
24
+
25
+ def initialize(name, options)
26
+ self.name, self.opts, self.steps = name, options, []
27
+ end
28
+
29
+ def opts=(options)
30
+ @opts = Mash.new(options)
31
+ end
32
+
33
+ def normalize_opts!
34
+ # TODO: fix caller[1] hack
35
+ opts.src_dir = File.expand_path(File.dirname(caller[1].split(':').first))
36
+ opts.template_dir = File.join(opts.src_dir, opts.templates)
37
+ opts.dest_dir = File.expand_path(File.join(Dir.pwd, opts.project))
38
+ end
39
+
40
+ def step(msg=nil, &blk)
41
+ steps << [msg, blk]
42
+ end
43
+
44
+ def dir(*dirs)
45
+ dirs.each do |d|
46
+ step do
47
+ FileUtils.mkdir_p(d)
48
+ end
49
+ end
50
+ end
51
+
52
+ def clone(src, dest)
53
+ step do
54
+ src = File.join(opts.src_dir, src) if URI::parse(src).scheme.nil?
55
+ open(src) do |sf|
56
+ File.open(dest,'wb') do |f|
57
+ f.write(sf.read)
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ def template(src_tmpl, dest, env={})
64
+ step do
65
+ src_tmpl = File.join(opts.template_dir, src_tmpl)
66
+ tmpl = File.open(src_tmpl){|f| f.read }
67
+
68
+ env = env.merge!(opts).to_mash
69
+ File.open(dest,'w') do |f|
70
+ f.write(ERB.new(tmpl).result(env.binding))
71
+ end
72
+ end
73
+ end
74
+
75
+ def magic!
76
+ make_and_change_to_dest! do
77
+ steps.each do |step|
78
+ puts step.first unless step.first.nil?
79
+ step.last.call
80
+ end
81
+ end
82
+ end
83
+
84
+ # private
85
+
86
+ def make_and_change_to_dest!(&blk)
87
+ FileUtils.mkdir_p opts.dest_dir
88
+ Dir.chdir(opts.dest_dir, &blk)
89
+ end
90
+
91
+ end
@@ -0,0 +1,31 @@
1
+ require File.join(File.dirname(__FILE__),'spec_helper')
2
+
3
+ describe Pixii do
4
+
5
+ def in_neverland(opts={}, &blk)
6
+ Pixii.called(:hook, {:project => 'pan'}.merge(opts), &blk)
7
+ end
8
+
9
+
10
+ it 'takes options' do
11
+ in_neverland(:foo => 'bar') do |m, o|
12
+ o.foo.should == 'bar'
13
+ end
14
+ end
15
+
16
+ it 'creates directories' do
17
+ dirs = %w(foo bar)
18
+
19
+ in_neverland do |m,o|
20
+ m.dir *dirs
21
+ m.magic!
22
+ end
23
+
24
+ dirs.each{|dir| File.directory?("/pan/#{dir}").should be_true}
25
+ end
26
+
27
+ after(:all) do
28
+ FakeFS::FileSystem.clear
29
+ end
30
+
31
+ end
@@ -0,0 +1,4 @@
1
+ $TESTING=true
2
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
3
+ require 'pixii'
4
+ require 'fakefs'
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chrislloyd-pixii
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Lloyd
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-16 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mash
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.3
24
+ version:
25
+ description:
26
+ email: christopher.lloyd@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - deps.rip
35
+ - Rakefile
36
+ - README.md
37
+ - lib/pixii.rb
38
+ - spec/pixii_spec.rb
39
+ - spec/spec_helper.rb
40
+ has_rdoc: false
41
+ homepage: http://github.com/chrislloyd/pixii
42
+ licenses:
43
+ post_install_message:
44
+ rdoc_options: []
45
+
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ requirements: []
61
+
62
+ rubyforge_project: pixii
63
+ rubygems_version: 1.3.5
64
+ signing_key:
65
+ specification_version: 2
66
+ summary: I believe in you, Peter Pan.
67
+ test_files: []
68
+