Class: Marv::Project::Create
- Inherits:
-
Object
- Object
- Marv::Project::Create
- Defined in:
- lib/marv/project/create.rb
Instance Method Summary collapse
-
#ask_author_details ⇒ Object
Ask author details.
-
#ask_builtin_project_layout ⇒ Object
Ask builtin project layout.
-
#ask_project_layout ⇒ Object
Ask project layout.
-
#config_template ⇒ Object
Project config template.
-
#create_config_file ⇒ Object
Create config file.
-
#create_project ⇒ Object
Create a new project.
-
#create_project_dirs ⇒ Object
Create project directories.
-
#initialize(task, dir) ⇒ Create
constructor
Initialize project creator.
-
#layout_path ⇒ Object
Choosen layout path.
-
#parse_layout_files ⇒ Object
Parse layout files in project dir.
-
#project_options ⇒ Object
Ask for project details.
-
#project_path ⇒ Object
Project path.
Constructor Details
Instance Method Details
#ask_author_details ⇒ Object
Ask author details
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/marv/project/create.rb', line 48 def = {} [:author] = @task.ask_input "Enter project author:", :default => @global.config[:author] [:author_uri] = @task.ask_input "Enter project author URI:", :default => @global.config[:author_uri] [:license_name] = @task.ask_input "Enter project license name:", :default => @global.config[:license_name] [:license_uri] = @task.ask_input "Enter project license URI:", :default => @global.config[:license_uri] return end |
#ask_builtin_project_layout ⇒ Object
Ask builtin project layout
78 79 80 81 82 83 84 85 |
# File 'lib/marv/project/create.rb', line 78 def ask_builtin_project_layout = {} [:local_layout] = false [:layout] = @task.ask_input "Which layout do you want to use?", :limited_to => ["theme", "plugin"], :default => "theme" return end |
#ask_project_layout ⇒ Object
Ask project layout
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/marv/project/create.rb', line 60 def ask_project_layout = {} if @global.layouts.empty? .merge!(ask_builtin_project_layout) else if @task.said_yes?("Do you want to use a local layout?") [:local_layout] = true [:layout] = @task.ask_input "Which layout do you want to use?", :limited_to => @global.layouts else .merge!(ask_builtin_project_layout) end end return end |
#config_template ⇒ Object
Project config template
99 100 101 |
# File 'lib/marv/project/create.rb', line 99 def config_template ::File.(::File.join(Marv.root, 'layouts', 'config', 'project.rb')) end |
#create_config_file ⇒ Object
Create config file
123 124 125 126 127 128 |
# 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 ⇒ Object
Create a new project
144 145 146 147 148 149 150 |
# 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 ⇒ Object
Create project directories
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# 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 ⇒ Object
Choosen layout path
88 89 90 91 92 93 94 95 96 |
# File 'lib/marv/project/create.rb', line 88 def layout_path layout = ::File.(::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 ⇒ Object
Parse layout files in project dir
131 132 133 134 135 136 137 138 139 140 141 |
# 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 ⇒ Object
Ask for project details
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/marv/project/create.rb', line 23 def # 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 = {} [:name] = @task.ask_input "Enter project name:", :default => @global.config.fetch(:name, @dir) [:uri] = @task.ask_input "Enter project URI:", :default => @global.config[:uri] [:version] = @task.ask_input "Enter project version:", :default => @global.config.fetch(:version, '0.1.0') [:description] = @task.ask_input "Enter project description:", :default => @global.config.fetch(:description, 'Created with Marv') .merge!() .merge!(ask_project_layout) return end |
#project_path ⇒ Object
Project path
18 19 20 |
# File 'lib/marv/project/create.rb', line 18 def project_path ::File.(@dir) end |