rascut 0.1.3 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.2.1 / 2009-03-03
2
+
3
+ * not dependency rack. (using mongrel)
4
+ * sum utils add.
5
+
1
6
  == 0.1.3 / 2007-10-09
2
7
 
3
8
  * Support new flex3 SDK beta version, maybe.
data/README CHANGED
@@ -16,14 +16,14 @@ Rascut is Ruby ActionSCript UTility :D
16
16
 
17
17
  == REQUIREMENTS:
18
18
 
19
- * hoe
20
- * rack
21
19
  * mongrel
22
20
  * rake
23
21
 
24
22
  == INSTALL:
25
23
 
26
24
  * gem install rascut
25
+ or
26
+ * gem install hotchpotch-rascut
27
27
 
28
28
  == OTHER:
29
29
  * vendor/js/swfobject.js is SWFObject by http://blog.deconcept.com/swfobject/
@@ -56,4 +56,4 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
56
56
  == SPECIAL THANKS
57
57
  Thank you feedback!
58
58
 
59
- id:os0x, yugui, id:wanpark, saqoosha, id:ameema
59
+ id:os0x, yugui, id:wanpark, saqoosha, id:ameema, id:cho45
data/Rakefile CHANGED
@@ -9,7 +9,8 @@ require 'rake/contrib/rubyforgepublisher'
9
9
  require 'fileutils'
10
10
  include FileUtils
11
11
 
12
- require 'lib/rascut'
12
+ $LOAD_PATH.unshift "lib"
13
+ require 'rascut'
13
14
 
14
15
  AUTHOR = "Yuichi Tateno"
15
16
  EMAIL = "hotchpotch@nospam@gmail.com"
@@ -62,7 +63,7 @@ spec = Gem::Specification.new do |s|
62
63
 
63
64
  s.add_dependency('rake')
64
65
  s.add_dependency('mongrel')
65
- s.add_dependency('rack')
66
+ s.add_dependency('json_pure')
66
67
  s.required_ruby_version = '>= 1.8.2'
67
68
 
68
69
  s.files = %w(README ChangeLog Rakefile) +
@@ -135,3 +136,9 @@ task :release => [:clean, :package] do |t|
135
136
  puts "Releasing #{NAME} v. #{VERS}"
136
137
  rf.add_release RUBYFORGE_PROJECT, NAME, VERS, *files
137
138
  end
139
+
140
+ desc 'Show information about the gem.'
141
+ task :debug_gem do
142
+ puts spec.to_ruby
143
+ end
144
+
data/bin/rascut CHANGED
File without changes
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'rascut/asdoc/data'
5
+ require 'rascut/asdoc/generator'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rascut/asdoc/generator'
9
+ end
10
+
11
+ c = ARGV.shift
12
+
13
+ case c
14
+ when 'dict'
15
+ puts Rascut::Asdoc::Data.asdoc_dict
16
+ when 'import_dict'
17
+ puts Rascut::Asdoc::Data.asdoc_import_dict
18
+ when 'generate'
19
+ g = Rascut::Asdoc::Generator.new
20
+ g.asdoc = '/home/gorou/local/flex3/bin/asdoc'
21
+ g.generate_asdoc ARGV.shift
22
+ else
23
+ puts 'rasdoc [dict import_dict generate]'
24
+ exit 1
25
+ end
@@ -1,6 +1,6 @@
1
1
 
2
2
  module Rascut
3
- VERSION = '0.1.3'
3
+ VERSION = '0.2.1'
4
4
  end
5
5
 
6
6
  require 'rascut/logger'
@@ -0,0 +1,125 @@
1
+
2
+ require 'rubygems'
3
+ require 'logger'
4
+ require 'rascut/utils'
5
+ require 'json'
6
+
7
+ class Array
8
+ def uniq_by
9
+ inject({}) do |hash, item|
10
+ hash[yield(item)] ||= item
11
+ hash
12
+ end.values
13
+ end
14
+ end
15
+
16
+
17
+ module Rascut
18
+ module Asdoc
19
+ class Data
20
+ class <<
21
+ include Utils
22
+ def asdoc_json
23
+ asdoc_data.to_json
24
+ end
25
+
26
+ def asdoc_import_dict
27
+ res = []
28
+ Utils.rascut_db_read do |db|
29
+ db[:asdoc].each do |key, val|
30
+ val.each {|v|
31
+ next if v[:classname][0..0].match(/[a-z]/)
32
+ res << "#{v[:classname]} #{v[:package]}.#{v[:classname]}"
33
+ }
34
+ end
35
+ end
36
+ res.sort.uniq.join("\n")
37
+ end
38
+
39
+ def asdoc_dict
40
+ res = []
41
+ Utils.rascut_db_read do |db|
42
+ db[:asdoc].each do |key, val|
43
+ val.each {|v|
44
+ res << v[:classname] if v[:classname].length >= 4
45
+ v[:methods].each {|met|
46
+ res << met[:name] if met[:name].length >= 4
47
+ }
48
+ }
49
+ end
50
+ end
51
+ res.sort.uniq.join("\n")
52
+ end
53
+
54
+ def asdoc_data
55
+ classes = []
56
+ packages = []
57
+ methods = []
58
+ Utils.rascut_db_read do |db|
59
+ db[:asdoc].each do |key, val|
60
+ val.each {|v|
61
+ classes << {
62
+ :classname => v[:classname],
63
+ :package => v[:package],
64
+ :asdoc_dir => v[:asdoc_dir]
65
+ }
66
+
67
+ packages << {
68
+ :package => v[:package],
69
+ :asdoc_dir => v[:asdoc_dir]
70
+ }
71
+
72
+ v[:methods].each {|met|
73
+ met.delete :code
74
+ met.delete :summary
75
+ met[:package] = v[:package]
76
+ met[:classname] = v[:classname]
77
+ met[:href] = "#{v[:asdoc_dir]}/#{v[:filename]}#{met[:href]}"
78
+ methods << met
79
+ }
80
+ }
81
+ end
82
+ end
83
+
84
+ packages = packages.uniq_by {|s| s.to_a.join('_')}.sort_by {|a| a[:package]}
85
+ classes = classes.uniq_by {|s| s.to_a.join('_')}.sort_by {|a| a[:classname]}
86
+ {
87
+ :methods => methods.sort_by {|a| a[:name]},
88
+ :classes => classes,
89
+ :packages => packages
90
+ }
91
+ end
92
+
93
+ end
94
+ end
95
+ end
96
+ end
97
+
98
+ if __FILE__ == $0
99
+ require 'benchmark'
100
+ puts Rascut::Asdoc::Data.asdoc_dict
101
+
102
+ #exit
103
+ #p res.select{|i| i[:name].index('draw') == 0 }.length
104
+
105
+ #Benchmark.bm do |x|
106
+ # x.report {
107
+ # 100.times {
108
+ # p = []
109
+ # res.select{|i| i[:name].index('draw') == 0 }
110
+ # }
111
+ # }
112
+ # x.report {
113
+ # 100.times {
114
+ # res.select{|i| i[:name].match(/^draw/) }
115
+ # }
116
+ # }
117
+ # x.report {
118
+ # 100.times {
119
+ # res.select{|i| i[:name][0..3] == 'draw' }
120
+ # }
121
+ # }
122
+ #end
123
+ end
124
+
125
+
@@ -0,0 +1,92 @@
1
+
2
+ require 'rubygems'
3
+ require 'hpricot'
4
+ require 'pp'
5
+ require 'nkf'
6
+ require 'logger'
7
+ require 'pathname'
8
+ require 'uri'
9
+ require 'rascut/utils'
10
+ require 'rascut/asdoc/parser'
11
+ require 'rascut/asdoc/data'
12
+
13
+ module Rascut
14
+ module Asdoc
15
+ class Generator
16
+ include Utils
17
+
18
+ def initialize(logger = nil)
19
+ @logger = Logger.new(STDOUT)
20
+ @logger.level = Logger::DEBUG
21
+ @asdoc = 'asdoc'
22
+ end
23
+ attr_accessor :asdoc
24
+
25
+ def generate_asdoc(source_path)
26
+ @logger.info "generate documents: #{source_path}"
27
+ cmd = "#{asdoc} -doc-sources '#{source_path}' -output '#{asdoc_home.join(path_escape(source_path.to_s))}'"
28
+ @logger.debug cmd
29
+ `#{cmd}`
30
+ generate_list_by_source_path(source_path)
31
+ end
32
+
33
+ def generate_asdoc_by_config(flex_config)
34
+ source = Hpricot(flex_config)
35
+ files = source.search('source-path path-element').map {|el| Pathname.new(el.inner_text) }
36
+ files.each do |file|
37
+ generate_asdoc file.realpath
38
+ end
39
+ end
40
+
41
+ def generate_list_by_source_path(source_path)
42
+ generate_list(path_escape(source_path.to_s))
43
+ end
44
+
45
+ def generate_list(path)
46
+ @logger.info "generate list"
47
+ #Pathname.glob("#{asdoc_home}/#{asdoc_dir}").each do |asdoc|
48
+ asdoc = asdoc_home.join(path)
49
+ @logger.info "#{asdoc}"
50
+ Pathname.glob("#{asdoc}/*/**/*.html") do |file|
51
+ next if file.to_s.match(/((class-list.html)|(package-detail.html))$/)
52
+ r = Rascut::Asdoc::Parser.new(file.read, @logger)
53
+ r.parse
54
+ #pp file.to_s, r.package, r.classname#, r.methods
55
+ list = {
56
+ :package => r.package,
57
+ :classname => r.classname,
58
+ :methods => r.methods,
59
+ :filename => file.relative_path_from(asdoc).to_s,
60
+ :asdoc_dir => asdoc.basename.to_s,
61
+ }
62
+ rascut_db do |db|
63
+ db[:asdoc] ||= {}
64
+ db[:asdoc][list[:asdoc_dir]] ||= []
65
+ db[:asdoc][list[:asdoc_dir]] << list
66
+ end
67
+ end
68
+ #end
69
+ #generate_json
70
+ end
71
+
72
+ def generate_json
73
+ @logger.info "generate asdoc's index(json)."
74
+ json = Rascut::Asdoc::Data.asdoc_json
75
+ asdoc_home.join('asdoc.json').open('w') {|f| f.puts json }
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+ if __FILE__ == $0
82
+ include Rascut::Asdoc
83
+ flex_config = '/home/gorou/local/flex2/frameworks/flex-config.xml'
84
+ g = Generator.new #
85
+ g.asdoc = '/home/gorou/local/flex3/bin/asdoc'
86
+ #g.generate_asdoc_by_config(open(flex_config).read)
87
+ #asdoc_dir = '/home/gorou/svn/as3/swfassist/src'
88
+ asdoc_dir = '/home/gorou/svn/as3rails2u/trunk/src'
89
+ #g.generate_asdoc(asdoc_dir)
90
+ g.generate_list_by_source_path asdoc_dir
91
+ end
92
+
@@ -0,0 +1,124 @@
1
+
2
+ require 'rubygems'
3
+ require 'mongrel'
4
+ require 'mongrel/handlers'
5
+
6
+ require 'rascut/utils'
7
+ require 'rascut/asdoc/data'
8
+ require 'thread'
9
+ require 'logger'
10
+ require 'pathname'
11
+ require 'json'
12
+
13
+ module Rascut
14
+ module Asdoc
15
+ class Httpd
16
+ include Utils
17
+ def initialize
18
+ @logger = Logger.new(STDOUT)
19
+ @threads = []
20
+ @data = Rascut::Asdoc::Data.asdoc_data
21
+ end
22
+ attr_reader :command
23
+
24
+ def run
25
+ port = config[:port] || 3002
26
+ host = config[:bind_address] || '0.0.0.0'
27
+
28
+ @http_server = Mongrel::HttpServer.new(host, port)
29
+ @http_server.register('/', Mongrel::DirHandler.new(asdoc_home.to_s))
30
+ @http_server.register('/json', json_handler)
31
+ @http_server.run
32
+ logger.info "Start Mongrel: http://#{host}:#{port}/"
33
+ end
34
+ attr_reader :data
35
+
36
+ def json_handler
37
+ ProcHandler.new do |req, res|
38
+ ary = []
39
+ params = Mongrel::HttpRequest.query_parse(req.params['QUERY_STRING'])
40
+ if word = params['word']
41
+ method_re, class_re, package_re = *search_regexes(word.strip)
42
+
43
+ c = 0
44
+ if method_re
45
+ @data[:methods].each do |i|
46
+ if i[:name].match method_re
47
+ next if class_re && !i[:classname].match(class_re)
48
+ next if package_re && !i[:package].match(package_re)
49
+ ary << i
50
+ c += 1
51
+ break if c >= 20
52
+ end
53
+ end
54
+ elsif class_re
55
+ @data[:classes].each do |i|
56
+ if i[:classname].match class_re
57
+ next if package_re && !i[:package].match(package_re)
58
+ ary << i
59
+ c += 1
60
+ break if c >= 20
61
+ end
62
+ end
63
+ elsif package_re
64
+ @data[:packages].each do |i|
65
+ if i[:package].match package_re
66
+ ary << i
67
+ c += 1
68
+ break if c >= 20
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+ res.start do |head, out|
75
+ head['Content-Type'] = 'application/json'
76
+ out << ary.to_json
77
+ end
78
+ end
79
+ end
80
+
81
+ def search_regexes(w)
82
+ method_re = class_re = package_re = nil
83
+
84
+ words = w.split(/\s+/)
85
+ words.each do |word|
86
+ case word[0..0]
87
+ when '.'
88
+ #package
89
+ package_re = /#{Regexp.escape(word[1..-1])}/
90
+ when /[A-Z]/
91
+ # class
92
+ class_re = /#{Regexp.escape(word)}/
93
+ #when '#'
94
+ else
95
+ # method
96
+ method_re = /^#{Regexp.escape(word.sub('#', ''))}/
97
+ end
98
+ end
99
+ [method_re, class_re, package_re]
100
+ end
101
+
102
+
103
+ def stop
104
+ # XXX
105
+ # @http_server.stop
106
+ end
107
+
108
+ def config
109
+ #command.config
110
+ {}
111
+ end
112
+
113
+ def logger
114
+ @logger
115
+ end
116
+ end
117
+ end
118
+ end
119
+
120
+ if __FILE__ == $0
121
+ Rascut::Asdoc::Httpd.new.run
122
+ Thread.stop
123
+ end
124
+
@@ -0,0 +1,69 @@
1
+
2
+ require 'rubygems'
3
+ require 'hpricot'
4
+ require 'pp'
5
+ require 'nkf'
6
+ require 'logger'
7
+
8
+ module Rascut
9
+ module Asdoc
10
+ class Parser
11
+ def initialize(source, logger = nil)
12
+ source = NKF::nkf('-m0 -w', source)
13
+ @logger = logger || Logger.new(STDOUT)
14
+ @logger.level = Logger::DEBUG
15
+ @source = Hpricot(source)
16
+ @methods = []
17
+ @package = nil
18
+ @classname = nil
19
+ end
20
+ attr_reader :methods, :package, :classname
21
+
22
+ def parse
23
+ title = @source.at('title').inner_text
24
+ @package = title.split('.')[0..-2].join('.')
25
+ @classname = title.split('.')[-1].split(/\s/)[0]
26
+ @logger.debug "parse: #{@package} #{@classname}"
27
+ @source.search('td.summaryTableSignatureCol').each {|el|
28
+ next if el.at('td.summaryTableInheritanceCol') || !el.at('a')
29
+
30
+ begin
31
+ method = {
32
+ :href => el.at('a')['href'],
33
+ :name => el.at('a').inner_text.strip,
34
+ :code => el.search('div:not(.summaryTableDescription)').inner_text.strip.gsub("\n", ' '),
35
+ }
36
+ if summary = el.at('div.summaryTableDescription')
37
+ s = summary.inner_text.strip.gsub("\n", ' ')
38
+ if s[0..0] == '[' && s[-1..-1] == ']'
39
+ method[:code] << " #{s}"
40
+ method[:code].strip!
41
+ else
42
+ method[:summary] = s
43
+ end
44
+ end
45
+ @methods << method
46
+ rescue NoMethodError => e
47
+ @logger.debug e.message
48
+ @logger.debug el.inner_text.strip.gsub("\n", ' ')
49
+ end
50
+ }
51
+ @logger.debug "parse: #{@methods.length} methods found"
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ if __FILE__ == $0
58
+ require 'pathname'
59
+ #Pathname.glob('/home/gorou/local/docs/flex201_documentation/langref/**/*.html') do |file|
60
+ Pathname.glob('/home/gorou/svn/as3rails2u/trunk/asdoc-output/*/**/*.html') do |file|
61
+ puts file.to_s
62
+ r = Rascut::Asdoc::Parser.new(file.read)
63
+ r.parse
64
+ pp r.package, r.classname#, r.methods
65
+ end
66
+ #Rascut::AsdocParser.new(open('/home/gorou/local/docs/flex201_documentation/langref/flash/display/Sprite.html').read).parse
67
+ #Rascut::AsdocParser.new(open('/home/gorou/svn/as3rails2u/trunk/asdoc-output/com/rails2u/net/JSONPLoader.html').read).parse
68
+ end
69
+
@@ -2,31 +2,29 @@ require 'optparse'
2
2
  require 'rascut/fcsh_wrapper'
3
3
  require 'rascut/logger'
4
4
  require 'rascut/config'
5
+ require 'rascut/utils'
5
6
  require 'pathname'
6
7
  require 'yaml'
7
8
 
8
9
  module Rascut
9
10
  class Command
11
+ include Utils
12
+
10
13
  def initialize
11
14
  @logger = Logger.new(STDOUT)
15
+ @httpd = nil
12
16
  end
13
17
  attr_accessor :logger
14
18
 
15
19
  def run(argv)
16
20
  @config = Config.new
17
21
 
18
- if ENV['HOME']
19
- home = Pathname.new ENV['HOME']
20
- end
21
-
22
- home.join('.rascut').mkpath if home
23
-
24
- if home && home.join('.rascutrc').readable?
25
- @config.merge_config home.join('.rascutrc')
22
+ if home.parent && home.parent.join('.rascutrc').readable?
23
+ @config.merge_config home.parent.join('.rascutrc')
26
24
  end
27
25
 
28
26
  if File.readable?('.rascut') && File.file?('.rascut')
29
- @config.merge_config('.rascut')
27
+ config.merge_config('.rascut')
30
28
  end
31
29
 
32
30
  @config.parse_argv!(argv)
@@ -111,7 +109,7 @@ module Rascut
111
109
  def start_server
112
110
  require 'rascut/httpd'
113
111
  @httpd = Httpd.new(self)
114
- @httpd.start
112
+ @httpd.run
115
113
  end
116
114
 
117
115
  def setting_signals
@@ -139,6 +137,7 @@ module Rascut
139
137
  logger.info 'exiting...'
140
138
  begin
141
139
  @wrapper.close
140
+ @httpd.stop if @httpd
142
141
  rescue Exception => e
143
142
  logger.error e.inspect
144
143
  end
@@ -62,8 +62,11 @@ module Rascut
62
62
  unless @process
63
63
  orig_lang = ENV['LANG']
64
64
  ENV['LANG'] = 'C' # for flex3 sdk beta locale
65
+ orig_java_options = ENV['_JAVA_OPTIONS']
66
+ ENV['_JAVA_OPTIONS'] = orig_java_options.to_s + ' -Duser.language=en'
65
67
  @process = IO.popen(@config[:fcsh_cmd] + ' 2>&1', 'r+') unless @process
66
68
  ENV['LANG'] = orig_lang
69
+ ENV['_JAVA_OPTIONS'] = orig_java_options
67
70
  end
68
71
  @process
69
72
  end
@@ -73,6 +76,7 @@ module Rascut
73
76
 
74
77
  @compile_mutex.synchronize do
75
78
  logger.info "Compile Start"
79
+ call_hook :compile_start
76
80
  out = nil
77
81
  if @compile_id
78
82
  out = process_sync_exec "compile #{@compile_id}"
@@ -90,7 +94,7 @@ module Rascut
90
94
  else
91
95
  call_hook :compile_error, out
92
96
  end
93
- call_hook :compile, out
97
+ call_hook :compile_finish
94
98
  end
95
99
  end
96
100
 
@@ -107,7 +111,12 @@ module Rascut
107
111
  def read_result(process)
108
112
  unless @not_first_read
109
113
  # first_time, FIXME uncool...
110
- process.expect(FCSH_WAIT_RE)
114
+ begin
115
+ process.expect(FCSH_WAIT_RE)
116
+ rescue NoMethodError => e
117
+ warn 'mxmlc not found. (check PATH)'
118
+ raise e
119
+ end
111
120
  @not_first_read = true
112
121
  end
113
122
 
@@ -29,6 +29,7 @@ module Rascut
29
29
  observe files
30
30
  end
31
31
  attr_accessor :options
32
+ attr_reader :files, :dirs
32
33
 
33
34
  def logger
34
35
  options[:logger]
@@ -125,7 +126,7 @@ module Rascut
125
126
 
126
127
  if !dir.directory?
127
128
  @dirs.delete dir
128
- elsif dir.to_s.match %r{/\.svn|/CVS}
129
+ elsif dir.to_s.match %r{/\.svn|/CVS|\.git}
129
130
  @dirs.delete dir
130
131
  elsif dir.mtime > mtime
131
132
  @dirs[dir] = dir.mtime
@@ -1,16 +1,10 @@
1
1
 
2
- begin
3
- require 'rack'
4
- rescue LoadError
5
- require 'rubygems'
6
- gem 'rack'
7
- end
2
+ require 'rubygems'
3
+ require 'mongrel'
4
+ require 'mongrel/handlers'
8
5
 
9
- require 'rack/showexceptions'
10
- require 'rack/urlmap'
11
- require 'rack/file'
12
- require 'rack/request'
13
- require 'rack/response'
6
+ require 'rascut/utils'
7
+ require 'rascut/asdoc/data'
14
8
  require 'thread'
15
9
  require 'logger'
16
10
  require 'pathname'
@@ -18,69 +12,49 @@ require 'open-uri'
18
12
 
19
13
  module Rascut
20
14
  class Httpd
21
- class FileOnly < Rack::File
22
- def _call(env)
23
- if env["PATH_INFO"].include? ".."
24
- return [403, {"Content-Type" => "text/plain"}, ["Forbidden\n"]]
25
- end
26
-
27
- @path = env["PATH_INFO"] == '/' ? @root : F.join(@root, env['PATH_INFO'])
28
- ext = F.extname(@path)[1..-1]
29
-
30
- if F.file?(@path) && F.readable?(@path)
31
- [200, {
32
- "Content-Type" => MIME_TYPES[ext] || "text/plain",
33
- "Content-Length" => F.size(@path).to_s
34
- }, self]
35
- else
36
- return [404, {"Content-Type" => "text/plain"},
37
- ["File not found: #{env["PATH_INFO"]}\n"]]
38
- end
39
- end
40
- end
15
+ include Utils
41
16
 
42
17
  def initialize(command)
43
18
  @command = command
19
+ @http_servet =
44
20
  @threads = []
45
21
  end
46
22
  attr_reader :command
47
23
 
48
- def start
24
+ def run
49
25
  swf_path = command.root.to_s
50
26
  logger.debug "swf_path: #{swf_path}"
51
27
  vendor = Pathname.new(__FILE__).parent.parent.parent.join('vendor')
52
28
  logger.debug "vendor_path: #{vendor}"
53
- reload = reload_handler
54
- index = index_handler
55
29
 
56
- #app = Rack::FixedBuilder.new do
57
- # use Rack::ShowExceptions
58
- # map('/reload') { run reload }
59
- # map('/swf/') { run Rack::File.new(swf_path) }
60
- # map('/') { run index }
61
- #end
30
+ file_mappings = [
31
+ ['/js/swfobject.js', vendor.join('js/swfobject.js').to_s],
32
+ ['/swf', swf_path]
33
+ ]
34
+ file_mappings.concat(config_url_mapping) if config[:mapping]
35
+ logger.debug 'url mappings: ' + file_mappings.inspect
62
36
 
63
- urls = []
64
- urls.concat(config_url_mapping) if config[:mapping]
65
-
66
- urls.concat([
67
- ['/js/swfobject.js', Rack::ShowExceptions.new(Httpd::FileOnly.new(vendor.join('js/swfobject.js').to_s))],
68
- ['/swf', Rack::ShowExceptions.new(Rack::File.new(swf_path))],
69
- ['/reload', Rack::ShowExceptions.new(reload_handler)],
70
- ['/proxy', Rack::ShowExceptions.new(proxy_handler)],
71
- ['/', Rack::ShowExceptions.new(index_handler)]
72
- ])
73
- logger.debug 'url mappings: ' + urls.map{|u| u.first}.inspect
74
- app = Rack::URLMap.new(urls)
75
37
  port = config[:port] || 3001
76
38
  host = config[:bind_address] || '0.0.0.0'
77
39
 
78
- _args = [app, {:Host => host, :Port => port}]
79
- server_handler = detect_server
80
- Thread.new(_args) do |args|
81
- server_handler.run *args
40
+ reload = reload_handler
41
+ index = index_handler
42
+
43
+ @http_server = Mongrel::HttpServer.new(host, port)
44
+ file_mappings.each do |mapping|
45
+ @http_server.register(mapping[0], Mongrel::DirHandler.new(mapping[1]))
82
46
  end
83
- logger.info "Start #{server_handler} http://#{host}:#{port}/"
47
+ @http_server.register('/proxy', proxy_handler)
48
+ @http_server.register('/save', save_handler)
49
+ @http_server.register('/reload', reload_handler)
50
+ @http_server.register('/', index_handler)
51
+ @http_server.run
52
+ logger.info "Start Mongrel: http://#{host}:#{port}/"
53
+ end
54
+
55
+ def stop
56
+ # XXX
57
+ # @http_server.stop
84
58
  end
85
59
 
86
60
  def config
@@ -104,52 +78,34 @@ module Rascut
104
78
  filepath = m[0]
105
79
  mappath = m[1]
106
80
  mappath = '/' + mappath if mappath[0..0] != '/'
107
- urls << [mappath, Rack::ShowExceptions.new(Rack::File.new(command.root.join(filepath).to_s))]
81
+ urls << [mappath, command.root.join(filepath).to_s]
108
82
  end
109
83
  urls
110
84
  end
111
85
 
112
- def detect_server
113
- begin
114
- case config[:server]
115
- when 'mongrel'
116
- require_mongrel_handler
117
- when 'webrick'
118
- require_webrick_handler
119
- else
120
- require_mongrel_handler
121
- end
122
- rescue Exception => e
123
- require_webrick_handler
124
- end
125
- end
126
-
127
- def require_mongrel_handler
128
- begin
129
- require 'mongrel'
130
- rescue LoadError
131
- require 'rubygems'
132
- gem 'mongrel', '> 1.0'
133
- end
134
- require 'rack/handler/mongrel'
135
- Rack::Handler::Mongrel
136
- end
137
-
138
- def require_webrick_handler
139
- require 'webrick'
140
- require 'rack/handler/webrick'
141
- Rack::Handler::WEBrick
142
- end
86
+ #def asdoc_mapping
87
+ # urls = []
88
+ # Pathname.glob(asdoc_home.to_s + '/*').each do |file|
89
+ # urls << ["/asdoc/#{file.basename}", Rack::ShowExceptions.new(FileIndex.new(file.to_s))]
90
+ # end
91
+ # urls << ["/asdoc/", Rack::ShowExceptions.new(FileIndex.new(asdoc_home.to_s))]
92
+ # urls
93
+ #end
143
94
 
144
95
  def reload_handler
145
- Proc.new do |env|
96
+ #Proc.new do |env|
97
+ ProcHandler.new do |req, res|
146
98
  @threads << Thread.current
147
99
  Thread.stop
148
100
 
149
101
  logger.debug 'httpd /reload reloading now'
150
- Rack::Response.new.finish do |r|
151
- r.write '1'
102
+ res.start do |head, out|
103
+ head["Content-Type"] = "text/plain"
104
+ out << 1
152
105
  end
106
+ #Rack::Response.new.finish do |r|
107
+ # r.write '1'
108
+ #end
153
109
  end
154
110
  end
155
111
 
@@ -160,33 +116,60 @@ module Rascut
160
116
  res = INDEX.sub('__SWFOBJECT__', swftag(command.target_script, config)).sub('<!--__RELOAD__-->', RELOAD_SCRIPT)
161
117
  end
162
118
 
163
- Proc.new do |env|
164
- req = Rack::Request.new(env)
165
- res.sub!('__SWF_VARS__', swfvars(req.GET))
166
- Rack::Response.new.finish do |r|
167
- r.write res
119
+ ProcHandler.new do |req, response|
120
+ #Proc.new do |env|
121
+ #req = Rack::Request.new(env)
122
+ r = res.sub('__SWF_VARS__', swfvars(Mongrel::HttpRequest.query_parse(req.params['QUERY_STRING'])))
123
+ response.start do |head, out|
124
+ out << r
168
125
  end
126
+ #Rack::Response.new.finish do |r|
127
+ # r.write res
128
+ #end
169
129
  end
170
130
  end
171
131
 
172
132
  def proxy_handler
173
- Proc.new do |env|
174
- req = Rack::Request.new(env)
175
- url = req.query_string
133
+ ProcHandler.new do |req, res|
134
+ url = req.params['QUERY_STRING'].to_s.strip
176
135
  if url.empty?
177
136
  url = req.path_info[1..-1].gsub(%r{^(https?:/)/?}, '\\1/')
178
137
  end
179
- Rack::Response.new.finish do |r|
138
+ res.start do |head, out|
180
139
  open(url) { |io|
181
- r['Content-Type'] = io.content_type
140
+ head['Content-Type'] = io.content_type
182
141
  while part = io.read(8192)
183
- r.write part
142
+ out << part
184
143
  end
185
144
  }
186
145
  end
187
146
  end
188
147
  end
189
148
 
149
+ def save_handler
150
+ ProcHandler.new do |req, res|
151
+ name = req.params['QUERY_STRING'].to_s.strip
152
+ path = command.root.join(name)
153
+ req.body.rewind
154
+ body = req.body.read
155
+
156
+ if name.empty? || body.length == 0
157
+ res.start do |head, out|
158
+ head['Content-Type'] = 'text/plain'
159
+ out << "don't save"
160
+ end
161
+ else
162
+ path.open('w') {|f| f.puts body }
163
+
164
+ res.start do |head, out|
165
+ head['Content-Type'] = 'text/plain'
166
+ out << "saved: #{path}"
167
+ end
168
+ end
169
+
170
+ end
171
+ end
172
+
190
173
  def swfvars(vars)
191
174
  res = []
192
175
  vars.each do |key, value|
@@ -253,6 +236,8 @@ module Rascut
253
236
  window.onload = function() {
254
237
  __SWF_VARS__
255
238
  so.addVariable('rascut', 'true');
239
+ so.addParam('allowFullScreen', 'true');
240
+ so.addParam('allowScriptAccess', 'always');
256
241
  so.write("content");
257
242
  }
258
243
  </script>
@@ -0,0 +1,23 @@
1
+ # append your ~/.ctags
2
+ # --langdef=actionscript
3
+ # --langmap=actionscript:.as
4
+ # --regex-actionscript=/^.*function[\t ]+([gs]et[\t ]+)?([A-Za-z0-9_]+)[\t ]*\(/\2/F,function/i
5
+ # --regex-actionscript=/^.*class[\t ]+([A-Za-z0-9_]+)/\1/C,class/i
6
+ #
7
+ require 'rascut/plugin/base'
8
+ require 'pathname'
9
+
10
+ module Rascut
11
+ module Plugin
12
+ class GenerateCtags < Base
13
+ def run
14
+ @ctags_cmd = config[:ctags] || 'ctags'
15
+ @command.file_observer.add_update_handler method(:generate_ctags)
16
+ end
17
+
18
+ def generate_ctags
19
+ `#{@ctags_cmd} -R --langmap=actionscript:.as -f #{@command.root.join('tags')}`
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,58 @@
1
+
2
+ require 'rascut/plugin/base'
3
+
4
+ module Rascut
5
+ module Plugin
6
+ class Screen < Base
7
+ STATUS = %q[%H %`%-w%{=b bw}%n %t%{-}%+w %=]
8
+
9
+ SCREEN_CMD = 'screen'
10
+ SCREEN_COLOR = {
11
+ :black => 'dd',
12
+ :blue => 'bk',
13
+ :green => 'gk',
14
+ :red => 'rw',
15
+ }
16
+
17
+ def run
18
+ @command.wrapper.hooks[:compile_start] << method(:start)
19
+ @command.wrapper.hooks[:compile_error] << method(:error)
20
+ @command.wrapper.hooks[:compile_success] << method(:success)
21
+ end
22
+
23
+ def start
24
+ message 'C'
25
+ end
26
+
27
+ def error
28
+ message 'E', :red
29
+ end
30
+
31
+ def success
32
+ message 'S', :blue
33
+ end
34
+
35
+ def message(msg, color = :black)
36
+ if run_screen_session?
37
+ col = SCREEN_COLOR[color]
38
+ msg = %Q[ %{=b #{col}} #{msg} %{-}]
39
+ send_cmd(msg)
40
+ end
41
+ end
42
+
43
+ def clear
44
+ send_cmd('')
45
+ end
46
+
47
+ def run_screen_session?
48
+ str = `#{SCREEN_CMD} -ls`
49
+ str.match(/(\d+) Socket/) && ($1.to_i > 0)
50
+ end
51
+
52
+ def send_cmd(msg)
53
+ cmd = %Q[#{SCREEN_CMD} -X eval 'hardstatus alwayslastline "#{(STATUS + msg).gsub('"', '\"')}"']
54
+ system cmd
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,65 @@
1
+ require 'pathname'
2
+ require 'uri'
3
+ require 'pstore'
4
+ require 'rubygems'
5
+ require 'mongrel/handlers'
6
+
7
+ module Rascut
8
+ module Utils
9
+ def home
10
+ if ENV['HOME']
11
+ home = Pathname.new ENV['HOME']
12
+ elsif ENV['USERPROFILE']
13
+ # win32
14
+ home = Pathname.new ENV['USERPROFILE']
15
+ else
16
+ raise 'HOME dir not found.'
17
+ end
18
+
19
+ home = home.join('.rascut')
20
+ home.mkpath
21
+ home
22
+ end
23
+ module_function :home
24
+
25
+ def asdoc_home
26
+ path = home.join('asdoc')
27
+ path.mkpath
28
+ path
29
+ end
30
+ module_function :asdoc_home
31
+
32
+ def rascut_db_path
33
+ home.join('rascut.db')
34
+ end
35
+ module_function :rascut_db_path
36
+
37
+ def rascut_db(readonly = false)
38
+ db = PStore.new home.join('rascut.db').to_s
39
+ db.transaction(readonly) do
40
+ yield db
41
+ end
42
+ end
43
+ module_function :rascut_db
44
+
45
+ def rascut_db_read(&block)
46
+ rascut_db(true, &block)
47
+ end
48
+ module_function :rascut_db_read
49
+
50
+ def path_escape(name)
51
+ URI.encode(name.to_s.gsub('/', '_'), /[^\w_\-]/)
52
+ end
53
+ module_function :path_escape
54
+
55
+ class ProcHandler < Mongrel::HttpHandler
56
+ def initialize(&block)
57
+ @proc = block
58
+ end
59
+
60
+ def process(req, res)
61
+ @proc.call(req, res)
62
+ end
63
+ end
64
+ end
65
+ end
metadata CHANGED
@@ -1,58 +1,90 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.1
3
- specification_version: 1
4
2
  name: rascut
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.1.3
7
- date: 2007-10-09 00:00:00 +09:00
8
- summary: Ruby ActionSCript UTility
9
- require_paths:
10
- - lib
11
- email: hotchpotch@nospam@gmail.com
12
- homepage: http://hotchpotch.rubyforge.org/rascut/
13
- rubyforge_project: hotchpotch
14
- description: Ruby ActionSCript UTility
15
- autorequire: ""
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 1.8.2
24
- version:
4
+ version: 0.2.1
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Yuichi Tateno
8
+ autorequire: ""
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-03 00:00:00 +09:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: mongrel
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: json_pure
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ description: Ruby ActionSCript UTility
46
+ email: hotchpotch@nospam@gmail.com
47
+ executables:
48
+ - rascut
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - README
53
+ - ChangeLog
31
54
  files:
32
55
  - README
33
56
  - ChangeLog
34
57
  - Rakefile
35
58
  - bin/rascut
59
+ - bin/rasdoc
36
60
  - test/test_rascut.rb
37
61
  - test/test_file_observer.rb
38
62
  - lib/rascut.rb
39
63
  - lib/rascut
40
64
  - lib/rascut/file_observer.rb
65
+ - lib/rascut/asdoc
66
+ - lib/rascut/asdoc/data.rb
67
+ - lib/rascut/asdoc/parser.rb
68
+ - lib/rascut/asdoc/httpd.rb
69
+ - lib/rascut/asdoc/generator.rb
41
70
  - lib/rascut/config.rb
42
71
  - lib/rascut/httpd.rb
43
72
  - lib/rascut/logger.rb
44
73
  - lib/rascut/plugin
45
74
  - lib/rascut/plugin/write_fcsh_error_output.rb
46
75
  - lib/rascut/plugin/base.rb
76
+ - lib/rascut/plugin/screen.rb
77
+ - lib/rascut/plugin/generate_ctags.rb
47
78
  - lib/rascut/command.rb
48
79
  - lib/rascut/fcsh_wrapper.rb
80
+ - lib/rascut/utils.rb
49
81
  - vendor/js
50
82
  - vendor/ruby
51
83
  - vendor/js/swfobject.js
52
84
  - vendor/ruby/expect.rb
53
- test_files:
54
- - test/test_rascut.rb
55
- - test/test_file_observer.rb
85
+ has_rdoc: true
86
+ homepage: http://hotchpotch.rubyforge.org/rascut/
87
+ post_install_message:
56
88
  rdoc_options:
57
89
  - --title
58
90
  - rascut documentation
@@ -66,40 +98,27 @@ rdoc_options:
66
98
  - --inline-source
67
99
  - --exclude
68
100
  - ^(examples|extras)/
69
- extra_rdoc_files:
70
- - README
71
- - ChangeLog
72
- executables:
73
- - rascut
74
- extensions: []
75
-
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: 1.8.2
108
+ version:
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: "0"
114
+ version:
76
115
  requirements: []
77
116
 
78
- dependencies:
79
- - !ruby/object:Gem::Dependency
80
- name: rake
81
- version_requirement:
82
- version_requirements: !ruby/object:Gem::Version::Requirement
83
- requirements:
84
- - - ">"
85
- - !ruby/object:Gem::Version
86
- version: 0.0.0
87
- version:
88
- - !ruby/object:Gem::Dependency
89
- name: mongrel
90
- version_requirement:
91
- version_requirements: !ruby/object:Gem::Version::Requirement
92
- requirements:
93
- - - ">"
94
- - !ruby/object:Gem::Version
95
- version: 0.0.0
96
- version:
97
- - !ruby/object:Gem::Dependency
98
- name: rack
99
- version_requirement:
100
- version_requirements: !ruby/object:Gem::Version::Requirement
101
- requirements:
102
- - - ">"
103
- - !ruby/object:Gem::Version
104
- version: 0.0.0
105
- version:
117
+ rubyforge_project: hotchpotch
118
+ rubygems_version: 1.2.0
119
+ signing_key:
120
+ specification_version: 2
121
+ summary: Ruby ActionSCript UTility
122
+ test_files:
123
+ - test/test_rascut.rb
124
+ - test/test_file_observer.rb