js2 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Changelog CHANGED
@@ -1,5 +1,12 @@
1
- == 0.0.2 2009-11-25
2
- * Fixed sass templating so that there is no default namespacing
1
+ == 0.0.4 2009-12-02
2
+ * Adding JS2.createClass() and JS2.getClass()
3
+ * Deprecating classes.js file in favor of js2bootstrap.js
4
+ * Adding super function
3
5
 
4
6
  == 0.0.3 2009-11-30
5
7
  * Selenium test bug fixes
8
+
9
+ == 0.0.2 2009-11-25
10
+ * Fixed sass templating so that there is no default namespacing
11
+
12
+
data/bin/js2 CHANGED
@@ -7,42 +7,61 @@ require 'js2'
7
7
 
8
8
  options = Hash.new
9
9
 
10
- usage = "Usage: js2 [options] <dir-with-js2>"
11
- op = OptionParser.new do |opts|
12
- opts.banner = usage
10
+ dir = nil
13
11
 
14
- opts.on("--js2-haml-dir DIR", "Directory with js2.haml files") do |haml|
15
- options[:js2_haml_dir] = haml
16
- end
12
+ # assume rails
13
+ if ARGV.empty? && File.directory?('public') && File.directory?('app') && File.directory?('vendor') && File.directory?('config')
17
14
 
18
- opts.on("--out-dir DIR", "Directory of js2 -> js output") do |out|
19
- options[:write_dir] = out
20
- end
15
+ puts "Detected Rails setup: using auto config"
16
+
17
+ dir = File.directory?('app/js2') ? './app/js2' : './js2'
18
+ puts "Using js2 dir: #{dir}"
19
+
20
+ options[:write_dir] = './public/javascripts'
21
+ puts "Writing to: #{options[:write_dir]}"
22
+
23
+ options[:daemonize] = true
24
+
25
+ options[:js2_haml_dir] = dir
26
+ puts "HAML dir (optional): #{options[:js2_haml_dir]}"
27
+
28
+ else
29
+
30
+ usage = "Usage: js2 [options] <dir-with-js2>"
31
+ op = OptionParser.new do |opts|
32
+ opts.banner = usage
21
33
 
22
- opts.on("-d", "--daemonize") do |d|
23
- options[:daemonize] = true
34
+ opts.on("--js2-haml-dir DIR", "Directory with js2.haml files") do |haml|
35
+ options[:js2_haml_dir] = haml
36
+ end
37
+
38
+ opts.on("--out-dir DIR", "Directory of js2 -> js output") do |out|
39
+ options[:write_dir] = out
40
+ end
41
+
42
+ opts.on("-d", "--daemonize") do |d|
43
+ options[:daemonize] = true
44
+ end
45
+
46
+ opts.on('-h', "--help", "Help Screen") do
47
+ puts opts
48
+ exit
49
+ end
24
50
  end
25
51
 
26
- opts.on('-h', "--help", "Help Screen") do
27
- puts opts
28
- exit
52
+ begin
53
+ op.parse!(ARGV)
54
+ rescue OptionParser::ParseError => e
55
+ puts op
29
56
  end
30
- end
31
57
 
32
- begin
33
- op.parse!(ARGV)
34
- rescue OptionParser::ParseError => e
35
- puts op
58
+ dir = ARGV.pop
36
59
  end
37
60
 
38
-
39
- dir = ARGV.pop
40
-
41
61
  if !dir && File.directory?("./public/javascripts")
42
62
  dir = "./public/javascripts"
43
63
  end
44
64
 
45
-
46
65
  unless dir
47
66
  puts op
48
67
  exit
@@ -14,29 +14,8 @@ class JS2::Decorator::Standard
14
14
  return str
15
15
  end
16
16
 
17
- def draw_classes (nodes)
18
- ret = []
19
- visited = Hash.new
20
- funct = "function () { if (this.initialize) this.initialize.apply(this, arguments); }"
21
- nodes.select { |n| n.is_a? JS2::AST::ClassNode }.sort { |a,b| a.name <=> b.name }.each do |n|
22
- splitted = n.name.split(/\./)
23
- running_name = []
24
-
25
- splitted.each_with_index do |sub_name, i|
26
- running_name << sub_name
27
- name = running_name.join('.')
28
- next if visited[name]
29
- visited[name] = true
30
-
31
- if i == 0
32
- ret << "var #{name}=#{funct};"
33
- else
34
- ret << " #{name}=#{funct};"
35
- end
36
-
37
- end
38
- end
39
- return ret.join("\n")
17
+ def draw_bootstrap ()
18
+ return File.read(File.dirname(__FILE__) + '/../../javascript/bootstrap.js')
40
19
  end
41
20
 
42
21
  private
@@ -111,6 +90,7 @@ class JS2::Decorator::Standard
111
90
 
112
91
  return <<-END
113
92
  // #{node.filename}:#{node.line_number}
93
+ JS2.createClass("#{node.name}");
114
94
  #{node.name}.prototype={#{meta}
115
95
  #{member_js.join(",\n") }
116
96
  };
@@ -8,10 +8,15 @@ class JS2::Process::FileHandler
8
8
  @mtimes = Hash.new
9
9
  end
10
10
 
11
+ # depricated
11
12
  def class_file
12
13
  return @write_dir + '/classes.js'
13
14
  end
14
15
 
16
+ def bootstrap_file
17
+ return @write_dir + '/js2bootstrap.js'
18
+ end
19
+
15
20
  def get_view_files
16
21
  return [] unless @view_dir
17
22
  return Dir.glob(@view_dir + '/**/*.haml')
@@ -37,10 +42,19 @@ class JS2::Process::FileHandler
37
42
  def write_class_file (str)
38
43
  FileUtils.mkpath(File.dirname(class_file))
39
44
  File.open(class_file, 'w') do |f|
45
+ f << "alert('classes.js is deprecated, please include js2bootstrap.js instead.');"
40
46
  f << str
41
47
  end
42
48
  end
43
49
 
50
+ def write_bootstrap_file (str)
51
+ FileUtils.mkpath(File.dirname(bootstrap_file))
52
+ File.open(bootstrap_file, 'w') do |f|
53
+ f << str
54
+ end
55
+ end
56
+
57
+
44
58
  def need_update!
45
59
  ret = false
46
60
  did = Hash.new
data/lib/js2/processor.rb CHANGED
@@ -131,8 +131,10 @@ class JS2::Processor
131
131
  @fh.write_file(nc.filename, str)
132
132
  end
133
133
 
134
- str = decorator.draw_classes(universe.node_containers.flatten)
134
+ str = decorator.draw_bootstrap()
135
+
135
136
  @fh.write_class_file(str)
137
+ @fh.write_bootstrap_file(str)
136
138
 
137
139
  if @test_mode
138
140
  decorator.write_references(@reference_dir)
data/lib/js2.rb CHANGED
@@ -2,7 +2,7 @@ $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
4
  module Js2
5
- VERSION = '0.0.3'
5
+ VERSION = '0.0.4'
6
6
  end
7
7
 
8
8
  module JS2
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: js2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Su
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-30 00:00:00 -08:00
12
+ date: 2009-12-02 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency