Class: Natstrap::Utils

Inherits:
Object
  • Object
show all
Defined in:
lib/natstrap/utils.rb

Class Method Summary collapse

Class Method Details

.add_bootstrap(dir) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# 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) ⇒ Object



19
20
21
22
# 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) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 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) ⇒ Object



78
79
80
81
82
# 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_initObject



71
72
73
74
75
76
# 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_publicObject



61
62
63
64
65
66
67
68
69
# 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 = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# 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