Class: Natstrap::Utils
- Inherits:
-
Object
- Object
- Natstrap::Utils
- Defined in:
- lib/natstrap/utils.rb
Class Method Summary collapse
- .add_bootstrap(dir) ⇒ Object
- .create_padrino(project_name) ⇒ Object
- .extend_padrino(project_name) ⇒ Object
- .git_commit(msg) ⇒ Object
- .git_init ⇒ Object
- .reorganize_public ⇒ Object
- .write_template(template, opts = {}) ⇒ Object
Class Method Details
.add_bootstrap(dir) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/natstrap/utils.rb', line 38 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 |
# 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 [ "padrino g model Entry text:text" ].each {|cmd| Kernel.system cmd } Natstrap::Utils.write_template "Rakefile" end |
.git_commit(msg) ⇒ Object
77 78 79 80 81 |
# File 'lib/natstrap/utils.rb', line 77 def self.git_commit msg g = Git.open(FileUtils.pwd, :log => Logger.new(STDOUT)) g.add('.') g.commit_all(msg) end |
.git_init ⇒ Object
70 71 72 73 74 75 |
# File 'lib/natstrap/utils.rb', line 70 def self.git_init g = Git.init Natstrap::Utils.write_template "README.md" g.add('README.md') g.commit('init.') end |
.reorganize_public ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/natstrap/utils.rb', line 60 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 |