apipie-dsl 2.2.4 → 2.2.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c3c16c0754fc726e6eae8d4aa5fe9286be77a788fe2ddc144945cb611051c395
4
- data.tar.gz: d180942cfe36c2ddc2fbe21bcad0bbce6d779a38cc570465726343323a08783f
3
+ metadata.gz: 06cfa92a5d84bc9ca6db419ec1948d66541b414a57a68cc5316c335142b98c8f
4
+ data.tar.gz: 5b2a03b6201ddcd2a61fd8e481be673a0383e06b012ba433f0b76cf266094f05
5
5
  SHA512:
6
- metadata.gz: 1b0cf349abab9287a0c2535dae30179d44db7fd0eda28e78bbdb2d1c6d6b8b68efa1950d6e46ccd792b051f91a6572b020f2821cbc87ee3f073c9ed90fe87e8b
7
- data.tar.gz: 31ec3ebce45e980f4abb156c9741095ca604b2616a8f967ec53484d9a0635fdcc5c463b8e593dfa2c6ad8a61af1eb4f420c53224880da687a7933f1dd604c19a
6
+ metadata.gz: f9684334d6aa6a515e4993601ca0b5f53187aebe2e64de43baad932f95abc51f5730945b8d81260baf61cc4af934b235d51bef161593334f4369111f9fc568e5
7
+ data.tar.gz: 77a23f53bb07eb0795a709f15b492e1cad04912770e0f32328092ba5cbe6cd1c70bc94f05564a05c97fa397daa8ac61ac9f44f6d0ab8fe9dd784364eebf4389d
@@ -12,8 +12,49 @@ module ApipieDslHelper
12
12
  end
13
13
  end
14
14
 
15
- def escaped_method_name(method, escaping = '')
16
- return method.gsub('?', escaping) if method.is_a?(String)
15
+ def escaped_method_name(method, options = {})
16
+ options[:escaping] ||= ''
17
+ options[:pattern] ||= /[?]/
18
+ return method.gsub(options[:pattern], options[:escaping]) if method.is_a?(String)
19
+ end
20
+
21
+ def apipie_dsl_menu
22
+ content_tag(:ul, class: 'breadcrumb') do
23
+ content = dsl_sections.map do |section|
24
+ content_tag(:li, class: section == @section ? 'active' : '') do
25
+ link_to(t("apipie_dsl.#{section}"), @doc[:doc_url] + section_ext(section) + @doc[:link_extension])
26
+ end
27
+ end.join(' | ').html_safe
28
+
29
+ unless ApipieDSL.configuration.help_layout.nil?
30
+ content += content_tag(:li, class: "pull-right #{'active' if @section == 'help'}") do
31
+ link_to(t("apipie_dsl.help"), @doc[:doc_url] + section_ext('help') + @doc[:link_extension])
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ def apipie_dsl_example(source, output = nil)
38
+ text = content_tag(:p, _('Example input:')) +
39
+ content_tag(:pre, source)
40
+
41
+ if output.present?
42
+ text += content_tag(:p, _('Example output:')) +
43
+ content_tag(:pre, output)
44
+ end
45
+
46
+ text.html_safe
47
+ end
48
+
49
+ def apipie_erb_wrap(content, mode: :loud, open_trim: false, close_trim: false)
50
+ case mode
51
+ when :loud
52
+ '<%= ' + content + " #{close_trim ? '-' : ''}%>"
53
+ when :comment
54
+ '<%# ' + content + " #{close_trim ? '-' : ''}%>"
55
+ else
56
+ "<%#{open_trim ? '- ' : ' '}" + content + " #{close_trim ? '-' : ''}%>"
57
+ end
17
58
  end
18
59
 
19
60
  def resolve_default(default)
@@ -22,6 +63,8 @@ module ApipieDslHelper
22
63
  'nil'
23
64
  when ''
24
65
  "\"\""
66
+ when Symbol
67
+ ":#{default}"
25
68
  else
26
69
  default
27
70
  end
@@ -58,6 +101,9 @@ module ApipieDslHelper
58
101
  # Try to convert to a constant in case of LazyValidator usage
59
102
  # Will raise const missing exception in case of wrong usage of the method
60
103
  if obj.is_a?(String)
104
+ ref = ApipieDSL.refs[version][ApipieDSL.get_class_name(obj)]
105
+ return "<a href='#{ref.doc_url(ref.sections.first)}#{link_extension}'>#{obj}</a>" if ref
106
+
61
107
  obj = ApipieDSL.configuration.rails? ? obj.constantize : obj.split('::').reduce(::Module, :const_get)
62
108
  end
63
109
  return obj.to_s unless [::Module, ::Class, ::Array].include?(obj.class)
@@ -1,7 +1,7 @@
1
1
  <% if prop[:show] %>
2
2
  <tr>
3
3
  <td>
4
- <a href='<%= doc_url %><%= link_extension %>#link-description-<%= escaped_method_name(prop[:name], '_') %>'>
4
+ <a href='<%= doc_url %><%= link_extension %>#link-description-<%= escaped_method_name(prop[:name], escaping: '_') %>'>
5
5
  <%= prop[:name] %>
6
6
  </a>
7
7
  <% if prop[:deprecated] %>
@@ -8,7 +8,7 @@
8
8
  <div>
9
9
  <% (meth[:signature] || [method_signature(meth)]).each do |signature| %>
10
10
  <h2>
11
- <a href='#description-<%= escaped_method_name(meth[:name], '_') %>'
11
+ <a href='#description-<%= escaped_method_name(meth[:name], escaping: '_') %>'
12
12
  class='accordion-toggle'
13
13
  data-toggle='collapse'
14
14
  data-parent='#meth-accordion'>
@@ -26,10 +26,10 @@
26
26
  </div>
27
27
 
28
28
  <% unless meth[:see].empty? %>
29
- Also see <%= meth[:see].map { |s| link_to(s[:description], "#{s[:link]}#{link_extension}") }.to_sentence.html_safe %>.
29
+ Also see <%= meth[:see].map { |s| link_to(s[:description] || s[:link], "#{s[:url]}#{link_extension}") }.to_sentence.html_safe %>.
30
30
  <% end %>
31
31
 
32
- <div id='description-<%= escaped_method_name(meth[:name], '_') %>' class='collapse accordion-body'>
32
+ <div id='description-<%= escaped_method_name(meth[:name], escaping: '_') %>' class='collapse accordion-body'>
33
33
  <%= render partial: 'method_detail', locals: { method: meth, h_level: 3 } %>
34
34
  </div>
35
35
  </td>
@@ -4,7 +4,7 @@
4
4
  <td>
5
5
  <div>
6
6
  <h2>
7
- <a id='link-description-<%= escaped_method_name(prop[:name], '_') %>' href='#description-<%= escaped_method_name(prop[:name], '_') %>'
7
+ <a id='link-description-<%= escaped_method_name(prop[:name], escaping: '_', pattern: /[?!]/) %>' href='#description-<%= escaped_method_name(prop[:name], escaping: '_', pattern: /[?!]/) %>'
8
8
  class='accordion-toggle'
9
9
  data-toggle='collapse'
10
10
  data-parent='#prop-accordion'>
@@ -15,7 +15,7 @@
15
15
  </h2>
16
16
  </div>
17
17
 
18
- <div id='description-<%= escaped_method_name(prop[:name], '_') %>' class='collapse accordion-body'>
18
+ <div id='description-<%= escaped_method_name(prop[:name], escaping: '_', pattern: /[?!]/) %>' class='collapse accordion-body'>
19
19
  <%= render partial: 'property_detail', locals: { property: prop, h_level: 3 } %>
20
20
  </div>
21
21
  </td>
@@ -1,18 +1,4 @@
1
- <ul class='breadcrumb'>
2
- <% dsl_sections.each do |section| %>
3
- <% if section == @section %>
4
- <li class='active'><a href='<%= @doc[:doc_url] %><%= section_ext(section) %><%= @doc[:link_extension] %>'><%= t("apipie_dsl.#{@section}") %></a></li>
5
- <% else %>
6
- <li><a href='<%= @doc[:doc_url] %><%= section_ext(section) %><%= @doc[:link_extension] %>'><%= t("apipie_dsl.#{section}") %></a></li>
7
- <% end %>
8
- <% end %>
9
- <% unless ApipieDSL.configuration.help_layout.nil? %>
10
- <li class='pull-right'>
11
- <% section = 'help' %>
12
- <a href='<%= @doc[:doc_url] %><%= section_ext(section) %><%= @doc[:link_extension] %>'><%= t("apipie_dsl.#{section}") %></a>
13
- </li>
14
- <% end %>
15
- </ul>
1
+ <%= apipie_dsl_menu %>
16
2
  <ul class='breadcrumb'>
17
3
  <li>
18
4
  <a href='<%= @doc[:doc_url] %><%= section_ext(@section) %><%= @doc[:link_extension] %>'><%= @doc[:name] %> <%= @klass[:version] %></a>
@@ -1,12 +1,4 @@
1
1
  <% if ApipieDSL.configuration.help_layout %>
2
- <ul class='breadcrumb'>
3
- <% dsl_sections.each do |section| %>
4
- <li><a href='<%= @doc[:doc_url] %><%= section_ext(section) %><%= @doc[:link_extension] %>'><%= t("apipie_dsl.#{section}") %></a></li>
5
- <% end %>
6
- <li class='active pull-right'>
7
- <% section = 'help' %>
8
- <a href='<%= @doc[:doc_url] %><%= section_ext(section) %><%= @doc[:link_extension] %>'><%= t("apipie_dsl.#{section}") %></a>
9
- </li>
10
- </ul>
2
+ <%= apipie_dsl_menu %>
11
3
  <%= render_help %>
12
4
  <% end %>
@@ -1,18 +1,5 @@
1
- <ul class='breadcrumb'>
2
- <% dsl_sections.each do |section| %>
3
- <% if section == @section %>
4
- <li class='active'><a href='<%= @doc[:doc_url] %><%= section_ext(section) %><%= @doc[:link_extension] %>'><%= t("apipie_dsl.#{@section}") %></a></li>
5
- <% else %>
6
- <li><a href='<%= @doc[:doc_url] %><%= section_ext(section) %><%= @doc[:link_extension] %>'><%= t("apipie_dsl.#{section}") %></a></li>
7
- <% end %>
8
- <% end %>
9
- <% unless ApipieDSL.configuration.help_layout.nil? %>
10
- <li class='pull-right'>
11
- <% section = 'help' %>
12
- <a href='<%= @doc[:doc_url] %><%= section_ext(section) %><%= @doc[:link_extension] %>'><%= t("apipie_dsl.#{section}") %></a>
13
- </li>
14
- <% end %>
15
- </ul>
1
+ <%= apipie_dsl_menu %>
2
+
16
3
  <ul class='breadcrumb'>
17
4
  <li class='active'><a href='<%= @doc[:doc_url] %><%= section_ext(@section) %><%= @doc[:link_extension] %>'><%= @doc[:name] %> <%= current_version(@doc[:classes]) %></a></li>
18
5
  <%= render(partial: 'languages', locals: { doc_url: @doc[:doc_url] + section_ext(@section) }) %>
@@ -1,18 +1,4 @@
1
- <ul class='breadcrumb'>
2
- <% dsl_sections.each do |section| %>
3
- <% if section == @section %>
4
- <li class='active'><a href='<%= @doc[:doc_url] %><%= section_ext(section) %><%= @doc[:link_extension] %>'><%= t("apipie_dsl.#{@section}") %></a></li>
5
- <% else %>
6
- <li><a href='<%= @doc[:doc_url] %><%= section_ext(section) %><%= @doc[:link_extension] %>'><%= t("apipie_dsl.#{section}") %></a></li>
7
- <% end %>
8
- <% end %>
9
- <% unless ApipieDSL.configuration.help_layout.nil? %>
10
- <li class='pull-right'>
11
- <% section = 'help' %>
12
- <a href='<%= @doc[:doc_url] %><%= section_ext(section) %><%= @doc[:link_extension] %>'><%= t("apipie_dsl.#{section}") %></a>
13
- </li>
14
- <% end %>
15
- </ul>
1
+ <%= apipie_dsl_menu %>
16
2
  <ul class='breadcrumb'>
17
3
  <li>
18
4
  <a href='<%= @doc[:doc_url] %><%= section_ext(@section) %><%= @doc[:link_extension] %>'><%= @doc[:name] %> <%= @klass[:version] %></a>
@@ -12,7 +12,7 @@ module ApipieDSL
12
12
  @properties = []
13
13
  @version = version || ApipieDSL.configuration.default_version
14
14
  @parent = ApipieDSL.get_class_description(ApipieDSL.superclass_for(klass), version)
15
- @refs = []
15
+ @refs = [@name]
16
16
  @sections = []
17
17
  @show = true
18
18
  update_from_dsl_data(dsl_data) if dsl_data
@@ -20,17 +20,22 @@ module ApipieDSL
20
20
 
21
21
  def update_from_dsl_data(dsl_data)
22
22
  @name = dsl_data[:class_name] if dsl_data[:class_name]
23
- @full_description = ApipieDSL.markup_to_html(dsl_data[:description])
24
- @short_description = dsl_data[:short_description]
23
+ @full_description = ApipieDSL.markup_to_html(dsl_data[:description]) if dsl_data[:description]
24
+ @short_description = dsl_data[:short_description] || @short_description
25
25
  @tag_list = dsl_data[:tag_list]
26
- @metadata = dsl_data[:meta]
26
+ if dsl_data[:meta]&.is_a?(Hash)
27
+ @metadata&.merge!(dsl_data[:meta])
28
+ elsif dsl_data[:meta]
29
+ @metadata = dsl_data[:meta]
30
+ end
27
31
  @deprecated = dsl_data[:deprecated] || false
28
32
  @show = dsl_data[:show] || @show
29
- @properties = (dsl_data[:properties] || []).map do |args|
30
- ApipieDSL::MethodDescription.from_dsl_data(self, args)
33
+ prop_names = @properties.map(&:name)
34
+ (dsl_data[:properties] || []).each do |args|
35
+ @properties << ApipieDSL::MethodDescription.from_dsl_data(self, args) unless prop_names.include?(args.first.to_s)
31
36
  end
32
- @refs = dsl_data[:refs] || [@name]
33
- @sections = dsl_data[:sections] || @sections
37
+ @refs = (@refs + dsl_data[:refs]).uniq if dsl_data[:refs]
38
+ @sections = (@sections + dsl_data[:sections]).uniq if dsl_data[:sections]
34
39
  return unless dsl_data[:app_info]
35
40
 
36
41
  ApipieDSL.configuration.app_info[version] = dsl_data[:app_info]
@@ -65,10 +70,6 @@ module ApipieDSL
65
70
  @methods.values
66
71
  end
67
72
 
68
- def property_descriptions
69
- @properties
70
- end
71
-
72
73
  def doc_url(section = nil)
73
74
  crumbs = []
74
75
  crumbs << version if ApipieDSL.configuration.version_in_url
@@ -347,7 +347,7 @@ module ApipieDSL
347
347
  include ApipieDSL::Klass
348
348
  include ApipieDSL::Method
349
349
 
350
- attr_reader :class_scope
350
+ attr_accessor :class_scope
351
351
 
352
352
  def initialize(class_scope)
353
353
  @class_scope = class_scope
@@ -385,7 +385,7 @@ module ApipieDSL
385
385
  end
386
386
 
387
387
  def self.extension_data
388
- @extension_data ||= []
388
+ @extension_data ||= { methods: [] }
389
389
  end
390
390
 
391
391
  # rubocop:disable Metrics/AbcSize
@@ -553,16 +553,19 @@ module ApipieDSL
553
553
 
554
554
  delegatee = Delegatee.instance_for(self).with(&block)
555
555
  delegatee.dsl_data[:update_only] = true
556
- # Don't eval the block, since it will be evaluated after method is defined
556
+
557
557
  return if context == :method
558
558
 
559
- # Currently method extensions are supported only
559
+ # Save instance to reuse when actual scope is set
560
+ Delegatee.extension_data[:class] = delegatee
560
561
  Delegatee.instance_reset
561
562
  end
562
563
 
563
564
  def prepended(klass)
564
565
  super
565
- Delegatee.extension_data.each do |method_name, dsl_data|
566
+ Delegatee.extension_data[:class]&.class_scope = klass
567
+ Delegatee.extension_data[:class]&.eval_dsl_for(:class)
568
+ Delegatee.extension_data[:methods].each do |method_name, dsl_data|
566
569
  class_scope = klass
567
570
  if dsl_data[:update_only]
568
571
  class_name = ApipieDSL.get_class_name(class_scope)
@@ -592,7 +595,7 @@ module ApipieDSL
592
595
  return if Delegatee.instance.nil?
593
596
 
594
597
  dsl_data = Delegatee.instance.eval_dsl_for(:method)
595
- Delegatee.extension_data << [method_name, dsl_data]
598
+ Delegatee.extension_data[:methods] << [method_name, dsl_data]
596
599
  ensure
597
600
  Delegatee.instance_reset
598
601
  end
@@ -23,7 +23,7 @@ namespace :apipie_dsl do
23
23
  ApipieDSL.configuration.sections.each do |section|
24
24
  ApipieDSL.url_prefix = "../../#{subdir}"
25
25
  doc = ApipieDSL.docs(version, nil, nil, lang, section)
26
- doc[:docs][:link_extension] = "#{lang_ext(lang)}.html"
26
+ doc[:docs][:link_extension] = "#{ApipieDSL::TasksUtils.lang_ext(lang)}.html"
27
27
  ApipieDSL::TasksUtils.generate_index_page(file_base_version, doc, include_json, true, lang, section)
28
28
  ApipieDSL.url_prefix = "../../../#{subdir}"
29
29
  section_out = "#{file_base_version}/#{section}"
@@ -33,7 +33,7 @@ namespace :apipie_dsl do
33
33
  end
34
34
  ApipieDSL.url_prefix = "../../#{subdir}"
35
35
  doc = ApipieDSL.docs(version, nil, nil, lang)
36
- doc[:docs][:link_extension] = "#{lang_ext(lang)}.html"
36
+ doc[:docs][:link_extension] = "#{ApipieDSL::TasksUtils.lang_ext(lang)}.html"
37
37
  ApipieDSL::TasksUtils.generate_help_page(file_base_version, doc, true, lang)
38
38
  end
39
39
  end
@@ -60,7 +60,7 @@ namespace :apipie_dsl do
60
60
  ApipieDSL.configuration.sections.each do |section|
61
61
  ApipieDSL.url_prefix = "../../#{subdir}"
62
62
  doc = ApipieDSL.docs(version, nil, nil, lang, section)
63
- doc[:docs][:link_extension] = "#{lang_ext(lang)}.html"
63
+ doc[:docs][:link_extension] = "#{ApipieDSL::TasksUtils.lang_ext(lang)}.html"
64
64
  ApipieDSL::TasksUtils.generate_index_page(file_base_version, doc, include_json, true, lang, section)
65
65
  ApipieDSL.url_prefix = "../../../#{subdir}"
66
66
  section_out = "#{file_base_version}/#{section}"
@@ -70,7 +70,7 @@ namespace :apipie_dsl do
70
70
  end
71
71
  ApipieDSL.url_prefix = "../../#{subdir}"
72
72
  doc = ApipieDSL.docs(version, nil, nil, lang)
73
- doc[:docs][:link_extension] = "#{lang_ext(lang)}.html"
73
+ doc[:docs][:link_extension] = "#{ApipieDSL::TasksUtils.lang_ext(lang)}.html"
74
74
  ApipieDSL::TasksUtils.generate_help_page(file_base_version, doc, true, lang)
75
75
  end
76
76
  end
@@ -73,7 +73,7 @@ module ApipieDSL
73
73
  class_file_base = File.join(file_base, class_desc[:id])
74
74
  FileUtils.mkdir_p(File.dirname(class_file_base)) unless File.exist?(File.dirname(class_file_base))
75
75
 
76
- doc = ApipieDSL.docs(version, class_name, nil, lang)
76
+ doc = ApipieDSL.docs(version, class_name, nil, lang, section)
77
77
  doc[:docs][:link_extension] = (lang ? ".#{lang}.html" : '.html')
78
78
  render_page("#{class_file_base}#{lang_ext(lang)}.html", 'class',
79
79
  doc: doc[:docs], klass: doc[:docs][:classes].first,
@@ -90,7 +90,7 @@ module ApipieDSL
90
90
  method_file_base = File.join(file_base, class_name.to_s, method[:name].to_s)
91
91
  FileUtils.mkdir_p(File.dirname(method_file_base)) unless File.exist?(File.dirname(method_file_base))
92
92
 
93
- doc = ApipieDSL.docs(version, class_name, method[:name], lang)
93
+ doc = ApipieDSL.docs(version, class_name, method[:name], lang, section)
94
94
  doc[:docs][:link_extension] = (lang ? ".#{lang}.html" : '.html')
95
95
  render_page("#{method_file_base}#{lang_ext(lang)}.html", 'method',
96
96
  doc: doc[:docs], klass: doc[:docs][:classes].first,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ApipieDSL
4
- VERSION = '2.2.4'
4
+ VERSION = '2.2.9'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apipie-dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.4
4
+ version: 2.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleh Fedorenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-23 00:00:00.000000000 Z
11
+ date: 2020-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler