Skip to content

Commit 44ee5a5

Browse files
committed
- Add 'madness theme css' command to copy the public css
1 parent 2ae423c commit 44ee5a5

6 files changed

Lines changed: 52 additions & 4 deletions

File tree

lib/madness/commands/theme.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,31 @@ class Theme < Base
44
summary 'Create files for theme customization'
55

66
usage 'madness theme full [PATH]'
7+
usage 'madness theme css'
78
usage 'madness config (-h|--help)'
89

910
command 'full', 'Create a full theme customization directory in PATH [default: _theme]'
11+
command 'css', 'Create a folder with the CSS file for customization'
1012

1113
def full_command
12-
raise InitError, "Directory #{path} already exists" if Dir.exist? path
14+
raise InitError, "Directory #{theme_path} already exists" if Dir.exist? theme_path
1315

14-
FileUtils.cp_r File.expand_path('../../../app', __dir__), path
15-
say "!txtgrn!Created #{path} theme folder"
16+
FileUtils.cp_r File.expand_path('../../../app', __dir__), theme_path
17+
say "!txtgrn!Created #{theme_path} theme folder"
18+
end
19+
20+
def css_command
21+
file = 'css/main.css'
22+
raise InitError, "File #{file} already exists" if File.exist? file
23+
24+
FileUtils.mkdir_p 'css'
25+
FileUtils.cp_r File.expand_path('../../../app/public/css/main.css', __dir__), 'css/main.css'
26+
say '!txtgrn!Created css/main.css'
1627
end
1728

1829
private
1930

20-
def path
31+
def theme_path
2132
args['PATH'] || '_theme'
2233
end
2334
end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Created css/main.css
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#<Madness::InitError: File css/main.css already exists>

spec/approvals/cli/theme/help

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ Create files for theme customization
22

33
Usage:
44
madness theme full [PATH]
5+
madness theme css
56
madness config (-h|--help)
67

78
Commands:
89
full
910
Create a full theme customization directory in PATH [default: _theme]
1011

12+
css
13+
Create a folder with the CSS file for customization
14+
1115
Options:
1216
-h --help
1317
Show this help

spec/approvals/cli/theme/usage

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
Usage:
22
madness theme full [PATH]
3+
madness theme css
34
madness config (-h|--help)

spec/madness/commands/theme_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,34 @@
3737
end
3838
end
3939
end
40+
41+
context 'with css command' do
42+
let(:theme_dir) { 'tmp/css' }
43+
44+
before do
45+
system "rm -rf #{theme_dir}" if Dir.exist? theme_dir
46+
expect(Dir).not_to exist theme_dir
47+
end
48+
49+
it 'copies the public css to css/main.css' do
50+
Dir.chdir 'tmp' do
51+
expect { subject.execute 'theme css' }.to output_approval('cli/theme/css-create')
52+
expect(Dir).to exist 'css'
53+
expect(File.read('css/main.css')).to eq File.read('../app/public/css/main.css')
54+
end
55+
end
56+
57+
context 'when dir already exists' do
58+
before do
59+
system "mkdir #{theme_dir}" unless Dir.exist? theme_dir
60+
system "touch #{theme_dir}/main.css"
61+
end
62+
63+
it 'does not overwrite it' do
64+
Dir.chdir 'tmp' do
65+
expect { subject.execute 'theme css' }.to raise_approval('cli/theme/css-exists')
66+
end
67+
end
68+
end
69+
end
4070
end

0 commit comments

Comments
 (0)