Class: Bones::Initializer
Class Method Summary collapse
- .ensure_directory(path) ⇒ Object
- .ensure_file(path, &block) ⇒ Object
- .relative_path(path) ⇒ Object
- .run(root = nil) ⇒ Object
Class Method Details
.ensure_directory(path) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/bones/initializer.rb', line 13 def self.ensure_directory(path) return nil if File.directory?(path) puts "** Directory #{relative_path(path)}" FileUtils.mkdir_p(path) return true end |
.ensure_file(path, &block) ⇒ Object
7 8 9 10 11 |
# File 'lib/bones/initializer.rb', line 7 def self.ensure_file(path, &block) return if File.exist?(path) puts "** Writing #{relative_path(path)}" File.open(path, 'w', &block) end |
.relative_path(path) ⇒ Object
3 4 5 |
# File 'lib/bones/initializer.rb', line 3 def self.relative_path(path) path.gsub(Bones.root + '/', '') end |
.run(root = nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/bones/initializer.rb', line 20 def self.run(root=nil) Bones.root = root puts "** Initializing" puts "** Directory: #{Bones.root}" ensure_directory(Bones.root / 'public' / 'javascripts') ensure_directory(Bones.root / 'public' / 'stylesheets') pages_new = ensure_directory(Bones.root / 'pages') ensure_directory(Bones.root / 'layouts') ensure_directory(Bones.root / 'helpers') ensure_directory(Bones.root / 'tmp') if pages_new ensure_file(Bones.root / 'pages' / 'index.html.erb') do |f| f.write File.read(Bones.system_path / 'pages' / 'intro.html.erb') end end ensure_file(Bones.root / 'layouts' / 'application.html.erb') do |f| f.write File.read(Bones.system_path / 'layouts' / 'application.html.erb') end ensure_file(Bones.root / 'public' / 'stylesheets' / 'styles.css') ensure_file(Bones.root / 'helpers' / 'application_helper.rb') do |f| f.write File.read(Bones.system_path / 'helpers' / 'application_helper.rb') end ensure_file(Bones.root / 'Rakefile') do |f| f.write File.read(Bones.system_path / '../pushables/Rakefile') end ensure_file(Bones.root / 'boot.rb') do |f| f.write File.read(Bones.system_path / '../pushables/boot.rb') end ensure_file(Bones.root / 'config.ru') do |f| f.write File.read(Bones.system_path / '../pushables/config.ru') end end |