class Genit::ProjectCreator

Create a skeleton project.

Public Class Methods

new(name, empty, haml) click to toggle source

Sole constructor.

name - The String name of the future project folder. empty - A Boolean telling if we produce a smoke test or not. haml - A Boolean telling if we want project’s files in haml or

not.
# File lib/genit/project/project_creator.rb, line 16
def initialize name, empty, haml
  @project_name = name
  @empty = empty
  @haml = haml
end

Private Class Methods

append_last_part(dest) click to toggle source

TODO document

# File lib/genit/project/project_creator.rb, line 184
def self.append_last_part dest
  src = File.join $GENIT_PATH, 'data', 'templates', 'main.html'
  content = File.open(src, "r").read
  File.open(dest, "a") {|out| out.puts content }
end

Public Instance Methods

create() click to toggle source

Public: Create the structure of the project, that is many files and folders.

Returns nothing.

# File lib/genit/project/project_creator.rb, line 26
def create
  begin
    create_the_project
  rescue SystemCallError
    puts "Cannot create project..."
  end
end

Private Instance Methods

copy_files(a_array) click to toggle source

Copy files to project.

a_array - An Array of String “subfolder/file” names

Example

copy_files ['templates/main.html', 'pages/index.html']

Returns nothing.

# File lib/genit/project/project_creator.rb, line 98
def copy_files a_array
  a_array.each do |file|
    src = File.join $GENIT_PATH, 'data', file
    dest =  File.join @project_name, file
    FileUtils.cp src, dest
  end
end
copy_first_part(dest) click to toggle source

TODO document

# File lib/genit/project/project_creator.rb, line 178
def copy_first_part dest
  src = File.join $GENIT_PATH, 'data', 'templates', "html_5"
  FileUtils.cp src, dest
end
copy_index() click to toggle source

TODO document

# File lib/genit/project/project_creator.rb, line 107
def copy_index
  dest = index_destination
  src = index_source
  FileUtils.cp src, dest
end
copy_main_template() click to toggle source

TODO document

# File lib/genit/project/project_creator.rb, line 146
def copy_main_template
  if @haml
    copy_main_template_haml
  else
    copy_main_template_html
  end
end
copy_main_template_haml() click to toggle source
# File lib/genit/project/project_creator.rb, line 154
def copy_main_template_haml
  dest =  File.join @project_name, 'src/templates', 'main.haml'
  src = File.join $GENIT_PATH, 'data', 'templates', "html_5.haml"
  FileUtils.cp src, dest
end
copy_main_template_html() click to toggle source
# File lib/genit/project/project_creator.rb, line 160
def copy_main_template_html
  dest =  File.join @project_name, 'src/templates', 'main.html'
  copy_first_part dest
  ProjectCreator.append_last_part dest
end
copy_menu_template() click to toggle source
# File lib/genit/project/project_creator.rb, line 166
def copy_menu_template
  if @haml
    dest =  File.join @project_name, 'src/templates', 'menu.haml'
    src = File.join $GENIT_PATH, 'data', 'templates', 'menu.haml'
  else
    dest =  File.join @project_name, 'src/templates', 'menu.html'
    src = File.join $GENIT_PATH, 'data', 'templates', 'menu.html'
  end
  FileUtils.cp src, dest
end
copy_screen_css() click to toggle source

TODO document

# File lib/genit/project/project_creator.rb, line 135
def copy_screen_css
  dest =  File.join @project_name, 'styles/screen.css'
  if @empty
    FileUtils.touch dest
  else
    src = File.join $GENIT_PATH, 'data/styles/screen.css'
    FileUtils.cp src, dest
  end
end
copy_the_project_files() click to toggle source
# File lib/genit/project/project_creator.rb, line 65
def copy_the_project_files
  copy_main_template
  copy_menu_template
  copy_files ['styles/handheld.css', 'styles/print.css']
  copy_index
  copy_screen_css
end
create_subfolders(a_array) click to toggle source

Create some subfolders inside the project folder.

a_array - An Array of String subfolder names

Examples

create_subfolders ['styles', 'scripts']

create_subfolders ['styles/css/alsa', 'styles/css/yui',
                   'styles/css/images']

Returns nothing.

# File lib/genit/project/project_creator.rb, line 61
def create_subfolders a_array
  a_array.each {|dir| FileUtils.makedirs File.join(@project_name, dir) }
end
create_the_project() click to toggle source
# File lib/genit/project/project_creator.rb, line 36
def create_the_project
  create_the_project_folders
  copy_the_project_files
  create_the_project_config
end
create_the_project_config() click to toggle source
# File lib/genit/project/project_creator.rb, line 73
def create_the_project_config
  version =  File.read(File.join($GENIT_PATH, 'VERSION')).strip
  write_config version, '.genit'

  config_file = { :address => 'http://www.example.com',
                  :rss => true, 
                  :rss_title => 'RSS TITLE',
                  :rss_description => 'RSS DESCRIPTION'}.to_yaml
  write_config config_file, 'config'
end
create_the_project_folders() click to toggle source
# File lib/genit/project/project_creator.rb, line 42
def create_the_project_folders
  FileUtils.makedirs @project_name
  create_subfolders ['src', 'src/fragments', 'src/news', 'src/pages',
                     'scripts', 'styles', 'src/templates', 
                     'styles/images', 'public']
end
index_destination() click to toggle source
# File lib/genit/project/project_creator.rb, line 113
def index_destination
  if @haml
    File.join @project_name, 'src/pages/index.haml'
  else
    File.join @project_name, 'src/pages/index.html'
  end
end
index_source() click to toggle source
# File lib/genit/project/project_creator.rb, line 121
def index_source
  if @empty
    src = File.join $GENIT_PATH, 'data/pages/index2.'
  else
    src = File.join $GENIT_PATH, 'data/pages/index.'
  end
  if @haml
    "#{src}haml"
  else
    "#{src}html"
  end
end
write_config(content, filename) click to toggle source
# File lib/genit/project/project_creator.rb, line 84
def write_config content, filename
  dest =  File.join @project_name, filename
  File.open(dest, "w") {|out| out.puts content }
end