Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit.

  • Loading branch information...
commit 9597e30aa7d6c30fdfd3a92fa1e91855f2b6bb65 0 parents
@postmodern authored
9 .gitignore
@@ -0,0 +1,9 @@
+doc
+pkg
+tmp/*
+.DS_Store
+.yardoc
+*.db
+*.log
+*.swp
+*~
1  .specopts
@@ -0,0 +1 @@
+--colour --format specdoc
1  .yardopts
@@ -0,0 +1 @@
+--markup markdown --title 'YARD Contextify Documentation' --protected --files ChangeLog.md,LICENSE.txt
5 ChangeLog.md
@@ -0,0 +1,5 @@
+### 0.1.0 / 2010-05-07
+
+* Initial release:
+ * Parses `contextify :name` class-methods.
+
21 LICENSE.txt
@@ -0,0 +1,21 @@
+
+Copyright (c) 2010 Hal Brodigan
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 README.md
@@ -0,0 +1,25 @@
+# yard-contextify
+
+* [github.com/postmodern/yard-contextify](http://github.com/postmodern/yard-contextify)
+* [github.com/postmodern/yard-contextify/issues](http://github.com/postmodern/yard-contextify/issues)
+
+## Description
+
+yard-contextify is a plugin for YARD for parsing contextified classes.
+
+## Features
+
+* Parses `contextify :name` class method-calls.
+
+## Requirements
+
+* [yard](http://yardoc.org/) >= 0.4.0
+
+## Install
+
+ $ sudo gem install yard-contextify
+
+## Copyright
+
+See {file:LICENSE.txt} for license information.
+
40 Rakefile
@@ -0,0 +1,40 @@
+require 'rubygems'
+require 'rake'
+
+begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |gem|
+ gem.name = "yard-contextify"
+ gem.license = 'MIT'
+ gem.summary = %Q{A plugin for YARD for parsing contextified classes.}
+ gem.description = %Q{yard-contextify is a plugin for YARD for parsing contextified classes.}
+ gem.email = "postmodern.mod3@gmail.com"
+ gem.homepage = "http://github.com/postmodern/yard-contextify"
+ gem.authors = ["postmodern"]
+ gem.add_dependency "yard", ">= 0.4.0"
+ gem.add_development_dependency "rspec", "~> 1.3.0"
+ gem.has_rdoc = 'yard'
+ end
+ Jeweler::GemcutterTasks.new
+rescue LoadError
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
+end
+
+require 'spec/rake/spectask'
+Spec::Rake::SpecTask.new(:spec) do |spec|
+ spec.libs += ['lib', 'spec']
+ spec.spec_files = FileList['spec/**/*_spec.rb']
+ spec.spec_opts = ['--options', '.specopts']
+end
+
+task :spec => :check_dependencies
+task :default => :spec
+
+begin
+ require 'yard'
+ YARD::Rake::YardocTask.new
+rescue LoadError
+ task :yard do
+ abort "YARD is not available. In order to run yard, you must: gem install yard"
+ end
+end
1  VERSION
@@ -0,0 +1 @@
+0.1.0
2  lib/yard-contextify.rb
@@ -0,0 +1,2 @@
+require 'yard-contextify/contextify_handler'
+require 'yard-contextify/legacy'
26 lib/yard-contextify/contextify_handler.rb
@@ -0,0 +1,26 @@
+module YARD
+ module Contextify
+ class ContextifyHandler < YARD::Handlers::Ruby::Base
+
+ handles method_call(:contextify)
+
+ def process
+ nobj = namespace
+ mscope = scope
+ name = statement.parameters[0].first
+
+ if name.type == :symbol
+ name = name.source[1..-1]
+
+ register ModuleObject.new('Kernel', name, :instance) do |o|
+ o.visibility = :public
+ o.source = statement.source
+ o.signature = "def #{name}"
+ p.parameters = [['*args', nil], ['&block', nil]]
+ end
+ end
+ end
+
+ end
+ end
+end
1  lib/yard-contextify/legacy.rb
@@ -0,0 +1 @@
+require 'yard-contextify/legacy/contextify_handler'
24 lib/yard-contextify/legacy/contextify_handler.rb
@@ -0,0 +1,24 @@
+module YARD
+ module Contextify
+ module Legacy
+ class ContextifyHandler < YARD::Handlers::Ruby::Legacy::Base
+
+ handles /\Acontextify\s+:/
+
+ def process
+ nobj = namespace
+ mscope = scope
+ name = statement.tokens[2,1].to_s[1..-1]
+
+ register MethodObject.new('Kernel', name, :instance) do |o|
+ o.visibility = :public
+ o.source = statement.source
+ o.signature = "def #{name}"
+ o.parameters = [['*args', nil]]
+ end
+ end
+
+ end
+ end
+ end
+end
29 spec/contextify_handler_spec.rb
@@ -0,0 +1,29 @@
+require 'spec_helper'
+require 'helpers/examples'
+
+require 'yard-contextify/contextify_handler'
+require 'yard-contextify/legacy/contextify_handler'
+
+describe "ContextifyHandler" do
+ include Helpers::Examples
+
+ context "valid" do
+ before(:all) do
+ parse_file :simple_contextify
+ end
+
+ it "should register a Kernel method for the class" do
+ yard('Kernel#simple_context').should be_instance_of(CodeObjects::ModuleObject)
+ end
+ end
+
+ context "invalid" do
+ before(:all) do
+ parse_file :bad_contextify
+ end
+
+ it "should not register a Kernel methods for variables" do
+ yard('Kenrel#contextify').should be_nil
+ end
+ end
+end
18 spec/helpers/examples.rb
@@ -0,0 +1,18 @@
+require 'yard'
+
+module Helpers
+ module Examples
+ EXAMPLES_DIR = File.expand_path(File.join(File.dirname(__FILE__),'examples'))
+
+ def parse_file(file,thisfile=__FILE__)
+ YARD::Registry.clear
+
+ path = File.join(Helpers::Examples::EXAMPLES_DIR, "#{file}.rb.txt")
+ YARD::Parser::SourceParser.parse(path)
+ end
+
+ def yard(name)
+ YARD::Registry.at(name)
+ end
+ end
+end
7 spec/helpers/examples/bad_contextify.rb.txt
@@ -0,0 +1,7 @@
+class BadClass
+
+ include Contextify
+
+ contextify = contextify.to_s.to_sym
+
+end
7 spec/helpers/examples/simple_contextify.rb.txt
@@ -0,0 +1,7 @@
+class SimpleClass
+
+ include Contextify
+
+ contextify :simple_context
+
+end
8 spec/spec_helper.rb
@@ -0,0 +1,8 @@
+require 'rubygems'
+gem 'rspec', '>=1.3.0'
+require 'spec'
+
+gem 'yard', '>=0.4.0'
+require 'yard'
+
+include YARD
69 yard-contextify.gemspec
@@ -0,0 +1,69 @@
+# Generated by jeweler
+# DO NOT EDIT THIS FILE DIRECTLY
+# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{yard-contextify}
+ s.version = "0.1.0"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["postmodern"]
+ s.date = %q{2010-05-07}
+ s.description = %q{yard-contextify is a plugin for YARD for parsing contextified classes.}
+ s.email = %q{postmodern.mod3@gmail.com}
+ s.extra_rdoc_files = [
+ "ChangeLog.md",
+ "LICENSE.txt",
+ "README.md"
+ ]
+ s.files = [
+ ".gitignore",
+ ".specopts",
+ ".yardopts",
+ "ChangeLog.md",
+ "LICENSE.txt",
+ "README.md",
+ "Rakefile",
+ "VERSION",
+ "lib/yard-contextify.rb",
+ "lib/yard-contextify/contextify_handler.rb",
+ "lib/yard-contextify/legacy.rb",
+ "lib/yard-contextify/legacy/contextify_handler.rb",
+ "spec/contextify_handler_spec.rb",
+ "spec/helpers/examples.rb",
+ "spec/helpers/examples/bad_contextify.rb.txt",
+ "spec/helpers/examples/simple_contextify.rb.txt",
+ "spec/spec_helper.rb",
+ "yard-contextify.gemspec"
+ ]
+ s.has_rdoc = %q{yard}
+ s.homepage = %q{http://github.com/postmodern/yard-contextify}
+ s.licenses = ["MIT"]
+ s.rdoc_options = ["--charset=UTF-8"]
+ s.require_paths = ["lib"]
+ s.rubygems_version = %q{1.3.6}
+ s.summary = %q{A plugin for YARD for parsing contextified classes.}
+ s.test_files = [
+ "spec/spec_helper.rb",
+ "spec/contextify_handler_spec.rb",
+ "spec/helpers/examples.rb"
+ ]
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
+ s.add_runtime_dependency(%q<yard>, [">= 0.4.0"])
+ s.add_development_dependency(%q<rspec>, ["~> 1.3.0"])
+ else
+ s.add_dependency(%q<yard>, [">= 0.4.0"])
+ s.add_dependency(%q<rspec>, ["~> 1.3.0"])
+ end
+ else
+ s.add_dependency(%q<yard>, [">= 0.4.0"])
+ s.add_dependency(%q<rspec>, ["~> 1.3.0"])
+ end
+end
+
Please sign in to comment.
Something went wrong with that request. Please try again.