apipie-rails 0.1.0 → 0.1.1

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.
@@ -2,6 +2,14 @@
2
2
  Changelog
3
3
  ===========
4
4
 
5
+ v0.1.1
6
+ ------
7
+
8
+ * backward compatibility with Ruby 1.8 [#218](https://github.com/Apipie/apipie-rails/pull/218) [@mbacovsky][]
9
+ * checksum calculation is lazy and respect use_cache config [#220](https://github.com/Apipie/apipie-rails/pull/220) [@mbacovsky][]
10
+ * fix generating the cache in production environment [#223](https://github.com/Apipie/apipie-rails/pull/223) [@iNecas][]
11
+ * fix loading regression with SafeYAML [#224](https://github.com/Apipie/apipie-rails/pull/224) [@iNecas][]
12
+
5
13
  v0.1.0
6
14
  ------
7
15
 
@@ -95,3 +103,4 @@ v0.0.15
95
103
  [@mtparet]: https://github.com/mtparet
96
104
  [@yonpols]: https://github.com/yonpols
97
105
  [@mkrajewski]: https://github.com/mkrajewski
106
+ [@iNecas]: https://github.com/iNecas
data/README.rst CHANGED
@@ -549,6 +549,10 @@ authenticate
549
549
  show_all_examples
550
550
  Set this to true to set show_in_doc=1 in all recorded examples
551
551
 
552
+ link_extension
553
+ The extension to use for API pages ('.html' by default). Link extensions
554
+ in static API docs cannot be changed from '.html'.
555
+
552
556
  Example:
553
557
 
554
558
  .. code:: ruby
@@ -908,15 +912,13 @@ And in your apipie initializer allow checksum calculation
908
912
 
909
913
  Apipie.configuration.update_checksum = true
910
914
 
911
- and make sure your documentation is loaded.
912
-
913
- .. code::
914
-
915
- Apipie.reload_documentation
916
915
 
917
916
  By default the header is added to responses for ``config.doc_base_url`` and ``/api``.
918
917
  It can be changed in configuration (see `Configuration Reference`_ for details).
919
918
 
919
+ The checksum calculation is lazy, done with first request. If you run with ``use_cache = true``,
920
+ do not forget to run the rake task ``apipie:cache``.
921
+
920
922
 
921
923
  ===================
922
924
  Tests Integration
@@ -17,10 +17,12 @@ Gem::Specification.new do |s|
17
17
  s.require_paths = ["lib"]
18
18
 
19
19
  s.add_dependency "rails", ">= 3.0.10"
20
+ s.add_dependency 'json'
20
21
  s.add_development_dependency "rspec-rails"
21
22
  s.add_development_dependency "sqlite3"
22
23
  s.add_development_dependency "minitest"
23
24
  s.add_development_dependency "maruku"
24
25
  s.add_development_dependency "RedCloth"
25
26
  s.add_development_dependency "rake"
27
+ s.add_development_dependency "rdoc"
26
28
  end
@@ -43,6 +43,7 @@ module Apipie
43
43
 
44
44
  @versions = Apipie.available_versions
45
45
  @doc = @doc[:docs]
46
+ @doc[:link_extension] = Apipie.configuration.link_extension
46
47
  if @doc[:resources].blank?
47
48
  render "getting_started" and return
48
49
  end
@@ -10,5 +10,5 @@
10
10
  </h1>
11
11
 
12
12
  <% if @doc %>
13
- Try going to <a href='<%= @doc[:doc_url] %>.html'><%= @doc[:name] %> API documentation homepage</a>
13
+ Try going to <a href='<%= @doc[:doc_url] %><%= @doc[:link_extension] %>'><%= @doc[:name] %> API documentation homepage</a>
14
14
  <% end %>
@@ -1,5 +1,5 @@
1
1
  <ul class='breadcrumb'>
2
- <li class='active'><a href='<%= @doc[:doc_url] %>.html'><%= @doc[:name] %> <%= @doc[:resources].values.first[:version] %></a></li>
2
+ <li class='active'><a href='<%= @doc[:doc_url] %><%= @doc[:link_extension] %>'><%= @doc[:name] %> <%= @doc[:resources].values.first[:version] %></a></li>
3
3
  <% if @versions && @versions.size > 1 %>
4
4
  <li class='pull-right'>
5
5
  <%= @versions.collect { |v| link_to v, Apipie.full_url(v) }.join(' / ').html_safe %>
@@ -13,7 +13,7 @@
13
13
 
14
14
  <% @doc[:resources].sort_by(&:first).each do |key, api| %>
15
15
  <h2>
16
- <a href='<%= api[:doc_url] %>.html'>
16
+ <a href='<%= api[:doc_url] %><%= @doc[:link_extension] %>'>
17
17
  <%= api[:name] %>
18
18
  </a><br>
19
19
  <small><%= api[:short_description] %></small>
@@ -29,7 +29,7 @@
29
29
  <% api[:methods].each do |m| %>
30
30
  <% m[:apis].each do |a| %>
31
31
  <tr>
32
- <td><a href='<%= m[:doc_url] %>.html'><%= a[:http_method] %> <%= a[:api_url] %></a></td>
32
+ <td><a href='<%= m[:doc_url] %><%= @doc[:link_extension] %>'><%= a[:http_method] %> <%= a[:api_url] %></a></td>
33
33
  <td width='60%'><%= a[:short_description] %></td>
34
34
  </tr>
35
35
  <% end %>
@@ -1,10 +1,10 @@
1
1
  <ul class='breadcrumb'>
2
2
  <li>
3
- <a href='<%= @doc[:doc_url] %>.html'><%= @doc[:name] %> <%= @resource[:version] %></a>
3
+ <a href='<%= @doc[:doc_url] %><%= @doc[:link_extension] %>'><%= @doc[:name] %> <%= @resource[:version] %></a>
4
4
  <span class='divider'>/</span>
5
5
  </li>
6
6
  <li>
7
- <a href='<%= @resource[:doc_url] %>.html'>
7
+ <a href='<%= @resource[:doc_url] %><%= @doc[:link_extension] %>'>
8
8
  <%= @resource[:name] %>
9
9
  <% if @resource[:version] %><% end %>
10
10
  </a>
@@ -24,7 +24,7 @@
24
24
 
25
25
  <div>
26
26
  <% unless @method[:see].empty? %>
27
- Also see <%= @method[:see].map { |s| link_to(s[:description], "#{s[:link]}.html") }.to_sentence.html_safe %>.
27
+ Also see <%= @method[:see].map { |s| link_to(s[:description], "#{s[:link]}#{@doc[:link_extension]}") }.to_sentence.html_safe %>.
28
28
  <% end %>
29
29
 
30
30
  <%= render(:partial => "method_detail", :locals => {:method => @method, :h_level => 2}) %>
@@ -1,6 +1,6 @@
1
1
  <ul class='breadcrumb'>
2
2
  <li>
3
- <a href='<%= @doc[:doc_url] %>.html'><%= @doc[:name] %> <%= @resource[:version] %></a>
3
+ <a href='<%= @doc[:doc_url] %><%= @doc[:link_extension] %>'><%= @doc[:name] %> <%= @resource[:version] %></a>
4
4
  <span class='divider'>/</span>
5
5
  </li>
6
6
  <li class='active'>
@@ -36,7 +36,7 @@
36
36
  <% @resource[:methods].each do |m| %>
37
37
  <hr>
38
38
  <div class='pull-right small'>
39
- <a href='<%= m[:doc_url] %>.html'> >>> </a>
39
+ <a href='<%= m[:doc_url] %><%= @doc[:link_extension] %>'> >>> </a>
40
40
  </div>
41
41
  <div>
42
42
  <% m[:apis].each do |api| %>
@@ -53,7 +53,7 @@
53
53
  </div>
54
54
 
55
55
  <% unless m[:see].empty? %>
56
- Also see <%= m[:see].map { |s| link_to(s[:description], "#{s[:link]}.html") }.to_sentence.html_safe %>.
56
+ Also see <%= m[:see].map { |s| link_to(s[:description], "#{s[:link]}#{@doc[:link_extension]}") }.to_sentence.html_safe %>.
57
57
  <% end %>
58
58
 
59
59
  <div id='description-<%= m[:name] %>' class='collapse accordion-body'>
@@ -211,7 +211,7 @@ module Apipie
211
211
  if File.exists?(tape_file)
212
212
  #if SafeYAML gem is enabled, it will load examples as an array of Hash, instead of hash
213
213
  if YAML.respond_to?(:safe_load_file) && defined?(SafeYAML)
214
- @recorded_examples = SafeYAML.load_file(tape_file, :safe=>false)
214
+ @recorded_examples = YAML.load_file(tape_file, :safe=>false)
215
215
  else
216
216
  @recorded_examples = YAML.load_file(tape_file)
217
217
  end
@@ -259,19 +259,32 @@ module Apipie
259
259
  end
260
260
 
261
261
  def reload_documentation
262
- rails_mark_classes_for_reload
263
- init_env
264
- reload_examples
262
+ if rails_mark_classes_for_reload
263
+ # if we are not able to mark classes for reload, we
264
+ # can't reinit the env, as we would loose the data that were
265
+ # already loaded
266
+ init_env
267
+ reload_examples
268
+ end
265
269
 
266
270
  api_controllers_paths.each do |f|
267
271
  load_controller_from_file f
268
272
  end
269
- @checksum = compute_checksum if Apipie.configuration.update_checksum
273
+ @checksum = nil if Apipie.configuration.update_checksum
270
274
  end
271
275
 
272
276
  def compute_checksum
273
- all_docs = Apipie.available_versions.inject({}) do |all, version|
274
- all.update(version => Apipie.to_json(version))
277
+ if Apipie.configuration.use_cache?
278
+ file_base = File.join(Apipie.configuration.cache_dir, Apipie.configuration.doc_base_url)
279
+ all_docs = {}
280
+ Dir.glob(file_base + '/*.json').sort.each do |f|
281
+ all_docs[File.basename(f, '.json')] = JSON.parse(File.read(f))
282
+ end
283
+ else
284
+ reload_documentation if available_versions == []
285
+ all_docs = Apipie.available_versions.inject({}) do |all, version|
286
+ all.update(version => Apipie.to_json(version))
287
+ end
275
288
  end
276
289
  Digest::MD5.hexdigest(JSON.dump(all_docs))
277
290
  end
@@ -341,9 +354,15 @@ module Apipie
341
354
  # docs, therefore we just force to reload all the code. This
342
355
  # happens only when reload_controllers is set to true and only
343
356
  # when showing the documentation.
357
+ #
358
+ # If cache_classes is set to false, it does nothing,
359
+ # as this would break loading of the controllers.
344
360
  def rails_mark_classes_for_reload
345
- ActiveSupport::DescendantsTracker.clear
346
- ActiveSupport::Dependencies.clear
361
+ unless Rails.application.config.cache_classes
362
+ ActiveSupport::DescendantsTracker.clear
363
+ ActiveSupport::Dependencies.clear
364
+ return true
365
+ end
347
366
  end
348
367
 
349
368
  end
@@ -5,7 +5,8 @@ module Apipie
5
5
  :api_base_url, :doc_base_url, :required_by_default, :layout,
6
6
  :default_version, :debug, :version_in_url, :namespaced_resources,
7
7
  :validate, :validate_value, :validate_presence, :authenticate, :doc_path,
8
- :show_all_examples, :process_params, :update_checksum, :checksum_path
8
+ :show_all_examples, :process_params, :update_checksum, :checksum_path,
9
+ :link_extension
9
10
 
10
11
  alias_method :validate?, :validate
11
12
  alias_method :required_by_default?, :required_by_default
@@ -130,6 +131,7 @@ module Apipie
130
131
  @process_params = false
131
132
  @checksum_path = [@doc_base_url, '/api/']
132
133
  @update_checksum = false
134
+ @link_extension = ".html"
133
135
  end
134
136
  end
135
137
  end
@@ -3,7 +3,7 @@ module Apipie
3
3
  module MapperExtensions
4
4
  def apipie
5
5
  namespace "apipie", :path => Apipie.configuration.doc_base_url do
6
- get 'apipie_checksum', to: "apipies#apipie_checksum", :format => "json"
6
+ get 'apipie_checksum', :to => "apipies#apipie_checksum", :format => "json"
7
7
  constraints(:version => /[^\/]+/) do
8
8
  get("(:version)/(:resource)/(:method)" => "apipies#index", :as => :apipie)
9
9
  end
@@ -365,7 +365,9 @@ module Apipie
365
365
  end
366
366
 
367
367
  def self.build(param_description, argument, options, block)
368
- self.new(param_description, block, options[:param_group]) if block.is_a?(Proc) && block.arity == 0 && argument == Array
368
+ # in Ruby 1.8.x the arity on block without args is -1
369
+ # while in Ruby 1.9+ it is 0
370
+ self.new(param_description, block, options[:param_group]) if block.is_a?(Proc) && block.arity <= 0 && argument == Array
369
371
  end
370
372
 
371
373
  def description
@@ -1,3 +1,3 @@
1
1
  module Apipie
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -25,6 +25,7 @@ namespace :apipie do
25
25
  Apipie.configuration.version_in_url = false
26
26
  Apipie.url_prefix = "./#{subdir}"
27
27
  doc = Apipie.to_json(args[:version])
28
+ doc[:docs][:link_extension] = '.html'
28
29
  generate_one_page(out, doc)
29
30
  generate_plain_page(out, doc)
30
31
  generate_index_page(out, doc)
@@ -264,7 +264,8 @@ describe UsersController do
264
264
  end
265
265
  context "with bad input" do
266
266
  it "should raise an error" do
267
- expect{ put :update,
267
+ expect{
268
+ put :update,
268
269
  {
269
270
  :id => 5,
270
271
  :user => {
@@ -276,7 +277,7 @@ describe UsersController do
276
277
  :comment => 'comment1'
277
278
  },
278
279
  {
279
- :comment => {bad_input: 5}
280
+ :comment => {:bad_input => 5}
280
281
  }
281
282
  ]
282
283
  }
@@ -64,6 +64,10 @@ Apipie.configure do |config|
64
64
  # specify disqus site shortname to show discusion on each page
65
65
  # to show it in custom layout, use `render 'disqus' if Apipie.configuration.use_disqus?`
66
66
  # config.disqus_shortname = 'paveltest'
67
+
68
+ # Hide '.html' extensions. Note that '.html' extensions are forced
69
+ # when generating static documentation
70
+ # config.link_extension = ""
67
71
  end
68
72
 
69
73
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apipie-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-03-03 00:00:00.000000000 Z
13
+ date: 2014-03-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -28,6 +28,22 @@ dependencies:
28
28
  - - ! '>='
29
29
  - !ruby/object:Gem::Version
30
30
  version: 3.0.10
31
+ - !ruby/object:Gem::Dependency
32
+ name: json
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
31
47
  - !ruby/object:Gem::Dependency
32
48
  name: rspec-rails
33
49
  requirement: !ruby/object:Gem::Requirement
@@ -124,6 +140,22 @@ dependencies:
124
140
  - - ! '>='
125
141
  - !ruby/object:Gem::Version
126
142
  version: '0'
143
+ - !ruby/object:Gem::Dependency
144
+ name: rdoc
145
+ requirement: !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ! '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ type: :development
152
+ prerelease: false
153
+ version_requirements: !ruby/object:Gem::Requirement
154
+ none: false
155
+ requirements:
156
+ - - ! '>='
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
127
159
  description: Rails REST API documentation tool
128
160
  email:
129
161
  - pajkycz@gmail.com