opal 0.3.9 → 0.3.10

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/lib/opal/nodes.rb CHANGED
@@ -225,7 +225,8 @@ module Opal
225
225
  # code << super(opts, level)
226
226
  code << @statements.generate(opts, level)
227
227
 
228
- pre = 'function $$(){'
228
+ pre = "function($rb, self, __FILE__) {"
229
+ pre += 'function $$(){'
229
230
  post = "\n}\n"
230
231
 
231
232
  unless @scope_vars.empty?
@@ -250,6 +251,7 @@ module Opal
250
251
  end
251
252
 
252
253
  post += "return $$();\n"
254
+ post += "}"
253
255
 
254
256
  pre + code.join('') + post
255
257
  end
@@ -0,0 +1,62 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+
4
+ module Opal
5
+ module Rake
6
+
7
+ class BundleTask
8
+
9
+ # The output file to bundle this package to. This should be a full
10
+ # path including '.js' extension. This defaults to
11
+ # name-version.js
12
+ #
13
+ # @return [String] full path to bundle package to.
14
+ attr_accessor :out
15
+
16
+ # The path to the package.yml file for the package to build. This
17
+ # defaults to package.yml in the current directory.
18
+ #
19
+ # @return [String] path to package.yml
20
+ attr_accessor :package
21
+
22
+ # A hash of parser options passed to each compile stage. This
23
+ # accepts various options such as `:method_missing`. See
24
+ # [Parser] for more information.
25
+ #
26
+ # @return [Hash] hash of parser options
27
+ attr_accessor :options
28
+
29
+ def initialize(name = :bundle)
30
+ @name = name
31
+ @options = {}
32
+ @package = 'package.yml'
33
+
34
+ yield self if block_given?
35
+
36
+ define
37
+ end
38
+
39
+ def define
40
+ desc "Bundle this package ready for a web browser"
41
+ task(@name) do
42
+ # lazy load rbp/bundle incase not installed yet - we dont want to
43
+ # disrupt other take tasks.
44
+ require 'opal/bundle'
45
+
46
+ path = File.expand_path(@package || 'package.yml')
47
+ raise "Cannot find package: `#{path}'" unless File.exists? path
48
+
49
+ package = Rbp::Package.load_path path
50
+ bundle = Bundle.new package
51
+ bundle.options = options
52
+ code = bundle.build
53
+
54
+ File.open("#{package.name}-#{package.version}.js", 'w+') do |out|
55
+ out.write code
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.9
4
+ version: 0.3.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-16 00:00:00.000000000Z
12
+ date: 2011-09-22 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: Ruby runtime and core library for javascript
15
15
  email:
@@ -20,17 +20,16 @@ extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
22
  - bin/opal
23
- - lib/opal/browserify.rb
24
23
  - lib/opal/builder.rb
24
+ - lib/opal/bundle.rb
25
25
  - lib/opal/command.rb
26
26
  - lib/opal/context.rb
27
27
  - lib/opal/lexer.rb
28
28
  - lib/opal/nodes.rb
29
29
  - lib/opal/parser.rb
30
30
  - lib/opal/parser.y
31
+ - lib/opal/rake/bundle_task.rb
31
32
  - lib/opal.rb
32
- - lib/rbp/package.rb
33
- - lib/rbp.rb
34
33
  - runtime/class.js
35
34
  - runtime/fs.js
36
35
  - runtime/init.js
@@ -1,34 +0,0 @@
1
- module Opal
2
-
3
- # Takes a package and builds it ready for the browser
4
- class Browserify
5
-
6
- def initialize(package)
7
- @package = package
8
- @builder = Builder.new
9
- end
10
-
11
- # Simple build - returns a string which can be written to a file
12
- # FIXME: hardcoded lib directory to './lib'
13
- def build
14
- libs = @package.lib_files
15
- libs.map! do |f|
16
- path = File.join @package.root, './lib', f
17
- src = @builder.compile_source path
18
- "\"#{f}\": #{src}"
19
- end
20
-
21
- bundle = []
22
- bundle << %[opal.package({\n]
23
- bundle << %[ name: "#{@package.name}",\n]
24
- bundle << %[ version: "#{@package.version}",\n]
25
- bundle << %[ libs: {\n]
26
- bundle << %[ #{libs.join ",\n "}\n]
27
- bundle << %[ }\n]
28
- bundle << %[});\n]
29
-
30
- bundle.join ''
31
- end
32
- end
33
- end
34
-
data/lib/rbp.rb DELETED
@@ -1,2 +0,0 @@
1
- require 'rbp/package'
2
-
data/lib/rbp/package.rb DELETED
@@ -1,49 +0,0 @@
1
- require 'yaml'
2
-
3
- module RBP
4
-
5
- class Package
6
-
7
- attr_reader :root
8
-
9
- def initialize(root = Dir.getwd)
10
- @root = root
11
- __load_yml
12
- end
13
-
14
- def __load_yml
15
- yml_path = File.join @root, 'package.yml'
16
-
17
- unless File.exists? yml_path
18
- raise "Missing package.yml in `#{@root}'"
19
- end
20
-
21
- @yml = YAML.load File.read(yml_path)
22
-
23
- raise "Bad package.yml" unless @yml and @yml['name'] and @yml['version']
24
- end
25
-
26
- # Returns an array of lib files relative to the root of
27
- # this package
28
- def lib_files
29
- libs = nil
30
-
31
- Dir.chdir(File.join @root, 'lib') do
32
- libs = Dir['**/*.rb']
33
- end
34
-
35
- libs
36
- end
37
-
38
- # package name
39
- def name
40
- @yml['name']
41
- end
42
-
43
- # package version
44
- def version
45
- @yml['version']
46
- end
47
- end
48
- end
49
-