vhost_writer 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/vhost_writer/cli.rb +30 -1
- data/lib/vhost_writer/scaffolds/apache.erb +8 -0
- data/lib/vhost_writer/version.rb +1 -1
- data/spec/cli_spec.rb +35 -0
- data/spec/spec_helper.rb +14 -0
- metadata +2 -1
data/lib/vhost_writer/cli.rb
CHANGED
@@ -3,12 +3,41 @@ require 'vhost_writer'
|
|
3
3
|
|
4
4
|
module VhostWriter
|
5
5
|
class CLI < Thor
|
6
|
+
include Thor::Actions
|
7
|
+
|
8
|
+
source_root "#{File.dirname __FILE__}/scaffolds/"
|
9
|
+
|
6
10
|
desc 'write [SITES_DIR] [CONF_DIR] [TEMPLATE]',
|
7
11
|
'Use the site directories in SITES_DIRECTORY to generate vhost configs in
|
8
|
-
|
12
|
+
CONFIG_DIRECTORY using TEMPLATE'
|
9
13
|
def write(sites_dir, conf_dir, template)
|
10
14
|
writer = VhostWriter::Writer.new :sites_dir => sites_dir, :conf_dir => conf_dir
|
11
15
|
writer.write_configs! File.read template
|
12
16
|
end
|
17
|
+
|
18
|
+
desc 'scaffold [WEB_SERVER]',
|
19
|
+
'Generate a default template for WEB_SERVER. Run without arguments for a
|
20
|
+
list of supported web servers.'
|
21
|
+
def scaffold(scaffold='')
|
22
|
+
if scaffold.empty?
|
23
|
+
say "Supported scaffolds:\n ", :yellow
|
24
|
+
say "#{supported_scaffolds.join("\n ")}"
|
25
|
+
else
|
26
|
+
write_scaffold scaffold
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def supported_scaffolds
|
32
|
+
Dir.glob("#{source_paths.first}*").map { |f| File.basename f, '.erb' }
|
33
|
+
end
|
34
|
+
|
35
|
+
def write_scaffold(scaffold)
|
36
|
+
if supported_scaffolds.include? scaffold
|
37
|
+
copy_file "#{scaffold}.erb"
|
38
|
+
else
|
39
|
+
say "Specified scaffold does not exist", :red
|
40
|
+
end
|
41
|
+
end
|
13
42
|
end
|
14
43
|
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<VirtualHost *:80>
|
2
|
+
ServerAdmin admin@<%= site %>
|
3
|
+
ServerName <%= site %>
|
4
|
+
ServerAlias www.<%= site %>
|
5
|
+
DocumentRoot /srv/www/<%= site %>/public_html/
|
6
|
+
ErrorLog /srv/www/<%= site %>/logs/error.log
|
7
|
+
CustomLog /srv/www/<%= site %>/logs/access.log combined
|
8
|
+
</VirtualHost>
|
data/lib/vhost_writer/version.rb
CHANGED
data/spec/cli_spec.rb
CHANGED
@@ -21,4 +21,39 @@ describe VhostWriter::CLI do
|
|
21
21
|
pending 'not yet implemented'
|
22
22
|
end
|
23
23
|
end
|
24
|
+
|
25
|
+
describe '#scaffold' do
|
26
|
+
context 'when a valid scaffold is specified' do
|
27
|
+
let(:scaffold_contents) { File.read 'lib/vhost_writer/scaffolds/apache.erb' }
|
28
|
+
before do
|
29
|
+
Dir.chdir('spec/test') { subject.scaffold 'apache' }
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should generate a file' do
|
33
|
+
expect(Dir.glob('spec/test/*').map { |f| File.basename f }).to include 'apache.erb'
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'the file should be copied from the scaffold' do
|
37
|
+
expect(File.read 'spec/test/apache.erb').to eql scaffold_contents
|
38
|
+
end
|
39
|
+
|
40
|
+
after { File.delete 'spec/test/apache.erb' }
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'when an invalid scaffold is specified' do
|
44
|
+
let(:output) { capture(:stdout) { subject.scaffold 'not-real' } }
|
45
|
+
|
46
|
+
it 'should return an error message' do
|
47
|
+
expect(output).to include 'Specified scaffold does not exist'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'when no scaffold is specified' do
|
52
|
+
let(:output) { capture(:stdout) { subject.scaffold } }
|
53
|
+
|
54
|
+
it 'should list the available scaffolds' do
|
55
|
+
expect(output).to include 'apache'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
24
59
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -8,3 +8,17 @@ RSpec.configure do |config|
|
|
8
8
|
# Use the specified formatter
|
9
9
|
config.formatter = :documentation # :progress, :html, :textmate
|
10
10
|
end
|
11
|
+
|
12
|
+
# from thor spec helper
|
13
|
+
def capture(stream)
|
14
|
+
begin
|
15
|
+
stream = stream.to_s
|
16
|
+
eval "$#{stream} = StringIO.new"
|
17
|
+
yield
|
18
|
+
result = eval("$#{stream}").string
|
19
|
+
ensure
|
20
|
+
eval("$#{stream} = #{stream.upcase}")
|
21
|
+
end
|
22
|
+
|
23
|
+
result
|
24
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vhost_writer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- bin/vhost_writer
|
61
61
|
- lib/vhost_writer.rb
|
62
62
|
- lib/vhost_writer/cli.rb
|
63
|
+
- lib/vhost_writer/scaffolds/apache.erb
|
63
64
|
- lib/vhost_writer/version.rb
|
64
65
|
- lib/vhost_writer/writer.rb
|
65
66
|
- spec/cli_spec.rb
|