apipie-dsl 2.2.5 → 2.2.10

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: 3abb36cc2c2a73c3d36df30adc52256d373862ef6e8d1d206502b35d2b6de2fc
4
- data.tar.gz: b38860b723fe7a8e805e8dc9f29d36edad87a249a4bd1c2ac3b5776afed9f450
3
+ metadata.gz: 990ebec629f1450a927333b32acec610e62378a52dd4d04247de392fa15376ad
4
+ data.tar.gz: 15a19b903fa3a51096eda59a022ffcfaaaf1bbe82d9253a25b7696a6c04321bc
5
5
  SHA512:
6
- metadata.gz: e83577ac774732338ed3ae5a9036aab988fd28fa95c173d331747f95e110c3a7393107728cdf92fdadde3e157b0731b01099a024deba10ea3625ee74a7271021
7
- data.tar.gz: 8dd6360df8ce33373c4657646df2be53e1b3bae450cce471e476b70108e30ef4d7a081c5afa381849972390abe9db73f9998bd5ac159059c2cc699862e03c802
6
+ metadata.gz: 8b0a2d9ea7df944cb6b1585db1bc18bc98220ffab60e612e832e9eddbd0e19668067da1b950b342b906a36e922c4f539d35ccf4a9d70977593a5931195d16e94
7
+ data.tar.gz: ab9e8070fed5ce6cb24c5da93ec3c4b297cb792fa704b5e3fcc2f74c40927deaf608e0401de6dc5eef46fc784e9a89300b9317768398a44f78805c2ccb766333
@@ -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(_(section.titleize), @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(_('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, class: 'wiki')
40
+
41
+ if output.present?
42
+ text += content_tag(:p, _('Example output:')) +
43
+ content_tag(:pre, output, class: 'wiki')
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)
@@ -5,3 +5,14 @@ body {
5
5
  .sidebar-nav {
6
6
  padding: 9px 0;
7
7
  }
8
+
9
+ pre:not(.prettyprint):not(.wiki) {
10
+ margin: 0 0 9px;
11
+ padding: 0;
12
+ font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
13
+ font-size: 13px;
14
+ line-height: 18px;
15
+ color: #333333;
16
+ background-color: inherit;
17
+ border: none;
18
+ }
@@ -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>
@@ -3,6 +3,16 @@
3
3
  <%= render(partial: 'metadata', locals: { meta: property[:metadata] }) %>
4
4
  <% end %>
5
5
 
6
+ <% unless property[:examples].blank? %>
7
+ <%= heading(t('apipie_dsl.examples'), h_level) %>
8
+ <% property[:examples].each do |example| %>
9
+ <% if example[:desc] %>
10
+ <p><%= example[:desc] %></p>
11
+ <% end %>
12
+ <pre class="prettyprint"><%= example[:example] %></pre>
13
+ <% end %>
14
+ <% end %>
15
+
6
16
  <% unless property[:params].blank? %>
7
17
  <%= heading(t('apipie_dsl.params'), h_level) %>
8
18
  <table class='table'>
@@ -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>
@@ -42,7 +42,10 @@
42
42
  <% unless prop[:examples].blank? %>
43
43
  <h4><%= t('apipie_dsl.examples') %></h4>
44
44
  <% prop[:examples].each do |example| %>
45
- <pre class="wiki"><%= example %></pre>
45
+ <% if example[:desc] %>
46
+ <p><%= example[:desc] %></p>
47
+ <% end %>
48
+ <pre class="wiki"><%= example[:example] %></pre>
46
49
  <% end %>
47
50
  <% end %>
48
51
 
@@ -79,7 +82,10 @@
79
82
  <% unless method[:examples].blank? %>
80
83
  <h4><%= t('apipie_dsl.examples') %></h4>
81
84
  <% method[:examples].each do |example| %>
82
- <pre class="wiki"><%= example %></pre>
85
+ <% if example[:desc] %>
86
+ <p><%= example[:desc] %></p>
87
+ <% end %>
88
+ <pre class="wiki"><%= example[:example] %></pre>
83
89
  <% end %>
84
90
  <% end %>
85
91
 
@@ -59,7 +59,10 @@
59
59
  <% unless prop[:examples].blank? %>
60
60
  <h2><%= t('apipie_dsl.examples') %></h2>
61
61
  <% prop[:examples].each do |example| %>
62
- <pre><%= example %></pre>
62
+ <% if example[:desc] %>
63
+ <p><%= example[:desc] %></p>
64
+ <% end %>
65
+ <pre><%= example[:example] %></pre>
63
66
  <% end %>
64
67
  <% end %>
65
68
 
@@ -107,7 +110,10 @@
107
110
  <% unless method[:examples].blank? %>
108
111
  <h2><%= t('apipie_dsl.examples') %></h2>
109
112
  <% method[:examples].each do |example| %>
110
- <pre><%= example %></pre>
113
+ <% if example[:desc] %>
114
+ <p><%= example[:desc] %></p>
115
+ <% end %>
116
+ <pre class="prettyprint"><%= example[:example] %></pre>
111
117
  <% end %>
112
118
  <% end %>
113
119
 
@@ -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
@@ -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.5'
4
+ VERSION = '2.2.10'
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.5
4
+ version: 2.2.10
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-26 00:00:00.000000000 Z
11
+ date: 2020-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler