marv 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. data/.document +5 -0
  2. data/CHANGELOG.md +13 -0
  3. data/Gemfile +8 -10
  4. data/Gemfile.lock +16 -43
  5. data/LICENSE +0 -24
  6. data/README.md +9 -10
  7. data/Rakefile +4 -20
  8. data/VERSION +1 -1
  9. data/bin/marv +1 -1
  10. data/layouts/config/global.rb +31 -0
  11. data/layouts/config/project.rb +27 -0
  12. data/layouts/config/{router.php.erb → router.php} +5 -1
  13. data/layouts/config/server.rb +12 -0
  14. data/layouts/config/{wp-config.php.erb → wp-config.php} +0 -0
  15. data/layouts/plugin/{images → assets/images}/screenshot.png +0 -0
  16. data/layouts/plugin/{javascripts → assets/javascripts}/admin.coffee +0 -0
  17. data/layouts/plugin/{javascripts → assets/javascripts}/admin.js +0 -0
  18. data/layouts/plugin/{javascripts → assets/javascripts}/plugin.coffee +0 -0
  19. data/layouts/plugin/assets/javascripts/plugin.js +1 -0
  20. data/layouts/plugin/{stylesheets → assets/stylesheets}/plugin.scss +0 -0
  21. data/layouts/plugin/functions/{plugin.php.erb → plugin.php} +8 -7
  22. data/layouts/theme/{images → assets/images}/screenshot.png +0 -0
  23. data/layouts/theme/{javascripts → assets/javascripts}/admin.coffee +0 -0
  24. data/layouts/theme/{javascripts → assets/javascripts}/admin.js +0 -0
  25. data/layouts/theme/{javascripts → assets/javascripts}/theme.coffee +0 -0
  26. data/layouts/theme/{javascripts → assets/javascripts}/theme.js +0 -0
  27. data/layouts/theme/assets/stylesheets/_header.scss +18 -0
  28. data/layouts/theme/{stylesheets/style.scss.erb → assets/stylesheets/style.scss} +0 -0
  29. data/layouts/theme/functions/{functions.php.erb → functions.php} +0 -0
  30. data/layouts/theme/includes/{filters-admin.php.erb → filters-admin.php} +0 -0
  31. data/layouts/theme/includes/{filters.php.erb → filters.php} +0 -0
  32. data/layouts/theme/includes/{helpers.php.erb → helpers.php} +0 -0
  33. data/layouts/theme/templates/{404.php.erb → pages/404.php} +0 -0
  34. data/layouts/theme/templates/{archive.php.erb → pages/archive.php} +0 -0
  35. data/layouts/theme/templates/{author.php.erb → pages/author.php} +0 -0
  36. data/layouts/theme/templates/{search.php.erb → pages/search.php} +0 -0
  37. data/layouts/theme/templates/partials/{comments.php.erb → comments.php} +0 -0
  38. data/layouts/theme/templates/partials/{content-none.php.erb → content-none.php} +0 -0
  39. data/layouts/theme/templates/partials/{content.php.erb → content.php} +0 -0
  40. data/layouts/theme/templates/partials/{searchform.php.erb → searchform.php} +0 -0
  41. data/lib/marv.rb +8 -8
  42. data/lib/marv/cli.rb +15 -192
  43. data/lib/marv/cli/project.rb +57 -0
  44. data/lib/marv/cli/server.rb +65 -0
  45. data/lib/marv/global.rb +285 -0
  46. data/lib/marv/project/actions.rb +144 -0
  47. data/lib/marv/project/builder.rb +61 -0
  48. data/lib/marv/project/builder/assets.rb +112 -0
  49. data/lib/marv/{engines.rb → project/builder/engines.rb} +3 -1
  50. data/lib/marv/project/builder/functions.rb +112 -0
  51. data/lib/marv/project/builder/templates.rb +37 -0
  52. data/lib/marv/project/create.rb +139 -0
  53. data/lib/marv/project/guard.rb +83 -0
  54. data/lib/marv/project/guard/assets.rb +37 -0
  55. data/lib/{guard/marv → marv/project/guard}/config.rb +5 -9
  56. data/lib/marv/project/guard/functions.rb +44 -0
  57. data/lib/marv/project/guard/templates.rb +35 -0
  58. data/lib/marv/project/project.rb +149 -0
  59. data/lib/marv/server/actions.rb +79 -0
  60. data/lib/marv/server/create.rb +100 -0
  61. data/lib/marv/server/server.rb +201 -0
  62. data/marv.gemspec +69 -71
  63. metadata +82 -107
  64. data/.rspec +0 -1
  65. data/features/step_definitions/marv_steps.rb +0 -38
  66. data/features/support/env.rb +0 -17
  67. data/layouts/config/project-config.rb +0 -17
  68. data/layouts/plugin/javascripts/plugin.js +0 -1
  69. data/layouts/theme/stylesheets/_header.scss.erb +0 -18
  70. data/lib/guard/marv/assets.rb +0 -33
  71. data/lib/guard/marv/folders.rb +0 -33
  72. data/lib/guard/marv/functions.rb +0 -34
  73. data/lib/guard/marv/templates.rb +0 -33
  74. data/lib/marv/builder.rb +0 -355
  75. data/lib/marv/error.rb +0 -8
  76. data/lib/marv/generator.rb +0 -140
  77. data/lib/marv/guard.rb +0 -68
  78. data/lib/marv/project.rb +0 -134
  79. data/lib/marv/server.rb +0 -284
  80. data/spec/lib/marv/project_spec.rb +0 -34
  81. data/spec/spec_helper.rb +0 -12
@@ -0,0 +1,18 @@
1
+ /*!
2
+ * Theme Name: <%= project_config[:name] %>
3
+ * Theme URI: <%= project_config[:uri] %>
4
+ * Author: <%= project_config[:author] %>
5
+ * Author URI: <%= project_config[:author_uri] %>
6
+ * Description: <%= project_config[:description] %>
7
+ * Version: <%= project_config[:version] %>
8
+ * License: <%= project_config[:license_name] %>
9
+ * License URI: <%= project_config[:license_uri] %>
10
+ * Tags: <%= project_config[:tags] %>
11
+ <% if project_config[:template] -%>
12
+ * Template: <%= project_config[:template] %>
13
+ <% end -%>
14
+ <%- unless project_config[:comments].nil? || project_config[:comments].empty? -%>
15
+ *
16
+ * Comments: <%= project_config[:comments] %>
17
+ <%- end -%>
18
+ */
data/lib/marv.rb CHANGED
@@ -1,11 +1,11 @@
1
- require 'marv/error'
1
+ require 'thor'
2
+ require 'marv/cli'
3
+ require 'marv/global'
2
4
 
3
5
  module Marv
4
- ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
5
- autoload :Guard, 'marv/guard'
6
- autoload :CLI, 'marv/cli'
7
- autoload :Project, 'marv/project'
8
- autoload :Builder, 'marv/builder'
9
- autoload :Generator, 'marv/generator'
10
- autoload :Server, 'marv/server'
6
+
7
+ def self.root
8
+ ::File.expand_path(::File.join(::File.dirname(__FILE__), '..'))
9
+ end
10
+
11
11
  end
data/lib/marv/cli.rb CHANGED
@@ -1,202 +1,25 @@
1
- require 'thor'
2
- require 'guard/marv/assets'
3
- require 'guard/marv/config'
4
- require 'guard/marv/templates'
5
- require 'guard/marv/functions'
6
- require 'guard/marv/folders'
1
+ require 'marv/cli/project'
2
+ require 'marv/cli/server'
7
3
 
8
4
  module Marv
9
- class CLI < Thor
5
+ module CLI
6
+ class Commands < Project
10
7
 
11
- include Thor::Actions
12
-
13
- def self.source_root
14
- File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'layouts'))
15
- end
16
-
17
- desc "create DIRECTORY", "Creates a Marv project into specified directory"
18
- long_desc "Creates a new project. Use the layout option to choose a scaffold"
19
- method_option :layout, :type => :string, :default => 'theme', :enum => %w{theme plugin}, :desc => "Scaffold layout for theme or plugin"
20
- method_option :local, :type => :boolean, :force => false, :desc => "Use custom layout from ~/.marv/layouts folder"
21
- def create(dir)
22
- theme = {}
23
- theme[:name] = dir
24
-
25
- project = Marv::Project.create(dir, theme, self, options[:layout], options[:local])
26
- end
27
-
28
- desc "link SERVER or DIRECTORY", "Create a symbolic link to the compilation directory"
29
- long_desc "This command will symlink the compiled version of the project to the specified server or WordPress install path."+
30
- "If you don't provide a directory or a server name, the symlink will be created in Marv global themes or plugins folder."
31
- method_option :folder, :type => :string, :enum => %w{themes plugins}, :required => true, :desc => "Link Marv project in themes or plugins folfer"
32
- def link(dir=nil)
33
- project = Marv::Project.new('.', self)
34
-
35
- unless File.directory?(project.build_path)
36
- FileUtils.mkdir_p project.build_path
37
- end
38
-
39
- if dir.nil?
40
- link_project_globaly(options, project)
41
- else
42
- wp_path = File.join(dir, 'wp-content', options[:folder])
43
- server_path = File.join(ENV['HOME'], '.marv', 'servers', dir, 'wp-content', options[:folder])
44
- link_project(wp_path, server_path, project)
45
- end
46
- end
47
-
48
- desc "watch", "Start watch process"
49
- long_desc "Watches the source directory in your Marv project for changes, and reflects those changes in a compile folder"
50
- method_option :config, :type => :string, :desc => "Name of alternate config file"
51
- def watch
52
- project = Marv::Project.new('.', self, nil, options[:config])
53
-
54
- # Empty the build directory before starting up to clean out old files
55
- FileUtils.rm_rf project.build_path
56
- FileUtils.mkdir_p project.build_path
57
-
58
- Marv::Guard.start(project, self)
59
- end
60
-
61
- desc "build DIRECTORY", "Build your theme into specified directory"
62
- method_option :config, :type => :string, :desc => "Name of alternate config file"
63
- def build(dir='build')
64
- project = Marv::Project.new('.', self, nil, options[:config])
65
-
66
- builder = Builder.new(project)
67
- builder.build
68
-
69
- Dir.glob(File.join(dir, '**', '*')).each do |file|
70
- shell.mute { remove_file(file) }
71
- end
72
-
73
- directory(project.build_path, dir)
74
- end
75
-
76
- desc "package FILENAME", "Compile and zip your Marv project to FILENAME.zip"
77
- method_option :config, :type => :string, :desc => "Name of alternate config file"
78
- def package(filename=nil)
79
- project = Marv::Project.new('.', self, nil, options[:config])
80
-
81
- builder = Builder.new(project)
82
- builder.build
83
- builder.zip(filename)
84
- end
85
-
86
- desc "server SERVER", "Create a Marv server with the specified name"
87
- method_option :list, :type => :boolean, :force => false, :desc => "List all available Marv servers"
88
- method_option :start, :type => :boolean, :force => false, :desc => "Create a new Marv server"
89
- method_option :stop, :type => :boolean, :force => false, :desc => "Stop a running Marv server"
90
- method_option :restart, :type => :boolean, :force => false, :desc => "Restart a Marv server"
91
- # method_option :backup, :type => :boolean, :force => false, :desc => "Backup a Marv server"
92
- # method_option :restore, :type => :boolean, :force => false, :desc => "Restore a Marv server"
93
- method_option :remove, :type => :boolean, :force => false, :desc => "Remove a Marv server"
94
- def server(name=nil)
95
- if options.empty?
96
- server = Marv::Server.new(name, self, server_config)
97
- server.create_server
8
+ def self.source_root
9
+ ::File.expand_path(::File.join(Marv.root, 'layouts'))
98
10
  end
99
11
 
100
- if options[:remove]
101
- server = Marv::Server.new(name, self, server_config(true, name))
102
- server.remove_server
12
+ # Configure marv
13
+ desc "config", "Configure Marv projects and servers"
14
+ long_desc "Creates a global config.rb file that can be used to auto-configure your projects and servers"
15
+ def config
16
+ global = Marv::Global.new(self)
17
+ global.reconfigure
103
18
  end
104
19
 
105
- if options[:start] or options[:stop] or options[:restart]
106
- server = Marv::Server.new(name, self, nil)
107
- control_server(options, name, server)
108
- end
20
+ desc "server [SUBCOMMAND]", "Manage marv servers (create, start and more...)"
21
+ subcommand "server", Server
109
22
 
110
- if options[:list]
111
- list_servers
112
- end
113
23
  end
114
-
115
- protected
116
-
117
- def link_project_globaly(options, project)
118
- project_folder = project.project_id.gsub('_', '-')
119
- global_folder = File.join(ENV['HOME'], '.marv', options[:folder])
120
-
121
- unless File.directory?(global_folder)
122
- FileUtils.mkdir_p global_folder
123
- end
124
-
125
- do_link(project, File.join(global_folder, project_folder))
126
-
127
- servers = Dir.glob(File.join(ENV['HOME'], '.marv', 'servers' , '*'))
128
-
129
- servers.each do |server|
130
- shell.mute { do_link(project, File.join(server, 'wp-content', options[:folder], project_folder)) }
131
- end
132
- end
133
-
134
- def server_config(remove=nil, name=nil)
135
- config = {}
136
-
137
- if remove.nil?
138
- say "This will create a new Marv server with WordPress installed:", :green
139
- else
140
- say "This will remove #{name} server:", :yellow
141
- end
142
-
143
- config[:user] = ask("Mysql username:", nil, {:default => "root"})
144
- config[:password] = ask("Mysql user password:", nil, {:default => "required"})
145
- config[:host] = ask("Mysql host:", nil, {:default => "localhost"})
146
- config[:port] = ask("Mysql port:", nil, {:default => "3306"})
147
-
148
- if remove.nil?
149
- config[:version] = ask("WordPress version:", nil, {:default => "latest"})
150
- end
151
-
152
- config
153
- end
154
-
155
- def control_server(options, name, server)
156
- if options[:start]
157
- server.start_server
158
- end
159
-
160
- if options[:stop]
161
- server.stop_server
162
- end
163
-
164
- if options[:restart]
165
- server.restart_server
166
- end
167
- end
168
-
169
- def list_servers
170
- servers_root = File.join(ENV['HOME'], '.marv', 'servers')
171
- servers = Dir.glob(File.join(servers_root, '*'))
172
-
173
- say "Available marv servers:"
174
- servers.each do |server|
175
- say '- ' + File.basename(server), :cyan
176
- end
177
- end
178
-
179
- def link_project( wp_path, server_path, project)
180
- project_folder = project.project_id.gsub('_', '-')
181
-
182
- if File.directory?(wp_path)
183
- do_link(project, File.join(wp_path, project_folder))
184
- else
185
- do_link(project, File.join(server_path, project_folder))
186
- end
187
- end
188
-
189
- def do_link(project, path)
190
- begin
191
- project.link(path)
192
- rescue LinkSourceDirNotFound
193
- say_status :error, "The path #{File.dirname(path)} does not exist", :red
194
- exit 2
195
- rescue Errno::EEXIST
196
- say_status :error, "The path #{path} already exists", :red
197
- exit 2
198
- end
199
- end
200
-
201
24
  end
202
- end
25
+ end
@@ -0,0 +1,57 @@
1
+ require 'marv/project/project'
2
+
3
+ module Marv
4
+ module CLI
5
+ class Project < Thor
6
+
7
+ include Thor::Actions
8
+
9
+ # Create a new Marv project
10
+ desc "create DIRECTORY", "Creates a Marv project into specified directory"
11
+ long_desc "Creates a new project. Use the layout option to choose a scaffold"
12
+ def create(dir)
13
+ Marv::Project::Create.new(self, dir)
14
+ end
15
+
16
+ # Link an existing project to a Marv server or an existing WordPress installation
17
+ desc "link SERVER or DIRECTORY", "Create a symbolic link to the compilation directory"
18
+ long_desc "This command will symlink the compiled version of the project to the specified server or WordPress install path."+
19
+ "If you don't provide a directory or a server name, the symlink will be created in Marv global themes or plugins folder."
20
+ def link(dir=nil)
21
+ project = Marv::Project::Project.new(self, '.', nil)
22
+ actions = Marv::Project::Actions.new(project, nil)
23
+ actions.link(dir)
24
+ end
25
+
26
+ # Watch a Marv project for changes
27
+ desc "watch", "Start watch process"
28
+ long_desc "Watches the source directory in your Marv project for changes, and reflects those changes in a compile folder"
29
+ method_option :config, :type => :string, :desc => "Name of alternate config file"
30
+ def watch
31
+ project = Marv::Project::Project.new(self, '.', options[:config])
32
+ builder = Marv::Project::Builder.new(project)
33
+ Marv::Project::Guard.start(project, builder)
34
+ end
35
+
36
+ # Build a Marv project to a directory
37
+ desc "build DIRECTORY", "Build your theme into specified directory"
38
+ method_option :config, :type => :string, :desc => "Name of alternate config file"
39
+ def build(dir='build')
40
+ project = Marv::Project::Project.new(self, '.', options[:config])
41
+ builder = Marv::Project::Builder.new(project)
42
+ builder.build_to(dir)
43
+ end
44
+
45
+ # Package a Marv project in a .zip file
46
+ desc "package FILENAME", "Compile and zip your Marv project to FILENAME.zip"
47
+ method_option :config, :type => :string, :desc => "Name of alternate config file"
48
+ def package(filename=nil)
49
+ project = Marv::Project::Project.new(self, '.', options[:config])
50
+ builder = Marv::Project::Builder.new(project)
51
+ actions = Marv::Project::Actions.new(project, builder)
52
+ actions.package(filename)
53
+ end
54
+
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,65 @@
1
+ require 'marv/server/server'
2
+
3
+ module Marv
4
+ module CLI
5
+ class Server < Thor
6
+
7
+ def self.source_root
8
+ ::File.expand_path(::File.join(Marv.root, 'layouts'))
9
+ end
10
+
11
+ include Thor::Actions
12
+
13
+ # List all Marv servers
14
+ desc "list", "List all Marv servers"
15
+ def list
16
+ servers = Marv::Global.new(self).servers
17
+
18
+ say "Available marv servers:"
19
+ servers.each do |server|
20
+ say '- ' + server, :cyan
21
+ end
22
+ end
23
+
24
+ # Create a new Marv server
25
+ desc "create SERVER", "Create a Marv server with the specified name"
26
+ def create(dir)
27
+ server = Marv::Server::Server.new(self, dir)
28
+ Marv::Server::Create.new(server)
29
+ end
30
+
31
+ # Start a Marv server
32
+ desc "start SERVER", "Start the specified Marv server"
33
+ def start(dir)
34
+ server = Marv::Server::Server.new(self, dir)
35
+ action = Marv::Server::Actions.new(server)
36
+ action.start
37
+ end
38
+
39
+ # Start a Marv server
40
+ desc "stop SERVER", "Stop the specified Marv server"
41
+ def stop(dir)
42
+ server = Marv::Server::Server.new(self, dir)
43
+ action = Marv::Server::Actions.new(server)
44
+ action.stop
45
+ end
46
+
47
+ # Start a Marv server
48
+ desc "restart SERVER", "Restart the specified Marv server"
49
+ def restart(dir)
50
+ server = Marv::Server::Server.new(self, dir)
51
+ action = Marv::Server::Actions.new(server)
52
+ action.restart
53
+ end
54
+
55
+ # Create a new Marv server
56
+ desc "remove SERVER", "Remove the specified Marv server"
57
+ def remove(dir)
58
+ server = Marv::Server::Server.new(self, dir)
59
+ action = Marv::Server::Actions.new(server)
60
+ action.remove
61
+ end
62
+
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,285 @@
1
+ module Marv
2
+ class Global
3
+
4
+ attr_accessor :config, :path, :servers, :plugins, :themes, :layouts
5
+
6
+ def initialize(task)
7
+ @task = task
8
+
9
+ create_global_folders
10
+ create_global_config
11
+
12
+ @path = global_path
13
+ @config = global_config
14
+ @servers = local_servers
15
+ @plugins = global_plugins
16
+ @themes = global_themes
17
+ @layouts = global_layouts
18
+
19
+ @task.shell.mute do
20
+ clean_broken_links(global_projects_paths)
21
+ link_global_projects
22
+ end
23
+ end
24
+
25
+ # Global Marv folder path
26
+ def global_path
27
+ ::File.join(ENV['HOME'], '.marv')
28
+ end
29
+
30
+ # Global config file
31
+ def config_file
32
+ ::File.join(::File.join(global_path, 'config.rb'))
33
+ end
34
+
35
+ # Load global config file
36
+ def global_config
37
+ load_ruby_config(config_file)
38
+ end
39
+
40
+ # Servers folder path
41
+ def servers_path
42
+ ::File.join(global_path, 'servers')
43
+ end
44
+
45
+ # Local servers array
46
+ def local_servers
47
+ @servers = subfolders_basenames(servers_path)
48
+ end
49
+
50
+ # Plugins path
51
+ def plugins_path
52
+ ::File.join(global_path, 'plugins')
53
+ end
54
+
55
+ # Themes path
56
+ def themes_path
57
+ ::File.join(global_path, 'themes')
58
+ end
59
+
60
+ # Layouts path
61
+ def layouts_path
62
+ ::File.join(global_path, 'layouts')
63
+ end
64
+
65
+ # Global themes array
66
+ def global_themes
67
+ @themes = subfolders_basenames(themes_path)
68
+ end
69
+
70
+ # Global plugins array
71
+ def global_plugins
72
+ @plugins = subfolders_basenames(plugins_path)
73
+ end
74
+
75
+ # Global layouts array
76
+ def global_layouts
77
+ @layouts = subfolders_basenames(layouts_path)
78
+ end
79
+
80
+ # Create global folders
81
+ def create_global_folders
82
+ @task.shell.mute do
83
+ create_global_path
84
+ create_servers_path
85
+ create_themes_path
86
+ create_plugins_path
87
+ create_layouts_path
88
+ end
89
+ end
90
+
91
+ # Create global path
92
+ def create_global_path
93
+ unless ::File.directory?(global_path)
94
+ @task.empty_directory global_path
95
+ end
96
+ end
97
+
98
+ # Create servers path
99
+ def create_servers_path
100
+ unless ::File.directory?(servers_path)
101
+ @task.empty_directory servers_path
102
+ end
103
+ end
104
+
105
+ # Create themes path
106
+ def create_themes_path
107
+ unless ::File.directory?(themes_path)
108
+ @task.empty_directory themes_path
109
+ end
110
+ end
111
+
112
+ # Create plugins path
113
+ def create_plugins_path
114
+ unless ::File.directory?(plugins_path)
115
+ @task.empty_directory plugins_path
116
+ end
117
+ end
118
+
119
+ # Create layouts path
120
+ def create_layouts_path
121
+ unless ::File.directory?(layouts_path)
122
+ @task.empty_directory layouts_path
123
+ end
124
+ end
125
+
126
+ # Server details
127
+ def ask_server_details
128
+ options = {}
129
+
130
+ if @task.yes?("Do you want to set default server settings?")
131
+ options[:server_host] = @task.ask "Default host for servers?", :default => "localhost"
132
+ options[:server_port] = @task.ask "Default port for servers?", :default => "3000"
133
+ end
134
+
135
+ return options
136
+ end
137
+
138
+ # Database details
139
+ def ask_database_details
140
+ options = {}
141
+
142
+ if @task.yes?("Do you want to set default database settings?")
143
+ options[:db_user] = @task.ask "Default database username?", :default => "root"
144
+ options[:db_password] = @task.ask "Default database password?", :default => "root"
145
+ options[:db_host] = @task.ask "Default database host?", :default => "localhost"
146
+ options[:db_port] = @task.ask "Default database port?", :default => "3306"
147
+ end
148
+
149
+ return options
150
+ end
151
+
152
+ # Wordpress details
153
+ def ask_wordpress_details
154
+ options = {}
155
+
156
+ if @task.yes?("Do you want to set default WordPress version?")
157
+ options[:wp_version] = @task.ask "Default WordPress version?", :default => "latest"
158
+ end
159
+
160
+ return options
161
+ end
162
+
163
+ # Get global options
164
+ def global_options
165
+ @options
166
+ end
167
+
168
+ # Ask global options
169
+ def ask_global_options
170
+ options = {}
171
+
172
+ @task.say "This will create a new global configuration file.", :cyan
173
+
174
+ if @task.yes?("Do you want to set default project details?")
175
+ options[:uri] = @task.ask "Default project URI"
176
+ options[:author] = @task.ask "Default project author"
177
+ options[:author_uri] = @task.ask "Default project author URI"
178
+ options[:license_name] = @task.ask "Default project license name"
179
+ options[:license_uri] = @task.ask "Default project license URI"
180
+ end
181
+
182
+ options.merge!(ask_server_details)
183
+ options.merge!(ask_database_details)
184
+ options.merge!(ask_wordpress_details)
185
+
186
+ @options = options
187
+ end
188
+
189
+ # Create global config
190
+ def create_global_config
191
+ unless ::File.exists?(config_file)
192
+ ask_global_options
193
+ template ::File.join(Marv.root, 'layouts', 'config', 'global.rb'), ::File.join(global_path, 'config.rb'), instance_eval('binding')
194
+ end
195
+ end
196
+
197
+ # Reconfig Marv global options
198
+ def reconfigure
199
+ @task.say "This will overwrite your global configuration file.", :cyan
200
+
201
+ if @task.yes?("Do you want to continue?")
202
+ @task.shell.mute do
203
+ @task.remove_file config_file
204
+ end
205
+
206
+ create_global_folders
207
+ create_global_config
208
+ end
209
+ end
210
+
211
+ # Global projects paths
212
+ def global_projects_paths
213
+ paths = ::Dir.glob(::File.join(plugins_path, '*'))
214
+ paths = paths + ::Dir.glob(::File.join(themes_path, '*'))
215
+
216
+ return paths
217
+ end
218
+
219
+ # Global servers paths
220
+ def global_servers_paths
221
+ ::Dir.glob(::File.join(servers_path, '*'))
222
+ end
223
+
224
+ # Clean broken global links
225
+ def clean_broken_links(paths)
226
+ paths.each do |path|
227
+ unless ::File.exists?(path)
228
+ ::FileUtils.rm_r path
229
+ end
230
+ end
231
+ end
232
+
233
+ # Link global projects
234
+ def link_global_projects
235
+ global_projects_paths.each do |project|
236
+ global_servers_paths.each do |server|
237
+ target = project.gsub(global_path, ::File.join(server, 'wp-content'))
238
+ @task.create_link target, project unless ::File.exists?(target)
239
+ end
240
+ end
241
+ end
242
+
243
+ # Load ruby config file
244
+ def load_ruby_config(file)
245
+ config = {}
246
+
247
+ begin
248
+ # Config file is just executed as straight ruby
249
+ eval(::File.read(file))
250
+ rescue Exception => e
251
+ @task.say "Error while evaluating config file:"
252
+ @task.say e.message, :red
253
+ end
254
+
255
+ return config
256
+ end
257
+
258
+ # Parse template from source to destination
259
+ def template(source, *args, &block)
260
+ config = args.last.is_a?(Hash) ? args.pop : {}
261
+ destination = args.first || source.sub(/\.tt$/, '')
262
+ context = args.last || instance_eval('binding')
263
+
264
+ source = ::File.expand_path(@task.find_in_source_paths(source.to_s))
265
+
266
+ @task.create_file destination, nil, config do
267
+ content = ERB.new(::File.binread(source), nil, '-', '@output_buffer').result(context)
268
+ content = block.call(content) if block
269
+ content
270
+ end
271
+ end
272
+
273
+ # Get subfolder basenames
274
+ def subfolders_basenames(folder)
275
+ subfolders = []
276
+
277
+ ::Dir.glob(::File.join(folder, '*')).each do |subfolder|
278
+ subfolders << ::File.basename(subfolder)
279
+ end
280
+
281
+ return subfolders
282
+ end
283
+
284
+ end
285
+ end