Class: Pixii
- Inherits:
-
Object
- Object
- Pixii
- Defined in:
- lib/pixii.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#opts ⇒ Object
Returns the value of attribute opts.
-
#steps ⇒ Object
Returns the value of attribute steps.
Class Method Summary collapse
Instance Method Summary collapse
- #clone(src, dest) ⇒ Object
- #dir(*dirs) ⇒ Object
-
#initialize(name, options) ⇒ Pixii
constructor
A new instance of Pixii.
-
#inside(dir, *file) ⇒ Object
private.
- #magic! ⇒ Object
- #make_dest ⇒ Object
- #normalize_opts! ⇒ Object
- #step(msg = nil, &blk) ⇒ Object
-
#template(src_tmpl, dest, env = {}) ⇒ Object
funkytown.
Constructor Details
#initialize(name, options) ⇒ Pixii
Returns a new instance of Pixii.
38 39 40 |
# File 'lib/pixii.rb', line 38 def initialize(name, ) self.name, self.opts, self.steps = name, self.class.defaults.merge(), [] end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
24 25 26 |
# File 'lib/pixii.rb', line 24 def name @name end |
#opts ⇒ Object
Returns the value of attribute opts.
23 24 25 |
# File 'lib/pixii.rb', line 23 def opts @opts end |
#steps ⇒ Object
Returns the value of attribute steps.
24 25 26 |
# File 'lib/pixii.rb', line 24 def steps @steps end |
Class Method Details
.called(name, options = {}) {|g, g.opts| ... } ⇒ Object
32 33 34 35 36 |
# File 'lib/pixii.rb', line 32 def self.called(name, ={}) g = new(name, ) g.normalize_opts! yield g, g.opts end |
.defaults ⇒ Object
26 27 28 |
# File 'lib/pixii.rb', line 26 def self.defaults @@defaults ||= {:project => ARGV.first} end |
.defaults=(hsh) ⇒ Object
30 |
# File 'lib/pixii.rb', line 30 def self.defaults=(hsh); @@defaults = hsh; end |
Instance Method Details
#clone(src, dest) ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/pixii.rb', line 65 def clone(src, dest) step do src = inside(:templates, src) if URI::parse(src).scheme.nil? open(src) do |sf| File.open(inside(:dest, dest), 'wb') do |f| f.write(sf.read) end # down end # down end # to end |
#dir(*dirs) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/pixii.rb', line 57 def dir(*dirs) dirs.each do |d| step do FileUtils.mkdir_p inside(:dest, d) end end end |
#inside(dir, *file) ⇒ Object
private
98 99 100 |
# File 'lib/pixii.rb', line 98 def inside(dir, *file) File.join(opts.send("#{dir}_dir"), *file) end |
#magic! ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/pixii.rb', line 88 def magic! make_dest steps.each do |step| puts step.first unless step.first.nil? step.last.call end end |
#make_dest ⇒ Object
102 103 104 |
# File 'lib/pixii.rb', line 102 def make_dest FileUtils.mkdir_p opts.dest_dir end |
#normalize_opts! ⇒ Object
46 47 48 49 50 51 |
# File 'lib/pixii.rb', line 46 def normalize_opts! # TODO fix caller[1] hack opts.src_dir ||= File.(File.dirname(caller[1].split(':').first)) opts.templates_dir = opts.templates || inside(:src, '..', 'templates') opts.dest_dir ||= File.(File.join(Dir.pwd, opts.project)) end |
#step(msg = nil, &blk) ⇒ Object
53 54 55 |
# File 'lib/pixii.rb', line 53 def step(msg=nil, &blk) steps << [msg, blk] end |
#template(src_tmpl, dest, env = {}) ⇒ Object
funkytown
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/pixii.rb', line 76 def template(src_tmpl, dest, env={}) step do src_tmpl = inside(:templates, src_tmpl) tmpl = File.open(src_tmpl){|f| f.read } env = env.merge!(opts).to_mash File.open(inside(:dest, dest), 'w') do |f| f.write(ERB.new(tmpl).result(env.binding)) end end end |