sibilant 0.0.1
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/.gitignore +17 -0
- data/.gitmodules +3 -0
- data/.travis.yml +3 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +22 -0
- data/README.md +47 -0
- data/Rakefile +5 -0
- data/lib/sibilant.rb +34 -0
- data/lib/sibilant/sinatra.rb +10 -0
- data/lib/sibilant/tilt.rb +21 -0
- data/lib/sibilant/version.rb +3 -0
- data/sibilant.gemspec +23 -0
- data/spec/fixture.sibilant +1 -0
- data/spec/sibilant_spec.rb +34 -0
- data/spec/sinatra_helper_spec.rb +48 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/tilt_helper_spec.rb +14 -0
- metadata +100 -0
data/.gitignore
ADDED
data/.gitmodules
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Jacob Rothstein
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
[](https://travis-ci.org/jbr/sibilant-gem)
|
2
|
+
[](https://coveralls.io/r/jbr/sibilant-gem)
|
3
|
+
|
4
|
+
# Sibilant Ruby Gem
|
5
|
+
|
6
|
+
This is a ruby wrapper for the sibilant compiler, which is written in
|
7
|
+
javascript. Instead of depending on ExecJS, it expects to find NodeJS
|
8
|
+
available on the path as node. Sibilant doesn't need to be installed.
|
9
|
+
|
10
|
+
# Tilt support
|
11
|
+
|
12
|
+
Providing sibilant code inside of a [tilt](https://github.com/rtomayko/tilt/) environment is provided by
|
13
|
+
|
14
|
+
require 'sibilant/tilt'
|
15
|
+
Tilt['test.sibilant'].new { "(+ 1 2 3)" }.render #=> '(1 + 2 + 3)'
|
16
|
+
|
17
|
+
# Sinatra
|
18
|
+
|
19
|
+
require 'sinatra'
|
20
|
+
require 'sibilant/sinatra'
|
21
|
+
helpers Sinatra::Sibilant
|
22
|
+
get('/inline.js') { sibilant "(alert 'here)" }
|
23
|
+
|
24
|
+
#./views/templated.sibilant
|
25
|
+
get('/templated.js') { sibilant :templated }
|
26
|
+
|
27
|
+
## When it's ready, here's how you'll install it
|
28
|
+
|
29
|
+
Add this line to your application's Gemfile:
|
30
|
+
|
31
|
+
gem 'sibilant'
|
32
|
+
|
33
|
+
And then execute:
|
34
|
+
|
35
|
+
$ bundle
|
36
|
+
|
37
|
+
Or install it yourself as:
|
38
|
+
|
39
|
+
$ gem install sibilant
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
1. Fork it
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/sibilant.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "sibilant/version"
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Sibilant
|
5
|
+
class Compiler
|
6
|
+
def sibilant_js_root
|
7
|
+
File.join File.dirname(__FILE__), '..', 'js', 'sibilant'
|
8
|
+
end
|
9
|
+
|
10
|
+
def package_json_file
|
11
|
+
File.open File.join(sibilant_js_root, 'package.json')
|
12
|
+
end
|
13
|
+
|
14
|
+
def package_json
|
15
|
+
JSON.parse package_json_file.read
|
16
|
+
end
|
17
|
+
|
18
|
+
def version
|
19
|
+
package_json[:version]
|
20
|
+
end
|
21
|
+
|
22
|
+
def sibilant_cli
|
23
|
+
File.join sibilant_js_root, 'bin', 'sibilant'
|
24
|
+
end
|
25
|
+
|
26
|
+
def translate(sibilant_code)
|
27
|
+
IO.popen("#{sibilant_cli} -i", 'r+') do |sibilant|
|
28
|
+
sibilant.puts sibilant_code
|
29
|
+
sibilant.close_write
|
30
|
+
sibilant.read
|
31
|
+
end.strip
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Tilt
|
2
|
+
module Sibilant
|
3
|
+
require 'sibilant'
|
4
|
+
require 'tilt'
|
5
|
+
|
6
|
+
class SibilantTemplate < Tilt::Template
|
7
|
+
self.default_mime_type = 'application/javascript'
|
8
|
+
|
9
|
+
def prepare
|
10
|
+
@compiler = ::Sibilant::Compiler.new
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
def evaluate(scope, locals, &block)
|
15
|
+
@compiler.translate data
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
register Tilt::Sibilant::SibilantTemplate, 'sibilant'
|
21
|
+
end
|
data/sibilant.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sibilant/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sibilant"
|
8
|
+
spec.version = Sibilant::VERSION
|
9
|
+
spec.authors = ["Jacob Rothstein"]
|
10
|
+
spec.email = ["hi@jbr.me"]
|
11
|
+
spec.description = %q{Ruby wrapper using ExecJS for the sibilant compiler}
|
12
|
+
spec.summary = %q{}
|
13
|
+
spec.homepage = "http://sibilantjs.info"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
(this-is-sibilant-code (+ 1 2 3))
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Sibilant do
|
4
|
+
describe 'with an instance of sibilant compiler' do
|
5
|
+
before(:each) { @compiler = Sibilant::Compiler.new }
|
6
|
+
|
7
|
+
it 'should exist' do
|
8
|
+
@compiler.should_not be_nil
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should have a #js_root that ends with js' do
|
12
|
+
@compiler.sibilant_js_root.should match(/\/js\/sibilant$/)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should have a package_json_file' do
|
16
|
+
@compiler.package_json_file.should be_a(File)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should properly parse the json from the #package_json_file as #package_json' do
|
20
|
+
@compiler.package_json['name'].should == 'sibilant'
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should properly translate sibilant' do
|
24
|
+
@compiler.translate('(console.log "foo")').should == 'console.log("foo");'
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should pull the #version from the #package_json' do
|
28
|
+
test_version = '9.8.6'
|
29
|
+
|
30
|
+
@compiler.should_receive(:package_json).once.and_return version: test_version
|
31
|
+
@compiler.version.should eq(test_version)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'sinatra'
|
3
|
+
require 'rack/test'
|
4
|
+
require 'sibilant/sinatra'
|
5
|
+
|
6
|
+
class SibilantApp < Sinatra::Base
|
7
|
+
helpers Sinatra::Sibilant
|
8
|
+
set :views, ->{ root }
|
9
|
+
get('/fixture.js') { sibilant :fixture }
|
10
|
+
get('/inline.js') { sibilant '(alert "hello world")' }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe SibilantApp do
|
14
|
+
include Rack::Test::Methods
|
15
|
+
def app() SibilantApp end
|
16
|
+
|
17
|
+
describe 'rendering inline sibilant' do
|
18
|
+
before(:each) { get '/inline.js' }
|
19
|
+
|
20
|
+
it 'should succeed' do
|
21
|
+
last_response.should be_ok
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should render the right content type' do
|
25
|
+
last_response.content_type.should match('application/javascript')
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should properly translate the provided sibilant' do
|
29
|
+
last_response.body.should == 'alert("hello world");'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'rendering fixture sibilant' do
|
34
|
+
before(:each) { get '/fixture.js' }
|
35
|
+
|
36
|
+
it 'should succeed' do
|
37
|
+
last_response.should be_ok
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should render the right content type' do
|
41
|
+
last_response.content_type.should match('application/javascript')
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should properly translate the fixture sibilant' do
|
45
|
+
last_response.body.should == 'thisIsSibilantCode((1 + 2 + 3));'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'tilt'
|
3
|
+
require 'sibilant/tilt'
|
4
|
+
|
5
|
+
describe Tilt::Sibilant::SibilantTemplate do
|
6
|
+
it 'should be registered for .sibilant files' do
|
7
|
+
Tilt['test.sibilant'].should equal(Tilt::Sibilant::SibilantTemplate)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'translates sibilant code on render' do
|
11
|
+
template = Tilt::Sibilant::SibilantTemplate.new { |t| "(console.log 'hello 'world)" }
|
12
|
+
template.render.strip.should eq('console.log("hello", "world");')
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sibilant
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jacob Rothstein
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Ruby wrapper using ExecJS for the sibilant compiler
|
47
|
+
email:
|
48
|
+
- hi@jbr.me
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- .gitmodules
|
55
|
+
- .travis.yml
|
56
|
+
- Gemfile
|
57
|
+
- LICENSE.txt
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- lib/sibilant.rb
|
61
|
+
- lib/sibilant/sinatra.rb
|
62
|
+
- lib/sibilant/tilt.rb
|
63
|
+
- lib/sibilant/version.rb
|
64
|
+
- sibilant.gemspec
|
65
|
+
- spec/fixture.sibilant
|
66
|
+
- spec/sibilant_spec.rb
|
67
|
+
- spec/sinatra_helper_spec.rb
|
68
|
+
- spec/spec_helper.rb
|
69
|
+
- spec/tilt_helper_spec.rb
|
70
|
+
homepage: http://sibilantjs.info
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 1.8.25
|
92
|
+
signing_key:
|
93
|
+
specification_version: 3
|
94
|
+
summary: ''
|
95
|
+
test_files:
|
96
|
+
- spec/fixture.sibilant
|
97
|
+
- spec/sibilant_spec.rb
|
98
|
+
- spec/sinatra_helper_spec.rb
|
99
|
+
- spec/spec_helper.rb
|
100
|
+
- spec/tilt_helper_spec.rb
|