js2 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Changelog CHANGED
@@ -0,0 +1,2 @@
1
+ == 0.0.2 2009-11-25
2
+ * Fixed sass templating so that there is no default namespacing
data/Manifest.txt CHANGED
@@ -41,3 +41,4 @@ lib/tasks/js2.rake
41
41
  meta/c_tokenizer.rl.erb
42
42
  meta/replace.rb
43
43
  bin/js2
44
+ website/index.txt
data/Rakefile CHANGED
@@ -12,9 +12,8 @@ Hoe.plugin :newgem
12
12
  # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
13
  $hoe = Hoe.spec 'js2' do
14
14
  self.developer 'Jeff Su', 'me@jeffsu.com'
15
- self.rubyforge_name = self.name
16
- # self.extra_deps = [['activesupport','>= 2.0.2']]
17
-
15
+ self.rubyforge_name = self.name
16
+ self.extra_deps = [['haml','>= 2.2.6'], [ 'RubyInline', '>= 3.8.3']]
18
17
  end
19
18
 
20
19
  require 'newgem/tasks'
data/bin/js2 CHANGED
@@ -35,8 +35,14 @@ rescue OptionParser::ParseError => e
35
35
  puts op
36
36
  end
37
37
 
38
+
38
39
  dir = ARGV.pop
39
40
 
41
+ if !dir && File.directory?("./public/javascripts")
42
+ dir = "./public/javascripts"
43
+ end
44
+
45
+
40
46
  unless dir
41
47
  puts op
42
48
  exit
@@ -51,9 +57,10 @@ config.write_dir = options[:write_dir] || dir
51
57
 
52
58
  p = JS2::Processor.get(config)
53
59
  if options[:daemonize]
60
+ puts "Daemonizing..."
54
61
  d = JS2::Daemon.new(p)
55
62
  d.run do
56
- "Recompiled at #{Time.now}"
63
+ puts "Recompiled at #{Time.now}"
57
64
  sleep 0.5
58
65
  end
59
66
  else
@@ -44,14 +44,16 @@ class JS2::Parser::Haml
44
44
  if m = line.match(/^\.?([\w\.]+)/)
45
45
  klass = Hash.new
46
46
  result[m[1]] = klass
47
- elsif m = line.match(/^ sass/)
47
+
48
+ elsif m = line.match(/^ sass(.*)/)
48
49
  key = 'sass'
49
- klass[key] = [ [ ], '' ]
50
+ klass[key] = [ [ ], '', true ]
51
+
50
52
  elsif m = line.match(/^ \.?([\w]+)(\(([^)]+)\))?/)
51
53
  key = m[1]
52
54
  klass[key] = [ [], m[3] ]
53
55
  elsif key
54
- if key == 'sass'
56
+ if key == 'sass' && ! klass[key][2]
55
57
  klass[key][0] << line.sub(/^ /, '')
56
58
  else
57
59
  klass[key][0] << line.sub(/^ /, '')
@@ -63,7 +65,10 @@ class JS2::Parser::Haml
63
65
  klass = result[class_name]
64
66
  klass.each_pair do |key, array|
65
67
  if key == 'sass'
66
- array[0].unshift ".#{class_name.sub(/\.\w+$/, '').sub(/\./, '')}"
68
+ unless array[2]
69
+ array[0].unshift ".#{class_name.sub(/\.\w+$/, '').sub(/\./, '')}"
70
+ end
71
+
67
72
  klass[key] = sassify(array[0].join("\n"))
68
73
  else
69
74
  klass[key] = functionize(array[0].join("\n"), array[1])
@@ -79,8 +84,10 @@ class JS2::Parser::Haml
79
84
  def sassify (string)
80
85
  begin
81
86
  css = @haml_engine.sassify(string)
82
- rescue
83
- raise string
87
+ rescue Exception => e
88
+ puts "Error Processing SASS:"
89
+ puts string
90
+ raise e
84
91
  end
85
92
  return css.gsub(/\n/, '').to_json
86
93
  end
@@ -88,8 +95,10 @@ class JS2::Parser::Haml
88
95
  def functionize (string, params)
89
96
  begin
90
97
  html = @haml_engine.hamlize(string)
91
- rescue
92
- raise string
98
+ rescue Exception => e
99
+ puts "Error Processing HAML:"
100
+ puts string
101
+ raise e
93
102
  end
94
103
 
95
104
  if params
@@ -42,10 +42,6 @@ class JS2::Test::SeleniumElement
42
42
  return self.check_attribute(':visible', true, wait_for);
43
43
  end
44
44
 
45
- def sel_visible?()
46
- return @sel.visible?(get_ele())
47
- end
48
-
49
45
  def hidden?(wait_for = nil)
50
46
  return self.check_attribute(':visible', false, wait_for);
51
47
  end
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.1'
5
+ VERSION = '0.0.2'
6
6
  end
7
7
 
8
8
  module JS2
data/website/index.txt ADDED
@@ -0,0 +1,86 @@
1
+ = Quick Setup =
2
+
3
+ install js2:
4
+ {{{
5
+ sudo gem install js2
6
+ js2 -h
7
+ }}}
8
+
9
+ in a rails app (rails root):
10
+ {{{
11
+ # if your js2 files reside in ./app/js2
12
+ js2 --out-dir=./public/javascripts ./app/js2
13
+ }}}
14
+
15
+ = OO Frustrations using Javascript =
16
+
17
+
18
+ For every Javascript developer that has ever wanted to create a library for his/her project, there comes a time when an Object Oriented approach is necessary (or extremely desired). Fortunately, there are a plethora of options to choose from:
19
+
20
+ using prototype (not the framework) and hashes:
21
+ {{{
22
+ var MyClass = function () {
23
+ this.member1 = "member";
24
+ };
25
+ MyClass.prototype = {
26
+ method1: function () { alert('method1 called'); }
27
+ }
28
+ }}}
29
+
30
+ embedding functions right in the instantiator:
31
+ {{{
32
+ function MyClass () {
33
+ this.member1 = "member1";
34
+ function method1 () {
35
+ alert("method1 called");
36
+ }
37
+ }
38
+ }}}
39
+
40
+ using jQuery (or any of the js OO frameworks) by passing in hashes:
41
+ {{{
42
+ var MyClass = Class.create({
43
+ member1: "member1",
44
+ method1: function(){ alert("method1 called") },
45
+ });
46
+ }}}
47
+
48
+ Unfortunately, these solutions are unnatural as far as Object Oriented languages are go.
49
+
50
+ = JS2 Solution =
51
+
52
+ JS2 language that is a superset of Javascript and the problem it tries to solve is bringing "natural" OO syntax to Javascript by adding a compilation layer.
53
+
54
+ So in myClass.js2 one could write:
55
+ {{{
56
+ class MyClass {
57
+ var member1 = "member1";
58
+
59
+ function method1 () {
60
+ alert("method1 called");
61
+ }
62
+ }}}
63
+
64
+ And after compilation myClass.js (notice the .js extension vs the .js2) would be:
65
+ {{{
66
+ var MyClass = function () { };
67
+ MyClass.prototype = {
68
+ member1: "member1",
69
+ method1: function () { alert("method1 called"); }
70
+ }
71
+ }}}
72
+
73
+ One of the nice things about this solution is that it allows us to "calculate" things like mixins and inheritance at compile time rather than runtime. This compilation layer opens the doors for features such as:
74
+ * Inheritance
75
+ * Mixins (Ruby's multiple inheritance solution)
76
+ * getters and setters
77
+ * IoC (Dependency Injection)
78
+ * AOP (Aspect Oriented Programming)
79
+ * foreach
80
+ * currying
81
+ * More [Features]
82
+
83
+
84
+ = Inspiration ==
85
+
86
+ HAML, SASS, Ruby, Perl, jQuery, Prototype.js
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.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Su
@@ -9,9 +9,29 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-23 00:00:00 -08:00
12
+ date: 2009-11-24 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: haml
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.2.6
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: RubyInline
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 3.8.3
34
+ version:
15
35
  - !ruby/object:Gem::Dependency
16
36
  name: hoe
17
37
  type: :development
@@ -33,6 +53,7 @@ extra_rdoc_files:
33
53
  - History.txt
34
54
  - Manifest.txt
35
55
  - PostInstall.txt
56
+ - website/index.txt
36
57
  files:
37
58
  - Changelog
38
59
  - History.txt
@@ -77,6 +98,7 @@ files:
77
98
  - meta/c_tokenizer.rl.erb
78
99
  - meta/replace.rb
79
100
  - bin/js2
101
+ - website/index.txt
80
102
  has_rdoc: true
81
103
  homepage: http://github.com/#{github_username}/#{project_name}
82
104
  licenses: []