Skip to content

Commit

Permalink
Let's use something which is made for parsing CLI and executing comma…
Browse files Browse the repository at this point in the history
…nds: Nake.
  • Loading branch information
botanicus committed Jul 6, 2012
1 parent b119103 commit 2fd37ca
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 145 deletions.
1 change: 1 addition & 0 deletions apiary.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Gem::Specification.new do |gem|

gem.files = Dir.glob("#{project_root}/{lib,spec,apiary.gemspec,Gemfile,README.md,LICENSE}/**/*")

gem.add_dependency "nake"
gem.add_dependency "rest-client", "~> 1.6.1"
gem.add_dependency "launchy", ">= 0.3.2"

Expand Down
21 changes: 11 additions & 10 deletions bin/apiary
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/usr/bin/env ruby
# encoding: UTF-8
#!/usr/bin/env nake
# encoding: utf-8

begin
require "pathname"
bin_file = Pathname.new(__FILE__).realpath
# Make sure symlinks to this file work.
real_bin_path = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
root_directory = File.expand_path(File.join(File.dirname(real_bin_path), ".."))
lib_directory = File.join(root_directory, "lib")

$:.unshift File.expand_path("../../lib", bin_file)

require "apiary/cli"
Apiary::CLI.start(*ARGV)
rescue Interrupt
# In development environment we want to use ./lib.
unless $LOAD_PATH.include?(lib_directory)
$LOAD_PATH.unshift(lib_directory)
end

require "apiary"
5 changes: 5 additions & 0 deletions lib/apiary.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# encoding: utf-8

require "nake"

require "apiary/commands/preview"
11 changes: 0 additions & 11 deletions lib/apiary/cli.rb

This file was deleted.

62 changes: 0 additions & 62 deletions lib/apiary/cmd.rb

This file was deleted.

43 changes: 0 additions & 43 deletions lib/apiary/commands/base.rb

This file was deleted.

33 changes: 14 additions & 19 deletions lib/apiary/commands/preview.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
require "apiary/commands/base"
# encoding: utf-8

# Display preview of local blueprint file
module Apiary
module Command
class Preview < Apiary::Command::Base
# Preview.
#
# Launch web browser and display preview of local blueprint file
def index
api_server = ENV.fetch("APIARY_API_HOST") { "api.apiary.io" }
Task.new(:preview) do |task|
task.description = "Display preview of local blueprint file"

require "launchy"
require "rest_client"

headers = {:accept => "text/html", :content_type => "text/plain"}
response = RestClient.post "https://#{api_server}/blueprint/generate", IO.read("apiary.apib"), headers
task.boot do
require "launchy"
require "rest_client"
end

file = File.new("/tmp/apiarypreview.html", "w")
file.write(response)
file.close
task.define do |api_server = "api.apiary.io"|
headers = {:accept => "text/html", :content_type => "text/plain"}
response = RestClient.post "https://#{api_server}/blueprint/generate", IO.read("apiary.apib"), headers

Launchy.open("file:///tmp/apiarypreview.html")
end
File.new("/tmp/apiarypreview.html", "w") do |file|
file.write(response)
end

Launchy.open("file:///tmp/apiarypreview.html")
end
end
2 changes: 2 additions & 0 deletions lib/apiary/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# encoding: utf-8

module Apiary
VERSION ||= "0.0.1"
end

0 comments on commit 2fd37ca

Please sign in to comment.