From 48fb10fef522ab9262061bc612b44d74a8bda17d Mon Sep 17 00:00:00 2001 From: Seba Gamboa Date: Fri, 25 Sep 2015 13:12:22 -0300 Subject: Listing functions --- lib/yard/mruby/code_objects/function_object.rb | 27 ++++++++++++++++++++++ lib/yard/mruby/code_objects/header_object.rb | 4 ++++ lib/yard/mruby/code_objects/headers_root.rb | 5 +++- lib/yard/mruby/templates.rb | 2 ++ lib/yard/mruby/templates/helpers.rb | 1 + lib/yard/mruby/templates/helpers/html_helper.rb | 20 ++++++++++++++++ .../function_details/html/function_signature.erb | 10 ++++++++ templates/default/function_details/html/header.erb | 3 +++ templates/default/function_details/html/source.erb | 10 ++++++++ templates/default/function_details/setup.rb | 12 ++++++++++ .../default/header/html/function_details_list.erb | 7 ++++++ templates/default/header/html/function_summary.erb | 16 +++++++++---- templates/default/header/html/includes.erb | 1 + templates/default/header/html/item_summary.erb | 19 +++++++++++++++ templates/default/header/html/pre_docstring.erb | 1 + templates/default/header/html/setup.rb | 10 ++++---- 16 files changed, 138 insertions(+), 10 deletions(-) create mode 100644 lib/yard/mruby/templates/helpers.rb create mode 100644 lib/yard/mruby/templates/helpers/html_helper.rb create mode 100644 templates/default/function_details/html/function_signature.erb create mode 100644 templates/default/function_details/html/header.erb create mode 100644 templates/default/function_details/html/source.erb create mode 100644 templates/default/function_details/setup.rb create mode 100644 templates/default/header/html/function_details_list.erb create mode 100644 templates/default/header/html/includes.erb create mode 100644 templates/default/header/html/item_summary.erb create mode 100644 templates/default/header/html/pre_docstring.erb 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] 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] 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 = "%s" % [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 @@ +

+ <%= fsignature(object, false) %> + + <% if object.aliases.size > 0 %> + Also known as: + <%= object.aliases.map {|o| + "" + h(o.name.to_s) + "" }.join(", ") %> + + <% end %> +

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 @@ +
+ <%= yieldall %> +
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 @@ + + + + + +
+
<%= "\n\n\n" %><%= h format_lines(object) %>
+
+
# File '<%= h object.file %>'<% if object.line %>, line <%= object.line %><% end %><%= "\n\n" %><%= html_syntax_highlight object.source %>
+
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 @@ +
+

Function Details

+ + <% function_listing.each_with_index do |func, i| %> + <%= yieldall :object => func, :owner => object, :index => i %> + <% end %> +
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 @@ -
    +<% if function_listing.size > 0 %> +

    + Function Summary + collapse +

    - <% function_listing.each do |func| %> - <%= yieldall :item => func %> - <% end %> -
+
    + <% function_listing.each do |func| %> + <%= yieldall :item => func %> + <% end %> +
+<% 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 @@ +
  • + + <%= fsignature(@item, true, false) %> + + <% if @item.aliases.size > 0 %> + (also: <%= @item.aliases.map {|o| h(o.name(true)) }.join(", ") %>) + <% end %> + + <% if @item.visibility != :public %><%= @item.visibility %><% end %> + <% if @item.has_tag?(:abstract) %>abstract<% end %> + <% if @item.has_tag?(:deprecated) %>deprecated<% end %> + <% if @item.has_tag?(:api) && @item.tag(:api).text == 'private' %>private<% end %> + + <% if @item.has_tag?(:deprecated) %> + Deprecated. <%= htmlify_line @item.tag(:deprecated).text %> + <% else %> + <%= htmlify_line docstring_summary(@item) %> + <% end %> +
  • 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 @@ +

    Overview

    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 -- cgit v1.2.3