summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSeba Gamboa <[email protected]>2015-09-24 18:25:12 -0300
committerSeba Gamboa <[email protected]>2015-09-24 18:25:12 -0300
commitc1f2404de71e9a8f73271b05f59a225728212069 (patch)
treeb4f3842661dd6edd38c594579335e1ae5ea61f33
parentcc49ade5e7029e4d8d8d62b7c09590042b43d65d (diff)
downloadyard-mruby-c1f2404de71e9a8f73271b05f59a225728212069.tar.gz
yard-mruby-c1f2404de71e9a8f73271b05f59a225728212069.zip
Generating C API HTML Layout
-rw-r--r--lib/yard/mruby.rb1
-rw-r--r--lib/yard/mruby/code_objects.rb1
-rw-r--r--lib/yard/mruby/code_objects/header_object.rb11
-rw-r--r--lib/yard/mruby/code_objects/namespace_object.rb16
-rw-r--r--lib/yard/mruby/handlers/header/base.rb2
-rw-r--r--lib/yard/mruby/templates.rb7
-rw-r--r--spec/handlers/header/function_handler_spec.rb2
-rw-r--r--templates/default/fulldoc/html/css/mruby.css0
-rw-r--r--templates/default/fulldoc/html/full_list_headers.erb1
-rw-r--r--templates/default/fulldoc/html/js/mruby.js0
-rw-r--r--templates/default/fulldoc/html/setup.rb57
-rw-r--r--templates/default/header/html/functions.erb1
-rw-r--r--templates/default/header/html/header.erb1
-rw-r--r--templates/default/header/html/setup.rb10
-rw-r--r--templates/default/includedirectory/html/headers_list.erb1
-rw-r--r--templates/default/includedirectory/html/setup.rb10
-rw-r--r--templates/default/layout/html/setup.rb41
17 files changed, 161 insertions, 1 deletions
diff --git a/lib/yard/mruby.rb b/lib/yard/mruby.rb
index 2ccd6e8..194c9e7 100644
--- a/lib/yard/mruby.rb
+++ b/lib/yard/mruby.rb
@@ -2,3 +2,4 @@ require_relative "mruby/version"
require_relative "mruby/code_objects"
require_relative "mruby/parser"
require_relative "mruby/handlers"
+require_relative "mruby/templates"
diff --git a/lib/yard/mruby/code_objects.rb b/lib/yard/mruby/code_objects.rb
index 83cf18d..65b2dd5 100644
--- a/lib/yard/mruby/code_objects.rb
+++ b/lib/yard/mruby/code_objects.rb
@@ -1,3 +1,4 @@
+require_relative 'code_objects/namespace_object'
require_relative 'code_objects/header_object'
require_relative 'code_objects/function_object'
require_relative 'code_objects/define_object'
diff --git a/lib/yard/mruby/code_objects/header_object.rb b/lib/yard/mruby/code_objects/header_object.rb
index 99fb3cf..519d76c 100644
--- a/lib/yard/mruby/code_objects/header_object.rb
+++ b/lib/yard/mruby/code_objects/header_object.rb
@@ -3,5 +3,16 @@ module YARD::MRuby::CodeObjects
# A HeaderObject represents a MRuby header inside an include directory
# It groups C Functions and define macros.
class HeaderObject < YARD::CodeObjects::NamespaceObject
+ def functions
+ children.find_all {|d| d.is_a?(FunctionObject) }
+ end
+
+ def path
+ self.name
+ end
+
+ def title
+ super.to_s
+ end
end
end
diff --git a/lib/yard/mruby/code_objects/namespace_object.rb b/lib/yard/mruby/code_objects/namespace_object.rb
new file mode 100644
index 0000000..896b84b
--- /dev/null
+++ b/lib/yard/mruby/code_objects/namespace_object.rb
@@ -0,0 +1,16 @@
+module YARD::MRuby::CodeObjects
+
+ class NamespaceObject < YARD::CodeObjects::NamespaceObject
+ def value ; nil ; end
+ end
+
+ class IncludeDirectory < NamespaceObject
+ def headers
+ children
+ end
+ end
+
+ INCLUDE_DIRECTORY = IncludeDirectory.new(:root, "include")
+ ## YARD::Registry.register INCLUDE_DIRECTORY
+
+end
diff --git a/lib/yard/mruby/handlers/header/base.rb b/lib/yard/mruby/handlers/header/base.rb
index 58178fe..42178d0 100644
--- a/lib/yard/mruby/handlers/header/base.rb
+++ b/lib/yard/mruby/handlers/header/base.rb
@@ -8,7 +8,7 @@ module YARD::MRuby::Handlers
path = path.gsub(/^.*include\//,'')
headers[path] ||= begin
- header = HeaderObject.new(:root, path)
+ header = HeaderObject.new(INCLUDE_DIRECTORY, path)
register header
header
end
diff --git a/lib/yard/mruby/templates.rb b/lib/yard/mruby/templates.rb
new file mode 100644
index 0000000..43ffd99
--- /dev/null
+++ b/lib/yard/mruby/templates.rb
@@ -0,0 +1,7 @@
+YARD::MRuby::TEMPLATES_PATH = File.expand_path('../../../../templates', __FILE__)
+
+# This registered template works for yardoc
+YARD::Templates::Engine.register_template_path YARD::MRuby::TEMPLATES_PATH
+
+# The following static paths and templates are for yard server
+# YARD::Server.register_static_path File.join(YARD::MRuby::TEMPLATES_PATH,'default/fulldoc/html')
diff --git a/spec/handlers/header/function_handler_spec.rb b/spec/handlers/header/function_handler_spec.rb
index 8ad5334..b97abb6 100644
--- a/spec/handlers/header/function_handler_spec.rb
+++ b/spec/handlers/header/function_handler_spec.rb
@@ -6,5 +6,7 @@ describe YARD::MRuby::Handlers::Header::FunctionHandler do
MRB_API void mrb_foo( void );
eof
expect(Registry.at('mrb_foo')).not_to be_nil
+
+ # puts Registry.send(:thread_local_store).inspect
end
end
diff --git a/templates/default/fulldoc/html/css/mruby.css b/templates/default/fulldoc/html/css/mruby.css
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/templates/default/fulldoc/html/css/mruby.css
diff --git a/templates/default/fulldoc/html/full_list_headers.erb b/templates/default/fulldoc/html/full_list_headers.erb
new file mode 100644
index 0000000..4b32c70
--- /dev/null
+++ b/templates/default/fulldoc/html/full_list_headers.erb
@@ -0,0 +1 @@
+TODO: Display C API
diff --git a/templates/default/fulldoc/html/js/mruby.js b/templates/default/fulldoc/html/js/mruby.js
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/templates/default/fulldoc/html/js/mruby.js
diff --git a/templates/default/fulldoc/html/setup.rb b/templates/default/fulldoc/html/setup.rb
new file mode 100644
index 0000000..81ac35c
--- /dev/null
+++ b/templates/default/fulldoc/html/setup.rb
@@ -0,0 +1,57 @@
+def init
+ super
+
+ YARD::MRuby::CodeObjects::INCLUDE_DIRECTORY.tap do |root|
+
+ # Generates the requirements splash page with the 'include' template
+ serialize root
+
+ root.headers.each do |header|
+ serialize header
+ end
+ end
+
+end
+
+def generate_header_list
+ puts "generate_header_list"
+ headers = Registry.all(:header)
+ headers_ordered_by_name = headers.sort {|x,y| x.value.to_s <=> y.value.to_s }
+ generate_full_list headers_ordered_by_name, :headers
+end
+
+# Helpler method to generate a full_list page of the specified objects with the
+# specified type.
+def generate_full_list(objects,type,options = {})
+ defaults = { :list_title => "#{type.to_s.capitalize} List",
+ :css_class => "class",
+ :list_filename => "#{type.to_s.gsub(/s$/,'')}_list.html" }
+
+ options = defaults.merge(options)
+
+ @items = objects
+ @list_type = type
+ @list_title = options[:list_title]
+ @list_class = options[:css_class]
+ asset options[:list_filename], erb(:full_list)
+end
+
+#
+# @note This method overrides YARD's default template class_list method.
+#
+# The existing YARD 'Class List' search field contains all the YARD namespace objects.
+# We, however, do not want the Include Namespace YARD Object (which holds the headers)
+# as it is a meta-object.
+#
+# This method removes the namespace from the root node, generates the class list,
+# and then adds it back into the root node.
+#
+def class_list(root = Registry.root)
+ return super unless root == Registry.root
+
+ include_namespace = YARD::MRuby::CodeObjects::INCLUDE_DIRECTORY
+ root.instance_eval { children.delete include_namespace }
+ out = super(root)
+ root.instance_eval { children.push include_namespace }
+ out
+end
diff --git a/templates/default/header/html/functions.erb b/templates/default/header/html/functions.erb
new file mode 100644
index 0000000..d5a7f72
--- /dev/null
+++ b/templates/default/header/html/functions.erb
@@ -0,0 +1 @@
+Header functions!
diff --git a/templates/default/header/html/header.erb b/templates/default/header/html/header.erb
new file mode 100644
index 0000000..dec59ee
--- /dev/null
+++ b/templates/default/header/html/header.erb
@@ -0,0 +1 @@
+<h1><%= format_object_title(object) %></h1>
diff --git a/templates/default/header/html/setup.rb b/templates/default/header/html/setup.rb
new file mode 100644
index 0000000..757657d
--- /dev/null
+++ b/templates/default/header/html/setup.rb
@@ -0,0 +1,10 @@
+def init
+ puts "header!"
+ puts object.inspect
+ super
+
+ sections.push :header
+ sections.push :functions
+rescue => error
+ puts error
+end
diff --git a/templates/default/includedirectory/html/headers_list.erb b/templates/default/includedirectory/html/headers_list.erb
new file mode 100644
index 0000000..1b524aa
--- /dev/null
+++ b/templates/default/includedirectory/html/headers_list.erb
@@ -0,0 +1 @@
+<h1>All headers</h1>
diff --git a/templates/default/includedirectory/html/setup.rb b/templates/default/includedirectory/html/setup.rb
new file mode 100644
index 0000000..5945ae4
--- /dev/null
+++ b/templates/default/includedirectory/html/setup.rb
@@ -0,0 +1,10 @@
+def init
+ super
+ sections.push :headers_list
+
+ @namespace = object
+end
+
+def headers
+ object.headers
+end
diff --git a/templates/default/layout/html/setup.rb b/templates/default/layout/html/setup.rb
new file mode 100644
index 0000000..c6e52d2
--- /dev/null
+++ b/templates/default/layout/html/setup.rb
@@ -0,0 +1,41 @@
+def init
+ super
+end
+
+#
+# Append yard-cucumber stylesheet to yard core stylesheets
+#
+def stylesheets
+ super + %w(css/mruby.css)
+end
+
+#
+# Append yard-cucumber javascript to yard core javascripts
+#
+def javascripts
+ super + %w(js/mruby.js)
+end
+
+#
+# Append yard-cucumber specific menus 'features' and 'tags'
+#
+# 'features' and 'tags' are enabled by default.
+#
+# 'step definitions' and 'steps' may be enabled by setting up a value in
+# yard configuration file '~/.yard/config'
+#
+# @example `~/.yard.config`
+#
+# yard-cucumber:
+# menus: [ 'features', 'directories', 'tags', 'step definitions', 'steps' ]
+#
+def menu_lists
+
+ [ {
+ type: 'header',
+ title: 'C API',
+ search_title: 'C API'
+ } ] + super
+
+end
+