yard-thunder 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ v0.1.0
2
+ + first version
@@ -0,0 +1,32 @@
1
+ [Yard-Thunder](http://stevenkaras.github.com/yard-thunder)
2
+ =======
3
+ YARD plugin for Thunder integration.
4
+
5
+ Code is based upon yard-thor by Loren Segal (who also maintains YARD itself). Way to go Loren!
6
+
7
+ Usage
8
+ -----
9
+
10
+ gem install yard-thunder
11
+
12
+ yard --plugin thunder COMMANDS
13
+
14
+ Goals
15
+ -----
16
+ Provide integration for Thunder CLI programs with YARD
17
+
18
+ Development Phases
19
+
20
+ 1. provide a section called "CLI usage" for each command (method)
21
+ 2. integrate options into the generated docs for a command
22
+ 3. handle subcommands (along with all the other stuff)
23
+ 4. add a CLI usage section/file in the YARD output (manpage style)
24
+ 5. activate only if Thunder is included (or has been included in a parent class)
25
+
26
+ Development
27
+ -----------
28
+ If you'd like to contribute, fork, commit, and request a pull. I'll get around to it. No special dependencies, or anything fancy
29
+
30
+ License
31
+ -------
32
+ MIT License
@@ -0,0 +1,47 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.test_files = FileList['test/*_test.rb']
5
+ t.test_files = FileList['test/test_*.rb']
6
+ t.test_files = FileList['spec/*_spec.rb']
7
+ t.test_files = FileList['spec/spec_*.rb']
8
+ t.libs << 'spec'
9
+ t.libs << 'test'
10
+ end
11
+
12
+ gemspec = eval(File.read(Dir["*.gemspec"].first))
13
+
14
+ desc "Run tests"
15
+ task :default => :test
16
+
17
+ desc "Validate the gemspec"
18
+ task :gemspec do
19
+ gemspec.validate
20
+ end
21
+
22
+ desc "Build the gem locally"
23
+ task :build => :gemspec do
24
+ system "gem build #{gemspec.name}.gemspec"
25
+ end
26
+
27
+ desc "Install the gem locally"
28
+ task :install => :build do
29
+ system "gem uninstall -a #{gemspec.name}"
30
+ system "gem install #{gemspec.name}-#{gemspec.version}.gem"
31
+ end
32
+
33
+ desc "check syntax"
34
+ task :syntax do
35
+ Dir["**/*.rb"].each do |file|
36
+ print "#{file}: "
37
+ system("ruby -c #{file}")
38
+ end
39
+ end
40
+
41
+ desc "delete all temporary files"
42
+ task :clean
43
+
44
+ desc "delete all temporary files and build artifacts"
45
+ task :clobber => :clean do
46
+ FileUtils.rm_rf Dir["#{gemspec.name}-*.gem"]
47
+ end
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.expand_path("../lib/", __FILE__)
4
+ require 'thunder'
5
+ require 'thunder/options/trollop'
6
+
7
+ class Bar
8
+ include Thunder
9
+
10
+ desc "doit", "do something with the Bar class"
11
+ option :verb, type: Boolean, desc: "verbosity"
12
+ def doit(options={})
13
+ p options
14
+ end
15
+ end
16
+
17
+ class Foo
18
+ include Thunder
19
+
20
+ #options_processor TrollopAdapter
21
+
22
+ desc "bar A", "desc"
23
+ def bar(a)
24
+ p a
25
+ end
26
+
27
+ desc "baz [options]"
28
+ option :flag, type: Boolean, desc: "run with a flag"
29
+ option :some, type: String, desc: "something", default: "some default value"
30
+ def baz(options = {})
31
+ p options
32
+ end
33
+
34
+ desc "quux COMMAND...", "send COMMAND to Bar"
35
+ subcommand "quux", ::Bar.new
36
+
37
+ end
38
+
39
+
40
+ Foo.new.start
@@ -0,0 +1,45 @@
1
+ $: << File.expand_path("..", __FILE__)
2
+
3
+ module YardThunder
4
+
5
+ require 'yard-thunder/description'
6
+ require 'yard-thunder/options'
7
+ require 'yard-thunder/subcommand'
8
+ require 'yard-thunder/default_command'
9
+
10
+ module ThunderMethodHandlerMixin
11
+ def register(*objs)
12
+ @registered_object = objs.first
13
+ super(*objs)
14
+ end
15
+ end
16
+ end
17
+
18
+ class YARD::Handlers::Processor
19
+ attr_accessor :extra_state
20
+ end
21
+
22
+ class YARD::Handlers::Ruby::MethodHandler
23
+ include YardThunder::ThunderMethodHandlerMixin
24
+ include YardThunder::MethodHandlerDescriptionMixin
25
+ include YardThunder::MethodHandlerOptionMixin
26
+ end
27
+
28
+ # class YARD::Handlers::Ruby::Legacy::MethodHandler
29
+ # include ::YardThunder::ThunderMethodHandlerMixin
30
+ # include ::YardThunder::MethodHandlerDescriptionMixin
31
+ # include YardThunder::MethodHandlerOptionMixin
32
+ # end
33
+
34
+ # module YARD::Templates::Helpers::HtmlHelper
35
+ # def signature_for_thunder_command(meth, link = true, *args)
36
+ # if meth.has_tag?(:thunder_command)
37
+ # sig = link ? link_object(meth, meth.signature) : meth.signature
38
+ # "$ " + sig
39
+ # else
40
+ # old_signature(meth, link, *args)
41
+ # end
42
+ # end
43
+ # alias old_signature signature
44
+ # alias signature signature_for_thunder_command
45
+ # end
@@ -0,0 +1,31 @@
1
+ module YardThunder
2
+ class DefaultCommandHandler < YARD::Handlers::Ruby::Base
3
+ handles method_call(:default_command)
4
+
5
+ process do
6
+ # statement.parameters(false).map do |param|
7
+ # param.jump(:string_content).source
8
+ # end
9
+ # name = statement.parameters.first.jump(:tstring_content, :ident).source
10
+ # object = YARD::CodeObjects::MethodObject.new(namespace, name)
11
+ # register(object)
12
+ # parse_block(statement.last.last, :owner => object)
13
+
14
+ # # modify the object
15
+ # object.dynamic = true
16
+
17
+ # # add custom metadata to the object
18
+ # object['custom_field'] = 'Generated by Methodify'
19
+ end
20
+ end
21
+
22
+ # class LegacyDefaultCommandHandler < YARD::Handlers::Ruby::Legacy::Base
23
+ # namespace_only
24
+ # handles /\Adefault_command(\s|\()/
25
+
26
+ # process do
27
+ # #TODO: write this
28
+ # end
29
+ # end
30
+
31
+ end
@@ -0,0 +1,46 @@
1
+ module YardThunder
2
+ class DescriptionHandler < YARD::Handlers::Ruby::Base
3
+ handles method_call(:desc)
4
+
5
+ process do
6
+ parser.extra_state.thunder_desc = statement.parameters(false).map do |param|
7
+ param.jump(:string_content).source
8
+ end
9
+ end
10
+ end
11
+
12
+ # class LegacyDescriptionHandler < YARD::Handlers::Ruby::Legacy::Base
13
+ # namespace_only
14
+ # handles /\Adesc(\s|\()/
15
+
16
+ # process do
17
+ # parser.extra_state ||= {}
18
+ # parser.extra_state[:thunder_desc] = tokval_list(statement.tokens[1..-1], :attr)
19
+ # end
20
+ # end
21
+
22
+ module MethodHandlerDescriptionMixin
23
+ def process
24
+ super
25
+ return unless parser.extra_state
26
+ #TODO: create a second code object for the thunder command itself
27
+
28
+ # handle a command description for this method
29
+ if parser.extra_state.thunder_desc
30
+ usage, desc = *parser.extra_state.thunder_desc
31
+ # drop in the description, if there is no "real" docstring
32
+ tags = @registered_object.tags
33
+ @registered_object.docstring = desc
34
+ tags.each { |tag| @registered_object.docstring.add_tag(tag) }
35
+ @registered_object.signature = usage
36
+
37
+ # add a second code object to describe the command line interface for this command
38
+ @registered_object.namespace.groups << ["Thunder Commands"] unless @registered_object.namespace.groups.include? "Thunder Commands"
39
+ # @registered_object.group = "Thunder Commands"
40
+ # @registered_object.docstring.add_tag YARD::Tags::Tag.new(:thunder_command, '')
41
+ parser.extra_state.thunder_desc = nil
42
+ end
43
+ end
44
+ end
45
+
46
+ end
@@ -0,0 +1,61 @@
1
+ module YardThunder
2
+ class OptionHandler < YARD::Handlers::Ruby::Base
3
+ handles method_call(:option)
4
+
5
+ process do
6
+ parser.extra_state.thunder_options ||= []
7
+ parser.extra_state.thunder_options << {}.tap do |option|
8
+ params = statement.parameters(false)
9
+ option[:name] = params[0].jump(:ident, :string_content).source
10
+ params[1].each do |param|
11
+ key = param.first.jump(:label, :ident)[0].to_sym
12
+ value = param[1][0].jump(:const, :kw, :string_content).source
13
+ option[key] = value
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ # class LegacyOptionHandler < YARD::Handlers::Ruby::Legacy::Base
20
+ # handles /\Aoption(\s|\()/
21
+
22
+ # process do
23
+ # parser.extra_state ||= {}
24
+ # parser.extra_state[:thunder_options] ||= []
25
+ # parser.extra_state[:thunder_options] << tokval_list(statement.tokens[1..-1], :attr)
26
+ # end
27
+ # end
28
+
29
+ module MethodHandlerOptionMixin
30
+ def process
31
+ super
32
+ return unless parser.extra_state
33
+ # handle any options for this command
34
+ if parser.extra_state.thunder_options
35
+ # add the options parameter to the method if it's not already there
36
+ unless @registered_object.tags(:param).find {|x| x.name == "options"}
37
+ option_param = YARD::Tags::Tag.new(:param, "a customizable set of options", "Hash", "options")
38
+ @registered_object.docstring.add_tag(option_param)
39
+ end
40
+
41
+ # trick the parser to parse the option as a YARDoc tag
42
+ parser.extra_state.thunder_options.each do |option|
43
+ name = option[:name]
44
+ description = option[:desc] || ""
45
+ if option[:default]
46
+ unless description.lstrip.start_with? /\(.+\)/
47
+ description = "(#{option[:default]}) #{description}"
48
+ end
49
+ end
50
+ type = option[:type] || "String"
51
+
52
+ text = "options #{name} [#{type}] #{description}"
53
+ option_tag = YARD::Tags::Library.default_factory.parse_tag_with_options(:option, text)
54
+ @registered_object.docstring.add_tag(option_tag)
55
+ end
56
+ parser.extra_state.thunder_options = nil
57
+ end
58
+ end
59
+ end
60
+
61
+ end
@@ -0,0 +1,31 @@
1
+ module YardThunder
2
+ class SubcommandHandler < YARD::Handlers::Ruby::Base
3
+ handles method_call(:subcommand)
4
+
5
+ process do
6
+ # statement.parameters(false).map do |param|
7
+ # param.jump(:string_content).source
8
+ # end
9
+ # name = statement.parameters.first.jump(:tstring_content, :ident).source
10
+ # object = YARD::CodeObjects::MethodObject.new(namespace, name)
11
+ # register(object)
12
+ # parse_block(statement.last.last, :owner => object)
13
+
14
+ # # modify the object
15
+ # object.dynamic = true
16
+
17
+ # # add custom metadata to the object
18
+ # object['custom_field'] = 'Generated by Methodify'
19
+ end
20
+ end
21
+
22
+ # class LegacySubcommandHandler < YARD::Handlers::Ruby::Legacy::Base
23
+ # namespace_only
24
+ # handles /\Asubcommand(\s|\()/
25
+
26
+ # process do
27
+ # #TODO: write this
28
+ # end
29
+ # end
30
+
31
+ end
@@ -0,0 +1,3 @@
1
+ module YardThunder
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yard-thunder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Steven Karas
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-20 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Integrates Thunder command line interfaces into YARD
15
+ email: steven.karas@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/sample.rb
21
+ - lib/yard-thunder/default_command.rb
22
+ - lib/yard-thunder/description.rb
23
+ - lib/yard-thunder/options.rb
24
+ - lib/yard-thunder/subcommand.rb
25
+ - lib/yard-thunder/version.rb
26
+ - lib/yard-thunder.rb
27
+ - CHANGELOG
28
+ - Rakefile
29
+ - README.md
30
+ homepage: http://stevenkaras.github.com/yard-thunder
31
+ licenses: []
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubyforge_project:
50
+ rubygems_version: 1.8.24
51
+ signing_key:
52
+ specification_version: 3
53
+ summary: YARD integration for Thunder
54
+ test_files: []
55
+ has_rdoc: