yard-mruby 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +10 -20
  3. data/exe/mrbdoc +5 -0
  4. data/lib/yard/mruby.rb +6 -1
  5. data/lib/yard/mruby/cli.rb +1 -0
  6. data/lib/yard/mruby/cli/yardoc.rb +14 -0
  7. data/lib/yard/mruby/code_objects.rb +2 -0
  8. data/lib/yard/mruby/code_objects/define_object.rb +1 -1
  9. data/lib/yard/mruby/code_objects/function_object.rb +66 -1
  10. data/lib/yard/mruby/code_objects/header_base_object.rb +15 -0
  11. data/lib/yard/mruby/code_objects/header_object.rb +19 -0
  12. data/lib/yard/mruby/code_objects/headers_root.rb +14 -0
  13. data/lib/yard/mruby/handlers.rb +1 -0
  14. data/lib/yard/mruby/handlers/c.rb +4 -0
  15. data/lib/yard/mruby/handlers/c/header.rb +4 -0
  16. data/lib/yard/mruby/handlers/c/header/base.rb +30 -0
  17. data/lib/yard/mruby/handlers/c/header/define_handler.rb +23 -0
  18. data/lib/yard/mruby/handlers/c/header/function_handler.rb +33 -0
  19. data/lib/yard/mruby/handlers/c/header/header_decl_handler.rb +20 -0
  20. data/lib/yard/mruby/handlers/c/source.rb +7 -0
  21. data/lib/yard/mruby/handlers/c/source/base.rb +56 -0
  22. data/lib/yard/{handlers/c/mruby_class_handler.rb → mruby/handlers/c/source/class_handler.rb} +2 -2
  23. data/lib/yard/mruby/handlers/c/source/init_handler.rb +16 -0
  24. data/lib/yard/{handlers/c/mruby_method_handler.rb → mruby/handlers/c/source/method_handler.rb} +2 -2
  25. data/lib/yard/{handlers/c/mruby_module_handler.rb → mruby/handlers/c/source/module_handler.rb} +2 -2
  26. data/lib/yard/{handlers/c/mruby_symbol_handler.rb → mruby/handlers/c/source/symbol_handler.rb} +3 -2
  27. data/lib/yard/mruby/parser.rb +1 -0
  28. data/lib/yard/mruby/parser/c.rb +4 -0
  29. data/lib/yard/mruby/parser/c/directive_statement.rb +6 -0
  30. data/lib/yard/mruby/parser/c/header_parser.rb +49 -0
  31. data/lib/yard/mruby/parser/c/parser.rb +10 -0
  32. data/lib/yard/mruby/parser/c/source_parser.rb +9 -0
  33. data/lib/yard/mruby/templates.rb +9 -0
  34. data/lib/yard/mruby/templates/helpers.rb +1 -0
  35. data/lib/yard/mruby/templates/helpers/html_helper.rb +32 -0
  36. data/lib/yard/mruby/version.rb +1 -1
  37. data/sample/.yardopts +1 -0
  38. data/{lib/yard/handlers/header/define_handler.rb → templates/default/fulldoc/html/css/mruby.css} +0 -0
  39. data/templates/default/fulldoc/html/full_list_functions.erb +10 -0
  40. data/templates/default/fulldoc/html/full_list_headers.erb +10 -0
  41. data/{lib/yard/handlers/header/function_handler.rb → templates/default/fulldoc/html/js/mruby.js} +0 -0
  42. data/templates/default/fulldoc/html/setup.rb +62 -0
  43. data/templates/default/function_details/html/function_signature.erb +10 -0
  44. data/templates/default/function_details/html/header.erb +3 -0
  45. data/templates/default/function_details/html/source.erb +10 -0
  46. data/templates/default/function_details/setup.rb +12 -0
  47. data/templates/default/header/html/define_summary.erb +11 -0
  48. data/templates/default/header/html/function_details_list.erb +7 -0
  49. data/templates/default/header/html/function_summary.erb +12 -0
  50. data/templates/default/header/html/functions.erb +1 -0
  51. data/templates/default/header/html/header.erb +1 -0
  52. data/templates/default/header/html/includes.erb +1 -0
  53. data/templates/default/header/html/item_summary.erb +19 -0
  54. data/templates/default/header/html/pre_docstring.erb +1 -0
  55. data/templates/default/header/html/setup.rb +24 -0
  56. data/templates/default/headersroot/html/headers_list.erb +6 -0
  57. data/templates/default/headersroot/html/setup.rb +10 -0
  58. data/templates/default/layout/html/footer.erb +5 -0
  59. data/templates/default/layout/html/setup.rb +52 -0
  60. data/templates/default/tags/setup.rb +7 -0
  61. metadata +56 -16
  62. data/lib/yard/handlers.rb +0 -2
  63. data/lib/yard/handlers/c.rb +0 -6
  64. data/lib/yard/handlers/c/mruby_base.rb +0 -47
  65. data/lib/yard/handlers/header.rb +0 -1
  66. data/lib/yard/handlers/header/base.rb +0 -11
  67. data/lib/yard/handlers/header/header_handler.rb +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e3468feb795ec8df9a061393de6d06130dcfa10
4
- data.tar.gz: af22a19aebc351efb2dd5cb6d7c6d8b96e1981e2
3
+ metadata.gz: 08d0469722f4af2b09e0684dbb47f03e2c060734
4
+ data.tar.gz: ac36637449d471f3cdd81fe509e560c475839ff3
5
5
  SHA512:
6
- metadata.gz: c89235ff1ffacc1ff1361baa8293a2be73682bf98c7814eb8c9fe1e4b52270a6e10a213f9bd547ab702e30af566018558f61d93a1b7c1641e0931bcf61e02bba
7
- data.tar.gz: fae8caf9251763d8fa92eeea5cd4c7b68d878f7c525436bf503c8ac6e1710512c11efc46a2b0741b1cfb8ec284eb3d7f3a7fceff16b6f075cc5cbbc54f79463b
6
+ metadata.gz: 45d9a46db9354c8dafe08badec6fa347daeb8d9a4a65e3a3003e6d9169e742b30ab03e2b2b9fe7b0da3aa4a23c68e389960e4b6f8d9712de0a1c1dc4d2dfb9f2
7
+ data.tar.gz: 39c79479b9381ca33988d6c91251e6fc7a1cdca11ea0fed07e3719b6bc29ee1358b5313668aea8796d7cb567010f9325bf9c86279343b21f191f29684e70fd42
data/README.md CHANGED
@@ -1,38 +1,28 @@
1
- # Yard::Mruby
1
+ # yard-mruby
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/yard/mruby`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [![Gem](https://img.shields.io/gem/v/yard-mruby.svg)](https://rubygems.org/gems/yard-mruby)
4
+ [![Travis](https://img.shields.io/travis/sagmor/yard-mruby.svg)](https://travis-ci.org/sagmor/yard-mruby)
4
5
 
5
- TODO: Delete this and the text above, and describe your gem
6
+ This is a plugin that allows YARD to parse and generate documentation for MRuby sources as well as documenting it's C APIs.
6
7
 
7
- ## Installation
8
+ It still has it's [rough edges and missing features](https://github.com/sagmor/yard-mruby/issues) but you can see a [sample from it's current state when executed on MRuby's core here](https://sagmor.com/mruby/)
8
9
 
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'yard-mruby'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle
10
+ ## Usage
18
11
 
19
- Or install it yourself as:
12
+ Install with rubygems
20
13
 
21
14
  $ gem install yard-mruby
22
15
 
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
16
+ And execute `mrbdoc` to generate the docs
26
17
 
27
18
  ## Development
28
19
 
29
20
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
21
+ To install this gem onto your local machine, run `bundle exec rake install`.
32
22
 
33
23
  ## Contributing
34
24
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/yard-mruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
25
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sagmor/yard-mruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
26
 
37
27
 
38
28
  ## License
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/yard/mruby'
4
+
5
+ YARD::CLI::Yardoc.run(*ARGV)
@@ -1,3 +1,8 @@
1
+ require 'yard'
2
+
1
3
  require_relative "mruby/version"
2
4
  require_relative "mruby/code_objects"
3
- require_relative "handlers"
5
+ require_relative "mruby/parser"
6
+ require_relative "mruby/handlers"
7
+ require_relative "mruby/templates"
8
+ require_relative "mruby/cli"
@@ -0,0 +1 @@
1
+ require_relative 'cli/yardoc'
@@ -0,0 +1,14 @@
1
+ module YARD::MRuby::CLI
2
+ module Yardoc
3
+
4
+ # Redefines default files for YARD::CLI::Yardoc
5
+ def parse_arguments(*args)
6
+ super(*args)
7
+ self.files = %w{mrblib/**/*.rb src/**/*.c include/**/*.h} if self.files.empty?
8
+ end
9
+ end
10
+
11
+ # Load Above modifications into YARD::CLI::Yardoc
12
+ YARD::CLI::Yardoc.include Yardoc
13
+ end
14
+
@@ -1,3 +1,5 @@
1
+ require_relative 'code_objects/headers_root'
2
+ require_relative 'code_objects/header_base_object'
1
3
  require_relative 'code_objects/header_object'
2
4
  require_relative 'code_objects/function_object'
3
5
  require_relative 'code_objects/define_object'
@@ -1,7 +1,7 @@
1
1
  module YARD::MRuby::CodeObjects
2
2
 
3
3
  # A DefineObject represents a MRuby C API define macro declaration inside a header inside an include directory
4
- class DefineObject < YARD::CodeObjects::Base
4
+ class DefineObject < HeaderBaseObject
5
5
  end
6
6
  end
7
7
 
@@ -1,7 +1,72 @@
1
1
  module YARD::MRuby::CodeObjects
2
2
 
3
3
  # A FunctionObject represents a MRuby C API function declaration inside a header inside an include directory
4
- class FunctionObject < YARD::CodeObjects::Base
4
+ class FunctionObject < HeaderBaseObject
5
+ ParameterType = Struct.new(:type,:name)
6
+
7
+ # Returns the list of parameters parsed out of the method signature
8
+ # with their default values.
9
+ #
10
+ # @return [Array<Array(String, String)>] a list of parameter names followed
11
+ # by their default values (or nil)
12
+ attr_accessor :parameters
13
+
14
+ def initialize(header, name, &block)
15
+ super
16
+ end
17
+
18
+ def attr_info
19
+ nil
20
+ end
21
+
22
+ def scope
23
+ ''
24
+ end
25
+
26
+ def return_type
27
+ @return_type
28
+ end
29
+
30
+ def return_type=(type)
31
+ @return_type = (type == 'void' ? nil : type)
32
+ end
33
+
34
+ # Returns the list of parameters parsed out of the method signature
35
+ # with their default values.
36
+ #
37
+ # @return [Array<Array(String, String)>] a list of parameter names followed
38
+ # by their default values (or nil)
39
+ def parameters
40
+ parameter_types.map{|t| [(t.type == '...' ? '...' : t.name), nil] }
41
+ end
42
+
43
+ def parameter_types
44
+ @parameter_types || []
45
+ end
46
+
47
+ def parse_parameter_types(parameters)
48
+ @parameter_types = []
49
+ return if parameters.match /^\s*void\s*$/
50
+
51
+ parameters.split(',').each do |parameter|
52
+ parameter.scan(/((?:const\s+)?(?:struct\s+)?(?:\w+|\.\.\.)(?:\s*\*)?)\s*(\w+)?/) do |type,name|
53
+ @parameter_types << ParameterType.new(type,name)
54
+ end
55
+ end
56
+
57
+ end
58
+
59
+
60
+ # Returns all alias names of the object
61
+ # @return [Array<Symbol>] the alias names
62
+ def aliases
63
+ list = []
64
+ return list unless namespace.is_a?(HeaderObject)
65
+ namespace.aliases.each do |o, aname|
66
+ list << o if aname == name && o.scope == scope
67
+ end
68
+ list
69
+ end
5
70
  end
6
71
  end
7
72
 
@@ -0,0 +1,15 @@
1
+ module YARD::MRuby::CodeObjects
2
+
3
+ # A FunctionObject represents a MRuby C API function declaration inside a header inside an include directory
4
+ class HeaderBaseObject < YARD::CodeObjects::Base
5
+
6
+ def header
7
+ self.namespace
8
+ end
9
+
10
+ # Header objects's shouln't be namespaced
11
+ def path
12
+ self.name.to_s
13
+ end
14
+ end
15
+ end
@@ -3,5 +3,24 @@ module YARD::MRuby::CodeObjects
3
3
  # A HeaderObject represents a MRuby header inside an include directory
4
4
  # It groups C Functions and define macros.
5
5
  class HeaderObject < YARD::CodeObjects::NamespaceObject
6
+ def functions
7
+ children.find_all {|d| d.is_a?(FunctionObject) }
8
+ end
9
+
10
+ def defines
11
+ children.find_all {|d| d.is_a?(DefineObject) }
12
+ end
13
+
14
+ def path
15
+ self.name
16
+ end
17
+
18
+ def title
19
+ super.to_s
20
+ end
21
+
22
+ def inheritance_tree(*args)
23
+ return [self]
24
+ end
6
25
  end
7
26
  end
@@ -0,0 +1,14 @@
1
+ module YARD::MRuby::CodeObjects
2
+
3
+ class HeadersRoot < YARD::CodeObjects::NamespaceObject
4
+ def headers
5
+ children
6
+ end
7
+
8
+ def inheritance_tree(*args)
9
+ return [self]
10
+ end
11
+ end
12
+
13
+ HEADERS_ROOT = HeadersRoot.new(:root, "headers")
14
+ end
@@ -0,0 +1 @@
1
+ require_relative 'handlers/c'
@@ -0,0 +1,4 @@
1
+ require_relative 'c/source'
2
+ require_relative 'c/header'
3
+
4
+ YARD::Handlers::Processor.namespace_for_handler.delete(:c)
@@ -0,0 +1,4 @@
1
+ require_relative 'header/base'
2
+ require_relative 'header/function_handler'
3
+ require_relative 'header/define_handler'
4
+ require_relative 'header/header_decl_handler'
@@ -0,0 +1,30 @@
1
+ module YARD::MRuby::Handlers
2
+ module C
3
+ module Header
4
+ class Base < YARD::Handlers::C::Base
5
+ include YARD::MRuby::CodeObjects
6
+
7
+ def header(path)
8
+ # Remove include prefix
9
+ path = path.gsub(/^.*include\//,'')
10
+
11
+ headers[path] ||= begin
12
+ header = HeaderObject.new(HEADERS_ROOT, path)
13
+ register header
14
+ header
15
+ end
16
+
17
+
18
+ end
19
+
20
+ def headers
21
+ globals.mruby_headers ||= {}
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+
28
+ YARD::Handlers::Processor.register_handler_namespace :header, Header
29
+ end
30
+ end
@@ -0,0 +1,23 @@
1
+ module YARD::MRuby::Handlers::C::Header
2
+ class DefineHandler < Base
3
+ MATCH = /
4
+ \#\s*define\s*(\w+)
5
+ /mx
6
+
7
+ handles MATCH
8
+ statement_class YARD::MRuby::Parser::C::DirectiveStatement
9
+
10
+ process do
11
+ header = self.header(statement.file)
12
+
13
+ statement.declaration.scan(MATCH) do |match|
14
+ register DefineObject.new(header, match.first) do |obj|
15
+ if statement.comments
16
+ register_docstring(obj, statement.comments.source, statement)
17
+ end
18
+ end
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,33 @@
1
+ module YARD::MRuby::Handlers::C::Header
2
+ class FunctionHandler < Base
3
+ MATCH = /
4
+ MRB_(API|INLINE)\s+
5
+ ((struct\s+)?\w+(\s*\*)?)\s*
6
+ ((\w+\s+)+)?(\w+)\s*
7
+ \(([\w\s\*,\.]*)\)
8
+ /mx
9
+
10
+ handles MATCH
11
+ statement_class ToplevelStatement
12
+
13
+ process do
14
+ handle_function(statement)
15
+ end
16
+
17
+ def handle_function(statement)
18
+ header = self.header(statement.file)
19
+
20
+ statement.source.scan(MATCH) do |type, retype, _,_,_,_, name, parameters|
21
+ register FunctionObject.new(header, name) do |obj|
22
+ if statement.comments
23
+ register_docstring(obj, statement.comments.source, statement)
24
+ end
25
+
26
+ obj.return_type = retype
27
+ obj.parse_parameter_types(parameters)
28
+
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,20 @@
1
+ module YARD::MRuby::Handlers::C::Header
2
+ class HeaderDeclHandler < Base
3
+ MATCH = /
4
+ MRB_BEGIN_DECL
5
+ /mx
6
+
7
+ handles MATCH
8
+ statement_class ToplevelStatement
9
+
10
+ process do
11
+ header = self.header(statement.file)
12
+
13
+ if statement.comments
14
+ register_docstring(header, statement.comments.source, statement)
15
+ end
16
+ end
17
+
18
+ end
19
+ end
20
+
@@ -0,0 +1,7 @@
1
+ require_relative 'source/base'
2
+ require_relative 'source/init_handler'
3
+ require_relative 'source/symbol_handler'
4
+ require_relative 'source/class_handler'
5
+ require_relative 'source/module_handler'
6
+ require_relative 'source/method_handler'
7
+
@@ -0,0 +1,56 @@
1
+ module YARD::MRuby::Handlers
2
+ module C
3
+ module Source
4
+ class Base < YARD::Handlers::C::Base
5
+
6
+ DEFAULT_NAMESPACES = {
7
+ # 'mrb->top_self' => '',
8
+ 'object_class' => 'Object',
9
+ 'class_class' => 'Class',
10
+ 'module_class' => 'Module',
11
+ 'proc_class' => 'Proc',
12
+ 'string_class' => 'String',
13
+ 'array_class' => 'Array',
14
+ 'hash_class' => 'Hash',
15
+ 'float_class' => 'Float',
16
+ 'fixnum_class' => 'Fixnum',
17
+ 'true_class' => 'TrueClass',
18
+ 'false_class' => 'FalseClass',
19
+ 'nil_class' => 'NilClass',
20
+ 'symbol_class' => 'Symbol',
21
+ 'kernel_module' => 'Kernel',
22
+ 'eException_class' => 'Exception',
23
+ 'eStandardError_class' => 'StandardError'
24
+ }
25
+
26
+ def namespace_for_variable(var)
27
+ DEFAULT_NAMESPACES[ var[/^\w+->(\w+)$/, 1] ] || super
28
+ end
29
+
30
+ def handle_class(var_name, class_name, parent, stmt, in_module = nil)
31
+ object = super(var_name, class_name, parent, in_module)
32
+
33
+ if stmt.comments
34
+ register_docstring(object, stmt.comments.source, stmt)
35
+ end
36
+
37
+ object
38
+ end
39
+
40
+ def handle_module(var_name, module_name, stmt, in_module = nil)
41
+ object = super(var_name, module_name, in_module)
42
+
43
+ if stmt.comments
44
+ register_docstring(object, stmt.comments.source, stmt)
45
+ end
46
+
47
+ object
48
+ end
49
+
50
+ end
51
+
52
+ end
53
+
54
+ YARD::Handlers::Processor.register_handler_namespace :source, Source
55
+ end
56
+ end
@@ -1,5 +1,5 @@
1
- module YARD::Handlers::C
2
- class MRubyClassHandler < MRubyBase
1
+ module YARD::MRuby::Handlers::C::Source
2
+ class ClassHandler < Base
3
3
 
4
4
  TOP_LEVEL_CLASS = /([\w]+)\s*=\s*mrb_define_class\s*
5
5
  \(
@@ -0,0 +1,16 @@
1
+ module YARD::MRuby::Handlers::C::Source
2
+ class InitHandler < Base
3
+ MATCH1 = /mrb_\w+_gem_init\s*\(/mx
4
+ MATCH2 = /mrb_init_/mx
5
+
6
+ handles MATCH1
7
+ handles MATCH2
8
+ statement_class ToplevelStatement
9
+
10
+ process do
11
+ parse_block
12
+ end
13
+
14
+ end
15
+ end
16
+
@@ -1,5 +1,5 @@
1
- module YARD::Handlers::C
2
- class MRubyMethodHandler < MRubyBase
1
+ module YARD::MRuby::Handlers::C::Source
2
+ class MethodHandler < Base
3
3
  MATCH1 = /mrb_define_(
4
4
  method |
5
5
  singleton_method |
@@ -1,5 +1,5 @@
1
- module YARD::Handlers::C
2
- class MRubyModuleHandler < MRubyBase
1
+ module YARD::MRuby::Handlers::C::Source
2
+ class ModuleHandler < Base
3
3
 
4
4
  TOP_LEVEL_MODULE = /([\w]+)\s*=\s*mrb_define_module\s*
5
5
  \(
@@ -1,6 +1,7 @@
1
- module YARD::Handlers::C
1
+ module YARD::MRuby::Handlers::C::Source
2
2
  # Keeps track of function bodies for symbol lookup during MRuby method declarations
3
- class MRubySymbolHandler < MRubyBase
3
+ class SymbolHandler < Base
4
+
4
5
  MATCH = /
5
6
  mrb_value\s*(\w+)\s*\(\s*mrb_state\s*\*\s*\w+,\s*mrb_value\s*\w+\s*\)
6
7
  /mx
@@ -0,0 +1 @@
1
+ require_relative 'parser/c'
@@ -0,0 +1,4 @@
1
+ require_relative 'c/parser'
2
+ require_relative 'c/source_parser'
3
+ require_relative 'c/header_parser'
4
+ require_relative 'c/directive_statement'
@@ -0,0 +1,6 @@
1
+ module YARD::MRuby::Parser::C
2
+ class DirectiveStatement < YARD::Parser::C::Statement
3
+ attr_accessor :declaration
4
+ attr_accessor :comments
5
+ end
6
+ end
@@ -0,0 +1,49 @@
1
+ module YARD::MRuby::Parser::C
2
+ class HeaderParser < Parser
3
+
4
+ # Consumes a directive and generates a DirectiveStatement
5
+ def consume_directive
6
+ super if @in_body_statements
7
+
8
+ @newline = false
9
+ start = @index
10
+ line = @line
11
+ statement = DirectiveStatement.new(nil, @file, line)
12
+ @statements << statement
13
+ attach_comment(statement)
14
+
15
+ multiline = false
16
+ advance_loop do
17
+ chr = char
18
+ case chr
19
+ when '\\'; multiline=true; advance
20
+ when /\s/; consume_whitespace
21
+ else advance
22
+ end
23
+
24
+ if @newline
25
+ if multiline
26
+ multiline = false
27
+ else
28
+ break
29
+ end
30
+ end
31
+ end
32
+
33
+ decl = @content[start...@index]
34
+
35
+ statement.declaration = decl
36
+ end
37
+
38
+ def consume_body_statements
39
+ @in_body_statements = true
40
+ result = super
41
+ @in_body_statements = false
42
+ result
43
+ end
44
+ end
45
+
46
+ #
47
+ # Register all header files (.h) to be processed with the above HeaderParser
48
+ YARD::Parser::SourceParser.register_parser_type :header, HeaderParser, 'h'
49
+ end
@@ -0,0 +1,10 @@
1
+ module YARD::MRuby::Parser
2
+ module C
3
+ class Parser < YARD::Parser::C::CParser
4
+ end
5
+
6
+ # Disable default C Parser
7
+ YARD::Parser::SourceParser.parser_types.delete(:c)
8
+ YARD::Parser::SourceParser.parser_type_extensions.delete(:c)
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ module YARD::MRuby::Parser::C
2
+ class SourceParser < Parser
3
+ end
4
+
5
+ #
6
+ # Register all header files (.h) to be processed with the above HeaderParser
7
+ YARD::Parser::SourceParser.register_parser_type :source, SourceParser, 'c'
8
+
9
+ end
@@ -0,0 +1,9 @@
1
+ require_relative 'templates/helpers'
2
+
3
+ YARD::MRuby::TEMPLATES_PATH = File.expand_path('../../../../templates', __FILE__)
4
+
5
+ # This registered template works for yardoc
6
+ YARD::Templates::Engine.register_template_path YARD::MRuby::TEMPLATES_PATH
7
+
8
+ # The following static paths and templates are for yard server
9
+ # YARD::Server.register_static_path File.join(YARD::MRuby::TEMPLATES_PATH,'default/fulldoc/html')
@@ -0,0 +1 @@
1
+ require_relative 'helpers/html_helper'
@@ -0,0 +1,32 @@
1
+ module YARD::MRuby::Templates
2
+ module Helpers
3
+ # Helper methods for text template formats.
4
+ module HTMLHelper
5
+
6
+ def fsignature(func, link = true, show_extras = true)
7
+ name = func.name
8
+ prefix = func.return_type || 'void'
9
+ params = if func.parameter_types.empty?
10
+ 'void'
11
+ else
12
+ func.parameter_types.map do |t|
13
+ if show_extras
14
+ [t.type, t.name].join(' ')
15
+ else
16
+ t.type
17
+ end
18
+ end.join(', ')
19
+ end
20
+ title = "%s <strong>%s</strong>(%s)" % [h(prefix), h(name), h(params)]
21
+
22
+ if link
23
+ url = url_for(func)
24
+ link_url(url, title, :title => name)
25
+ else
26
+ title
27
+ end
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -1,5 +1,5 @@
1
1
  module YARD
2
2
  module MRuby
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -1,3 +1,4 @@
1
1
  --plugin mruby
2
2
  mrblib/**/*.rb
3
3
  src/**/*.c
4
+ include/**/*.h
@@ -0,0 +1,10 @@
1
+ <% even_odd = 'odd' %>
2
+ <% @items.each do |item| %>
3
+ <li class="<%= even_odd %> <%= item.has_tag?(:deprecated) ? 'deprecated' : '' %>">
4
+ <div class="item">
5
+ <%= linkify item, h(item.name(true)) %>
6
+ <small><%= item.header.title %></small>
7
+ </div>
8
+ </li>
9
+ <% even_odd = (even_odd == 'even' ? 'odd' : 'even') %>
10
+ <% end %>
@@ -0,0 +1,10 @@
1
+ <li id="object_" class="odd"><div class="item" style="padding-left:30px"><%= link_object(YARD::MRuby::CodeObjects::HEADERS_ROOT, "All Headers", nil, false) %></div></li>
2
+ <% even_odd = 'odd' %>
3
+ <% @items.each do |item| %>
4
+ <li class="<%= even_odd %>">
5
+ <div class="item">
6
+ <%= linkify item, h(item.name(true)) %>
7
+ </div>
8
+ </li>
9
+ <% even_odd = (even_odd == 'even' ? 'odd' : 'even') %>
10
+ <% end %>
@@ -0,0 +1,62 @@
1
+ def init
2
+ super
3
+
4
+ YARD::MRuby::CodeObjects::HEADERS_ROOT.tap do |root|
5
+
6
+ # Generates the requirements splash page with the 'include' template
7
+ serialize root
8
+
9
+ root.headers.each do |header|
10
+ serialize header
11
+ end
12
+ end
13
+
14
+ end
15
+
16
+ def generate_header_list
17
+ headers = Registry.all(:header)
18
+ headers_ordered_by_name = headers.sort {|x,y| x.name.to_s <=> y.name.to_s }
19
+ generate_full_list headers_ordered_by_name, :headers
20
+ end
21
+
22
+ def generate_function_list
23
+ functions = Registry.all(:function)
24
+ functions_ordered_by_name = functions.sort {|x,y| x.name.to_s <=> y.name.to_s }
25
+ generate_full_list functions_ordered_by_name, :functions
26
+ end
27
+
28
+ # Helpler method to generate a full_list page of the specified objects with the
29
+ # specified type.
30
+ def generate_full_list(objects,type,options = {})
31
+ defaults = { :list_title => "#{type.to_s.capitalize} List",
32
+ :css_class => "class",
33
+ :list_filename => "#{type.to_s.gsub(/s$/,'')}_list.html" }
34
+
35
+ options = defaults.merge(options)
36
+
37
+ @items = objects
38
+ @list_type = type
39
+ @list_title = options[:list_title]
40
+ @list_class = options[:css_class]
41
+ asset options[:list_filename], erb(:full_list)
42
+ end
43
+
44
+ #
45
+ # @note This method overrides YARD's default template class_list method.
46
+ #
47
+ # The existing YARD 'Class List' search field contains all the YARD namespace objects.
48
+ # We, however, do not want the Include Namespace YARD Object (which holds the headers)
49
+ # as it is a meta-object.
50
+ #
51
+ # This method removes the namespace from the root node, generates the class list,
52
+ # and then adds it back into the root node.
53
+ #
54
+ def class_list(root = Registry.root)
55
+ return super unless root == Registry.root
56
+
57
+ include_namespace = YARD::MRuby::CodeObjects::HEADERS_ROOT
58
+ root.instance_eval { children.delete include_namespace }
59
+ out = super(root)
60
+ root.instance_eval { children.push include_namespace }
61
+ out
62
+ end
@@ -0,0 +1,10 @@
1
+ <h3 class="signature <%= 'first' if @index == 0 %>" id="<%= anchor_for(object) %>">
2
+ <%= fsignature(object, false) %>
3
+
4
+ <% if object.aliases.size > 0 %>
5
+ <span class="aliases">Also known as:
6
+ <span class="names"><%= object.aliases.map {|o|
7
+ "<span id='#{anchor_for(o)}'>" + h(o.name.to_s) + "</span>" }.join(", ") %></span>
8
+ </span>
9
+ <% end %>
10
+ </h3>
@@ -0,0 +1,3 @@
1
+ <div class="method_details <%= @index == 0 ? 'first' : '' %>">
2
+ <%= yieldall %>
3
+ </div>
@@ -0,0 +1,10 @@
1
+ <table class="source_code">
2
+ <tr>
3
+ <td>
4
+ <pre class="lines"><%= "\n\n\n" %><%= h format_lines(object) %></pre>
5
+ </td>
6
+ <td>
7
+ <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>
8
+ </td>
9
+ </tr>
10
+ </table>
@@ -0,0 +1,12 @@
1
+ include YARD::MRuby::Templates::Helpers::HTMLHelper
2
+
3
+ def init
4
+ sections :header, [:function_signature, T('docstring'), :source]
5
+ end
6
+
7
+ def source
8
+ return if owner != object.namespace
9
+ return if Tags::OverloadTag === object
10
+ return if object.source.nil?
11
+ erb(:source)
12
+ end
@@ -0,0 +1,11 @@
1
+ <% if define_listing.size > 0 %>
2
+ <h2>Define Summary</h2>
3
+ <dl class="constants">
4
+ <% define_listing.each do |define| %>
5
+ <dt id="<%= anchor_for(define) %>" class="<%= define.has_tag?(:deprecated) ? 'deprecated' : '' %>"><small>#define</small> <%= define.name %>
6
+ <%= yieldall :object => define %>
7
+ </dt>
8
+ <dd><pre class="code"><%#= format_constant define.value %></pre></dd>
9
+ <% end %>
10
+ </dl>
11
+ <% end %>
@@ -0,0 +1,7 @@
1
+ <div id="functions_details" class="method_details_list">
2
+ <h2>Function Details</h2>
3
+
4
+ <% function_listing.each_with_index do |func, i| %>
5
+ <%= yieldall :object => func, :owner => object, :index => i %>
6
+ <% end %>
7
+ </div>
@@ -0,0 +1,12 @@
1
+ <% if function_listing.size > 0 %>
2
+ <h2>
3
+ Function Summary
4
+ <small><a href="#" class="summary_toggle">collapse</a></small>
5
+ </h2>
6
+
7
+ <ul class="summary">
8
+ <% function_listing.each do |func| %>
9
+ <%= yieldall :item => func %>
10
+ <% end %>
11
+ </ul>
12
+ <% end %>
@@ -0,0 +1 @@
1
+ Header functions!
@@ -0,0 +1 @@
1
+ <h1><%= format_object_title(object) %></h1>
@@ -0,0 +1 @@
1
+ Included heaers
@@ -0,0 +1,19 @@
1
+ <li class="<%= @item.visibility %> <%= @item.has_tag?(:deprecated) ? 'deprecated' : '' %>">
2
+ <span class="summary_signature">
3
+ <%= fsignature(@item, true, false) %>
4
+
5
+ <% if @item.aliases.size > 0 %>
6
+ (also: <%= @item.aliases.map {|o| h(o.name(true)) }.join(", ") %>)
7
+ <% end %>
8
+ </span>
9
+ <% if @item.visibility != :public %><span class="note title <%= @item.visibility %>"><%= @item.visibility %></span><% end %>
10
+ <% if @item.has_tag?(:abstract) %><span class="abstract note title">abstract</span><% end %>
11
+ <% if @item.has_tag?(:deprecated) %><span class="deprecated note title">deprecated</span><% end %>
12
+ <% if @item.has_tag?(:api) && @item.tag(:api).text == 'private' %><span class="private note title">private</span><% end %>
13
+
14
+ <% if @item.has_tag?(:deprecated) %>
15
+ <span class="summary_desc"><strong>Deprecated.</strong> <%= htmlify_line @item.tag(:deprecated).text %></span>
16
+ <% else %>
17
+ <span class="summary_desc"><%= htmlify_line docstring_summary(@item) %></span>
18
+ <% end %>
19
+ </li>
@@ -0,0 +1 @@
1
+ <h2>Overview</h2>
@@ -0,0 +1,24 @@
1
+ include T('default/module')
2
+ include YARD::MRuby::Templates::Helpers::HTMLHelper
3
+
4
+ def init
5
+ sections :header, :pre_docstring, T('docstring'), :includes,
6
+ :function_summary, [:item_summary],
7
+ :define_summary, [T('docstring')],
8
+ :function_details_list, [T('function_details')]
9
+ end
10
+
11
+
12
+ def function_listing
13
+ return @funcs if @funcs
14
+
15
+ @funcs = object.functions
16
+ @funcs
17
+ end
18
+
19
+ def define_listing
20
+ return @defines if @defines
21
+
22
+ @defines = object.defines
23
+ @defines
24
+ end
@@ -0,0 +1,6 @@
1
+ <h2>All headers</h2>
2
+ <p class="children">
3
+ <% headers.each do |header| %>
4
+ <%= linkify(header, header.name(true)) %>
5
+ <% end %>
6
+ </p>
@@ -0,0 +1,10 @@
1
+ def init
2
+ super
3
+ sections.push :headers_list
4
+
5
+ @namespace = object
6
+ end
7
+
8
+ def headers
9
+ object.headers
10
+ end
@@ -0,0 +1,5 @@
1
+ <div id="footer">
2
+ Generated on <%= Time.now.strftime("%c") %> by
3
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
4
+ <%= YARD::VERSION %> in <a href="https://github.com/sagmor/yard-mruby">mruby mode</a> <%= YARD::MRuby::VERSION %> (ruby-<%= RUBY_VERSION %>).
5
+ </div>
@@ -0,0 +1,52 @@
1
+ def init
2
+ super
3
+ end
4
+
5
+ #
6
+ # Append yard-cucumber stylesheet to yard core stylesheets
7
+ #
8
+ def stylesheets
9
+ super + %w(css/mruby.css)
10
+ end
11
+
12
+ #
13
+ # Append yard-cucumber javascript to yard core javascripts
14
+ #
15
+ def javascripts
16
+ super + %w(js/mruby.js)
17
+ end
18
+
19
+ #
20
+ # Append yard-cucumber specific menus 'features' and 'tags'
21
+ #
22
+ # 'features' and 'tags' are enabled by default.
23
+ #
24
+ # 'step definitions' and 'steps' may be enabled by setting up a value in
25
+ # yard configuration file '~/.yard/config'
26
+ #
27
+ # @example `~/.yard.config`
28
+ #
29
+ # yard-cucumber:
30
+ # menus: [ 'features', 'directories', 'tags', 'step definitions', 'steps' ]
31
+ #
32
+ def menu_lists
33
+ menus = super
34
+ last = menus.pop
35
+
36
+ menus.push({
37
+ type: 'header',
38
+ title: 'Headers',
39
+ search_title: 'Header List'
40
+ })
41
+
42
+ menus.push({
43
+ type: 'function',
44
+ title: 'Functions',
45
+ search_title: 'Function List'
46
+ })
47
+
48
+ menus.push last
49
+
50
+ menus
51
+ end
52
+
@@ -0,0 +1,7 @@
1
+ def init
2
+ super
3
+ end
4
+
5
+ def param
6
+ super || tag(:param) if object.type == :function
7
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yard-mruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seba Gamboa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-23 00:00:00.000000000 Z
11
+ date: 2015-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard
@@ -69,7 +69,8 @@ dependencies:
69
69
  description: Generate Yard documentation for MRuby projects.
70
70
  email:
71
71
  - me@sagmor.com
72
- executables: []
72
+ executables:
73
+ - mrbdoc
73
74
  extensions: []
74
75
  extra_rdoc_files: []
75
76
  files:
@@ -83,24 +84,40 @@ files:
83
84
  - Rakefile
84
85
  - bin/console
85
86
  - bin/setup
87
+ - exe/mrbdoc
86
88
  - lib/yard-mruby.rb
87
- - lib/yard/handlers.rb
88
- - lib/yard/handlers/c.rb
89
- - lib/yard/handlers/c/mruby_base.rb
90
- - lib/yard/handlers/c/mruby_class_handler.rb
91
- - lib/yard/handlers/c/mruby_method_handler.rb
92
- - lib/yard/handlers/c/mruby_module_handler.rb
93
- - lib/yard/handlers/c/mruby_symbol_handler.rb
94
- - lib/yard/handlers/header.rb
95
- - lib/yard/handlers/header/base.rb
96
- - lib/yard/handlers/header/define_handler.rb
97
- - lib/yard/handlers/header/function_handler.rb
98
- - lib/yard/handlers/header/header_handler.rb
99
89
  - lib/yard/mruby.rb
90
+ - lib/yard/mruby/cli.rb
91
+ - lib/yard/mruby/cli/yardoc.rb
100
92
  - lib/yard/mruby/code_objects.rb
101
93
  - lib/yard/mruby/code_objects/define_object.rb
102
94
  - lib/yard/mruby/code_objects/function_object.rb
95
+ - lib/yard/mruby/code_objects/header_base_object.rb
103
96
  - lib/yard/mruby/code_objects/header_object.rb
97
+ - lib/yard/mruby/code_objects/headers_root.rb
98
+ - lib/yard/mruby/handlers.rb
99
+ - lib/yard/mruby/handlers/c.rb
100
+ - lib/yard/mruby/handlers/c/header.rb
101
+ - lib/yard/mruby/handlers/c/header/base.rb
102
+ - lib/yard/mruby/handlers/c/header/define_handler.rb
103
+ - lib/yard/mruby/handlers/c/header/function_handler.rb
104
+ - lib/yard/mruby/handlers/c/header/header_decl_handler.rb
105
+ - lib/yard/mruby/handlers/c/source.rb
106
+ - lib/yard/mruby/handlers/c/source/base.rb
107
+ - lib/yard/mruby/handlers/c/source/class_handler.rb
108
+ - lib/yard/mruby/handlers/c/source/init_handler.rb
109
+ - lib/yard/mruby/handlers/c/source/method_handler.rb
110
+ - lib/yard/mruby/handlers/c/source/module_handler.rb
111
+ - lib/yard/mruby/handlers/c/source/symbol_handler.rb
112
+ - lib/yard/mruby/parser.rb
113
+ - lib/yard/mruby/parser/c.rb
114
+ - lib/yard/mruby/parser/c/directive_statement.rb
115
+ - lib/yard/mruby/parser/c/header_parser.rb
116
+ - lib/yard/mruby/parser/c/parser.rb
117
+ - lib/yard/mruby/parser/c/source_parser.rb
118
+ - lib/yard/mruby/templates.rb
119
+ - lib/yard/mruby/templates/helpers.rb
120
+ - lib/yard/mruby/templates/helpers/html_helper.rb
104
121
  - lib/yard/mruby/version.rb
105
122
  - sample/.gitignore
106
123
  - sample/.inch.yml
@@ -116,6 +133,29 @@ files:
116
133
  - sample/mrblib/sample.rb
117
134
  - sample/src/sample.c
118
135
  - sample/test/sample_spec.rb
136
+ - templates/default/fulldoc/html/css/mruby.css
137
+ - templates/default/fulldoc/html/full_list_functions.erb
138
+ - templates/default/fulldoc/html/full_list_headers.erb
139
+ - templates/default/fulldoc/html/js/mruby.js
140
+ - templates/default/fulldoc/html/setup.rb
141
+ - templates/default/function_details/html/function_signature.erb
142
+ - templates/default/function_details/html/header.erb
143
+ - templates/default/function_details/html/source.erb
144
+ - templates/default/function_details/setup.rb
145
+ - templates/default/header/html/define_summary.erb
146
+ - templates/default/header/html/function_details_list.erb
147
+ - templates/default/header/html/function_summary.erb
148
+ - templates/default/header/html/functions.erb
149
+ - templates/default/header/html/header.erb
150
+ - templates/default/header/html/includes.erb
151
+ - templates/default/header/html/item_summary.erb
152
+ - templates/default/header/html/pre_docstring.erb
153
+ - templates/default/header/html/setup.rb
154
+ - templates/default/headersroot/html/headers_list.erb
155
+ - templates/default/headersroot/html/setup.rb
156
+ - templates/default/layout/html/footer.erb
157
+ - templates/default/layout/html/setup.rb
158
+ - templates/default/tags/setup.rb
119
159
  - yard-mruby.gemspec
120
160
  homepage: https://github.com/sagmor/yard-mruby
121
161
  licenses:
@@ -137,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
177
  version: '0'
138
178
  requirements: []
139
179
  rubyforge_project:
140
- rubygems_version: 2.4.5
180
+ rubygems_version: 2.4.5.1
141
181
  signing_key:
142
182
  specification_version: 4
143
183
  summary: Generate Yard documentation for MRuby projects.
@@ -1,2 +0,0 @@
1
- require_relative 'handlers/c'
2
- #require_relative 'handlers/header'
@@ -1,6 +0,0 @@
1
- require_relative 'c/mruby_base'
2
- require_relative 'c/mruby_symbol_handler'
3
- require_relative 'c/mruby_class_handler'
4
- require_relative 'c/mruby_module_handler'
5
- require_relative 'c/mruby_method_handler'
6
-
@@ -1,47 +0,0 @@
1
- module YARD::Handlers::C
2
- class MRubyBase < Base
3
-
4
- DEFAULT_NAMESPACES = {
5
- # 'mrb->top_self' => '',
6
- 'object_class' => 'Object',
7
- 'class_class' => 'Class',
8
- 'module_class' => 'Module',
9
- 'proc_class' => 'Proc',
10
- 'string_class' => 'String',
11
- 'array_class' => 'Array',
12
- 'hash_class' => 'Hash',
13
- 'float_class' => 'Float',
14
- 'fixnum_class' => 'Fixnum',
15
- 'true_class' => 'TrueClass',
16
- 'false_class' => 'FalseClass',
17
- 'nil_class' => 'NilClass',
18
- 'symbol_class' => 'Symbol',
19
- 'kernel_module' => 'Kernel'
20
- }
21
-
22
- def namespace_for_variable(var)
23
- DEFAULT_NAMESPACES[ var[/^\w+->(\w+)$/, 1] ] || super
24
- end
25
-
26
- def handle_class(var_name, class_name, parent, stmt, in_module = nil)
27
- object = super(var_name, class_name, parent, in_module)
28
-
29
- if stmt.comments
30
- register_docstring(object, stmt.comments.source, stmt)
31
- end
32
-
33
- object
34
- end
35
-
36
- def handle_module(var_name, module_name, stmt, in_module = nil)
37
- object = super(var_name, module_name, in_module)
38
-
39
- if stmt.comments
40
- register_docstring(object, stmt.comments.source, stmt)
41
- end
42
-
43
- object
44
- end
45
-
46
- end
47
- end
@@ -1 +0,0 @@
1
- require_relative 'header/base'
@@ -1,11 +0,0 @@
1
- module YARD
2
- module MRuby
3
- module Handlers
4
- module Header
5
- class Base < YARD::Handlers::Base
6
- include YARD::Parser::C
7
- end
8
- end
9
- end
10
- end
11
- end