Skip to content

Commit b97adc8

Browse files
committed
Merge branch 'custom_logo'
2 parents a3ae7db + 718c0ad commit b97adc8

File tree

6 files changed

+114
-1
lines changed

6 files changed

+114
-1
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Changelog
2+
3+
## Version 1.1.0
4+
5+
*Unreleased*
6+
7+
**Features**
8+
9+
- Added an optional `-l, [--logo=LOGO]` option to specify a path to the custom logo file to use in the slate install
10+
11+
## Version 1.0.0
12+
13+
*September 29, 2016*
14+
15+
Initial release

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ To install slate into your docs folder run
5252
$ slate-installer install
5353
```
5454

55+
You can optionally specify the path to a custom logo to have that overwrite the slate logo during install
56+
57+
```shell
58+
$ slate-installer install -l path/to/logo.png
59+
```
60+
5561
## Development
5662

5763
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

lib/slate/installer/cli.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,50 @@ def self.source_paths
1616
end
1717

1818
desc "install", "creates a docs folder and installs latest slate into it"
19+
method_option :logo, :type => :string, :aliases => "-l", :desc => "path to custom logo file", :lazy_default => ""
1920
def install
21+
if options[:logo]
22+
logo = determine_logo_path(options[:logo])
23+
end
24+
2025
Dir.mktmpdir("slate-src-") do |tmpdir|
2126
output, _status = Open3.capture2e("git", "clone", "--depth", "1", "--progress", "https://github.com/lord/slate.git", tmpdir)
2227
puts output
28+
29+
if logo
30+
slate_logo_path = File.join(tmpdir, "source", "images", "logo.png")
31+
logo_mode = File.stat(slate_logo_path).mode
32+
create_file slate_logo_path, File.binread(logo), {:force => true}
33+
chmod slate_logo_path, logo_mode, {}
34+
end
35+
2336
directory Pathname.new(tmpdir).basename, "docs", \
2437
mode: :preserve, recursive: true, exclude_pattern: /(?:\.git(?:hub)?\/)|(?:\.travis)/
2538
end
2639
end
40+
41+
private
42+
43+
def self.exit_on_failure?
44+
true
45+
end
46+
47+
def determine_logo_path(logo)
48+
logo = String(logo)
49+
if logo.empty?
50+
logo = ask("Enter the path to the logo file:", :path => true)
51+
end
52+
53+
if logo.empty?
54+
raise ::Thor::MalformattedArgumentError, "A logo path must be provided when using the logo option"
55+
end
56+
57+
unless File.file?(File.expand_path(logo))
58+
raise ::Thor::MalformattedArgumentError, "The logo path provided is not a file"
59+
end
60+
61+
logo
62+
end
2763
end
2864
end
2965
end

slate-installer.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
99
spec.authors = ["Kevin Glowacz"]
1010
spec.email = ["[email protected]"]
1111

12-
spec.summary = "Easily slate powered docs to your app"
12+
spec.summary = "Easily add slate powered docs to your app"
1313
spec.description = "This provides a utility to add and update your docs " \
1414
"folder with the latest slate source"
1515
spec.homepage = "https://github.com/kjg/slate-installer"

spec/fixtures/MyLogo.png

2.69 KB
Loading

spec/slate/installer/cli_spec.rb

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,61 @@
2727
deploys_sh = File.new("docs/deploy.sh")
2828
expect(deploys_sh.stat).to be_executable
2929
end
30+
31+
context "when no logo option" do
32+
it "keeps the original logo" do
33+
output
34+
expect(FileUtils).not_to be_identical(File.expand_path("../../../fixtures/MyLogo.png", __FILE__), "docs/source/images/logo.png")
35+
end
36+
end
37+
38+
context "when specifying the logo option" do
39+
context "when blank" do
40+
subject { Slate::Installer::Cli.new([], {:logo => ""}) }
41+
42+
it "asks for a path" do
43+
expect(subject).to receive(:ask).with("Enter the path to the logo file:", :path => true).and_return ""
44+
begin
45+
subject.install
46+
rescue Thor::MalformattedArgumentError
47+
end
48+
end
49+
50+
context "and user input is also blank" do
51+
it "raises an error" do
52+
allow(subject).to receive(:ask).with("Enter the path to the logo file:", :path => true).and_return ""
53+
expect {subject.install}.to raise_error(Thor::MalformattedArgumentError, "A logo path must be provided when using the logo option")
54+
end
55+
end
56+
end
57+
58+
context "when a directory" do
59+
subject { Slate::Installer::Cli.new([], {:logo => File.expand_path("..", __FILE__)}) }
60+
61+
it "raises an error" do
62+
allow(subject).to receive(:ask).with("Enter the path to the logo file:", :path => true).and_return ""
63+
expect {subject.install}.to raise_error(Thor::MalformattedArgumentError, "The logo path provided is not a file")
64+
end
65+
end
66+
67+
context "when not a file" do
68+
subject { Slate::Installer::Cli.new([], {:logo => File.expand_path("../not_a_file.txt", __FILE__)}) }
69+
70+
it "raises an error" do
71+
allow(subject).to receive(:ask).with("Enter the path to the logo file:", :path => true).and_return ""
72+
expect {subject.install}.to raise_error(Thor::MalformattedArgumentError, "The logo path provided is not a file")
73+
end
74+
end
75+
76+
context "when a valid file" do
77+
subject { Slate::Installer::Cli.new([], {:logo => File.expand_path("../../../fixtures/MyLogo.png", __FILE__)}) }
78+
let(:output) { capture(:stdout) { subject.install } }
79+
80+
it "installs into the docs dir" do
81+
output
82+
expect(FileUtils).to be_identical(File.expand_path("../../../fixtures/MyLogo.png", __FILE__), "docs/source/images/logo.png")
83+
end
84+
end
85+
end
3086
end
3187
end

0 commit comments

Comments
 (0)