Skip to content

Commit

Permalink
Merge branch 'custom_logo'
Browse files Browse the repository at this point in the history
  • Loading branch information
kjg committed Oct 14, 2016
2 parents a3ae7db + 718c0ad commit b97adc8
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 1 deletion.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Changelog

## Version 1.1.0

*Unreleased*

**Features**

- Added an optional `-l, [--logo=LOGO]` option to specify a path to the custom logo file to use in the slate install

## Version 1.0.0

*September 29, 2016*

Initial release
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ To install slate into your docs folder run
$ slate-installer install
```

You can optionally specify the path to a custom logo to have that overwrite the slate logo during install

```shell
$ slate-installer install -l path/to/logo.png
```

## Development

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.
Expand Down
36 changes: 36 additions & 0 deletions lib/slate/installer/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,50 @@ def self.source_paths
end

desc "install", "creates a docs folder and installs latest slate into it"
method_option :logo, :type => :string, :aliases => "-l", :desc => "path to custom logo file", :lazy_default => ""
def install
if options[:logo]
logo = determine_logo_path(options[:logo])
end

Dir.mktmpdir("slate-src-") do |tmpdir|
output, _status = Open3.capture2e("git", "clone", "--depth", "1", "--progress", "https://github.com/lord/slate.git", tmpdir)
puts output

if logo
slate_logo_path = File.join(tmpdir, "source", "images", "logo.png")
logo_mode = File.stat(slate_logo_path).mode
create_file slate_logo_path, File.binread(logo), {:force => true}
chmod slate_logo_path, logo_mode, {}
end

directory Pathname.new(tmpdir).basename, "docs", \
mode: :preserve, recursive: true, exclude_pattern: /(?:\.git(?:hub)?\/)|(?:\.travis)/
end
end

private

def self.exit_on_failure?
true
end

def determine_logo_path(logo)
logo = String(logo)
if logo.empty?
logo = ask("Enter the path to the logo file:", :path => true)
end

if logo.empty?
raise ::Thor::MalformattedArgumentError, "A logo path must be provided when using the logo option"
end

unless File.file?(File.expand_path(logo))
raise ::Thor::MalformattedArgumentError, "The logo path provided is not a file"
end

logo
end
end
end
end
2 changes: 1 addition & 1 deletion slate-installer.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
spec.authors = ["Kevin Glowacz"]
spec.email = ["[email protected]"]

spec.summary = "Easily slate powered docs to your app"
spec.summary = "Easily add slate powered docs to your app"
spec.description = "This provides a utility to add and update your docs " \
"folder with the latest slate source"
spec.homepage = "https://github.com/kjg/slate-installer"
Expand Down
Binary file added spec/fixtures/MyLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 56 additions & 0 deletions spec/slate/installer/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,61 @@
deploys_sh = File.new("docs/deploy.sh")
expect(deploys_sh.stat).to be_executable
end

context "when no logo option" do
it "keeps the original logo" do
output
expect(FileUtils).not_to be_identical(File.expand_path("../../../fixtures/MyLogo.png", __FILE__), "docs/source/images/logo.png")
end
end

context "when specifying the logo option" do
context "when blank" do
subject { Slate::Installer::Cli.new([], {:logo => ""}) }

it "asks for a path" do
expect(subject).to receive(:ask).with("Enter the path to the logo file:", :path => true).and_return ""
begin
subject.install
rescue Thor::MalformattedArgumentError
end
end

context "and user input is also blank" do
it "raises an error" do
allow(subject).to receive(:ask).with("Enter the path to the logo file:", :path => true).and_return ""
expect {subject.install}.to raise_error(Thor::MalformattedArgumentError, "A logo path must be provided when using the logo option")
end
end
end

context "when a directory" do
subject { Slate::Installer::Cli.new([], {:logo => File.expand_path("..", __FILE__)}) }

it "raises an error" do
allow(subject).to receive(:ask).with("Enter the path to the logo file:", :path => true).and_return ""
expect {subject.install}.to raise_error(Thor::MalformattedArgumentError, "The logo path provided is not a file")
end
end

context "when not a file" do
subject { Slate::Installer::Cli.new([], {:logo => File.expand_path("../not_a_file.txt", __FILE__)}) }

it "raises an error" do
allow(subject).to receive(:ask).with("Enter the path to the logo file:", :path => true).and_return ""
expect {subject.install}.to raise_error(Thor::MalformattedArgumentError, "The logo path provided is not a file")
end
end

context "when a valid file" do
subject { Slate::Installer::Cli.new([], {:logo => File.expand_path("../../../fixtures/MyLogo.png", __FILE__)}) }
let(:output) { capture(:stdout) { subject.install } }

it "installs into the docs dir" do
output
expect(FileUtils).to be_identical(File.expand_path("../../../fixtures/MyLogo.png", __FILE__), "docs/source/images/logo.png")
end
end
end
end
end

0 comments on commit b97adc8

Please sign in to comment.