yard-amp 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/.yardoc/checksums ADDED
@@ -0,0 +1,5 @@
1
+ LICENSE 665ec4d7a681c6d942fe132844434b5f81e34999
2
+ README.rdoc e8e816eaee11fbfd5dbe5170541a2fbe9b35bb5c
3
+ lib/yard-amp.rb f2d20f66f531520be5409d7f94aacd4bdd91c619
4
+ lib/yard-amp/modern_handler.rb 9469c52c02117165008f813690449bb4833ac178
5
+ spec/examples/examples/simple_command.rb.txt 069ec92690ebdb1d263cf050951c1107dae4c316
Binary file
Binary file
@@ -0,0 +1,2 @@
1
+ {"YARD::Handlers::Ruby::Base:
2
+ class"YARD::CodeObjects: module
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Michael Edgar
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # yard-amp
2
+
3
+ Description goes here.
4
+
5
+ ## Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ ## Copyright
16
+
17
+ Copyright (c) 2010 Michael Edgar. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,47 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "yard-amp"
8
+ gem.summary = %Q{Automatically create YARD documentation for Amp commands.}
9
+ gem.description = %Q{yard-amp is a YARD plugin that enables the automatic creation of YARD } +
10
+ %Q{documentation from amp command declarations.}
11
+ gem.email = "michael.j.edgar@dartmouth.edu"
12
+ gem.homepage = "http://github.com/michaeledgar/yard-amp"
13
+ gem.authors = ["Michael Edgar"]
14
+ gem.add_dependency "yard", ">= 0.4.0"
15
+ gem.add_development_dependency "rspec", ">= 1.2.9"
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
+ end
22
+
23
+ require 'spec/rake/spectask'
24
+ Spec::Rake::SpecTask.new(:spec) do |spec|
25
+ spec.libs << 'lib' << 'spec'
26
+ spec.spec_files = FileList['spec/**/*_spec.rb']
27
+ spec.verbose = true
28
+ end
29
+
30
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
31
+ spec.libs << 'lib' << 'spec'
32
+ spec.pattern = 'spec/**/*_spec.rb'
33
+ spec.rcov = true
34
+ end
35
+
36
+ task :spec => :check_dependencies
37
+
38
+ task :default => :spec
39
+
40
+ begin
41
+ require 'yard'
42
+ YARD::Rake::YardocTask.new
43
+ rescue LoadError
44
+ task :yardoc do
45
+ abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
46
+ end
47
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.4.0
data/lib/yard-amp.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'yard'
2
+ require File.join(File.dirname(__FILE__), 'yard-amp', 'option')
3
+ require File.join(File.dirname(__FILE__), 'yard-amp', 'parsing_helpers')
4
+ require File.join(File.dirname(__FILE__), 'yard-amp', 'modern_handler') if RUBY_VERSION >= "1.9"
5
+ require File.join(File.dirname(__FILE__), 'yard-amp', 'legacy_handler') unless RUBY_VERSION >= "1.9"
6
+
7
+ YARD::Templates::Engine.register_template_path File.join(File.dirname(__FILE__), '..', 'templates')
@@ -0,0 +1,117 @@
1
+ module YARD::Amp
2
+ ##
3
+ # This handler is used by the Ruby 1.9+ parser engine. Uses AST nodes.
4
+ #
5
+ # All the interesting logic is actually all in SharedMethods. This class
6
+ # specifically defines the parsing logic to get the data ready for the
7
+ # Shared Methods.
8
+ class LegacyCommandHandler < YARD::Handlers::Ruby::Legacy::Base
9
+ MATCH = /command\(?\s*(.*?)\s*\)?\s*(do|\{)/
10
+ handles MATCH
11
+ #include YARD::CodeObjects
12
+ include ParsingHelpers
13
+
14
+ def process
15
+ params = statement.tokens.to_s[MATCH, 1].split(",").map {|x| clean_string(x)}
16
+ if params.size != 1
17
+ raise YARD::Parser::UndocumentableError, 'command declaration with invalid parameters'
18
+ end
19
+
20
+ command_name = params.first
21
+ command_name = command_name[1..-1] if command_name[0,1] == ":"
22
+ #
23
+ klass = ClassObject.new(commands_module, command_name.capitalize) do |o|
24
+ o.superclass = P("Amp::Command")
25
+ o.superclass.type = :class if o.superclass.is_a?(Proxy)
26
+ end
27
+ klass[:amp_data] ||= {}
28
+ klass[:amp_data].merge!(:docstring => statement.comments)
29
+ #
30
+ parse_block(:owner => klass)
31
+ register klass
32
+ construct_docstring(klass)
33
+ end
34
+
35
+ def commands_module
36
+ mod = register ModuleObject.new(:root, "Amp")
37
+ com_mod = register ModuleObject.new(mod, "Commands")
38
+ end
39
+ end
40
+ #
41
+ class LegacyAmpCommandHandler < YARD::Handlers::Ruby::Legacy::Base
42
+ include ParsingHelpers
43
+ def process
44
+ return nil unless owner.inheritance_tree(false).include?(P("Amp::Command"))
45
+ owner[:amp_data] ||= {}
46
+ true
47
+ end
48
+
49
+ def attach_metadata(meta = {})
50
+ owner[:amp_data].merge!(meta)
51
+ end
52
+
53
+ end
54
+ #
55
+ class LegacyHelpHandler < LegacyAmpCommandHandler
56
+ MATCH = /help=?\(?\s*(.*)\s*\)?\s*/
57
+ handles MATCH
58
+
59
+ def process
60
+ return unless super
61
+ param = clean_string(statement.tokens.to_s[MATCH, 1].strip)
62
+ attach_metadata(:help => param)
63
+ end
64
+ end
65
+ #
66
+ class LegacyDescriptionHandler < LegacyAmpCommandHandler
67
+ MATCH = /desc=?\(?\s*(.*)\s*\)?\s*/
68
+ handles MATCH
69
+
70
+ def process
71
+ return unless super
72
+
73
+ param = clean_string(statement.tokens.to_s[MATCH, 1].strip)
74
+ attach_metadata.merge!(:desc => param)
75
+ end
76
+ end
77
+ #
78
+ class LegacyWorkflowHandler < LegacyAmpCommandHandler
79
+ MATCH = /workflow=?\(?\s*(.*)\s*\)?\s*/
80
+ handles MATCH
81
+
82
+ def process
83
+ return unless super
84
+ param = clean_string(statement.tokens.to_s[MATCH, 1].strip)
85
+ attach_metadata.merge!(:workflow => param)
86
+ end
87
+ end
88
+ #
89
+ class LegacyOptionHandler < LegacyAmpCommandHandler
90
+ MATCH = /(opt|add_opt)\(?\s*(.*)\s*\)?\s*/
91
+ handles MATCH
92
+
93
+ def process
94
+ return unless super
95
+ params = split_by_comma_smart(statement.tokens.to_s[MATCH, 2]).map {|x| clean_string(x.strip)}
96
+ option = parse_parameters(params)
97
+ owner[:amp_data][:options] ||= []
98
+ owner[:amp_data][:options] << option
99
+ end
100
+
101
+ def parse_parameters(params)
102
+ name = clean_string(params.first)
103
+ description = clean_string(params[1])
104
+ option = OptionObject.new(owner, name, description)
105
+ if params[2..-1]
106
+ reg = /(.*?)\s*=>\s*([^,]*)/
107
+ params[2..-1].each do |param|
108
+ if param =~ reg
109
+ option.options[clean_string($1)] = clean_string $2
110
+ end
111
+ end
112
+ end
113
+ option.docstring = statement.comments
114
+ option
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,108 @@
1
+ module YARD::Amp
2
+ ##
3
+ # This handler is used by the Ruby 1.9+ parser engine. Uses AST nodes.
4
+ #
5
+ # All the interesting logic is actually all in SharedMethods. This class
6
+ # specifically defines the parsing logic to get the data ready for the
7
+ # Shared Methods.
8
+ class ModernCommandHandler < YARD::Handlers::Ruby::Base
9
+ handles method_call(:command)
10
+ include YARD::CodeObjects
11
+ include ParsingHelpers
12
+
13
+ def process
14
+ if statement.parameters.size != 2
15
+ raise YARD::Parser::UndocumentableError, 'command declaration with invalid parameters'
16
+ end
17
+ command_name = statement.parameters.first.source
18
+ command_name = command_name[1..-1] if command_name[0,1] == ":"
19
+
20
+ klass = ClassObject.new(commands_module, command_name.capitalize) do |o|
21
+ o.superclass = P("Amp::Command")
22
+ o.superclass.type = :class if o.superclass.is_a?(Proxy)
23
+ end
24
+ klass[:amp_data] ||= {}
25
+ klass[:amp_data].merge!(:docstring => statement.comments)
26
+
27
+ parse_block statement[2].children[1], owner: klass
28
+ register klass
29
+ construct_docstring(klass)
30
+ end
31
+
32
+ def workflow_module(workflow)
33
+ register ModuleObject.new(commands_module, workflow.to_s.capitalize)
34
+ end
35
+
36
+ def commands_module
37
+ mod = register ModuleObject.new(:root, "Amp")
38
+ com_mod = register ModuleObject.new(mod, "Commands")
39
+ end
40
+ end
41
+
42
+ class ModernAmpCommandHandler < YARD::Handlers::Ruby::Base
43
+ include ParsingHelpers
44
+ def process
45
+ return nil unless owner.inheritance_tree(false).include?(P("Amp::Command"))
46
+ owner[:amp_data] ||= {}
47
+ true
48
+ end
49
+
50
+ def attach_metadata(meta = {})
51
+ owner[:amp_data].merge!(meta)
52
+ end
53
+
54
+ end
55
+
56
+ class ModernHelpHandler < ModernAmpCommandHandler
57
+ handles method_call(:help), method_call(:help=)
58
+
59
+ def process
60
+ return unless super
61
+ params = statement.parameters
62
+ attach_metadata(help: clean_string(params.first.source))
63
+ end
64
+ end
65
+
66
+ class ModernDescriptionHandler < ModernAmpCommandHandler
67
+ handles method_call(:desc), method_call(:desc=)
68
+
69
+ def process
70
+ return unless super
71
+ params = statement.parameters
72
+ attach_metadata.merge!(desc: clean_string(params.first.source))
73
+ end
74
+ end
75
+
76
+ class ModernWorkflowHandler < ModernAmpCommandHandler
77
+ handles method_call(:workflow), method_call(:workflow=)
78
+
79
+ def process
80
+ return unless super
81
+ params = statement.parameters
82
+ attach_metadata.merge!(workflow: clean_string(params.first.source))
83
+ end
84
+ end
85
+
86
+ class ModernOptionHandler < ModernAmpCommandHandler
87
+ handles method_call(:opt), method_call(:add_opt)
88
+
89
+ def process
90
+ return unless super
91
+ params = statement.parameters
92
+ option = parse_parameters(params)
93
+ owner[:amp_data][:options] ||= []
94
+ owner[:amp_data][:options] << option
95
+ end
96
+
97
+ def parse_parameters(params)
98
+ name = clean_string(params.first.source)
99
+ description = clean_string(params[1].source)
100
+ option = OptionObject.new(owner, name, description)
101
+ if params[2]
102
+ option.options = parse_hash(params[2])
103
+ end
104
+ option.docstring = statement.comments
105
+ option
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,26 @@
1
+ module YARD::Amp
2
+ class OptionObject < YARD::CodeObjects::Base
3
+ attr_accessor :description, :options
4
+ def initialize(namespace, name, description, opts = {}, *args)
5
+ super
6
+ self.description, self.options = description, opts
7
+ opts["type"] ||= "flag"
8
+ end
9
+
10
+ def signature
11
+ "--#{self.name}" +
12
+ (options["short"] && options["short"] != "none" ? ", -#{options["short"]}" : "") +
13
+ case options["type"]
14
+ when "flag"; ""
15
+ when "int"; " &lt;i&gt;"
16
+ when "ints"; " &lt;i+&gt;"
17
+ when "string"; " &lt;s&gt;"
18
+ when "strings"; " &lt;s+&gt;"
19
+ when "float"; " &lt;f&gt;"
20
+ when "floats"; " &lt;f+&gt;"
21
+ when "io"; " &lt;filename/uri&gt;"
22
+ when "ios"; " &lt;filename/uri+&gt;"
23
+ end.to_s
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,62 @@
1
+ module YARD::Amp
2
+ module ParsingHelpers
3
+ def clean_string(str)
4
+ if str[0,2] == ":\"" && str[-1,1] == "\""
5
+ str[2..-2]
6
+ elsif str[0,1] == ":"
7
+ str[1..-1]
8
+ elsif str[0,1] =~ /['"]/ && str[-1,1] == str[0,1]
9
+ str[1..-2]
10
+ elsif str[0,3] =~ /%q\{/i && str[-1,1] == "}"
11
+ str[3..-2]
12
+ elsif str[0,3] == "<<-"
13
+ prefix = str[3..-1] =~ /[\S]+/
14
+ if prefix
15
+ prefix = $&
16
+ # check if it starts and ends with it
17
+ if str[-1 * prefix.size..-1] == str[3...prefix.size+3]
18
+ return str[3 + prefix.size..(-1 * prefix.size - 2)]
19
+ end
20
+ end
21
+ str
22
+ else
23
+ str
24
+ end
25
+ end
26
+
27
+ def construct_docstring(klass)
28
+ klass.docstring = "== #{klass[:amp_data][:desc]}\n\n#{klass[:amp_data][:help]}\n#{klass[:amp_data][:docstring]}"
29
+ end
30
+
31
+ def parse_hash(node)
32
+ node.children.inject({}) do |hash, pair|
33
+ unless pair.type == :assoc
34
+ raise YARD::Parser::UndocumentableError, %Q{expected an :assoc in a hash but got #{pair.type}}
35
+ end
36
+ key = clean_string pair[0].source
37
+ val = clean_string pair[1].source
38
+ hash[key] = val
39
+ hash
40
+ end
41
+ end
42
+
43
+ def split_by_comma_smart(string)
44
+ result = []
45
+ in_quote = false
46
+ last_spot = 0
47
+ string.split(//).each_with_index do |char, idx|
48
+ if char =~ /['"]/
49
+ in_quote = !in_quote
50
+ elsif char == "," && !in_quote
51
+ result << string[last_spot..(idx - 1)]
52
+ last_spot = idx + 1
53
+ end
54
+ end
55
+ unless last_spot == string.size - 1
56
+ result << string[last_spot..-1]
57
+ end
58
+ result
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,23 @@
1
+ require 'yard'
2
+
3
+ ##
4
+ # Stolen from http://github.com/postmodern/yard-parameters/blob/master/spec/helpers/examples.rb.
5
+ #
6
+ # Thanks!
7
+
8
+ module Helpers
9
+ module Examples
10
+ EXAMPLES_DIR = File.expand_path(File.join(File.dirname(__FILE__),'examples'))
11
+
12
+ def parse_file(file, thisfile = __FILE__)
13
+ YARD::Registry.clear
14
+
15
+ path = File.join(Helpers::Examples::EXAMPLES_DIR, "#{file}.rb.txt")
16
+ YARD::Parser::SourceParser.parse(path)
17
+ end
18
+
19
+ def yard(name)
20
+ YARD::Registry.at(name)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,40 @@
1
+ ##
2
+ # @example
3
+ # amp init --type=git
4
+ # @example
5
+ # amp init --source=http://bitbucket.org/carbonica/amp/
6
+ command :init do |c|
7
+ c.workflow :all
8
+ c.help %Q{Help info for init}
9
+ c.desc "Initializes a new repository in the current directory."
10
+ # This option is used for the multi-repo-ness of amp
11
+ c.opt :type, "Which type of repository (git, hg)", :short => '-t', :type => :string, :default => 'hg'
12
+ # @example amp init --source='http://github.com/michaeledgar/amp/'
13
+ c.opt :source, "Where the source repository could be found", :short => '-s', :multi => true
14
+ c.opt :"no-opts", "This has no extra configuration things" if x && y
15
+
16
+ c.on_run do |options, args|
17
+ path = args.first ? args.first : '.'
18
+
19
+ case options[:type]
20
+ when 'hg'
21
+ Amp::Repositories::Mercurial::LocalRepository.new(path, true, options[:global_config])
22
+ when 'git'
23
+ Amp::Repositories::Git::LocalRepository.new(path, true, options[:global_config])
24
+ else
25
+ raise "Unknown repository type #{options[:type].inspect}"
26
+ end
27
+
28
+ puts "New #{options[:type]} repository initialized."
29
+ end
30
+ end
31
+
32
+ command(:braced) {|c|
33
+ c.help "Some Help Info"
34
+ c.desc "More Descriptive stuff"
35
+ }
36
+
37
+ class NotACommand
38
+ help "Other help should never show up"
39
+ desc "Some description to be ignored"
40
+ end
@@ -0,0 +1,50 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe ::YARD::Amp::ParsingHelpers, '#clean_string' do
4
+ include YARD::Amp::ParsingHelpers
5
+ it "cleans normal symbols" do
6
+ clean_string(":some_symbol").should == "some_symbol"
7
+ end
8
+
9
+ it "cleans quoted symbols" do
10
+ clean_string(":\"long symbol\"").should == "long symbol"
11
+ end
12
+
13
+ it "cleans normal strings" do
14
+ clean_string("\"a big long string\"").should == "a big long string"
15
+ end
16
+
17
+ it "cleans special-quoted strings" do
18
+ clean_string("%Q{some big long string}").should == "some big long string"
19
+ end
20
+
21
+ it "cleans heredocs" do
22
+ clean_string("<<-EOF\nsome string\n another lines\n another line\nEOF").should == "\nsome string\n another lines\n another line"
23
+ end
24
+ end
25
+
26
+ describe ::YARD::Amp::ParsingHelpers, '#split_by_comma_smart' do
27
+ include YARD::Amp::ParsingHelpers
28
+ it "splits simple strings" do
29
+ split_by_comma_smart(":hello, :world, :im_mike").should == [":hello", " :world", " :im_mike"]
30
+ end
31
+
32
+ it "splits slightly tougher strings" do
33
+ split_by_comma_smart(":hello, \"a big long, string\", :is_nice").should == [":hello", " \"a big long, string\"", " :is_nice"]
34
+ end
35
+ end
36
+
37
+ if RUBY19
38
+ describe ::YARD::Amp::ParsingHelpers, '#parse_hash' do
39
+ include YARD::Amp::ParsingHelpers
40
+ it "parses hashes into hash objects" do
41
+ ast = YARD::Parser::SourceParser.parse_string("{\"hello\" => \"world\"}").ast.first
42
+ parse_hash(ast).should == {"hello" => "world"}
43
+ end
44
+
45
+ it "parses hashes with symbols into string-based hashes" do
46
+ ast = YARD::Parser::SourceParser.parse_string("{:\"no-color\" => true}").ast.first
47
+ parse_hash(ast).should == {"no-color" => "true"}
48
+ end
49
+ end
50
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rubygems'
4
+ require 'yard-amp'
5
+ require 'spec'
6
+ require 'spec/autorun'
7
+ require 'examples/example_helper'
8
+
9
+ Spec::Runner.configure do |config|
10
+
11
+ end
12
+ include YARD
@@ -0,0 +1,105 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "::YARD::Amp::#{}ModernCommandHandler" do
4
+ include Helpers::Examples
5
+ before(:all) do
6
+ parse_file :simple_command
7
+ @init_cmd = Registry.at("Amp::Commands::Init")
8
+ @braced_cmd = Registry.at("Amp::Commands::Braced")
9
+ end
10
+
11
+ it "creates commands when parsing a command declaration" do
12
+ @init_cmd.should_not be_nil
13
+ end
14
+
15
+ it "assigns commands the superclass of Amp::Command" do
16
+ @init_cmd.superclass.path.should == "Amp::Command"
17
+ end
18
+
19
+ it "creates a metadata hash on amp command classes" do
20
+ @init_cmd[:amp_data].should_not be_nil
21
+ end
22
+
23
+ it "extracts help information and attaches it as metadata" do
24
+ @init_cmd[:amp_data].should have_key(:help)
25
+ @init_cmd[:amp_data][:help].should == "Help info for init"
26
+ end
27
+
28
+ it "extracts description information and attaches it as metadata" do
29
+ @init_cmd[:amp_data].should have_key(:desc)
30
+ @init_cmd[:amp_data][:desc].should == "Initializes a new repository in the current directory."
31
+ end
32
+
33
+ it "retains the docstring attached to the call to #command" do
34
+ @init_cmd.docstring.tags(:example).size.should_not == 0
35
+ end
36
+
37
+ it "ignores help or description calls not in a command" do
38
+ Registry.at("NotACommand")[:amp_data].should be_nil
39
+ end
40
+
41
+ it "parses brace syntax as well as do...end syntax" do
42
+ @braced_cmd.should_not be_nil
43
+ end
44
+
45
+ it "constructs a reasonable docstring" do
46
+ @init_cmd.docstring.should == "== Initializes a new repository in the current directory.\n\nHelp info for init"
47
+ end
48
+
49
+ it "processes all the command-line options" do
50
+ @init_cmd[:amp_data].should have_key(:options)
51
+ @init_cmd[:amp_data][:options].size.should == 3
52
+ end
53
+
54
+ it "extracts the names of command-line options" do
55
+ found_opts = @init_cmd[:amp_data][:options]
56
+ ["type", "source", "no-opts"].each do |expected_opt|
57
+ opt = found_opts.find {|x| x.name.to_s == expected_opt}
58
+ fail "Option '#{expected_opt}' not found on the Init command." unless opt
59
+ end
60
+ end
61
+
62
+ it "extracts the descriptions of command-line options" do
63
+ found_opts = @init_cmd[:amp_data][:options]
64
+ expected_descriptions = ["Which type of repository (git, hg)", "Where the source repository could be found"]
65
+ expected_descriptions.each do |expected_desc|
66
+ opt = found_opts.find {|x| x.description == expected_desc}
67
+ fail "Option with description '#{expected_desc}' not found on the Init command." unless opt
68
+ end
69
+ end
70
+
71
+ it "extracts the additional options associated with individual command-line options" do
72
+ found_opts = @init_cmd[:amp_data][:options]
73
+ type_opt = found_opts.find {|x| x.name == :type}
74
+ source_opt = found_opts.find {|x| x.name == :source}
75
+ none_opt = found_opts.find {|x| x.name == :"no-opts"}
76
+
77
+ type_opt.should_not be_nil
78
+ source_opt.should_not be_nil
79
+ type_opt[:options].should_not be_nil
80
+ source_opt[:options].should_not be_nil
81
+
82
+ type_opt[:options]["short"].should == "-t"
83
+ type_opt[:options]["type"].should == "string"
84
+ type_opt[:options]["default"].should == "hg"
85
+
86
+ source_opt[:options]["short"].should == "-s"
87
+ source_opt[:options]["multi"].should == "true"
88
+
89
+ none_opt[:options].should == {"type" => "flag"}
90
+ end
91
+
92
+ it "attaches comments to parsed options" do
93
+ found_opts = @init_cmd[:amp_data][:options]
94
+ type_opt = found_opts.find {|x| x.name == :type}
95
+
96
+ type_opt.docstring.should == "This option is used for the multi-repo-ness of amp"
97
+ end
98
+
99
+ it "attaches tags to parsed options" do
100
+ found_opts = @init_cmd[:amp_data][:options]
101
+ source_opt = found_opts.find {|x| x.name == :source}
102
+
103
+ source_opt.docstring.tags(:example).should_not be_empty
104
+ end
105
+ end
@@ -0,0 +1,15 @@
1
+ <% if @amp_options.size > 0 %>
2
+ <h2>Command-line Options</h2>
3
+ <ul class="summary">
4
+ <% @amp_options.each do |option| %>
5
+ <li class="public">
6
+ <span class="summary_signature"><%= option.signature %></span>
7
+ <span class="summary_desc">
8
+ <div class="inline">
9
+ <p><%= option.description %></p>
10
+ </div>
11
+ </span>
12
+ </li>
13
+ <% end %>
14
+ </ul>
15
+ <% end %>
@@ -0,0 +1,15 @@
1
+ def init
2
+ super
3
+ sections.place(:amp_options).before(:constant_summary)
4
+ end
5
+
6
+ def amp_options
7
+ unless object[:amp_data] && object[:amp_data][:options]
8
+ @amp_options = []
9
+ else
10
+ @amp_options = object[:amp_data][:options].sort do |x, y|
11
+ x.name <=> y.name
12
+ end
13
+ end
14
+ erb(:amp_options)
15
+ end
File without changes
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yard-amp
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 4
8
+ - 0
9
+ version: 0.4.0
10
+ platform: ruby
11
+ authors:
12
+ - Michael Edgar
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-05-14 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: yard
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 4
30
+ - 0
31
+ version: 0.4.0
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rspec
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 2
44
+ - 9
45
+ version: 1.2.9
46
+ type: :development
47
+ version_requirements: *id002
48
+ description: yard-amp is a YARD plugin that enables the automatic creation of YARD documentation from amp command declarations.
49
+ email: michael.j.edgar@dartmouth.edu
50
+ executables: []
51
+
52
+ extensions: []
53
+
54
+ extra_rdoc_files:
55
+ - LICENSE
56
+ - README.md
57
+ files:
58
+ - .document
59
+ - .gitignore
60
+ - .yardoc/checksums
61
+ - .yardoc/objects/YARD/Amp.dat
62
+ - .yardoc/objects/YARD/Amp/ModernCommandHandler.dat
63
+ - .yardoc/objects/YARD/Amp/ModernCommandHandler/commands_module_i.dat
64
+ - .yardoc/objects/YARD/Amp/ModernCommandHandler/process_i.dat
65
+ - .yardoc/objects/root.dat
66
+ - .yardoc/proxy_types
67
+ - LICENSE
68
+ - README.md
69
+ - Rakefile
70
+ - VERSION
71
+ - lib/yard-amp.rb
72
+ - lib/yard-amp/legacy_handler.rb
73
+ - lib/yard-amp/modern_handler.rb
74
+ - lib/yard-amp/option.rb
75
+ - lib/yard-amp/parsing_helpers.rb
76
+ - spec/examples/example_helper.rb
77
+ - spec/examples/examples/simple_command.rb.txt
78
+ - spec/parsing_helpers_spec.rb
79
+ - spec/spec.opts
80
+ - spec/spec_helper.rb
81
+ - spec/yard-amp_spec.rb
82
+ - templates/default/class/html/amp_options.erb
83
+ - templates/default/class/setup.rb
84
+ - templates/default/class/text/amp_options.erb
85
+ has_rdoc: true
86
+ homepage: http://github.com/michaeledgar/yard-amp
87
+ licenses: []
88
+
89
+ post_install_message:
90
+ rdoc_options:
91
+ - --charset=UTF-8
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ segments:
99
+ - 0
100
+ version: "0"
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ requirements: []
109
+
110
+ rubyforge_project:
111
+ rubygems_version: 1.3.6
112
+ signing_key:
113
+ specification_version: 3
114
+ summary: Automatically create YARD documentation for Amp commands.
115
+ test_files:
116
+ - spec/examples/example_helper.rb
117
+ - spec/parsing_helpers_spec.rb
118
+ - spec/spec_helper.rb
119
+ - spec/yard-amp_spec.rb