class Natstrap::Utils

Public Class Methods

add_bootstrap(dir) click to toggle source
# File lib/natstrap/utils.rb, line 39
def self.add_bootstrap dir
  bootstrap = "http://twitter.github.com/bootstrap/assets/bootstrap.zip"
  open bootstrap do |data|
    Zip::Archive.open_buffer(data.read) do |ar|
      ar.each do |zf|
        if zf.directory?
          dirname = zf.name.sub('bootstrap', dir)
          FileUtils.mkdir_p dirname, :verbose => Natstrap::DEV
        else
          filename = zf.name.sub('bootstrap', dir)
          dirname = File.dirname(filename)
          FileUtils.mkdir_p dirname, :verbose => Natstrap::DEV

          open(filename, 'wb') do |f|
            f << zf.read
          end
        end
      end
    end
  end
end
create_padrino(project_name) click to toggle source
# File lib/natstrap/utils.rb, line 19
def self.create_padrino project_name
  cmd = "padrino g project #{project_name} -i -e erb -d activerecord -s jquery -c sass -m rr -t minitest"
  Kernel.system cmd
end
extend_padrino(project_name) click to toggle source
# File lib/natstrap/utils.rb, line 24
def self.extend_padrino project_name
  Natstrap::Utils.write_template "Gemfile"

  Kernel.system "bundle update"

  Natstrap::Utils.write_template "config/database.rb", :name => project_name
  Natstrap::Utils.write_template "config/apps.rb", :name => project_name

  [
    "padrino g model Entry text:text"
  ].each {|cmd| Kernel.system cmd }

  Natstrap::Utils.write_template "Rakefile"
end
git_commit(msg) click to toggle source
# File lib/natstrap/utils.rb, line 78
def self.git_commit msg
  g = Git.open(FileUtils.pwd, :log => Logger.new(STDOUT))
  g.add('.')
  g.commit_all(msg)
end
git_init() click to toggle source
# File lib/natstrap/utils.rb, line 71
def self.git_init
  g = Git.init
  Natstrap::Utils.write_template "README.md"
  g.add('README.md')
  g.commit('init.')
end
reorganize_public() click to toggle source
# File lib/natstrap/utils.rb, line 61
def self.reorganize_public
  [
    ['images', 'img'],
    ['javascripts', 'js'],
    ['stylesheets', 'css'],
  ].each do |from, to|
    FileUtils.mv "public/#{from}", "public/#{to}", :verbose => Natstrap::DEV
  end
end
write_template(template, opts = {}) click to toggle source

Based off of github.com/wycats/thor/blob/master/lib/thor/actions/file_manipulation.rb#L103

# File lib/natstrap/utils.rb, line 5
def self.write_template template, opts = {}
  template_dir = File.join(File.dirname(__FILE__), "templates")

  source = File.join(template_dir, "#{template}.tt")

  namespace = OpenStruct.new(opts)
  context = namespace.instance_eval { binding }

  content = ERB.new(::File.binread(source), nil, '-', '@output_buffer').result(context)
  open(template, 'wb') do |f|
    f << content
  end
end