jason 0.3.0 → 0.3.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.
@@ -1,4 +1,4 @@
1
- script: 'rake test'
1
+ script: 'bundle exec rake test'
2
2
  rvm:
3
3
  - 1.8.7
4
4
  - 1.9.2
data/Rakefile CHANGED
@@ -15,6 +15,6 @@ end
15
15
  task 'test:rails' do
16
16
  sh <<-CMD
17
17
  cd test/rails
18
- rake
18
+ bundle exec rake
19
19
  CMD
20
20
  end
@@ -32,6 +32,13 @@ module Jason
32
32
  "#{eruby_template(template).src}; Jason.process(_buf)"
33
33
  end
34
34
 
35
+ # Process a rendered buffer.
36
+ #
37
+ # Removes any trailing commas and compresses the buffer.
38
+ #
39
+ # Usually, you should not have to call this method.
40
+ #
41
+ # @param [String] buffer
35
42
  def self.process(buffer)
36
43
  JSON.load(remove_trailing_commas(buffer)).to_json
37
44
  end
@@ -42,7 +49,11 @@ module Jason
42
49
  JSONEruby.new(template)
43
50
  end
44
51
 
52
+ # Based upon the string scanner found in jnunemaker's crack.
53
+ #
54
+ # @see https://github.com/jnunemaker/crack crack
45
55
  def self.remove_trailing_commas(json)
56
+ json = json.dup
46
57
  comma_position = nil
47
58
  quoting = nil
48
59
  scanner = StringScanner.new(json)
@@ -56,7 +67,7 @@ module Jason
56
67
  quoting = nil
57
68
  end
58
69
  when ']', '}'
59
- if comma_position && json[comma_position + 1...scanner.pos - 1] =~ /^\s*$/
70
+ if comma_position && json[comma_position + 1...scanner.pos - 1] =~ /\A\s*\z/
60
71
  json[comma_position] = ''
61
72
  scanner.pos -= 1
62
73
  comma_position = nil
@@ -1,3 +1,3 @@
1
1
  module Jason
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
@@ -1,5 +1,6 @@
1
1
  ENV['RAILS_ENV'] = 'test'
2
2
  require File.expand_path('../../config/environment', __FILE__)
3
+ require 'journo'
3
4
  require 'rails/test_help'
4
5
 
5
6
  MiniTest::Unit.runner = Journo::SuiteRunner.new
@@ -3,18 +3,46 @@ require 'test_helper'
3
3
  class TestJason < MiniTest::Unit::TestCase
4
4
  test '.render without binding' do
5
5
  template = <<-EOF
6
- {
7
- "foo": "bar",
8
- "baz": [
9
- <% if true %>
10
- "quz",
11
- <% end %>
12
- "quuz",
6
+ {
7
+ "message": "OK",
8
+ "user": {
9
+ "id": <%= 'test' %>,
10
+ "name": <%= 'blah' %>,
11
+ <% if true %>
12
+ "link": [
13
+ <% if true %>
14
+ {
15
+ "rel": "self",
16
+ "href": <%= 'hablaba' %>
17
+ },
18
+ <% end %>
19
+ {
20
+ "rel": "checkins",
21
+ "href": <%= 'hablaba' %>
22
+ }
23
+ ]
24
+ <% end %>
25
+ }
26
+ }
27
+ EOF
28
+
29
+ assert_equal({
30
+ 'message' => 'OK',
31
+ 'user' => {
32
+ 'id' => 'test',
33
+ 'name' => 'blah',
34
+ 'link' => [
35
+ {
36
+ 'rel' => 'self',
37
+ 'href' => 'hablaba'
38
+ },
39
+ {
40
+ 'rel' => 'checkins',
41
+ 'href' => 'hablaba'
42
+ }
13
43
  ]
14
44
  }
15
- EOF
16
-
17
- assert_equal({ 'foo' => 'bar', 'baz' => ['quz', 'quuz'] }, JSON.load(Jason.render(template)))
45
+ }, JSON.load(Jason.render(template)))
18
46
  end
19
47
 
20
48
  test '.render with binding' do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: jason
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.0
5
+ version: 0.3.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Alexander Kern
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-31 00:00:00 -07:00
13
+ date: 2011-06-01 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency