Permalink
Browse files

Initial import of what should be a working source tree.

  • Loading branch information...
0 parents commit c349217461d67593fb360a1864dd54d4e91410fa @cpence committed Oct 2, 2011
No changes.
@@ -0,0 +1,7 @@
+pkg
+doc
+tmp
+.DS_Store
+.bundle
+.yardoc
+*~
@@ -0,0 +1 @@
+--color --format documentation
@@ -0,0 +1,5 @@
+--markup markdown
+--title 'yard-rails Documentation'
+--protected
+--files ChangeLog.md,LICENSE.txt
+
@@ -0,0 +1,5 @@
+### 0.1.0 / 2011-10-02
+
+* Initial release:
+ * Parse `{c,m}attr_*` Rails constructs as class attributes
+
21 Gemfile
@@ -0,0 +1,21 @@
+source 'https://rubygems.org'
+
+gem 'yard', :group => [:development, :runtime]
+
+group(:development) do
+ gem 'rake'
+ gem 'jeweler'
+end
+
+group(:doc) do
+ case RUBY_PLATFORM
+ when 'java'
+ gem 'maruku'
+ else
+ gem 'rdiscount'
+ end
+end
+
+gem 'rspec', :group => [:development, :test]
+
+
@@ -0,0 +1,30 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ diff-lcs (1.1.3)
+ git (1.2.5)
+ jeweler (1.6.4)
+ bundler (~> 1.0)
+ git (>= 1.2.5)
+ rake
+ rake (0.9.2)
+ rdiscount (1.6.8)
+ rspec (2.6.0)
+ rspec-core (~> 2.6.0)
+ rspec-expectations (~> 2.6.0)
+ rspec-mocks (~> 2.6.0)
+ rspec-core (2.6.4)
+ rspec-expectations (2.6.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.6.0)
+ yard (0.7.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ jeweler
+ rake
+ rdiscount
+ rspec
+ yard
@@ -0,0 +1,24 @@
+
+Copyright (c) 2011 Charles H. Pence
+
+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.
+
+
+
@@ -0,0 +1,45 @@
+# yard-rails
+
+* [github.com/cpence/yard-rails](http://github.com/cpence/yard-rails/)
+* [github.com/cpence/yard-rails/issues](http://github.com/cpence/yard-rails/issues)
+* Charles Pence (charles at charlespence.net)
+
+## Description
+
+A YARD plugin for parsing the custom Ruby syntax added by Rails.
+
+Once yard-rails is installed, YARD will automatically load the plugin whenever
+the `yardoc` utility is run on a project.
+
+## Features
+
+Parses the following statements:
+
+ cattr_reader :attr
+
+ cattr_writer :attr
+
+ cattr_accessor :attr
+
+ mattr_reader :attr
+
+ mattr_writer :attr
+
+ mattr_accessor :attr
+
+## Requirements
+
+* [yard](http://yardoc.org) >= 0.4.0
+
+## Install
+
+ $ sudo gem install yard-rails
+
+## License
+
+See LICENSE.txt for license information.
+
+## Thanks
+
+Thanks to Postmodern's `yard-dm` gem, which provided much of the framework
+I've used to package `yard-rails`.
@@ -0,0 +1,38 @@
+require 'rubygems'
+require 'bundler'
+
+begin
+ Bundler.setup(:development, :doc)
+rescue Bundler::BundlerError => e
+ STDERR.puts e.message
+ STDERR.puts "Run `bundle install` to install missing gems"
+ exit e.status_code
+end
+
+require 'rake'
+require 'jeweler'
+
+Jeweler::Tasks.new do |gem|
+ gem.name = 'yard-rails'
+ gem.license = 'MIT'
+ gem.summary = %Q{A YARD plugin for parsing custom Rails syntax.}
+ gem.description = %Q{Once yard-rails is installed, YARD will automatically load the plugin whenever the `yardoc` utility is run on a project.}
+ gem.email = 'charles@charlespence.net'
+ gem.homepage = 'http://github.com/cpence/yard-rails'
+ gem.authors = ['Charles H. Pence']
+ gem.has_rdoc = 'yard'
+end
+
+require 'rspec/core/rake_task'
+RSpec::Core::RakeTask.new(:rspec) do |spec|
+ # The automatic bundler detecton causes trouble on my
+ # development machine.
+ spec.skip_bundler = true
+ spec.rspec_opts = ['--options', '.specopts']
+end
+
+task :test => :rspec
+task :default => :rspec
+
+require 'yard'
+YARD::Rake::YardocTask.new
@@ -0,0 +1,2 @@
+0.1.0
+
@@ -0,0 +1,2 @@
+require 'yard-rails/class_attribute_handler'
+require 'yard-rails/legacy/class_attribute_handler'
@@ -0,0 +1,25 @@
+require 'yard/parser/ruby/ast_node'
+
+module YARD
+ module Rails
+ class ClassAttributeHandler < YARD::Handlers::Ruby::AttributeHandler
+ handles method_call(:cattr_accessor)
+ handles method_call(:cattr_reader)
+ handles method_call(:cattr_writer)
+ handles method_call(:mattr_accessor)
+ handles method_call(:mattr_reader)
+ handles method_call(:mattr_writer)
+ namespace_only
+
+ def process
+ # HACK: Strip the [c,m] off of the front of the method, so that
+ # AttributeHandler will be able to correctly detect the resulting
+ # method as read/write.
+ name = statement[0].source[1..-1]
+ statement[0] = YARD::Parser::Ruby::AstNode.node_class_for(:ident).new(:ident, [name])
+
+ push_state(:scope => :class) { super }
+ end
+ end
+ end
+end
@@ -0,0 +1,21 @@
+
+module YARD
+ module Rails
+ module Legacy
+ class ClassAttributeHandler < YARD::Handlers::Ruby::Legacy::AttributeHandler
+ handles /\A[cm]attr_(reader|writer|accessor)(?:\s|\()/
+ namespace_only
+
+ def process
+ # HACK: Strip the [c,m] off of the front of the method, so that
+ # AttributeHandler will be able to correctly detect the resulting
+ # method as read/write.
+ new_text = statement.tokens.first.text.to_s[1..-1]
+ statement.tokens.first.set_text(new_text)
+
+ push_state(:scope => :class) { super }
+ end
+ end
+ end
+ end
+end
@@ -0,0 +1,86 @@
+require 'spec_helper'
+require 'helpers/examples'
+
+require 'yard-rails/class_attribute_handler'
+require 'yard-rails/legacy/class_attribute_handler'
+
+describe "ClassAttributeHandler" do
+ include Helpers::Examples
+
+ describe "valid" do
+ before(:all) do
+ parse_file :simple_cattrs
+ end
+
+ it "should define a class method for the cattr_reader method" do
+ yard('SimpleCattrs.num_widgets').should be_instance_of(CodeObjects::MethodObject)
+ end
+
+ it "should define a class method for the cattr_writer method" do
+ yard('SimpleCattrs.widget_destination=').should be_instance_of(CodeObjects::MethodObject)
+ end
+
+ it "should define reader class method for the cattr_accessor method" do
+ yard('SimpleCattrs.widget_type').should be_instance_of(CodeObjects::MethodObject)
+ end
+
+ it "should define writer class method for the cattr_accessor method" do
+ yard('SimpleCattrs.widget_type=').should be_instance_of(CodeObjects::MethodObject)
+ end
+
+ it "should define a class method for the mattr_reader method" do
+ yard('SimpleCattrs.num_sprockets').should be_instance_of(CodeObjects::MethodObject)
+ end
+
+ it "should define a class method for the mattr_writer method" do
+ yard('SimpleCattrs.sprocket_destination=').should be_instance_of(CodeObjects::MethodObject)
+ end
+
+ it "should define reader class method for the mattr_accessor method" do
+ yard('SimpleCattrs.sprocket_type').should be_instance_of(CodeObjects::MethodObject)
+ end
+
+ it "should define writer class method for the mattr_accessor method" do
+ yard('SimpleCattrs.sprocket_type=').should be_instance_of(CodeObjects::MethodObject)
+ end
+ end
+
+ describe "legacy" do
+ before(:all) do
+ parse_file :simple_cattrs, true
+ end
+
+ it "should define a class method for the cattr_reader method" do
+ yard('SimpleCattrs.num_widgets').should be_instance_of(CodeObjects::MethodObject)
+ end
+
+ it "should define a class method for the cattr_writer method" do
+ yard('SimpleCattrs.widget_destination=').should be_instance_of(CodeObjects::MethodObject)
+ end
+
+ it "should define reader class method for the cattr_accessor method" do
+ yard('SimpleCattrs.widget_type').should be_instance_of(CodeObjects::MethodObject)
+ end
+
+ it "should define writer class method for the cattr_accessor method" do
+ yard('SimpleCattrs.widget_type=').should be_instance_of(CodeObjects::MethodObject)
+ end
+
+ it "should define a class method for the mattr_reader method" do
+ yard('SimpleCattrs.num_sprockets').should be_instance_of(CodeObjects::MethodObject)
+ end
+
+ it "should define a class method for the mattr_writer method" do
+ yard('SimpleCattrs.sprocket_destination=').should be_instance_of(CodeObjects::MethodObject)
+ end
+
+ it "should define reader class method for the mattr_accessor method" do
+ yard('SimpleCattrs.sprocket_type').should be_instance_of(CodeObjects::MethodObject)
+ end
+
+ it "should define writer class method for the mattr_accessor method" do
+ yard('SimpleCattrs.sprocket_type=').should be_instance_of(CodeObjects::MethodObject)
+ end
+ end
+end
+
@@ -0,0 +1,24 @@
+require 'yard'
+
+module Helpers
+ module Examples
+ EXAMPLES_DIR = File.expand_path(File.join(File.dirname(__FILE__),'examples'))
+
+ def parse_file(file, legacy = false, thisfile = __FILE__)
+ YARD::Registry.clear
+
+ if legacy
+ YARD::Parser::SourceParser.parser_type = :ruby18
+ else
+ YARD::Parser::SourceParser.parser_type = :ruby
+ end
+
+ 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
@@ -0,0 +1,9 @@
+class SimpleCattrs
+ cattr_reader :num_widgets
+ cattr_writer :widget_destination
+ cattr_accessor :widget_type
+
+ mattr_reader :num_sprockets
+ mattr_writer :sprocket_destination
+ mattr_accessor :sprocket_type
+end
@@ -0,0 +1,15 @@
+require 'rubygems'
+require 'bundler'
+
+begin
+ Bundler.setup(:runtime, :test)
+rescue Bundler::BundlerError => e
+ STDERR.puts e.message
+ STDERR.puts "Run `bundle install` to install missing gems"
+ exit e.status_code
+end
+
+require 'rspec'
+require 'yard'
+
+include YARD
@@ -0,0 +1,7 @@
+require 'yard'
+
+YARD::Rake::YardocTask.new do |t|
+ t.files = ['lib/**/*.rb']
+end
+
+task :docs => :yard

0 comments on commit c349217

Please sign in to comment.