livescript 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dfbc44276427b5e4247cc0f0d705fe0c041699ef
4
+ data.tar.gz: 4516d88edf05885fc1220d2678f53417946487fa
5
+ SHA512:
6
+ metadata.gz: 47d13a88e05134a9495806acce2437128afec6ef5bcc2648ebe96f51d3dbfceb7198f051d086ab0b18819a6d0dc698f6db82014c179628581ffa07e535250e61
7
+ data.tar.gz: 7584497ea688ca9cb14556574936410c9fa58f3ea938b504358ae57c9b1b38927173ef2bae6048d6b53dad8d3e3403f1faeef5d22c6fba21547f8d4af10faa6a
data/LICENSE CHANGED
@@ -1,22 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 Bian Jiaping
1
4
  Copyright (c) 2010 Joshua Peek
2
5
 
3
- Permission is hereby granted, free of charge, to any person
4
- obtaining a copy of this software and associated documentation
5
- files (the "Software"), to deal in the Software without
6
- restriction, including without limitation the rights to use,
7
- copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- copies of the Software, and to permit persons to whom the
9
- Software is furnished to do so, subject to the following
10
- conditions:
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
11
12
 
12
- The above copyright notice and this permission notice shall be
13
- included in all copies or substantial portions of the Software.
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
14
15
 
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
- OTHER DEALINGS IN THE SOFTWARE.
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
data/README.md CHANGED
@@ -1,41 +1,49 @@
1
- Ruby LiveScript
2
- =================
1
+ # Ruby LiveScript
3
2
 
4
- Ruby LiveScript is a bridge to the official LiveScript compiler.
3
+ Ruby LiveScript compiler.
5
4
 
6
- LiveScript.compile File.read("script.ls)
5
+ It uses [execjs](https://github.com/rails/execjs) to run LiveScript javascript compiler.
7
6
 
8
- This gem is a fork of `ruby-coffee-script` adapted for LiveScript.
7
+ Depends on [livescript-source](https://github.com/Roonin-mx/livescript-source).
9
8
 
10
- Installation
11
- ------------
9
+ ## Installation
12
10
 
13
- gem install livescript
11
+ ```
12
+ gem install livescript
13
+ ```
14
14
 
15
+ If you are using Bundler, add the following to your `Gemfile`:
15
16
 
16
- Dependencies
17
- ------------
17
+ ```
18
+ gem 'livescript'
19
+ ```
18
20
 
19
- This library depends on the `livescript-source` gem which is
20
- updated any time a new version of LiveScript is released. (The
21
- `livescript-source` gem's version number is synced with each
22
- official LiveScript release.) This way you can build against
23
- different versions of LiveScript by requiring the correct version of
24
- the `livescript-source` gem.
21
+ ## Usage
25
22
 
26
- In addition, you can use this library with unreleased versions of
27
- LiveScript by setting the `LIVESCRIPT_SOURCE_PATH` environment
28
- variable:
23
+ ```ruby
24
+ require 'livescript'
29
25
 
30
- export LIVESCRIPT_SOURCE_PATH=/path/to/LiveScript/extras/livescript.js
26
+ options = {bare: true, header: false}
31
27
 
32
- ### JSON
28
+ result = LiveScript.compile(source_code, options)
33
29
 
34
- The `json` library is also required but is not explicitly stated as a
35
- gem dependency. If you're on Ruby 1.8 you'll need to install the
36
- `json` or `json_pure` gem. On Ruby 1.9, `json` is included in the
37
- standard library.
30
+ # get default options
31
+ options = LiveScript.default_options
38
32
 
39
- ### ExecJS
33
+ # set default options
34
+ LiveScript.default_options = options
35
+ ```
40
36
 
41
- The [ExecJS](https://github.com/sstephenson/execjs) library is used to automatically choose the best JavaScript engine for your platform. Check out its [README](https://github.com/sstephenson/execjs/blob/master/README.md) for a complete list of supported engines.
37
+ Available options:
38
+
39
+ * bare: Default true. If true, compile without the top-level function wrapper
40
+ * header: Default true. If true, add the "Generated by" header
41
+ * const: Default false. If true, compile all variables as constants
42
+ * filename: An optional filename used for compilation errors
43
+ * map: Source map type
44
+
45
+ See `Programmatic API` section at [livescript.net](http://livescript.net) for more.
46
+
47
+ ## License
48
+
49
+ MIT
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ end
6
+
7
+ desc 'Run tests'
8
+ task :default => :test
@@ -0,0 +1,3 @@
1
+ module LiveScript
2
+ VERSION = '2.3.0'
3
+ end
data/lib/livescript.rb CHANGED
@@ -1,60 +1,49 @@
1
1
  require 'execjs'
2
2
  require 'livescript/source'
3
+ require_relative 'livescript/version'
3
4
 
4
5
  module LiveScript
5
- EngineError = ExecJS::RuntimeError
6
- CompilationError = ExecJS::ProgramError
6
+ # compile options. See Programmatic API section at http://livescript.net/
7
+ @default_options = {}
8
+ @context = ExecJS.compile LiveScript::Source.contents
7
9
 
8
- module Source
9
- def self.path
10
- @path ||= ENV['LIVESCRIPT_SOURCE_PATH'] || bundled_path
11
- end
12
-
13
- def self.path=(path)
14
- @contents = @version = @bare_option = @context = nil
15
- @path = path
16
- end
17
-
18
- def self.contents
19
- @contents ||= File.read(path)
20
- end
10
+ def self.context
11
+ @context
12
+ end
21
13
 
22
- def self.version
23
- @version ||= contents[/LiveScript Compiler v([\d.]+)/, 1]
24
- end
14
+ def self.context=(context)
15
+ @context = context
16
+ end
25
17
 
26
- def self.bare_option
27
- @bare_option ||= contents.match(/noWrap/) ? 'noWrap' : 'bare'
28
- end
18
+ def self.default_options
19
+ @default_options
20
+ end
29
21
 
30
- def self.context
31
- @context ||= ExecJS.compile(contents)
22
+ def self.default_options=(options)
23
+ if options.nil? || !options.kind_of?(Hash)
24
+ raise "Wrong parameter for default_options: #{options.inspect}"
25
+ else
26
+ @default_options = options
32
27
  end
33
28
  end
34
29
 
35
- class << self
36
- def engine
37
- end
30
+ # Compile a script (String or IO) to JavaScript.
31
+ def self.compile(script, options = {})
32
+ # Read content if script is IO object
33
+ script = script.read if script.respond_to?(:read)
38
34
 
39
- def engine=(engine)
40
- end
35
+ options = @default_options.merge(options)
41
36
 
42
- def version
43
- Source.version
44
- end
37
+ @context.call('LiveScript.compile', script, options)
38
+ end
45
39
 
46
- # Compile a script (String or IO) to JavaScript.
47
- def compile(script, options = {})
48
- script = script.read if script.respond_to?(:read)
40
+ def self.engine
41
+ end
49
42
 
50
- if options.key?(:bare)
51
- elsif options.key?(:no_wrap)
52
- options[:bare] = options[:no_wrap]
53
- else
54
- options[:bare] = false
55
- end
43
+ def self.version
44
+ LiveScript::VERSION
45
+ end
56
46
 
57
- Source.context.call("LiveScript.compile", script, options)
58
- end
47
+ def self.engine=(engine)
59
48
  end
60
49
  end
@@ -0,0 +1,65 @@
1
+ require 'minitest/autorun'
2
+ require 'execjs'
3
+ require 'livescript'
4
+
5
+ class LiveScriptSourceTest < Minitest::Test
6
+ def setup
7
+ # source => expected compiled result
8
+ @source_codes = {
9
+ %Q{alert 'hi'} => %Q{alert('hi')},
10
+ %Q{add 1, 2} => %Q{add(1, 2)},
11
+ %Q{(x, y) -> x + y} => %Q{function(x, y)}
12
+ }
13
+ end
14
+
15
+ def test_compile
16
+ @source_codes.each do |source, result|
17
+ assert_match result, LiveScript.compile(source)
18
+ end
19
+ end
20
+
21
+ def test_compile_with_io
22
+ @source_codes.each do |source, result|
23
+ assert_match result, LiveScript.compile(StringIO.new(source))
24
+ end
25
+ end
26
+
27
+ def test_compile_errors
28
+ code = <<-CODE
29
+ sayHello = ->
30
+ console.log 'hello, world'
31
+ if
32
+ CODE
33
+
34
+ assert_raises do
35
+ LiveScript.compile(code)
36
+ end
37
+ end
38
+
39
+ def test_default_options
40
+ assert_empty LiveScript.default_options
41
+ assert_match 'Generated by LiveScript', LiveScript.compile("alert 'hi'")
42
+ assert_match '(function()', LiveScript.compile("alert 'hi'")
43
+
44
+ LiveScript.default_options = {bare: true, header: false}
45
+ refute_match 'Generated by LiveScript', LiveScript.compile("alert 'hi'")
46
+ refute_match '(function()', LiveScript.compile("alert 'hi'")
47
+
48
+ # override default options
49
+ assert_match '(function()', LiveScript.compile("alert 'hi'", bare: false)
50
+ assert_match 'Generated by LiveScript', LiveScript.compile("alert 'hi'", header: true)
51
+
52
+ # avoid affecting other tests
53
+ LiveScript.default_options = {}
54
+ end
55
+
56
+ def test_options
57
+ # bare
58
+ assert_match '(function()', LiveScript.compile("alert 'hi'", bare: false)
59
+ refute_match '(function()', LiveScript.compile("alert 'hi'", bare: true)
60
+
61
+ # header
62
+ assert_match 'Generated by LiveScript', LiveScript.compile("alert 'hi'", header: true)
63
+ refute_match 'Generated by LiveScript', LiveScript.compile("alert 'hi'", header: false)
64
+ end
65
+ end
metadata CHANGED
@@ -1,81 +1,143 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: livescript
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
5
- prerelease:
4
+ version: 2.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Victor Hugo Borja
8
+ - Bian Jiaping
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2010-03-11 00:00:00.000000000 Z
12
+ date: 2016-04-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: livescript-source
16
16
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
17
  requirements:
19
- - - ! '>='
18
+ - - ">="
20
19
  - !ruby/object:Gem::Version
21
- version: '0'
20
+ version: 1.4.0.rc.1
21
+ - - "<="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.5.0
22
24
  type: :runtime
23
25
  prerelease: false
24
26
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
27
  requirements:
27
- - - ! '>='
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ version: 1.4.0.rc.1
31
+ - - "<="
28
32
  - !ruby/object:Gem::Version
29
- version: '0'
33
+ version: 1.5.0
30
34
  - !ruby/object:Gem::Dependency
31
35
  name: execjs
32
36
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
37
  requirements:
35
- - - ! '>='
38
+ - - "~>"
36
39
  - !ruby/object:Gem::Version
37
- version: '0'
40
+ version: '2.0'
38
41
  type: :runtime
39
42
  prerelease: false
40
43
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
44
  requirements:
43
- - - ! '>='
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ - !ruby/object:Gem::Dependency
49
+ name: bundler
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.11'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
44
60
  - !ruby/object:Gem::Version
45
- version: '0'
46
- description: ! ' Ruby LiveScript is a bridge to the JS LiveScript compiler.
47
-
48
- '
49
- email: vic.borja@gmail.com
61
+ version: '1.11'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '11.1'
69
+ type: :development
70
+ prerelease: false
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '11.1'
76
+ - !ruby/object:Gem::Dependency
77
+ name: minitest
78
+ requirement: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.8'
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '5.8'
90
+ - !ruby/object:Gem::Dependency
91
+ name: execjs
92
+ requirement: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.6'
97
+ type: :development
98
+ prerelease: false
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.6'
104
+ description: Ruby LiveScript is a bridge to the JS LiveScript compiler.
105
+ email:
106
+ - vic.borja@gmail.com
107
+ - ssbianjp@gmail.com
50
108
  executables: []
51
109
  extensions: []
52
110
  extra_rdoc_files: []
53
111
  files:
54
- - lib/livescript.rb
55
112
  - LICENSE
56
113
  - README.md
114
+ - Rakefile
115
+ - lib/livescript.rb
116
+ - lib/livescript/version.rb
117
+ - test/test_livescript.rb
57
118
  homepage: http://github.com/Roonin-mx/livescript-ruby
58
- licenses: []
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
59
122
  post_install_message:
60
123
  rdoc_options: []
61
124
  require_paths:
62
125
  - lib
63
126
  required_ruby_version: !ruby/object:Gem::Requirement
64
- none: false
65
127
  requirements:
66
- - - ! '>='
128
+ - - ">="
67
129
  - !ruby/object:Gem::Version
68
130
  version: '0'
69
131
  required_rubygems_version: !ruby/object:Gem::Requirement
70
- none: false
71
132
  requirements:
72
- - - ! '>='
133
+ - - ">="
73
134
  - !ruby/object:Gem::Version
74
135
  version: '0'
75
136
  requirements: []
76
137
  rubyforge_project:
77
- rubygems_version: 1.8.24
138
+ rubygems_version: 2.5.1
78
139
  signing_key:
79
- specification_version: 3
140
+ specification_version: 4
80
141
  summary: Ruby LiveScript Compiler
81
142
  test_files: []
143
+ has_rdoc: