diff options
| -rw-r--r-- | lib/yard/mruby/code_objects/function_object.rb | 27 | ||||
| -rw-r--r-- | lib/yard/mruby/code_objects/header_object.rb | 4 | ||||
| -rw-r--r-- | lib/yard/mruby/code_objects/headers_root.rb | 5 | ||||
| -rw-r--r-- | lib/yard/mruby/templates.rb | 2 | ||||
| -rw-r--r-- | lib/yard/mruby/templates/helpers.rb | 1 | ||||
| -rw-r--r-- | lib/yard/mruby/templates/helpers/html_helper.rb | 20 | ||||
| -rw-r--r-- | templates/default/function_details/html/function_signature.erb | 10 | ||||
| -rw-r--r-- | templates/default/function_details/html/header.erb | 3 | ||||
| -rw-r--r-- | templates/default/function_details/html/source.erb | 10 | ||||
| -rw-r--r-- | templates/default/function_details/setup.rb | 12 | ||||
| -rw-r--r-- | templates/default/header/html/function_details_list.erb | 7 | ||||
| -rw-r--r-- | templates/default/header/html/function_summary.erb | 16 | ||||
| -rw-r--r-- | templates/default/header/html/includes.erb | 1 | ||||
| -rw-r--r-- | templates/default/header/html/item_summary.erb | 19 | ||||
| -rw-r--r-- | templates/default/header/html/pre_docstring.erb | 1 | ||||
| -rw-r--r-- | templates/default/header/html/setup.rb | 10 |
16 files changed, 138 insertions, 10 deletions
diff --git a/lib/yard/mruby/code_objects/function_object.rb b/lib/yard/mruby/code_objects/function_object.rb index 0a835b5..c726762 100644 --- a/lib/yard/mruby/code_objects/function_object.rb +++ b/lib/yard/mruby/code_objects/function_object.rb @@ -2,6 +2,14 @@ module YARD::MRuby::CodeObjects # A FunctionObject represents a MRuby C API function declaration inside a header inside an include directory class FunctionObject < YARD::CodeObjects::Base + + # Returns the list of parameters parsed out of the method signature + # with their default values. + # + # @return [Array<Array(String, String)>] a list of parameter names followed + # by their default values (or nil) + attr_accessor :parameters + def initialize(header, name, &block) super end @@ -14,6 +22,25 @@ module YARD::MRuby::CodeObjects def path self.name end + + def attr_info + nil + end + + def scope + '' + end + + # Returns all alias names of the object + # @return [Array<Symbol>] the alias names + def aliases + list = [] + return list unless namespace.is_a?(HeaderObject) + namespace.aliases.each do |o, aname| + list << o if aname == name && o.scope == scope + end + list + end end end diff --git a/lib/yard/mruby/code_objects/header_object.rb b/lib/yard/mruby/code_objects/header_object.rb index 519d76c..2e70230 100644 --- a/lib/yard/mruby/code_objects/header_object.rb +++ b/lib/yard/mruby/code_objects/header_object.rb @@ -14,5 +14,9 @@ module YARD::MRuby::CodeObjects def title super.to_s end + + def inheritance_tree(*args) + return [self] + end end end diff --git a/lib/yard/mruby/code_objects/headers_root.rb b/lib/yard/mruby/code_objects/headers_root.rb index 45806ff..6522c9a 100644 --- a/lib/yard/mruby/code_objects/headers_root.rb +++ b/lib/yard/mruby/code_objects/headers_root.rb @@ -4,8 +4,11 @@ module YARD::MRuby::CodeObjects def headers children end + + def inheritance_tree(*args) + return [self] + end end HEADERS_ROOT = HeadersRoot.new(:root, "headers") - end diff --git a/lib/yard/mruby/templates.rb b/lib/yard/mruby/templates.rb index 43ffd99..3010ee8 100644 --- a/lib/yard/mruby/templates.rb +++ b/lib/yard/mruby/templates.rb @@ -1,3 +1,5 @@ +require_relative 'templates/helpers' + YARD::MRuby::TEMPLATES_PATH = File.expand_path('../../../../templates', __FILE__) # This registered template works for yardoc diff --git a/lib/yard/mruby/templates/helpers.rb b/lib/yard/mruby/templates/helpers.rb new file mode 100644 index 0000000..c1fe8bb --- /dev/null +++ b/lib/yard/mruby/templates/helpers.rb @@ -0,0 +1 @@ +require_relative 'helpers/html_helper' diff --git a/lib/yard/mruby/templates/helpers/html_helper.rb b/lib/yard/mruby/templates/helpers/html_helper.rb new file mode 100644 index 0000000..46b8664 --- /dev/null +++ b/lib/yard/mruby/templates/helpers/html_helper.rb @@ -0,0 +1,20 @@ +module YARD::MRuby::Templates + module Helpers + # Helper methods for text template formats. + module HTMLHelper + + def fsignature(func, link = true, show_extras = true) + name = func.name + title = "<strong>%s</strong>" % [h(name)] + + if link + url = url_for(func) + link_url(url, title, :title => title) + else + title + end + end + + end + end +end diff --git a/templates/default/function_details/html/function_signature.erb b/templates/default/function_details/html/function_signature.erb new file mode 100644 index 0000000..cbd318e --- /dev/null +++ b/templates/default/function_details/html/function_signature.erb @@ -0,0 +1,10 @@ +<h3 class="signature <%= 'first' if @index == 0 %>" id="<%= anchor_for(object) %>"> + <%= fsignature(object, false) %> + + <% if object.aliases.size > 0 %> + <span class="aliases">Also known as: + <span class="names"><%= object.aliases.map {|o| + "<span id='#{anchor_for(o)}'>" + h(o.name.to_s) + "</span>" }.join(", ") %></span> + </span> + <% end %> +</h3> diff --git a/templates/default/function_details/html/header.erb b/templates/default/function_details/html/header.erb new file mode 100644 index 0000000..2dd9d11 --- /dev/null +++ b/templates/default/function_details/html/header.erb @@ -0,0 +1,3 @@ +<div class="method_details <%= @index == 0 ? 'first' : '' %>"> + <%= yieldall %> +</div> diff --git a/templates/default/function_details/html/source.erb b/templates/default/function_details/html/source.erb new file mode 100644 index 0000000..12740cb --- /dev/null +++ b/templates/default/function_details/html/source.erb @@ -0,0 +1,10 @@ +<table class="source_code"> + <tr> + <td> + <pre class="lines"><%= "\n\n\n" %><%= h format_lines(object) %></pre> + </td> + <td> + <pre class="code"><span class="info file"># File '<%= h object.file %>'<% if object.line %>, line <%= object.line %><% end %></span><%= "\n\n" %><%= html_syntax_highlight object.source %></pre> + </td> + </tr> +</table> diff --git a/templates/default/function_details/setup.rb b/templates/default/function_details/setup.rb new file mode 100644 index 0000000..33cce5d --- /dev/null +++ b/templates/default/function_details/setup.rb @@ -0,0 +1,12 @@ +include YARD::MRuby::Templates::Helpers::HTMLHelper + +def init + sections :header, [:function_signature, T('docstring'), :source] +end + +def source + return if owner != object.namespace + return if Tags::OverloadTag === object + return if object.source.nil? + erb(:source) +end diff --git a/templates/default/header/html/function_details_list.erb b/templates/default/header/html/function_details_list.erb new file mode 100644 index 0000000..37a9cc8 --- /dev/null +++ b/templates/default/header/html/function_details_list.erb @@ -0,0 +1,7 @@ +<div id="functions_details" class="method_details_list"> + <h2>Function Details</h2> + + <% function_listing.each_with_index do |func, i| %> + <%= yieldall :object => func, :owner => object, :index => i %> + <% end %> +</div> diff --git a/templates/default/header/html/function_summary.erb b/templates/default/header/html/function_summary.erb index 037daa4..f37f075 100644 --- a/templates/default/header/html/function_summary.erb +++ b/templates/default/header/html/function_summary.erb @@ -1,6 +1,12 @@ -<ul class="summary"> +<% if function_listing.size > 0 %> + <h2> + Function Summary + <small><a href="#" class="summary_toggle">collapse</a></small> + </h2> - <% function_listing.each do |func| %> - <%= yieldall :item => func %> - <% end %> -</ul> + <ul class="summary"> + <% function_listing.each do |func| %> + <%= yieldall :item => func %> + <% end %> + </ul> +<% end %> diff --git a/templates/default/header/html/includes.erb b/templates/default/header/html/includes.erb new file mode 100644 index 0000000..6731e2b --- /dev/null +++ b/templates/default/header/html/includes.erb @@ -0,0 +1 @@ +Included heaers diff --git a/templates/default/header/html/item_summary.erb b/templates/default/header/html/item_summary.erb new file mode 100644 index 0000000..522a3a1 --- /dev/null +++ b/templates/default/header/html/item_summary.erb @@ -0,0 +1,19 @@ +<li class="<%= @item.visibility %> <%= @item.has_tag?(:deprecated) ? 'deprecated' : '' %>"> + <span class="summary_signature"> + <%= fsignature(@item, true, false) %> + + <% if @item.aliases.size > 0 %> + (also: <%= @item.aliases.map {|o| h(o.name(true)) }.join(", ") %>) + <% end %> + </span> + <% if @item.visibility != :public %><span class="note title <%= @item.visibility %>"><%= @item.visibility %></span><% end %> + <% if @item.has_tag?(:abstract) %><span class="abstract note title">abstract</span><% end %> + <% if @item.has_tag?(:deprecated) %><span class="deprecated note title">deprecated</span><% end %> + <% if @item.has_tag?(:api) && @item.tag(:api).text == 'private' %><span class="private note title">private</span><% end %> + + <% if @item.has_tag?(:deprecated) %> + <span class="summary_desc"><strong>Deprecated.</strong> <%= htmlify_line @item.tag(:deprecated).text %></span> + <% else %> + <span class="summary_desc"><%= htmlify_line docstring_summary(@item) %></span> + <% end %> +</li> diff --git a/templates/default/header/html/pre_docstring.erb b/templates/default/header/html/pre_docstring.erb new file mode 100644 index 0000000..f3475da --- /dev/null +++ b/templates/default/header/html/pre_docstring.erb @@ -0,0 +1 @@ +<h2>Overview</h2> diff --git a/templates/default/header/html/setup.rb b/templates/default/header/html/setup.rb index 6e5f8f9..52eb81c 100644 --- a/templates/default/header/html/setup.rb +++ b/templates/default/header/html/setup.rb @@ -1,8 +1,10 @@ -def init - super +include T('default/module') +include YARD::MRuby::Templates::Helpers::HTMLHelper - sections.push :header - sections.push :function_summary +def init + sections :header, :pre_docstring, T('docstring'), :includes, + :function_summary, [:item_summary], + :function_details_list, [T('function_details')] end |
