Permalink
Browse files

getting rdoc "hello world" working

  • Loading branch information...
1 parent e066587 commit 5a2a34508727c989c38863e980a0f548a473305d @jeffsu jeffsu committed Mar 28, 2010
View
@@ -36,14 +36,6 @@ test/fixtures/foo.js2
test/fixtures/member.js2
test/fixtures/private.js2
test/fixtures/property.js2
-test/out/bar.js
-test/out/basic.comp.js
-test/out/basic.js
-test/out/curry.js
-test/out/foo.js
-test/out/member.js
-test/out/private.js
-test/out/property.js
test/test_helper.rb
test/test_js2.rb
wiki/features.md
View
@@ -117,4 +117,7 @@ if main_action == 'daemon'
end
elsif main_action == 'compile'
puts "compiling once! use daemon to monitor changes and compile automatically."
+elsif main_action == 'rdoc'
+ res = processor.process!
+ JS2::Util::Rdoc.build(res[:klasses])
end
View
@@ -6,13 +6,13 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
s.authors = ["Jeff Su"]
- s.date = %q{2010-03-26}
+ s.date = %q{2010-03-27}
s.default_executable = %q{js2}
s.description = %q{}
s.email = %q{me@jeffsu.com}
s.executables = ["js2"]
s.extra_rdoc_files = ["README.md", "bin/js2", "lib/js2.rb", "lib/js2/parser/haml.rb", "lib/js2/parser/haml_engine.rb", "lib/js2/parser/lexer.rb", "lib/js2/parser/tokenizer.rb", "lib/js2/ragel/helper.rb", "lib/js2/ragel/tokenizer.rl", "lib/js2/ragel/tokenizer.rl.erb", "lib/js2/standard/class_node.rb", "lib/js2/standard/factory.rb", "lib/js2/standard/node.rb", "lib/js2/util/compilation.rb", "lib/js2/util/config.rb", "lib/js2/util/exec.rb", "lib/js2/util/file_handler.rb", "lib/js2/util/js2bootstrap.js2", "lib/js2/util/processor.rb", "lib/js2/util/rdoc.rb", "lib/js2/util/sel_decorator.rb"]
- s.files = ["Manifest", "README.md", "Rakefile", "bin/js2", "config/js2.yml", "js2.gemspec", "lib/js2.rb", "lib/js2/parser/haml.rb", "lib/js2/parser/haml_engine.rb", "lib/js2/parser/lexer.rb", "lib/js2/parser/tokenizer.rb", "lib/js2/ragel/helper.rb", "lib/js2/ragel/tokenizer.rl", "lib/js2/ragel/tokenizer.rl.erb", "lib/js2/standard/class_node.rb", "lib/js2/standard/factory.rb", "lib/js2/standard/node.rb", "lib/js2/util/compilation.rb", "lib/js2/util/config.rb", "lib/js2/util/exec.rb", "lib/js2/util/file_handler.rb", "lib/js2/util/js2bootstrap.js2", "lib/js2/util/processor.rb", "lib/js2/util/rdoc.rb", "lib/js2/util/sel_decorator.rb", "test/compiled/bar.js", "test/compiled/basic.comp.js", "test/compiled/basic.js", "test/compiled/foo.js", "test/fixtures/bar.js2", "test/fixtures/basic.js2", "test/fixtures/basic.js2.haml", "test/fixtures/basic.js2.yml", "test/fixtures/curry.js2", "test/fixtures/foo.js2", "test/fixtures/member.js2", "test/fixtures/private.js2", "test/fixtures/property.js2", "test/out/bar.js", "test/out/basic.comp.js", "test/out/basic.js", "test/out/curry.js", "test/out/foo.js", "test/out/member.js", "test/out/private.js", "test/out/property.js", "test/test_helper.rb", "test/test_js2.rb", "wiki/features.md", "wiki/installation.md"]
+ s.files = ["Manifest", "README.md", "Rakefile", "bin/js2", "config/js2.yml", "js2.gemspec", "lib/js2.rb", "lib/js2/parser/haml.rb", "lib/js2/parser/haml_engine.rb", "lib/js2/parser/lexer.rb", "lib/js2/parser/tokenizer.rb", "lib/js2/ragel/helper.rb", "lib/js2/ragel/tokenizer.rl", "lib/js2/ragel/tokenizer.rl.erb", "lib/js2/standard/class_node.rb", "lib/js2/standard/factory.rb", "lib/js2/standard/node.rb", "lib/js2/util/compilation.rb", "lib/js2/util/config.rb", "lib/js2/util/exec.rb", "lib/js2/util/file_handler.rb", "lib/js2/util/js2bootstrap.js2", "lib/js2/util/processor.rb", "lib/js2/util/rdoc.rb", "lib/js2/util/sel_decorator.rb", "test/compiled/bar.js", "test/compiled/basic.comp.js", "test/compiled/basic.js", "test/compiled/foo.js", "test/fixtures/bar.js2", "test/fixtures/basic.js2", "test/fixtures/basic.js2.haml", "test/fixtures/basic.js2.yml", "test/fixtures/curry.js2", "test/fixtures/foo.js2", "test/fixtures/member.js2", "test/fixtures/private.js2", "test/fixtures/property.js2", "test/test_helper.rb", "test/test_js2.rb", "wiki/features.md", "wiki/installation.md"]
s.homepage = %q{http://github.com/jeffsu/js2}
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Js2", "--main", "README.md"]
s.require_paths = ["lib"]
@@ -149,26 +149,20 @@ def handle_ending (str)
class JS2::Standard::MethodNode < JS2::Standard::Node
+ attr_accessor :name, :args, :static
+
REGEX = /^(\s*)(static\s+)?function\s+([\$\w\.]+)\s*\(([^)]*)\)\s*\{(.*)/m
def handle_first_string (s)
m = s.match(REGEX)
space = m[1]
- static = m[2]
- name = m[3]
- args = m[4]
- start = m[5]
+ @static = m[2]
+ @name = m[3]
+ @args = m[4]
+ @start = m[5]
m = static ? 'staticMember' : 'method'
- return %|#{space}K.oo('#{m}', "#{name}", function (#{args}) {#{start}|
- end
-
- def name
- if m = @string[@start_idx .. @stop_idx].match(REGEX)
- return m[3]
- end
-
- return ''
+ return %|#{space}K.oo('#{m}', "#{@name}", function (#{@args}) {#{@start}|
end
def handle_ending (str)
View
@@ -6,6 +6,7 @@ def initialize (start_idx, str, factory)
@string = str
@children = []
@factory = factory
+ @output = ''
end
def add_child (type, start_idx)
@@ -16,9 +17,14 @@ def add_child (type, start_idx)
def stop (idx)
@stop_idx = idx
+ process!
end
- def to_s ()
+ def to_s
+ return @output
+ end
+
+ def process! ()
last_idx = @start_idx
str = ''
@@ -45,7 +51,7 @@ def to_s ()
str = handle_ending(str)
- return str
+ @output = str
end
private
@@ -28,7 +28,7 @@ def self.reset!
@@already = Hash.new
end
- def compile (klasses)
+ def compile (klasses, errors = [])
return unless @make_compilation
main_file = nil
@@ -53,8 +53,14 @@ def compile (klasses)
end
file = main_file.sub(/\.js$/, '.comp.js')
- all_files = before + [ main_file ] + after
- str = all_files.collect { |f| File.read(f) }.join("\n")
+ str = ''
+ (before + [ main_file ] + after).each do |f|
+ if File.exist?(f)
+ str << File.read(f)
+ else
+ errors << [ "#{file} references #{f}, but js2 can't find it" ]
+ end
+ end
File.open(file, 'w') { |f| f << str }
end
@@ -1,10 +1,11 @@
class JS2::Util::FileHandler
- attr_accessor :js2_dir, :out_dir, :haml_dir
+ attr_accessor :js2_dir, :out_dir, :haml_dir, :doc_dir
def initialize
@js2_dir = '.'
@out_dir = '.'
@haml_dir = '.'
+ @doc_dir = '.'
@lookup = {
:js2 => :js2_dir,
@@ -15,6 +16,10 @@ def initialize
@mtimes = Hash.new
end
+ def docfile (file)
+ return file.sub(/^#{@js2_dir}/, @doc_dir).sub(/\.js2$/, '.js')
+ end
+
def needs_update
@found = Hash.new
Oops, something went wrong.

0 comments on commit 5a2a345

Please sign in to comment.