apipie-dsl 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +485 -0
- data/app/controllers/apipie_dsl/apipie_dsls_controller.rb +190 -0
- data/app/helpers/apipie_dsl_helper.rb +110 -0
- data/app/public/apipie_dsl/javascripts/apipie_dsl.js +6 -0
- data/app/public/apipie_dsl/javascripts/bundled/bootstrap-collapse.js +138 -0
- data/app/public/apipie_dsl/javascripts/bundled/bootstrap.js +1726 -0
- data/app/public/apipie_dsl/javascripts/bundled/jquery.js +5 -0
- data/app/public/apipie_dsl/javascripts/bundled/prettify.js +28 -0
- data/app/public/apipie_dsl/stylesheets/application.css +7 -0
- data/app/public/apipie_dsl/stylesheets/bundled/bootstrap-responsive.min.css +12 -0
- data/app/public/apipie_dsl/stylesheets/bundled/bootstrap.min.css +689 -0
- data/app/public/apipie_dsl/stylesheets/bundled/prettify.css +30 -0
- data/app/views/apipie_dsl/apipie_dsls/_index_class_meth.erb +11 -0
- data/app/views/apipie_dsl/apipie_dsls/_index_class_prop.erb +13 -0
- data/app/views/apipie_dsl/apipie_dsls/_languages.erb +6 -0
- data/app/views/apipie_dsl/apipie_dsls/_metadata.erb +1 -0
- data/app/views/apipie_dsl/apipie_dsls/_method.erb +34 -0
- data/app/views/apipie_dsl/apipie_dsls/_method_detail.erb +58 -0
- data/app/views/apipie_dsl/apipie_dsls/_params.html.erb +47 -0
- data/app/views/apipie_dsl/apipie_dsls/_params_plain.html.erb +19 -0
- data/app/views/apipie_dsl/apipie_dsls/_property.erb +24 -0
- data/app/views/apipie_dsl/apipie_dsls/_property_detail.erb +35 -0
- data/app/views/apipie_dsl/apipie_dsls/_raises.html.erb +23 -0
- data/app/views/apipie_dsl/apipie_dsls/_returns.html.erb +53 -0
- data/app/views/apipie_dsl/apipie_dsls/apipie_dsl_404.html.erb +17 -0
- data/app/views/apipie_dsl/apipie_dsls/class.html.erb +75 -0
- data/app/views/apipie_dsl/apipie_dsls/custom_help.html.erb +10 -0
- data/app/views/apipie_dsl/apipie_dsls/getting_started.html.erb +4 -0
- data/app/views/apipie_dsl/apipie_dsls/index.html.erb +72 -0
- data/app/views/apipie_dsl/apipie_dsls/method.html.erb +52 -0
- data/app/views/apipie_dsl/apipie_dsls/plain.html.erb +116 -0
- data/app/views/apipie_dsl/apipie_dsls/static.html.erb +158 -0
- data/app/views/layouts/apipie_dsl/apipie_dsl.html.erb +26 -0
- data/lib/apipie-dsl.rb +3 -0
- data/lib/apipie_dsl.rb +28 -0
- data/lib/apipie_dsl/Rakefile +6 -0
- data/lib/apipie_dsl/apipie_dsl_module.rb +51 -0
- data/lib/apipie_dsl/application.rb +321 -0
- data/lib/apipie_dsl/class_description.rb +107 -0
- data/lib/apipie_dsl/configuration.rb +87 -0
- data/lib/apipie_dsl/dsl.rb +596 -0
- data/lib/apipie_dsl/errors.rb +68 -0
- data/lib/apipie_dsl/exception_description.rb +39 -0
- data/lib/apipie_dsl/markup.rb +41 -0
- data/lib/apipie_dsl/method_description.rb +112 -0
- data/lib/apipie_dsl/parameter_description.rb +152 -0
- data/lib/apipie_dsl/railtie.rb +15 -0
- data/lib/apipie_dsl/return_description.rb +71 -0
- data/lib/apipie_dsl/routing.rb +17 -0
- data/lib/apipie_dsl/see_description.rb +35 -0
- data/lib/apipie_dsl/static_dispatcher.rb +70 -0
- data/lib/apipie_dsl/tag_list_description.rb +11 -0
- data/lib/apipie_dsl/tasks/apipie_dsl/cache.rake +43 -0
- data/lib/apipie_dsl/tasks/apipie_dsl/static.rake +43 -0
- data/lib/apipie_dsl/tasks/apipie_dsl/static_json.rake +29 -0
- data/lib/apipie_dsl/tasks_utils.rb +137 -0
- data/lib/apipie_dsl/utils.rb +83 -0
- data/lib/apipie_dsl/validator.rb +479 -0
- data/lib/apipie_dsl/version.rb +5 -0
- data/lib/generators/apipie_dsl/install/install_generator.rb +21 -0
- data/lib/generators/apipie_dsl/install/templates/initializer.rb.erb +9 -0
- data/lib/generators/apipie_dsl/views_generator.rb +14 -0
- data/test/test_helper.rb +6 -0
- metadata +220 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
module ApipieDSL
|
2
|
+
module Routing
|
3
|
+
module MapperExtensions
|
4
|
+
def apipie_dsl(options = {})
|
5
|
+
namespace 'apipie_dsl', path: ApipieDSL.configuration.doc_base_url do
|
6
|
+
get 'apipie_dsl_checksum', to: 'apipie_dsls#apipie_dsl_checksum', format: 'json'
|
7
|
+
constraints(version: /[^\/]+/, section: /[^\/]+/, class: /[^\/]+/,
|
8
|
+
method: /[^\/]+/) do
|
9
|
+
get(options.reverse_merge("(:version)/(:section)/(:class)/(:method)" => 'apipie_dsls#index', as: :apipie_dsl))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
ActionDispatch::Routing::Mapper.send :include, ApipieDSL::Routing::MapperExtensions
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ApipieDSL
|
4
|
+
class SeeDescription
|
5
|
+
attr_reader :link, :description
|
6
|
+
|
7
|
+
def initialize(method, options = {})
|
8
|
+
@method = method
|
9
|
+
@link = options[:link]
|
10
|
+
@description = options[:desc] || options[:description]
|
11
|
+
@scope = options[:scope]
|
12
|
+
end
|
13
|
+
|
14
|
+
def docs
|
15
|
+
{ link: link, url: see_url, description: description }
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def see_url
|
21
|
+
method_description = if @scope
|
22
|
+
if @scope.is_a?(ApipieDSL::ClassDescription)
|
23
|
+
@scope.method_description(@method)
|
24
|
+
else
|
25
|
+
ApipieDSL.get_method_description(@scope.to_s, @method)
|
26
|
+
end
|
27
|
+
else
|
28
|
+
ApipieDSL.get_method_description(@method)
|
29
|
+
end
|
30
|
+
raise ArgumentError, "Method #{@method} referenced in 'see' does not exist." if method_description.nil?
|
31
|
+
|
32
|
+
method_description.doc_url(method_description.klass.sections.first)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ApipieDSL
|
4
|
+
class FileHandler
|
5
|
+
def initialize(root)
|
6
|
+
@root = root.chomp('/')
|
7
|
+
@compiled_root = /^#{Regexp.escape(root)}/
|
8
|
+
@file_server = ::Rack::File.new(@root)
|
9
|
+
end
|
10
|
+
|
11
|
+
def match?(path)
|
12
|
+
# Replace all null bytes
|
13
|
+
path = ::Rack::Utils.unescape(path || '').gsub(/\x0/, '')
|
14
|
+
|
15
|
+
full_path = path.empty? ? @root : File.join(@root, path)
|
16
|
+
paths = "#{full_path}#{ext}"
|
17
|
+
|
18
|
+
matches = Dir[paths]
|
19
|
+
match = matches.detect { |m| File.file?(m) }
|
20
|
+
if match
|
21
|
+
match.sub!(@compiled_root, '')
|
22
|
+
match
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def call(env)
|
27
|
+
@file_server.call(env)
|
28
|
+
end
|
29
|
+
|
30
|
+
def ext
|
31
|
+
@ext ||= begin
|
32
|
+
ext = cache_extension
|
33
|
+
"{,#{ext},/index#{ext}}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def cache_extension
|
38
|
+
if ::ActionController::Base.respond_to?(:default_static_extension)
|
39
|
+
::ActionController::Base.default_static_extension
|
40
|
+
else
|
41
|
+
::ActionController::Base.page_cache_extension
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class StaticDispatcher
|
48
|
+
# Dispatches the static files. Similar to ActionDispatch::Static, but
|
49
|
+
# it supports different baseurl configurations
|
50
|
+
def initialize(app, path)
|
51
|
+
@app = app
|
52
|
+
@file_handler = ApipieDSL::FileHandler.new(path)
|
53
|
+
end
|
54
|
+
|
55
|
+
def call(env)
|
56
|
+
@baseurl ||= ApipieDSL.configuration.doc_base_url
|
57
|
+
case env['REQUEST_METHOD']
|
58
|
+
when 'GET', 'HEAD'
|
59
|
+
path = env['PATH_INFO'].sub("#{@baseurl}/","/apipie_dsl/").chomp('/')
|
60
|
+
|
61
|
+
if match = @file_handler.match?(path)
|
62
|
+
env["PATH_INFO"] = match
|
63
|
+
return @file_handler.call(env)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
@app.call(env)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../tasks_utils'
|
4
|
+
|
5
|
+
namespace :apipie_dsl do
|
6
|
+
desc 'Generate cache to avoid production dependencies on markup languages'
|
7
|
+
task :cache, [:include_json] => :environment do |_task, args|
|
8
|
+
args.with_defaults(include_json: false)
|
9
|
+
include_json = %w[1 true].include?(args[:include_json])
|
10
|
+
time_start = Time.now
|
11
|
+
puts "#{time_start} | Started"
|
12
|
+
ApipieDSL::TasksUtils.with_loaded_documentation do
|
13
|
+
puts "#{Time.now} | Documents loaded..."
|
14
|
+
([nil] + ApipieDSL.configuration.languages).each do |lang|
|
15
|
+
I18n.locale = lang || ApipieDSL.configuration.default_locale
|
16
|
+
puts "#{Time.now} | Processing docs for #{lang}"
|
17
|
+
cache_dir = ENV['OUT'] || ApipieDSL.configuration.cache_dir
|
18
|
+
file_base = File.join(cache_dir, ApipieDSL.configuration.doc_base_url)
|
19
|
+
subdir = File.basename(file_base)
|
20
|
+
ApipieDSL.available_versions.each do |version|
|
21
|
+
file_base_version = File.join(file_base, version)
|
22
|
+
ApipieDSL.configuration.sections.each do |section|
|
23
|
+
ApipieDSL.url_prefix = "../../#{subdir}"
|
24
|
+
doc = ApipieDSL.docs(version, nil, nil, lang, section)
|
25
|
+
doc[:docs][:link_extension] = "#{lang_ext(lang)}.html"
|
26
|
+
ApipieDSL::TasksUtils.generate_index_page(file_base_version, doc, include_json, true, lang, section)
|
27
|
+
ApipieDSL.url_prefix = "../../../#{subdir}"
|
28
|
+
section_out = "#{file_base_version}/#{section}"
|
29
|
+
ApipieDSL::TasksUtils.generate_class_pages(version, section_out, doc, include_json, lang, section)
|
30
|
+
ApipieDSL.url_prefix = "../../../../#{subdir}"
|
31
|
+
ApipieDSL::TasksUtils.generate_method_pages(version, section_out, doc, include_json, lang, section)
|
32
|
+
end
|
33
|
+
ApipieDSL.url_prefix = "../../#{subdir}"
|
34
|
+
doc = ApipieDSL.docs(version, nil, nil, lang)
|
35
|
+
doc[:docs][:link_extension] = "#{lang_ext(lang)}.html"
|
36
|
+
ApipieDSL::TasksUtils.generate_help_page(file_base_version, doc, true, lang)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
time_end = Time.now
|
41
|
+
puts "#{time_end} | Finished in #{time_end - time_start}"
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../tasks_utils'
|
4
|
+
|
5
|
+
namespace :apipie_dsl do
|
6
|
+
desc 'Generate static documentation'
|
7
|
+
if defined?(Rails)
|
8
|
+
task :static, [:version, :include_json] => :environment do |_task, args|
|
9
|
+
ApipieDSL::TasksUtils.with_loaded_documentation do
|
10
|
+
args.with_defaults(
|
11
|
+
version: ApipieDSL.configuration.default_version,
|
12
|
+
include_json: false
|
13
|
+
)
|
14
|
+
include_json = %w[1 true].include?(args[:include_json])
|
15
|
+
out = ENV['OUT'] || File.join(::Rails.root, ApipieDSL.configuration.doc_path, 'dsldoc')
|
16
|
+
subdir = File.basename(out)
|
17
|
+
ApipieDSL::TasksUtils.copy_jscss(out)
|
18
|
+
ApipieDSL.configuration.version_in_url = false
|
19
|
+
([nil] + ApipieDSL.configuration.languages).each do |lang|
|
20
|
+
I18n.locale = lang || ApipieDSL.configuration.default_locale
|
21
|
+
ApipieDSL.url_prefix = "../#{subdir}"
|
22
|
+
doc = ApipieDSL.docs(args[:version], nil, nil, lang)
|
23
|
+
doc[:docs][:link_extension] = "#{lang_ext(lang)}.html"
|
24
|
+
ApipieDSL::TasksUtils.generate_one_page(out, doc, lang)
|
25
|
+
ApipieDSL::TasksUtils.generate_plain_page(out, doc, lang)
|
26
|
+
ApipieDSL.configuration.sections.each do |section|
|
27
|
+
ApipieDSL.url_prefix = "../#{subdir}"
|
28
|
+
doc = ApipieDSL.docs(args[:version], nil, nil, lang, section)
|
29
|
+
doc[:docs][:link_extension] = "#{lang_ext(lang)}.html"
|
30
|
+
ApipieDSL::TasksUtils.generate_index_page(out, doc, include_json, false, lang, section)
|
31
|
+
ApipieDSL.url_prefix = "../../#{subdir}"
|
32
|
+
section_out = "#{out}/#{section}"
|
33
|
+
ApipieDSL::TasksUtils.generate_class_pages(args[:version], section_out, doc, include_json, lang, section)
|
34
|
+
ApipieDSL.url_prefix = "../../../#{subdir}"
|
35
|
+
ApipieDSL::TasksUtils.generate_method_pages(args[:version], section_out, doc, include_json, lang, section)
|
36
|
+
end
|
37
|
+
ApipieDSL.url_prefix = "../#{subdir}"
|
38
|
+
ApipieDSL::TasksUtils.generate_help_page(out, doc, false, lang)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../tasks_utils'
|
4
|
+
|
5
|
+
namespace :apipie_dsl do
|
6
|
+
desc 'Generate static documentation json'
|
7
|
+
if defined?(Rails)
|
8
|
+
task static_json: :environment do |_task, args|
|
9
|
+
ApipieDSL::TasksUtils.with_loaded_documentation do
|
10
|
+
args.with_defaults(version: ApipieDSL.configuration.default_version)
|
11
|
+
out = ENV['OUT'] || File.join(::Rails.root, ApipieDSL.configuration.doc_path, 'dsldoc')
|
12
|
+
([nil] + ApipieDSL.configuration.languages).each do |lang|
|
13
|
+
doc = ApipieDSL.docs(args[:version], nil, nil, lang)
|
14
|
+
ApipieDSL::TasksUtils.generate_json_page(out, doc, lang)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
else
|
19
|
+
task :static_json do |_task, args|
|
20
|
+
ApipieDSL.reload_documentation
|
21
|
+
args.with_defaults(version: ApipieDSL.configuration.default_version)
|
22
|
+
out = ENV['OUT'] || File.join(Rake.original_dir, ApipieDSL.configuration.doc_path, 'dsldoc')
|
23
|
+
([nil] + ApipieDSL.configuration.languages).each do |lang|
|
24
|
+
doc = ApipieDSL.docs(args[:version], nil, nil, lang)
|
25
|
+
ApipieDSL::TasksUtils.generate_json_page(out, doc, lang)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require_relative '../../app/helpers/apipie_dsl_helper'
|
5
|
+
|
6
|
+
module ApipieDSL
|
7
|
+
module TasksUtils
|
8
|
+
def self.generate_json_page(file_base, doc, lang = nil)
|
9
|
+
FileUtils.mkdir_p(file_base) unless File.exist?(file_base)
|
10
|
+
|
11
|
+
filename = "schema_apipie_dsl#{lang_ext(lang)}.json"
|
12
|
+
File.open("#{file_base}/#{filename}", 'w') { |file| file.write(JSON.pretty_generate(doc)) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.renderer
|
16
|
+
return @renderer if @renderer
|
17
|
+
|
18
|
+
@renderer = if defined?(Rails)
|
19
|
+
rails_renderer
|
20
|
+
else
|
21
|
+
simple_renderer
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.simple_renderer
|
26
|
+
raise NotImplementedError
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.rails_renderer
|
30
|
+
base_paths = [File.expand_path('../../app/views/apipie_dsl/apipie_dsls', __dir__)]
|
31
|
+
base_paths.unshift("#{Rails.root}/app/views/apipie_dsl/apipie_dsls") if File.directory?("#{Rails.root}/app/views/apipie_dsl/apipie_dsls")
|
32
|
+
|
33
|
+
layouts_paths = [File.expand_path('../../app/views/layouts', __dir__)]
|
34
|
+
layouts_paths.unshift("#{Rails.root}/app/views/layouts") if File.directory?("#{Rails.root}/app/views/layouts/apipie_dsl")
|
35
|
+
paths = ActionView::PathSet.new(base_paths + layouts_paths)
|
36
|
+
r_renderer = ActionView::Base.new(ActionController::Base.append_view_path(paths), {})
|
37
|
+
r_renderer.singleton_class.send(:include, ::ApipieDslHelper)
|
38
|
+
r_renderer
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.render_page(file_name, template, variables, layout = 'apipie_dsl')
|
42
|
+
File.open(file_name, 'w') do |f|
|
43
|
+
variables.each do |var, val|
|
44
|
+
renderer.instance_variable_set("@#{var}", val)
|
45
|
+
end
|
46
|
+
f.write(renderer.render(template: template.to_s,
|
47
|
+
layout: (layout && "apipie_dsl/#{layout}")))
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.generate_one_page(file_base, doc, lang = nil)
|
52
|
+
FileUtils.mkdir_p(File.dirname(file_base)) unless File.exist?(File.dirname(file_base))
|
53
|
+
|
54
|
+
render_page("#{file_base}/#{File.basename(file_base)}-onepage#{lang_ext(lang)}.html", 'static',
|
55
|
+
doc: doc[:docs], language: lang,
|
56
|
+
languages: ApipieDSL.configuration.languages)
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.generate_plain_page(file_base, doc, lang = nil)
|
60
|
+
FileUtils.mkdir_p(File.dirname(file_base)) unless File.exist?(File.dirname(file_base))
|
61
|
+
|
62
|
+
render_page("#{file_base}/#{File.basename(file_base)}-plain#{lang_ext(lang)}.html", 'plain',
|
63
|
+
{ doc: doc[:docs], language: lang,
|
64
|
+
languages: ApipieDSL.configuration.languages }, nil)
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.generate_index_page(file_base, doc, include_json = false, show_versions = false, lang = nil, section = nil)
|
68
|
+
versions = show_versions && ApipieDSL.available_versions
|
69
|
+
section_file = "#{file_base}/#{section}"
|
70
|
+
FileUtils.mkdir_p(File.dirname(section_file)) unless File.exist?(File.dirname(section_file))
|
71
|
+
render_page("#{section_file}#{lang_ext(lang)}.html",
|
72
|
+
'index', doc: doc[:docs], versions: versions, language: lang,
|
73
|
+
languages: ApipieDSL.configuration.languages, section: section)
|
74
|
+
File.open("#{file_base}#{lang_ext(lang)}.json", 'w') { |f| f << doc.to_json } if include_json
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.generate_class_pages(version, file_base, doc, include_json = false, lang = nil, section = nil)
|
78
|
+
doc[:docs][:classes].each do |class_name, class_desc|
|
79
|
+
next unless ApipieDslHelper.in_section?(section, class_name)
|
80
|
+
|
81
|
+
class_file_base = File.join(file_base, class_desc[:id])
|
82
|
+
FileUtils.mkdir_p(File.dirname(class_file_base)) unless File.exist?(File.dirname(class_file_base))
|
83
|
+
|
84
|
+
doc = ApipieDSL.docs(version, class_name, nil, lang)
|
85
|
+
doc[:docs][:link_extension] = (lang ? ".#{lang}.html" : '.html')
|
86
|
+
render_page("#{class_file_base}#{lang_ext(lang)}.html", 'class',
|
87
|
+
doc: doc[:docs], klass: doc[:docs][:classes].first,
|
88
|
+
language: lang, languages: ApipieDSL.configuration.languages)
|
89
|
+
File.open("#{class_file_base}#{lang_ext(lang)}.json", 'w') { |f| f << doc.to_json } if include_json
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.generate_method_pages(version, file_base, doc, include_json = false, lang = nil, section = nil)
|
94
|
+
doc[:docs][:classes].each do |class_name, class_params|
|
95
|
+
next unless ApipieDslHelper.in_section?(section, class_name)
|
96
|
+
|
97
|
+
class_params[:methods].each do |method|
|
98
|
+
method_file_base = File.join(file_base, class_name.to_s, method[:name].to_s)
|
99
|
+
FileUtils.mkdir_p(File.dirname(method_file_base)) unless File.exist?(File.dirname(method_file_base))
|
100
|
+
|
101
|
+
doc = ApipieDSL.docs(version, class_name, method[:name], lang)
|
102
|
+
doc[:docs][:link_extension] = (lang ? ".#{lang}.html" : '.html')
|
103
|
+
render_page("#{method_file_base}#{lang_ext(lang)}.html", 'method',
|
104
|
+
doc: doc[:docs], klass: doc[:docs][:classes].first,
|
105
|
+
method: doc[:docs][:classes].first[:methods].first,
|
106
|
+
language: lang, languages: ApipieDSL.configuration.languages)
|
107
|
+
|
108
|
+
File.open("#{method_file_base}#{lang_ext(lang)}.json", 'w') { |f| f << doc.to_json } if include_json
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def self.generate_help_page(file_base, doc, show_versions = false, lang = nil)
|
114
|
+
versions = show_versions && ApipieDSL.available_versions
|
115
|
+
section_file = "#{file_base}/help"
|
116
|
+
FileUtils.mkdir_p(File.dirname(section_file)) unless File.exist?(File.dirname(section_file))
|
117
|
+
render_page("#{section_file}#{lang_ext(lang)}.html", 'custom_help',
|
118
|
+
doc: doc[:docs], versions: versions, language: lang,
|
119
|
+
languages: ApipieDSL.configuration.languages, section: 'help')
|
120
|
+
end
|
121
|
+
|
122
|
+
def self.lang_ext(lang = nil)
|
123
|
+
lang ? ".#{lang}" : ''
|
124
|
+
end
|
125
|
+
|
126
|
+
def self.copy_jscss(dest)
|
127
|
+
src = File.expand_path('../../app/public/apipie_dsl', __dir__)
|
128
|
+
FileUtils.mkdir_p dest
|
129
|
+
FileUtils.cp_r "#{src}/.", dest
|
130
|
+
end
|
131
|
+
|
132
|
+
def self.with_loaded_documentation
|
133
|
+
ApipieDSL.reload_documentation
|
134
|
+
yield
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# rubocop:disable Style/FrozenStringLiteralComment
|
2
|
+
module ApipieDSL
|
3
|
+
module Utils
|
4
|
+
attr_accessor :url_prefix
|
5
|
+
|
6
|
+
def superclass_for(klass_or_module)
|
7
|
+
return klass_or_module.superclass if klass_or_module.respond_to?(:superclass)
|
8
|
+
|
9
|
+
parent_name = to_s.split('::')[-2]
|
10
|
+
return nil if parent_name.nil?
|
11
|
+
|
12
|
+
Module.const_get(parent_name)
|
13
|
+
end
|
14
|
+
|
15
|
+
def markup_to_html(text)
|
16
|
+
return '' if text.nil?
|
17
|
+
|
18
|
+
if ApipieDSL.configuration.markup.respond_to?(:to_html)
|
19
|
+
ApipieDSL.configuration.markup.to_html(text)
|
20
|
+
else
|
21
|
+
text
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def request_script_name
|
26
|
+
Thread.current[:apipie_dsl_req_script_name] || ''
|
27
|
+
end
|
28
|
+
|
29
|
+
def request_script_name=(script_name)
|
30
|
+
Thread.current[:apipie_dsl_req_script_name] = script_name
|
31
|
+
end
|
32
|
+
|
33
|
+
def full_url(path)
|
34
|
+
unless @url_prefix
|
35
|
+
@url_prefix = request_script_name.to_s
|
36
|
+
@url_prefix << ApipieDSL.configuration.doc_base_url
|
37
|
+
end
|
38
|
+
path = path.sub(%r{^/}, '')
|
39
|
+
ret = "#{@url_prefix}/#{path}"
|
40
|
+
ret.insert(0, '/') unless ret =~ %r{\A[./]}
|
41
|
+
ret.sub!(%r{/*\Z}, '')
|
42
|
+
ret
|
43
|
+
end
|
44
|
+
|
45
|
+
def include_javascripts
|
46
|
+
%w[bundled/jquery.js
|
47
|
+
bundled/bootstrap-collapse.js
|
48
|
+
bundled/prettify.js
|
49
|
+
apipie_dsl.js ].map do |file|
|
50
|
+
"<script type='text/javascript' src='#{ApipieDSL.full_url("javascripts/#{file}")}'></script>"
|
51
|
+
end.join("\n").html_safe
|
52
|
+
end
|
53
|
+
|
54
|
+
def include_stylesheets
|
55
|
+
%w[bundled/bootstrap.min.css
|
56
|
+
bundled/prettify.css
|
57
|
+
bundled/bootstrap-responsive.min.css ].map do |file|
|
58
|
+
"<link type='text/css' rel='stylesheet' href='#{ApipieDSL.full_url("stylesheets/#{file}")}'/>"
|
59
|
+
end.join("\n").html_safe
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
if RUBY_VERSION < '2.5.0'
|
64
|
+
class Hash
|
65
|
+
def transform_keys
|
66
|
+
result = {}
|
67
|
+
each do |key, value|
|
68
|
+
new_key = yield key
|
69
|
+
result[new_key] = value
|
70
|
+
end
|
71
|
+
result
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
if defined? Rails
|
76
|
+
class Module
|
77
|
+
# https://github.com/rails/rails/pull/35035
|
78
|
+
def as_json(options = nil)
|
79
|
+
name
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
# rubocop:enable Style/FrozenStringLiteralComment
|