buttless 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,28 @@
1
+ source :gemcutter #"http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem 'rest-client'
7
+ gem 'json'
8
+ gem 'pdfkit'
9
+ gem 'activesupport'
10
+ gem 'minitest'
11
+ gem 'googlecharts'
12
+ gem 'array_stats'
13
+ gem 'redcarpet'
14
+ gem 'webmock'
15
+ gem 'rake'
16
+ gem 'tilt'
17
+ gem 'minitest-reporters'
18
+ gem 'sinatra'
19
+
20
+ # Add dependencies to develop your gem here.
21
+ # Include everything needed to run rake, tests, features, etc.
22
+ group :development do
23
+ gem "shoulda", ">= 0"
24
+ gem "rdoc", "~> 3.12"
25
+ gem "bundler", "~> 1.0.0"
26
+ gem "jeweler", "~> 1.8.3"
27
+ gem "simplecov", ">= 0"
28
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,77 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (3.2.2)
5
+ i18n (~> 0.6)
6
+ multi_json (~> 1.0)
7
+ addressable (2.2.7)
8
+ ansi (1.4.2)
9
+ array_stats (0.6.0)
10
+ crack (0.3.1)
11
+ git (1.2.5)
12
+ googlecharts (1.6.8)
13
+ i18n (0.6.0)
14
+ jeweler (1.8.3)
15
+ bundler (~> 1.0)
16
+ git (>= 1.2.5)
17
+ rake
18
+ rdoc
19
+ json (1.6.5)
20
+ mime-types (1.18)
21
+ minitest (2.11.4)
22
+ minitest-reporters (0.5.1)
23
+ ansi
24
+ minitest (~> 2.0)
25
+ ruby-progressbar
26
+ multi_json (1.1.0)
27
+ pdfkit (0.5.2)
28
+ rack (1.4.1)
29
+ rack-protection (1.2.0)
30
+ rack
31
+ rake (0.9.2.2)
32
+ rdoc (3.12)
33
+ json (~> 1.4)
34
+ redcarpet (2.1.1)
35
+ rest-client (1.6.7)
36
+ mime-types (>= 1.16)
37
+ ruby-progressbar (0.0.10)
38
+ shoulda (3.0.1)
39
+ shoulda-context (~> 1.0.0)
40
+ shoulda-matchers (~> 1.0.0)
41
+ shoulda-context (1.0.0)
42
+ shoulda-matchers (1.0.0)
43
+ simplecov (0.6.1)
44
+ multi_json (~> 1.0)
45
+ simplecov-html (~> 0.5.3)
46
+ simplecov-html (0.5.3)
47
+ sinatra (1.3.2)
48
+ rack (~> 1.3, >= 1.3.6)
49
+ rack-protection (~> 1.2)
50
+ tilt (~> 1.3, >= 1.3.3)
51
+ tilt (1.3.3)
52
+ webmock (1.8.4)
53
+ addressable (>= 2.2.7)
54
+ crack (>= 0.1.7)
55
+
56
+ PLATFORMS
57
+ ruby
58
+
59
+ DEPENDENCIES
60
+ activesupport
61
+ array_stats
62
+ bundler (~> 1.0.0)
63
+ googlecharts
64
+ jeweler (~> 1.8.3)
65
+ json
66
+ minitest
67
+ minitest-reporters
68
+ pdfkit
69
+ rake
70
+ rdoc (~> 3.12)
71
+ redcarpet
72
+ rest-client
73
+ shoulda
74
+ simplecov
75
+ sinatra
76
+ tilt
77
+ webmock
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Engine Room Apps
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README_old.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = buttless
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to buttless
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2012 Tobin Harris. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,60 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "buttless"
18
+ gem.homepage = "http://github.com/tobinharris/buttless"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Design, document and develop against an API without having a backend.}
21
+ gem.description = %Q{Buttless gives you a way to quickly flesh out an API in detail. It generates sexy documentation. And, you can quickly run the API and simulate various scenarios without neededing a backend.}
22
+ gem.email = "tobin@tobinharris.com"
23
+ gem.authors = ["Tobin Harris"]
24
+ gem.files.include 'lib/template/*'
25
+ gem.files.include 'lib/template/api-doc/*'
26
+ gem.files.include 'lib/template/api-doc/images/*'
27
+ gem.files.include 'lib/template/code_samples/*'
28
+ gem.files.include 'lib/template/json_examples/*'
29
+ gem.files.include 'lib/template/server/*'
30
+ gem.files.include 'lib/template/test/*'
31
+ # dependencies defined in Gemfile
32
+ end
33
+ Jeweler::RubygemsDotOrgTasks.new
34
+
35
+ require 'rake/testtask'
36
+ Rake::TestTask.new(:test) do |test|
37
+ test.libs << 'lib' << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ end
41
+
42
+ # require 'simplecov/simplecovtask'
43
+ # Rcov::RcovTask.new do |test|
44
+ # test.libs << 'test'
45
+ # test.pattern = 'test/**/test_*.rb'
46
+ # test.verbose = true
47
+ # test.rcov_opts << '--exclude "gems/*"'
48
+ # end
49
+
50
+ task :default => :test
51
+
52
+ require 'rdoc/task'
53
+ Rake::RDocTask.new do |rdoc|
54
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
55
+
56
+ rdoc.rdoc_dir = 'rdoc'
57
+ rdoc.title = "buttless #{version}"
58
+ rdoc.rdoc_files.include('README*')
59
+ rdoc.rdoc_files.include('lib/**/*.rb')
60
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/bin/buttless ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
4
+
5
+ unless ARGV.empty?
6
+ file = File.expand_path(File.dirname(__FILE__)) + '/..'
7
+
8
+ if ARGV[0] == "--update"
9
+ exec "cp -r #{file}/lib/template/server/* server/"
10
+ exec "cp #{file}/lib/template/Rakefile ."
11
+ exec "cp #{file}/lib/template/Gemfile ."
12
+ else
13
+ cmd = "cp -r #{file}/lib/template #{ARGV[0]}"
14
+ puts cmd
15
+ end
16
+ else
17
+ puts "\n\nButtless\nLets you design, document and develop against an API without having a backend.\n\nUsage\n\n\tbuttless my_api_project # Generates an empty buttless folder"
18
+ end
data/buttless.gemspec ADDED
@@ -0,0 +1,127 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "buttless"
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Tobin Harris"]
12
+ s.date = "2012-04-01"
13
+ s.description = "Buttless gives you a way to quickly flesh out an API in detail. It generates sexy documentation. And, you can quickly run the API and simulate various scenarios without neededing a backend."
14
+ s.email = "tobin@tobinharris.com"
15
+ s.executables = ["buttless"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README_old.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README_old.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/buttless",
29
+ "buttless.gemspec",
30
+ "lib/buttless.rb",
31
+ "lib/template/.DS_Store",
32
+ "lib/template/Gemfile",
33
+ "lib/template/Gemfile.lock",
34
+ "lib/template/Rakefile",
35
+ "lib/template/api-doc/.DS_Store",
36
+ "lib/template/api-doc/images/logo.png",
37
+ "lib/template/api-doc/index.html",
38
+ "lib/template/api-doc/index.md.erb",
39
+ "lib/template/api-doc/report.css",
40
+ "lib/template/api-doc/screen.css",
41
+ "lib/template/api-doc/template.html.erb",
42
+ "lib/template/code_samples/prthw.md.erb",
43
+ "lib/template/config.yaml",
44
+ "lib/template/database.yaml",
45
+ "lib/template/install",
46
+ "lib/template/json_examples/funky_stuff.json",
47
+ "lib/template/json_examples/funky_stuff_info.json",
48
+ "lib/template/json_examples/funky_thing.json",
49
+ "lib/template/json_examples/post_ok.json",
50
+ "lib/template/readme.textile",
51
+ "lib/template/server/config.ru",
52
+ "lib/template/test/test_helper.rb",
53
+ "lib/template/test/test_stuff.rb",
54
+ "readme.textile",
55
+ "test/helper.rb",
56
+ "test/test_buttless.rb"
57
+ ]
58
+ s.homepage = "http://github.com/tobinharris/buttless"
59
+ s.licenses = ["MIT"]
60
+ s.require_paths = ["lib"]
61
+ s.rubygems_version = "1.8.11"
62
+ s.summary = "Design, document and develop against an API without having a backend."
63
+
64
+ if s.respond_to? :specification_version then
65
+ s.specification_version = 3
66
+
67
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
68
+ s.add_runtime_dependency(%q<rest-client>, [">= 0"])
69
+ s.add_runtime_dependency(%q<json>, [">= 0"])
70
+ s.add_runtime_dependency(%q<pdfkit>, [">= 0"])
71
+ s.add_runtime_dependency(%q<activesupport>, [">= 0"])
72
+ s.add_runtime_dependency(%q<minitest>, [">= 0"])
73
+ s.add_runtime_dependency(%q<googlecharts>, [">= 0"])
74
+ s.add_runtime_dependency(%q<array_stats>, [">= 0"])
75
+ s.add_runtime_dependency(%q<redcarpet>, [">= 0"])
76
+ s.add_runtime_dependency(%q<webmock>, [">= 0"])
77
+ s.add_runtime_dependency(%q<rake>, [">= 0"])
78
+ s.add_runtime_dependency(%q<tilt>, [">= 0"])
79
+ s.add_runtime_dependency(%q<minitest-reporters>, [">= 0"])
80
+ s.add_runtime_dependency(%q<sinatra>, [">= 0"])
81
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
82
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
83
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
84
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
85
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
86
+ else
87
+ s.add_dependency(%q<rest-client>, [">= 0"])
88
+ s.add_dependency(%q<json>, [">= 0"])
89
+ s.add_dependency(%q<pdfkit>, [">= 0"])
90
+ s.add_dependency(%q<activesupport>, [">= 0"])
91
+ s.add_dependency(%q<minitest>, [">= 0"])
92
+ s.add_dependency(%q<googlecharts>, [">= 0"])
93
+ s.add_dependency(%q<array_stats>, [">= 0"])
94
+ s.add_dependency(%q<redcarpet>, [">= 0"])
95
+ s.add_dependency(%q<webmock>, [">= 0"])
96
+ s.add_dependency(%q<rake>, [">= 0"])
97
+ s.add_dependency(%q<tilt>, [">= 0"])
98
+ s.add_dependency(%q<minitest-reporters>, [">= 0"])
99
+ s.add_dependency(%q<sinatra>, [">= 0"])
100
+ s.add_dependency(%q<shoulda>, [">= 0"])
101
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
102
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
103
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
104
+ s.add_dependency(%q<simplecov>, [">= 0"])
105
+ end
106
+ else
107
+ s.add_dependency(%q<rest-client>, [">= 0"])
108
+ s.add_dependency(%q<json>, [">= 0"])
109
+ s.add_dependency(%q<pdfkit>, [">= 0"])
110
+ s.add_dependency(%q<activesupport>, [">= 0"])
111
+ s.add_dependency(%q<minitest>, [">= 0"])
112
+ s.add_dependency(%q<googlecharts>, [">= 0"])
113
+ s.add_dependency(%q<array_stats>, [">= 0"])
114
+ s.add_dependency(%q<redcarpet>, [">= 0"])
115
+ s.add_dependency(%q<webmock>, [">= 0"])
116
+ s.add_dependency(%q<rake>, [">= 0"])
117
+ s.add_dependency(%q<tilt>, [">= 0"])
118
+ s.add_dependency(%q<minitest-reporters>, [">= 0"])
119
+ s.add_dependency(%q<sinatra>, [">= 0"])
120
+ s.add_dependency(%q<shoulda>, [">= 0"])
121
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
122
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
123
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
124
+ s.add_dependency(%q<simplecov>, [">= 0"])
125
+ end
126
+ end
127
+
data/lib/buttless.rb ADDED
File without changes
Binary file
@@ -0,0 +1,14 @@
1
+ source :gemcutter
2
+ gem 'rest-client'
3
+ gem 'json'
4
+ gem 'pdfkit'
5
+ gem 'activesupport'
6
+ gem 'minitest'
7
+ gem 'googlecharts'
8
+ gem 'array_stats'
9
+ gem 'redcarpet'
10
+ gem 'webmock'
11
+ gem 'rake'
12
+ gem 'tilt'
13
+ gem 'minitest-reporters'
14
+ gem 'sinatra'
@@ -0,0 +1,53 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (3.1.0)
5
+ multi_json (~> 1.0)
6
+ addressable (2.2.7)
7
+ ansi (1.4.2)
8
+ array_stats (0.6.0)
9
+ crack (0.3.1)
10
+ googlecharts (1.6.8)
11
+ json (1.6.3)
12
+ mime-types (1.17.2)
13
+ minitest (2.11.2)
14
+ minitest-reporters (0.5.1)
15
+ ansi
16
+ minitest (~> 2.0)
17
+ ruby-progressbar
18
+ multi_json (1.0.4)
19
+ pdfkit (0.5.2)
20
+ rack (1.3.5)
21
+ rack-protection (1.1.4)
22
+ rack
23
+ rake (0.9.2.2)
24
+ redcarpet (2.1.0)
25
+ rest-client (1.6.7)
26
+ mime-types (>= 1.16)
27
+ ruby-progressbar (0.0.10)
28
+ sinatra (1.3.1)
29
+ rack (>= 1.3.4, ~> 1.3)
30
+ rack-protection (>= 1.1.2, ~> 1.1)
31
+ tilt (>= 1.3.3, ~> 1.3)
32
+ tilt (1.3.3)
33
+ webmock (1.8.0)
34
+ addressable (>= 2.2.7)
35
+ crack (>= 0.1.7)
36
+
37
+ PLATFORMS
38
+ ruby
39
+
40
+ DEPENDENCIES
41
+ activesupport
42
+ array_stats
43
+ googlecharts
44
+ json
45
+ minitest
46
+ minitest-reporters
47
+ pdfkit
48
+ rake
49
+ redcarpet
50
+ rest-client
51
+ sinatra
52
+ tilt
53
+ webmock
@@ -0,0 +1,96 @@
1
+ require 'rubygems'
2
+ require "bundler/setup"
3
+ require 'rake/testtask'
4
+ require 'pdfkit'
5
+ require 'redcarpet'
6
+ require 'erb'
7
+ require 'tilt'
8
+
9
+ class Helper
10
+ def example_path(method, ip=nil)
11
+ path = method["path"]
12
+ params = []
13
+ method["parameters"].each do |p|
14
+ next if p["optional"] or p["type"]=="POST"
15
+ if path.include?(":#{p['name']}")
16
+ path.gsub!(":#{p['name']}", p["example"].to_s)
17
+ next
18
+ end
19
+ params << "#{p["name"]}=#{p["example"]}"
20
+ end unless method["parameters"].nil?
21
+
22
+ api_call = "#{path}?#{params.join('&')}"
23
+ #puts "**** WARNING **** \n Method length is #{api_call.length}, which is greater than 19 so won't work on some embedded devices: #{api_call}" if "#{path}?#{params.join('&')}".length > 19
24
+ "#{ip}#{api_call}"
25
+ end
26
+
27
+ def example_curl(method, ip="http://192.168.1.3", no=2)
28
+ path = example_path(method, ip)
29
+ i = 0
30
+ params = []
31
+ method["parameters"].select{|p|p["type"]=="POST"}.each do |p|
32
+ break unless i < no or p["optional"] == false
33
+ i=i+1
34
+ params << "#{p["name"]}=#{p["example"]}"
35
+ end if method["parameters"]
36
+ data = nil
37
+ unless params.empty?
38
+ data = "--data \"#{params.join('&')}\" \\\n"
39
+ end
40
+ "curl -v #{data.nil? ? '' : "\\\n #{data}"} #{path}".chomp('?')
41
+ end
42
+ end
43
+
44
+ Rake::TestTask.new do |t|
45
+ t.pattern = "test/test_*.rb"
46
+ end
47
+
48
+ desc "Run tests"
49
+ task :default => :test
50
+
51
+ desc "Generate HTML and PDF"
52
+ task :gen => [:html, :pdf]
53
+
54
+ desc "Generate HTML docs"
55
+ task :html => :prepare do
56
+ File.open('index.html','w').write(@html)
57
+ end
58
+
59
+ desc "Generate PDF docs"
60
+ task :pdf => :prepare do
61
+ `/Applications/wkhtmltopdf.app/Contents/MacOS/wkhtmltopdf --page-size A4 --margin-left 20mm --margin-right 20mm --margin-top 20mm --margin-bottom 20mm index.html #{@config["full_title"]}.pdf`
62
+ #`wkhtmltopdf --page-size A4 --margin-left 20mm --margin-right 20mm --margin-top 20mm --margin-bottom 20mm index.html #{@config["full_title"]}.pdf`
63
+
64
+ # PDFKit.configure do |config|
65
+ # config.root_url = @root_url
66
+ # end
67
+ #
68
+ # kit = PDFKit.new(@html, :page_size => 'A4') #:print_media_type => true,
69
+ # kit.stylesheets << 'report.css'
70
+ # file = kit.to_file("#{@config["full_title"]}.pdf")
71
+ end
72
+
73
+ desc "Prepare for generation"
74
+ task :prepare do
75
+ @home_dir = File.dirname(__FILE__)
76
+ Dir.chdir('api-doc')
77
+ @root_url = "file://localhost#{Dir.pwd}/"
78
+
79
+ @config = YAML::load( File.open( "#{@home_dir}/config.yaml" ) )
80
+ @db = YAML::load( File.open( "#{@home_dir}/database.yaml" ) )
81
+
82
+ doc = Tilt.new("index.md.erb").render(self, :db=>@db, :helper=>Helper.new, :config=>@config)
83
+ md = Redcarpet::Markdown.new(Redcarpet::Render::HTML.new(render_options={}), extensions={:tables=>true})
84
+ #toc = Redcarpet::Markdown.new(Redcarpet::Render::HTML_TOC.new())
85
+ @content = md.render(doc)
86
+
87
+ @html = ERB.new(File.open('template.html.erb','r').read()).result(binding())
88
+ @html = @html.gsub(/root_url/,@root_url)
89
+
90
+ end
91
+
92
+ def example(name)
93
+ return "TODO" if name.nil?
94
+ name = name.to_s
95
+ File.open("#{@home_dir}/json_examples/#{name}.json".downcase,'r').read()
96
+ end
Binary file