class Marv::Project::Create
Public Class Methods
new(task, dir)
click to toggle source
Initialize project creator
# File lib/marv/project/create.rb, line 6 def initialize(task, dir) @task = task @dir = dir @path = project_path @global = Marv::Global.new(task) @options = project_options @layout = layout_path create_project end
Public Instance Methods
ask_builtin_project_layout()
click to toggle source
Ask builtin project layout
# File lib/marv/project/create.rb, line 78 def ask_builtin_project_layout options = {} options[:local_layout] = false options[:layout] = @task.ask_input "Which layout do you want to use?", :limited_to => ["theme", "plugin"], :default => "theme" return options end
ask_project_layout()
click to toggle source
Ask project layout
# File lib/marv/project/create.rb, line 60 def ask_project_layout options = {} if @global.layouts.empty? options.merge!(ask_builtin_project_layout) else if @task.said_yes?("Do you want to use a local layout?") options[:local_layout] = true options[:layout] = @task.ask_input "Which layout do you want to use?", :limited_to => @global.layouts else options.merge!(ask_builtin_project_layout) end end return options end
config_template()
click to toggle source
Project
config template
# File lib/marv/project/create.rb, line 99 def config_template ::File.expand_path(::File.join(Marv.root, 'layouts', 'config', 'project.rb')) end
create_config_file()
click to toggle source
Create
config file
# File lib/marv/project/create.rb, line 123 def create_config_file @project = Marv::Project::Project.new(@task, @path, @options) config_rb = ::File.join(@path, 'config.rb') @global.template config_template, config_rb, @project.context unless ::File.exists?(config_rb) end
create_project()
click to toggle source
Create
a new project
# File lib/marv/project/create.rb, line 144 def create_project @task.say_empty(2) create_project_dirs create_config_file parse_layout_files end
create_project_dirs()
click to toggle source
Create
project directories
# File lib/marv/project/create.rb, line 104 def create_project_dirs ::Dir.glob(::File.join(@layout, '**', '*')).each do |dir| if ::File.directory?(dir) # Get source and target files source_dir = dir.gsub(@layout, '') target_dir = ::File.join(@path, 'source', source_dir) @task.empty_directory target_dir unless ::File.directory?(target_dir) end end # Create .wacth dir @task.shell.mute do watch_dir = ::File.join(@path, '.watch', 'build') @task.empty_directory watch_dir unless ::File.directory?(watch_dir) end end
layout_path()
click to toggle source
Choosen layout path
# File lib/marv/project/create.rb, line 88 def layout_path layout = ::File.expand_path(::File.join(Marv.root, 'layouts', @options[:layout])) if @options[:local_layout] layout = ::File.join(@global.layouts_path, @options[:layout]) end return layout end
parse_layout_files()
click to toggle source
Parse layout files in project dir
# File lib/marv/project/create.rb, line 131 def parse_layout_files ::Dir.glob(::File.join(@layout, '**', '*')).each do |file| unless ::File.directory?(file) # Get source and target files source_file = file.gsub(@layout, '') target_file = ::File.join(@path, 'source', source_file) # Parse template file @global.template file, target_file, @project.context end end end
project_options()
click to toggle source
Ask for project details
# File lib/marv/project/create.rb, line 23 def project_options # Check if project exists and abort if ::File.directory?(@path) @task.say_error "Project already exists", nil, false abort end @task.say_info "This will create a new project." @task.say_warning "Please enter project details below." # Get project options options = {} options[:name] = @task.ask_input "Enter project name:", :default => @global.config.fetch(:name, @dir) options[:uri] = @task.ask_input "Enter project URI:", :default => @global.config[:uri] options[:version] = @task.ask_input "Enter project version:", :default => @global.config.fetch(:version, '0.1.0') options[:description] = @task.ask_input "Enter project description:", :default => @global.config.fetch(:description, 'Created with Marv') options.merge!(ask_author_details) options.merge!(ask_project_layout) return options end
project_path()
click to toggle source
Project
path
# File lib/marv/project/create.rb, line 18 def project_path ::File.expand_path(@dir) end