restapi 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. data/app/controllers/restapi/restapis_controller.rb +24 -0
  2. data/app/public/{javascripts → restapi/javascripts/bundled}/backbone.js +0 -0
  3. data/app/public/{javascripts → restapi/javascripts/bundled}/bootstrap-collapse.js +0 -0
  4. data/app/public/{javascripts → restapi/javascripts/bundled}/bootstrap.js +0 -0
  5. data/app/public/{javascripts → restapi/javascripts/bundled}/jquery-1.7.2.js +0 -0
  6. data/app/public/{javascripts → restapi/javascripts/bundled}/json2.js +0 -0
  7. data/app/public/{javascripts → restapi/javascripts/bundled}/underscore.js +0 -0
  8. data/app/public/{javascripts/restapi → restapi/javascripts}/jst.js +0 -0
  9. data/app/public/{javascripts/restapi → restapi/javascripts}/restapi.js +3 -1
  10. data/app/public/{javascripts/restapi → restapi/javascripts}/routers/documentation_router.js +0 -0
  11. data/app/public/{stylesheets/restapi → restapi/stylesheets}/application.css +0 -0
  12. data/app/public/{stylesheets → restapi/stylesheets/bundled}/bootstrap-responsive.css +0 -0
  13. data/app/public/{stylesheets → restapi/stylesheets/bundled}/bootstrap-responsive.min.css +0 -0
  14. data/app/public/{stylesheets → restapi/stylesheets/bundled}/bootstrap.css +0 -0
  15. data/app/public/{stylesheets → restapi/stylesheets/bundled}/bootstrap.min.css +0 -0
  16. data/app/views/restapi/restapis/index.html.erb +34 -0
  17. data/lib/restapi/application.rb +3 -3
  18. data/lib/restapi/helpers.rb +19 -0
  19. data/lib/restapi/restapi_module.rb +4 -10
  20. data/lib/restapi/routing.rb +5 -7
  21. data/lib/restapi/static_dispatcher.rb +58 -0
  22. data/lib/restapi/version.rb +1 -2
  23. data/restapi.gemspec +2 -3
  24. data/spec/controllers/restapis_controller_spec.rb +2 -2
  25. data/spec/dummy/config/environments/production.rb +2 -2
  26. data/spec/dummy/config/initializers/restapi.rb +2 -1
  27. data/spec/dummy/config/routes.rb +1 -1
  28. metadata +38 -22
  29. data/app/controllers/restapis_controller.rb +0 -11
  30. data/app/views/restapis/index.html.erb +0 -47
@@ -0,0 +1,24 @@
1
+ module Restapi
2
+ class RestapisController < ActionController::Base
3
+ layout false
4
+
5
+ def index
6
+ respond_to do |format|
7
+ format.json { render :json => Restapi.to_json(params[:resource], params[:method]) }
8
+ format.html
9
+ end
10
+ end
11
+
12
+ protected
13
+
14
+ helper_method :restapi_javascript_src
15
+ def restapi_javascript_src(file)
16
+ "#{Restapi.configuration.doc_base_url}/javascripts/#{file}"
17
+ end
18
+
19
+ helper_method :restapi_stylesheet_src
20
+ def restapi_stylesheet_src(file)
21
+ "#{Restapi.configuration.doc_base_url}/stylesheets/#{file}"
22
+ end
23
+ end
24
+ end
@@ -6,7 +6,9 @@ var Restapi = {
6
6
  new Restapi.Routers.Documentation();
7
7
  var base = '/' + window.location.pathname.split('/')[1];
8
8
  Backbone.history.start({pushState: true, root: base});
9
- }
9
+ },
10
+
11
+ baseurl: function() { return document.location.toString().replace(/#.*/,""); }
10
12
  };
11
13
 
12
14
  $(document).ready(function() {
@@ -0,0 +1,34 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>API documentation</title>
5
+ <% %w[bundled/bootstrap.css application.css bundled/bootstrap-responsive.css].each do |file| %>
6
+ <link type="text/css" rel="stylesheet" href="<%= Restapi.full_url("stylesheets/#{file}") %>"/>
7
+ <% end %>
8
+ <!-- IE6-8 support of HTML5 elements -->
9
+ <!--[if lt IE 9]>
10
+ <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
11
+ <![endif]-->
12
+ </head>
13
+ <body>
14
+ <div class="container">
15
+ <div class="row">
16
+ <div id='container'></div>
17
+ </div>
18
+ <hr>
19
+ <footer></footer>
20
+ </div>
21
+ <% %w[
22
+ bundled/jquery-1.7.2.js
23
+ bundled/json2.js
24
+ bundled/underscore.js
25
+ bundled/backbone.js
26
+ bundled/bootstrap-collapse.js
27
+
28
+ restapi.js
29
+ jst.js
30
+ routers/documentation_router.js ].each do |file| %>
31
+ <script type="text/javascript" src="<%= Restapi.full_url("javascripts/#{file}") %>"></script>
32
+ <% end %>
33
+ </body>
34
+ </html>
@@ -1,4 +1,5 @@
1
1
  require 'ostruct'
2
+ require 'restapi/static_dispatcher'
2
3
 
3
4
  module Restapi
4
5
 
@@ -7,8 +8,7 @@ module Restapi
7
8
  # we need engine just for serving static assets
8
9
  class Engine < Rails::Engine
9
10
  initializer "static assets" do |app|
10
- # app.middleware.use ::ActionDispatch::Static, "#{root}/app/public"
11
- app.middleware.insert_after ::ActionDispatch::Static, ::ActionDispatch::Static, "#{root}/app/public"
11
+ app.middleware.use ::Restapi::StaticDispatcher, "#{root}/app/public", Restapi.configuration.doc_base_url
12
12
  end
13
13
  end
14
14
 
@@ -152,4 +152,4 @@ module Restapi
152
152
  end
153
153
 
154
154
  end
155
- end
155
+ end
@@ -0,0 +1,19 @@
1
+ module Restapi
2
+ module Helpers
3
+ def rdoc
4
+ @rdoc ||= RDoc::Markup::ToHtml.new
5
+ end
6
+
7
+ def full_url(path)
8
+ unless @prefix
9
+ @prefix = ""
10
+ if rails_prefix = ENV["RAILS_RELATIVE_URL_ROOT"]
11
+ @prefix << rails_prefix
12
+ end
13
+ @prefix << Restapi.configuration.doc_base_url
14
+ end
15
+ path = path.sub(/^\//,"")
16
+ "#{@prefix}/#{path}"
17
+ end
18
+ end
19
+ end
@@ -1,16 +1,10 @@
1
+ require "restapi/helpers"
1
2
  require "restapi/application"
2
3
  require "ostruct"
3
4
  require "erb"
4
5
 
5
6
  module Restapi
6
-
7
- def self.rdoc
8
- @rdoc ||= RDoc::Markup::ToHtml.new
9
- end
10
-
11
- def self.convert_markup(text)
12
- Restapi.rdoc.convert(text.strip_heredoc)
13
- end
7
+ extend Restapi::Helpers
14
8
 
15
9
  def self.app
16
10
  @application ||= Restapi::Application.new
@@ -37,7 +31,7 @@ module Restapi
37
31
  attr_accessor :app_name, :app_info, :copyright, :markup_language, :validate, :api_base_url, :doc_base_url
38
32
 
39
33
  def app_info=(text)
40
- @app_info = Restapi.convert_markup(text)
34
+ @app_info = Restapi.rdoc.convert(text.strip_heredoc)
41
35
  end
42
36
 
43
37
  def initialize
@@ -47,7 +41,7 @@ module Restapi
47
41
  @copyright = nil
48
42
  @validate = true
49
43
  @api_base_url = ""
50
- @doc_base_url = "/apidoc"
44
+ @doc_base_url = "/restapi"
51
45
  end
52
46
  end
53
47
 
@@ -1,15 +1,13 @@
1
1
  module Restapi
2
2
  module Routing
3
3
  module MapperExtensions
4
- def restapi(route = "/apidoc")
5
-
6
- Restapi.configuration.doc_base_url = route
7
-
8
- self.get("#{route}/(:resource)/(:method)" => "restapis#index")
9
-
4
+ def restapi
5
+ namespace "restapi", :path => Restapi.configuration.doc_base_url do
6
+ get("(:resource)/(:method)" => "restapis#index" )
7
+ end
10
8
  end
11
9
  end
12
10
  end
13
11
  end
14
-
12
+
15
13
  ActionDispatch::Routing::Mapper.send :include, Restapi::Routing::MapperExtensions
@@ -0,0 +1,58 @@
1
+ module Restapi
2
+
3
+ class FileHandler
4
+ def initialize(root)
5
+ @root = root.chomp('/')
6
+ @compiled_root = /^#{Regexp.escape(root)}/
7
+ @file_server = ::Rack::File.new(@root)
8
+ end
9
+
10
+ def match?(path)
11
+ path = path.dup
12
+
13
+ full_path = path.empty? ? @root : File.join(@root, ::Rack::Utils.unescape(path))
14
+ paths = "#{full_path}#{ext}"
15
+
16
+ matches = Dir[paths]
17
+ match = matches.detect { |m| File.file?(m) }
18
+ if match
19
+ match.sub!(@compiled_root, '')
20
+ match
21
+ end
22
+ end
23
+
24
+ def call(env)
25
+ @file_server.call(env)
26
+ end
27
+
28
+ def ext
29
+ @ext ||= begin
30
+ ext = ::ActionController::Base.page_cache_extension
31
+ "{,#{ext},/index#{ext}}"
32
+ end
33
+ end
34
+ end
35
+
36
+ class StaticDispatcher
37
+ # Dispatches the statis files. Simillar to ActionDispatch::Static, but
38
+ # it supports different baseurl configurations
39
+ def initialize(app, path, baseurl)
40
+ @app = app
41
+ @baseurl = baseurl
42
+ @file_handler = Restapi::FileHandler.new(path)
43
+ end
44
+
45
+ def call(env)
46
+ case env['REQUEST_METHOD']
47
+ when 'GET', 'HEAD'
48
+ path = env['PATH_INFO'].sub("#{@baseurl}/","/restapi/").chomp('/')
49
+ if match = @file_handler.match?(path)
50
+ env["PATH_INFO"] = match
51
+ return @file_handler.call(env)
52
+ end
53
+ end
54
+
55
+ @app.call(env)
56
+ end
57
+ end
58
+ end
@@ -1,4 +1,3 @@
1
1
  module Restapi
2
- # gem version
3
- VERSION = "0.0.1"
2
+ VERSION = '0.0.2'
4
3
  end
@@ -7,11 +7,10 @@ Gem::Specification.new do |s|
7
7
  s.version = Restapi::VERSION
8
8
  s.authors = ["Pavel Pokorny"]
9
9
  s.email = ["pajkycz@gmail.com"]
10
- s.homepage = "http://github.com/Pajk/restapi"
10
+ s.homepage = "http://github.com/Pajk/rails-restapi"
11
11
  s.summary = %q{REST API documentation tool}
12
12
  s.description = %q{Maintain your API documentation up to date!}
13
13
 
14
- s.rubyforge_project = "restapi"
15
14
 
16
15
  s.files = `git ls-files`.split("\n")
17
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -19,5 +18,5 @@ Gem::Specification.new do |s|
19
18
 
20
19
  s.add_development_dependency "rspec-rails"
21
20
  s.add_development_dependency "rcov"
22
- # s.add_runtime_dependency "rest-client"
21
+ s.add_runtime_dependency "rest-client"
23
22
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe RestapisController do
3
+ describe Restapi::RestapisController do
4
4
 
5
5
  describe "GET index" do
6
6
 
@@ -10,4 +10,4 @@ describe RestapisController do
10
10
  assert_response :success
11
11
  end
12
12
  end
13
- end
13
+ end
@@ -10,7 +10,7 @@ Dummy::Application.configure do
10
10
  config.action_controller.perform_caching = true
11
11
 
12
12
  # Specifies the header that your server uses for sending files
13
- config.action_dispatch.x_sendfile_header = "X-Sendfile"
13
+ # config.action_dispatch.x_sendfile_header = "X-Sendfile"
14
14
 
15
15
  # For nginx:
16
16
  # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
@@ -29,7 +29,7 @@ Dummy::Application.configure do
29
29
 
30
30
  # Disable Rails's static asset server
31
31
  # In production, Apache or nginx will already do this
32
- config.serve_static_assets = true
32
+ # config.serve_static_assets = true
33
33
 
34
34
  # Enable serving of images, stylesheets, and javascripts from an asset server
35
35
  # config.action_controller.asset_host = "http://assets.example.com"
@@ -24,7 +24,8 @@ Restapi.configure do |config|
24
24
  "Welcome aboard: You're riding Ruby on Rails!"
25
25
  EOS
26
26
  config.copyright = "&copy; 2012 Pavel Pokorny"
27
+ config.doc_base_url = "/restapi"
27
28
  config.api_base_url = "/api"
28
29
  config.markup_language = :rdoc
29
30
  # config.validate = false
30
- end
31
+ end
@@ -8,7 +8,7 @@ Dummy::Application.routes.draw do
8
8
  resources :dogs
9
9
  resources :twitter_example
10
10
 
11
- restapi "/docs"
11
+ restapi
12
12
 
13
13
  # The priority is based upon order of creation:
14
14
  # first created -> highest priority.
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restapi
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Pavel Pokorny
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-04-08 00:00:00 Z
18
+ date: 2012-04-18 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rspec-rails
@@ -45,6 +45,20 @@ dependencies:
45
45
  version: "0"
46
46
  type: :development
47
47
  version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: rest-client
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ type: :runtime
61
+ version_requirements: *id003
48
62
  description: Maintain your API documentation up to date!
49
63
  email:
50
64
  - pajkycz@gmail.com
@@ -64,32 +78,34 @@ files:
64
78
  - MIT-LICENSE
65
79
  - README.rdoc
66
80
  - Rakefile
67
- - app/controllers/restapis_controller.rb
68
- - app/public/javascripts/backbone.js
69
- - app/public/javascripts/bootstrap-collapse.js
70
- - app/public/javascripts/bootstrap.js
71
- - app/public/javascripts/jquery-1.7.2.js
72
- - app/public/javascripts/json2.js
73
- - app/public/javascripts/restapi/jst.js
74
- - app/public/javascripts/restapi/restapi.js
75
- - app/public/javascripts/restapi/routers/documentation_router.js
76
- - app/public/javascripts/underscore.js
77
- - app/public/stylesheets/bootstrap-responsive.css
78
- - app/public/stylesheets/bootstrap-responsive.min.css
79
- - app/public/stylesheets/bootstrap.css
80
- - app/public/stylesheets/bootstrap.min.css
81
- - app/public/stylesheets/restapi/application.css
82
- - app/views/restapis/index.html.erb
81
+ - app/controllers/restapi/restapis_controller.rb
82
+ - app/public/restapi/javascripts/bundled/backbone.js
83
+ - app/public/restapi/javascripts/bundled/bootstrap-collapse.js
84
+ - app/public/restapi/javascripts/bundled/bootstrap.js
85
+ - app/public/restapi/javascripts/bundled/jquery-1.7.2.js
86
+ - app/public/restapi/javascripts/bundled/json2.js
87
+ - app/public/restapi/javascripts/bundled/underscore.js
88
+ - app/public/restapi/javascripts/jst.js
89
+ - app/public/restapi/javascripts/restapi.js
90
+ - app/public/restapi/javascripts/routers/documentation_router.js
91
+ - app/public/restapi/stylesheets/application.css
92
+ - app/public/restapi/stylesheets/bundled/bootstrap-responsive.css
93
+ - app/public/restapi/stylesheets/bundled/bootstrap-responsive.min.css
94
+ - app/public/restapi/stylesheets/bundled/bootstrap.css
95
+ - app/public/restapi/stylesheets/bundled/bootstrap.min.css
96
+ - app/views/restapi/restapis/index.html.erb
83
97
  - lib/restapi.rb
84
98
  - lib/restapi/application.rb
85
99
  - lib/restapi/dsl_definition.rb
86
100
  - lib/restapi/error_description.rb
101
+ - lib/restapi/helpers.rb
87
102
  - lib/restapi/method_description.rb
88
103
  - lib/restapi/param_description.rb
89
104
  - lib/restapi/railtie.rb
90
105
  - lib/restapi/resource_description.rb
91
106
  - lib/restapi/restapi_module.rb
92
107
  - lib/restapi/routing.rb
108
+ - lib/restapi/static_dispatcher.rb
93
109
  - lib/restapi/validator.rb
94
110
  - lib/restapi/version.rb
95
111
  - restapi.gemspec
@@ -132,7 +148,7 @@ files:
132
148
  - spec/dummy/public/stylesheets/.gitkeep
133
149
  - spec/dummy/script/rails
134
150
  - spec/spec_helper.rb
135
- homepage: http://github.com/Pajk/restapi
151
+ homepage: http://github.com/Pajk/rails-restapi
136
152
  licenses: []
137
153
 
138
154
  post_install_message:
@@ -160,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
176
  version: "0"
161
177
  requirements: []
162
178
 
163
- rubyforge_project: restapi
179
+ rubyforge_project:
164
180
  rubygems_version: 1.8.21
165
181
  signing_key:
166
182
  specification_version: 3
@@ -1,11 +0,0 @@
1
- class RestapisController < ActionController::Base
2
- layout false
3
-
4
- def index
5
- respond_to do |format|
6
- format.json { render :json => Restapi.to_json(params[:resource], params[:method]) }
7
- format.html { render 'index' }
8
- end
9
- end
10
-
11
- end
@@ -1,47 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>API documentation</title>
5
-
6
- <link type="text/css" rel="stylesheet" href="/stylesheets/bootstrap.css">
7
- <link type="text/css" rel="stylesheet" href="/stylesheets/restapi/application.css">
8
- <link type="text/css" rel="stylesheet" href="/stylesheets/bootstrap-responsive.css">
9
- <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
10
- <!--[if lt IE 9]>
11
- <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
12
- <![endif]-->
13
- </head>
14
- <body>
15
- <!-- <div class="navbar navbar-fixed-top">
16
- <div class="navbar-inner">
17
- <div class="container-fluid">
18
- <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
19
- <span class="icon-bar"></span>
20
- <span class="icon-bar"></span>
21
- <span class="icon-bar"></span>
22
- </a>
23
- <a id="api-title" class="brand" href="">Loading...</a>
24
- </div>
25
- </div>
26
- </div>
27
- </div> -->
28
-
29
- <div class="container">
30
- <div class="row">
31
- <div id='container'></div>
32
- </div>
33
- <hr>
34
- <footer></footer>
35
-
36
- </div>
37
-
38
- <script type="text/javascript" src="/javascripts/jquery-1.7.2.js"></script>
39
- <script type="text/javascript" src="/javascripts/json2.js"></script>
40
- <script type="text/javascript" src="/javascripts/underscore.js"></script>
41
- <script type="text/javascript" src="/javascripts/backbone.js"></script>
42
- <script type="text/javascript" src="/javascripts/bootstrap-collapse.js"></script>
43
- <script type="text/javascript" src="/javascripts/restapi/restapi.js"></script>
44
- <script type="text/javascript" src="/javascripts/restapi/jst.js"></script>
45
- <script type="text/javascript" src="/javascripts/restapi/routers/documentation_router.js"></script>
46
- </body>
47
- </html>