jsonnet 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0608c5c013b33c3336b6032b17e8a42266d3b273
4
+ data.tar.gz: ce3d29f5b2be96106b458cd93765a1b2b2063287
5
+ SHA512:
6
+ metadata.gz: 830a1cb02c29949849ffa25d116a65096715054fcf077133a854025c1485f57b6ce796ced668d15c0cdd8e243c019708b09a8ff3b87f1b13033834fd11fab18f
7
+ data.tar.gz: 3634f878aaa031ff2699963ab4c12c23dba41f52495e1b9915c71073b5ef8cbee8c3f7a4e7053e5f7c7f0fc4c84865a948a7cfb7633c7b7f1e9b71afe90c6809
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jsonnet.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Yuki Yugui Sonoda
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.
@@ -0,0 +1,34 @@
1
+ # Jsonnet
2
+
3
+ Jsonnet processor library. Wraps the official C++ implementation with a Ruby extention library.
4
+
5
+ ## Status
6
+ Pre-alpha. Under development.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'jsonnet'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install jsonnet
23
+
24
+ ## Usage
25
+
26
+ TODO: Write usage instructions here
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it ( https://github.com/yugui/jsonnet/fork )
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create a new Pull Request
@@ -0,0 +1,16 @@
1
+ require 'bundler/gem_tasks'
2
+ require "rake/extensiontask"
3
+ require 'rake/testtask'
4
+
5
+ task :default => :compile
6
+
7
+ Rake::ExtensionTask.new do |t|
8
+ t.name = 'jsonnet_wrap'
9
+ t.ext_dir = 'ext/jsonnet'
10
+ t.lib_dir = 'lib/jsonnet'
11
+ end
12
+
13
+ Rake::TestTask.new('test' => 'compile') do |t|
14
+ t.libs << 'test'
15
+ t.verbose = true
16
+ end
@@ -0,0 +1,2 @@
1
+ Makefile
2
+ *.o
@@ -0,0 +1,6 @@
1
+ require 'mkmf'
2
+
3
+ dir_config('jsonnet')
4
+ abort 'libjsonnet.h not found' unless have_header('libjsonnet.h')
5
+ abort 'libjsonnet not found' unless have_library('jsonnet')
6
+ create_makefile('jsonnet/jsonnet_wrap')
@@ -0,0 +1,92 @@
1
+ #include <ruby/ruby.h>
2
+ #include <libjsonnet.h>
3
+
4
+ /*
5
+ * Jsonnet evaluator
6
+ */
7
+ static VALUE cVM;
8
+ static VALUE eEvaluationError;
9
+
10
+ static void vm_free(void *ptr);
11
+ static const rb_data_type_t jsonnet_vm_type = {
12
+ "JsonnetVm",
13
+ {
14
+ /* dmark = */ 0,
15
+ /* dfree = */ vm_free,
16
+ /* dsize = */ 0,
17
+ },
18
+ /* parent = */ 0,
19
+ /* data = */ 0,
20
+ /* flags = */ RUBY_TYPED_FREE_IMMEDIATELY
21
+ };
22
+
23
+ /*
24
+ * call-seq:
25
+ * Jsonnet.version -> String
26
+ *
27
+ * Returns the version of the underlying C++ implementation of Jsonnet.
28
+ */
29
+ static VALUE
30
+ jw_s_version(VALUE mod) {
31
+ return rb_usascii_str_new_cstr(jsonnet_version());
32
+ }
33
+
34
+ static VALUE
35
+ vm_s_new(VALUE mod) {
36
+ struct JsonnetVm *const vm = jsonnet_make();
37
+ return TypedData_Wrap_Struct(cVM, &jsonnet_vm_type, vm);
38
+ }
39
+
40
+ static void
41
+ vm_free(void *ptr) {
42
+ jsonnet_destroy((struct JsonnetVm*)ptr);
43
+ }
44
+
45
+ static VALUE
46
+ vm_evaluate_file(VALUE self, VALUE fname) {
47
+ struct JsonnetVm *vm;
48
+ int error;
49
+ char* result;
50
+
51
+ TypedData_Get_Struct(self, struct JsonnetVm, &jsonnet_vm_type, vm);
52
+ FilePathValue(fname);
53
+ result = jsonnet_evaluate_file(vm, StringValueCStr(fname), &error);
54
+ if (error) {
55
+ rb_raise(eEvaluationError, "%s", result);
56
+ }
57
+ return rb_utf8_str_new_cstr(result);
58
+ }
59
+
60
+ static VALUE
61
+ vm_evaluate(int argc, VALUE *argv, VALUE self) {
62
+ struct JsonnetVm *vm;
63
+ int error;
64
+ char* result;
65
+ VALUE snippet, fname = Qnil;
66
+
67
+ rb_scan_args(argc, argv, "11", &snippet, &fname);
68
+
69
+ TypedData_Get_Struct(self, struct JsonnetVm, &jsonnet_vm_type, vm);
70
+ result = jsonnet_evaluate_snippet(
71
+ vm,
72
+ fname == Qnil ? "(jsonnet)" : (FilePathValue(fname), StringValueCStr(fname)),
73
+ StringValueCStr(snippet),
74
+ &error);
75
+ if (error) {
76
+ rb_raise(eEvaluationError, "%s", result);
77
+ }
78
+ return rb_utf8_str_new_cstr(result);
79
+ }
80
+
81
+ void
82
+ Init_jsonnet_wrap(void) {
83
+ VALUE mJsonnet = rb_define_module("Jsonnet");
84
+ rb_define_singleton_method(mJsonnet, "libversion", jw_s_version, 0);
85
+
86
+ cVM = rb_define_class_under(mJsonnet, "VM", rb_cData);
87
+ rb_define_singleton_method(cVM, "new", vm_s_new, 0);
88
+ rb_define_method(cVM, "evaluate_file", vm_evaluate_file, 1);
89
+ rb_define_method(cVM, "evaluate", vm_evaluate, -1);
90
+
91
+ eEvaluationError = rb_define_class_under(mJsonnet, "EvaluationError", rb_eRuntimeError);
92
+ }
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jsonnet/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jsonnet"
8
+ spec.version = Jsonnet::VERSION
9
+ spec.authors = ["Yuki Yugui Sonoda"]
10
+ spec.email = ["yugui@yugui.jp"]
11
+ spec.summary = %q{Jsonnet library}
12
+ spec.description = %q{Wraps the official C++ implementation of Jsonnet}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.extensions = ['ext/jsonnet/extconf.rb']
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "test-unit", "~> 3.1.3"
25
+ spec.add_development_dependency "rake-compiler", "~> 0.9.5"
26
+ end
@@ -0,0 +1,6 @@
1
+ require "jsonnet/version"
2
+ require "jsonnet/jsonnet_wrap"
3
+
4
+ module Jsonnet
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,3 @@
1
+ module Jsonnet
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ {
2
+ // unbound variable
3
+ ["foo" + myvar]: myvar,
4
+ }
5
+
@@ -0,0 +1,4 @@
1
+ local myvar = 1;
2
+ {
3
+ ["foo" + myvar]: myvar,
4
+ }
@@ -0,0 +1,8 @@
1
+ require 'jsonnet'
2
+ require 'test/unit'
3
+
4
+ class TestJsonnet < Test::Unit::TestCase
5
+ test 'libversion returns a String' do
6
+ assert_kind_of String, Jsonnet.libversion
7
+ end
8
+ end
@@ -0,0 +1,68 @@
1
+ require 'jsonnet'
2
+
3
+ require 'json'
4
+ require 'test/unit'
5
+
6
+ class TestVM < Test::Unit::TestCase
7
+ test 'Jsonnet::VM#evaluate_file evaluates file' do
8
+ vm = Jsonnet::VM.new
9
+ result = vm.evaluate_file example_file('example.jsonnet')
10
+
11
+ assert_equal JSON.parse(<<-EOS), JSON.parse(result)
12
+ {"foo1": 1}
13
+ EOS
14
+ end
15
+
16
+ test 'Jsonnet::VM#evaluate_file raises an EvaluationError on error' do
17
+ vm = Jsonnet::VM.new
18
+ assert_raise(Jsonnet::EvaluationError) do
19
+ vm.evaluate_file example_file('error.jsonnet')
20
+ end
21
+ end
22
+
23
+ test 'Jsonnet::VM#evaluate evaluates snippet' do
24
+ vm = Jsonnet::VM.new
25
+ result = vm.evaluate(<<-EOS, 'example.snippet')
26
+ local myvar = 1;
27
+ {
28
+ ["foo" + myvar]: myvar,
29
+ }
30
+ EOS
31
+
32
+ assert_equal JSON.parse(<<-EOS), JSON.parse(result)
33
+ {"foo1": 1}
34
+ EOS
35
+ end
36
+
37
+ test 'Jsonnet::VM#evaluate can be called without filename' do
38
+ vm = Jsonnet::VM.new
39
+ result = vm.evaluate(<<-EOS)
40
+ local myvar = 1;
41
+ {
42
+ ["foo" + myvar]: myvar,
43
+ }
44
+ EOS
45
+
46
+ assert_equal JSON.parse(<<-EOS), JSON.parse(result)
47
+ {"foo1": 1}
48
+ EOS
49
+ end
50
+
51
+ test 'Jsonnet::VM#evaluate raises an EvaluationError on error' do
52
+ vm = Jsonnet::VM.new
53
+ assert_raise(Jsonnet::EvaluationError) do
54
+ vm.evaluate(<<-EOS, 'example.snippet')
55
+ {
56
+ // unbound variable
57
+ ["foo" + myvar]: myvar,
58
+ }
59
+ EOS
60
+ end
61
+ end
62
+
63
+ private
64
+ def example_file(name)
65
+ File.join(File.dirname(__FILE__), name)
66
+ end
67
+ end
68
+
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jsonnet
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yuki Yugui Sonoda
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.1.3
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.1.3
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake-compiler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.5
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.9.5
69
+ description: Wraps the official C++ implementation of Jsonnet
70
+ email:
71
+ - yugui@yugui.jp
72
+ executables: []
73
+ extensions:
74
+ - ext/jsonnet/extconf.rb
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - ext/jsonnet/.gitignore
83
+ - ext/jsonnet/extconf.rb
84
+ - ext/jsonnet/jsonnet.c
85
+ - jsonnet.gemspec
86
+ - lib/jsonnet.rb
87
+ - lib/jsonnet/version.rb
88
+ - test/error.jsonnet
89
+ - test/example.jsonnet
90
+ - test/test_jsonnet.rb
91
+ - test/test_vm.rb
92
+ homepage: ''
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.4.5
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Jsonnet library
116
+ test_files:
117
+ - test/error.jsonnet
118
+ - test/example.jsonnet
119
+ - test/test_jsonnet.rb
120
+ - test/test_vm.rb