jason 0.1.0 → 0.2.0

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 CHANGED
@@ -16,4 +16,7 @@ InstalledFiles
16
16
  # YARD artifacts
17
17
  .yardoc
18
18
  _yardoc
19
- doc/
19
+ doc/
20
+
21
+ # Gem-specific
22
+ Gemfile.lock
data/.yardopts ADDED
@@ -0,0 +1,6 @@
1
+ --readme README.md
2
+ --markup markdown
3
+ --markup-provider maruku
4
+ --default-return ""
5
+ --title "Jason Documentation"
6
+ --hide-void-return
data/README.md CHANGED
@@ -6,24 +6,28 @@ There's no easy way to create JSON templates in Ruby.
6
6
 
7
7
  ## Solution ##
8
8
 
9
- Use YAML and ERb to make the simplest thing that could possibly work.
9
+ Use YAML and Ember to make the simplest thing that could possibly work.
10
10
 
11
11
  ## Installation ##
12
12
 
13
- Without bundler:
14
-
15
13
  gem install jason
16
14
 
17
- With bundler:
18
-
19
- gem 'jason'
20
-
21
15
  ## Usage ##
22
16
 
23
- You write jason templates in plain YAML and ERb. Jason will take care of the
24
- (ultra-simple) conversion to JSON.
17
+ You write jason templates in plain YAML and Ember. Jason will take care of the
18
+ (ultra-simple) conversion to JSON. You can use the Ember shorthand syntax, leave
19
+ off the `end` of blocks, and use natural indentation, since Ember will
20
+ automatically unindent blocks for you.
25
21
 
26
- Jason.render("foo: bar") # => '{"foo": "bar"}'
22
+ Jason.render('foo: bar') # => '{"foo":"bar"}'
23
+
24
+ Jason.render(<<-EOS
25
+ test:
26
+ % if true
27
+ - foo
28
+ - bar
29
+ EOS
30
+ ) # => '{"test":["foo","bar"]}'
27
31
 
28
32
  That's it.
29
33
 
@@ -34,12 +38,11 @@ Name your view template with the extension `jason`. Everything else is the same.
34
38
  # in view_name.jason
35
39
  foo: bar
36
40
  baz:
37
- <% unless @we_started_the_fire %>
41
+ % unless @we_started_the_fire
38
42
  - quz
39
43
  - quuz
40
- <% end %>
41
44
 
42
- # Renders: {"foo": "bar", "baz": ["quz", "quuz"]}
45
+ # Renders: {"foo":"bar","baz":["quz","quuz"]}
43
46
 
44
47
  ## Note on Patches/Pull Requests ##
45
48
 
data/jason.gemspec CHANGED
@@ -10,20 +10,23 @@ Gem::Specification.new do |s|
10
10
  s.email = ['alex@kernul.com']
11
11
  s.homepage = 'https://github.com/CapnKernul/jason'
12
12
  s.summary = %q{Insanely simple JSON templates}
13
- s.description = %q{Create JSON templates using YAML and ERb}
14
-
13
+ s.description = %q{Create JSON templates using YAML and Ember}
14
+
15
15
  s.rubyforge_project = 'jason'
16
-
16
+
17
17
  s.files = `git ls-files`.split("\n")
18
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ['lib']
21
21
 
22
+ s.add_dependency 'ember'
23
+
22
24
  s.add_development_dependency 'minitest', '~> 2.0'
23
- s.add_development_dependency 'mocha', '~> 0.9'
24
- s.add_development_dependency 'autotest', '~> 4.4'
25
- s.add_development_dependency 'rails', '3.0.5'
26
- s.add_development_dependency 'json', '~> 1.5'
27
- s.add_development_dependency 'yard', '~> 0.6'
28
- s.add_development_dependency 'maruku', '~> 0.6'
25
+ s.add_development_dependency 'mocha'
26
+ s.add_development_dependency 'rails', '3.0.7'
27
+ s.add_development_dependency 'json'
28
+ s.add_development_dependency 'yard'
29
+ s.add_development_dependency 'maruku'
30
+ s.add_development_dependency 'journo'
31
+ s.add_development_dependency 'test_declarative'
29
32
  end
data/lib/jason.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'erb'
1
+ require 'ember'
2
2
  require 'json'
3
3
  require 'yaml'
4
4
 
@@ -9,11 +9,16 @@ module Jason
9
9
  # @example
10
10
  # Jason.render('foo: bar') # => '{"foo": "bar"}'
11
11
  #
12
- # @param template [String] the template to render
13
- # @param binding [Binding] the binding to render the template in
12
+ # @param [String] template the template to render
13
+ # @param [Binding] binding the binding to render the template in
14
14
  # @return [String] the rendered template
15
15
  def self.render(template, binding = nil)
16
- yaml = ERB.new(template).result(binding)
16
+ if binding
17
+ yaml = ember_template(template).render(binding)
18
+ else
19
+ yaml = ember_template(template).render
20
+ end
21
+
17
22
  YAML::load(yaml).to_json
18
23
  end
19
24
 
@@ -21,10 +26,19 @@ module Jason
21
26
  #
22
27
  # Eval the returned value to render the template within the current binding.
23
28
  #
24
- # @param template [String] the template to compile
29
+ # @param [String] template the template to compile
25
30
  # @return [String] the compiled template
26
31
  def self.compile(template)
27
- "#{ERB.new(template).src}; YAML::load(_erbout).to_json"
32
+ "YAML::load(#{ember_template(template).program}).to_json"
33
+ end
34
+
35
+ private
36
+
37
+ def self.ember_template(template)
38
+ Ember::Template.new(template,
39
+ :unindent => true,
40
+ :infer_end => true,:shorthand => true
41
+ )
28
42
  end
29
43
  end
30
44
 
@@ -10,7 +10,7 @@ module Jason
10
10
 
11
11
  # Compile the Rails template.
12
12
  #
13
- # @param template [Class] the Rails template class
13
+ # @param [Class] template the Rails template class
14
14
  # @return [String] the compiled template
15
15
  def call(template)
16
16
  Jason.compile(template.source)
data/lib/jason/version.rb CHANGED
@@ -1,4 +1,3 @@
1
1
  module Jason
2
- # Jason version number
3
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
4
3
  end
data/test/rails/Gemfile CHANGED
@@ -1,11 +1,11 @@
1
- source 'http://rubygems.org'
1
+ source :rubygems
2
2
 
3
- gem 'rails', '3.0.5'
3
+ gem 'rails', '3.0.7'
4
4
  gem 'jason', :path => '../../'
5
5
 
6
6
  group :development, :test do
7
7
  gem 'minitest', '~> 2.0'
8
- gem 'mocha', '~> 0.9'
9
- gem 'autotest', '~> 4.4'
10
- gem 'json', '~> 1.5'
8
+ gem 'mocha'
9
+ gem 'json'
10
+ gem 'journo'
11
11
  end
@@ -2,47 +2,51 @@ PATH
2
2
  remote: ../../
3
3
  specs:
4
4
  jason (0.1.0)
5
+ ember
5
6
 
6
7
  GEM
7
8
  remote: http://rubygems.org/
8
9
  specs:
9
- ZenTest (4.5.0)
10
10
  abstract (1.0.0)
11
- actionmailer (3.0.5)
12
- actionpack (= 3.0.5)
11
+ actionmailer (3.0.7)
12
+ actionpack (= 3.0.7)
13
13
  mail (~> 2.2.15)
14
- actionpack (3.0.5)
15
- activemodel (= 3.0.5)
16
- activesupport (= 3.0.5)
14
+ actionpack (3.0.7)
15
+ activemodel (= 3.0.7)
16
+ activesupport (= 3.0.7)
17
17
  builder (~> 2.1.2)
18
18
  erubis (~> 2.6.6)
19
- i18n (~> 0.4)
19
+ i18n (~> 0.5.0)
20
20
  rack (~> 1.2.1)
21
- rack-mount (~> 0.6.13)
21
+ rack-mount (~> 0.6.14)
22
22
  rack-test (~> 0.5.7)
23
23
  tzinfo (~> 0.3.23)
24
- activemodel (3.0.5)
25
- activesupport (= 3.0.5)
24
+ activemodel (3.0.7)
25
+ activesupport (= 3.0.7)
26
26
  builder (~> 2.1.2)
27
- i18n (~> 0.4)
28
- activerecord (3.0.5)
29
- activemodel (= 3.0.5)
30
- activesupport (= 3.0.5)
27
+ i18n (~> 0.5.0)
28
+ activerecord (3.0.7)
29
+ activemodel (= 3.0.7)
30
+ activesupport (= 3.0.7)
31
31
  arel (~> 2.0.2)
32
32
  tzinfo (~> 0.3.23)
33
- activeresource (3.0.5)
34
- activemodel (= 3.0.5)
35
- activesupport (= 3.0.5)
36
- activesupport (3.0.5)
37
- arel (2.0.9)
38
- autotest (4.4.6)
39
- ZenTest (>= 4.4.1)
33
+ activeresource (3.0.7)
34
+ activemodel (= 3.0.7)
35
+ activesupport (= 3.0.7)
36
+ activesupport (3.0.7)
37
+ ansi (1.2.5)
38
+ arel (2.0.10)
40
39
  builder (2.1.2)
40
+ ember (0.3.1)
41
41
  erubis (2.6.6)
42
42
  abstract (>= 1.0.0)
43
43
  i18n (0.5.0)
44
+ journo (0.2.0)
45
+ ansi
46
+ minitest (~> 2.0)
47
+ ruby-progressbar
44
48
  json (1.5.1)
45
- mail (2.2.15)
49
+ mail (2.2.19)
46
50
  activesupport (>= 2.3.6)
47
51
  i18n (>= 0.4.0)
48
52
  mime-types (~> 1.16)
@@ -51,37 +55,38 @@ GEM
51
55
  minitest (2.1.0)
52
56
  mocha (0.9.12)
53
57
  polyglot (0.3.1)
54
- rack (1.2.2)
55
- rack-mount (0.6.13)
58
+ rack (1.2.3)
59
+ rack-mount (0.6.14)
56
60
  rack (>= 1.0.0)
57
61
  rack-test (0.5.7)
58
62
  rack (>= 1.0)
59
- rails (3.0.5)
60
- actionmailer (= 3.0.5)
61
- actionpack (= 3.0.5)
62
- activerecord (= 3.0.5)
63
- activeresource (= 3.0.5)
64
- activesupport (= 3.0.5)
63
+ rails (3.0.7)
64
+ actionmailer (= 3.0.7)
65
+ actionpack (= 3.0.7)
66
+ activerecord (= 3.0.7)
67
+ activeresource (= 3.0.7)
68
+ activesupport (= 3.0.7)
65
69
  bundler (~> 1.0)
66
- railties (= 3.0.5)
67
- railties (3.0.5)
68
- actionpack (= 3.0.5)
69
- activesupport (= 3.0.5)
70
+ railties (= 3.0.7)
71
+ railties (3.0.7)
72
+ actionpack (= 3.0.7)
73
+ activesupport (= 3.0.7)
70
74
  rake (>= 0.8.7)
71
75
  thor (~> 0.14.4)
72
76
  rake (0.8.7)
77
+ ruby-progressbar (0.0.10)
73
78
  thor (0.14.6)
74
79
  treetop (1.4.9)
75
80
  polyglot (>= 0.3.1)
76
- tzinfo (0.3.25)
81
+ tzinfo (0.3.27)
77
82
 
78
83
  PLATFORMS
79
84
  ruby
80
85
 
81
86
  DEPENDENCIES
82
- autotest (~> 4.4)
83
87
  jason!
84
- json (~> 1.5)
88
+ journo
89
+ json
85
90
  minitest (~> 2.0)
86
- mocha (~> 0.9)
87
- rails (= 3.0.5)
91
+ mocha
92
+ rails (= 3.0.7)
@@ -1,3 +1,6 @@
1
1
  ENV['RAILS_ENV'] = 'test'
2
2
  require File.expand_path('../../config/environment', __FILE__)
3
- require 'rails/test_help'
3
+ require 'rails/test_help'
4
+
5
+ MiniTest::Unit.runner = Journo::SuiteRunner.new
6
+ MiniTest::Unit.runner.reporters << Journo::Reporters::ProgressReporter.new
data/test/test_helper.rb CHANGED
@@ -1,7 +1,11 @@
1
1
  require 'bundler/setup'
2
2
  require 'minitest/autorun'
3
- require 'minitest/pride'
4
3
  require 'mocha'
5
4
  require 'jason'
5
+ require 'journo'
6
+ require 'test_declarative'
6
7
 
7
- Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each { |f| require f }
8
+ Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each { |f| require f }
9
+
10
+ MiniTest::Unit.runner = Journo::SuiteRunner.new
11
+ MiniTest::Unit.runner.reporters << Journo::Reporters::ProgressReporter.new
data/test/test_jason.rb CHANGED
@@ -1,32 +1,41 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class TestJason < MiniTest::Unit::TestCase
4
- def test_render_without_binding
4
+ test '#render without binding' do
5
5
  template = <<-EOF
6
6
  foo: bar
7
7
  baz:
8
- - quz
8
+ % if true
9
+ - quz
9
10
  - quuz
10
11
  EOF
11
12
 
12
- assert_equal({'foo' => 'bar', 'baz' => ['quz', 'quuz']}, JSON.parse(Jason.render(template)))
13
+ assert_equal({'foo' => 'bar', 'baz' => ['quz', 'quuz']}, JSON.load(Jason.render(template)))
13
14
  end
14
15
 
15
- def test_render_with_binding
16
+ test '#render with binding' do
16
17
  test_string = 'bar'
17
18
  template = <<-EOF
18
19
  foo: <%= test_string %>
19
20
  EOF
20
21
 
21
- assert_equal({'foo' => 'bar' }, JSON.parse(Jason.render(template, binding)))
22
+ assert_equal({'foo' => 'bar' }, JSON.load(Jason.render(template, binding)))
22
23
  end
23
24
 
24
- def test_compile
25
+ test '#compile' do
25
26
  test_string = 'bar'
26
27
  template = <<-EOF
27
28
  foo: <%= test_string %>
28
29
  EOF
29
30
 
30
- assert_equal({'foo' => 'bar' }, JSON.parse(eval(Jason.compile(template))))
31
+ assert_equal({'foo' => 'bar' }, JSON.load(eval(Jason.compile(template))))
31
32
  end
32
- end
33
+ end
34
+
35
+ puts Jason.render(<<-EOS
36
+ test:
37
+ % if true
38
+ - foo
39
+ - bar
40
+ EOS
41
+ )
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: jason
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Alexander Kern
@@ -10,40 +10,40 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-19 00:00:00 -07:00
13
+ date: 2011-05-29 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
- name: minitest
17
+ name: ember
18
18
  prerelease: false
19
19
  requirement: &id001 !ruby/object:Gem::Requirement
20
20
  none: false
21
21
  requirements:
22
- - - ~>
22
+ - - ">="
23
23
  - !ruby/object:Gem::Version
24
- version: "2.0"
25
- type: :development
24
+ version: "0"
25
+ type: :runtime
26
26
  version_requirements: *id001
27
27
  - !ruby/object:Gem::Dependency
28
- name: mocha
28
+ name: minitest
29
29
  prerelease: false
30
30
  requirement: &id002 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
33
  - - ~>
34
34
  - !ruby/object:Gem::Version
35
- version: "0.9"
35
+ version: "2.0"
36
36
  type: :development
37
37
  version_requirements: *id002
38
38
  - !ruby/object:Gem::Dependency
39
- name: autotest
39
+ name: mocha
40
40
  prerelease: false
41
41
  requirement: &id003 !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
- - - ~>
44
+ - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: "4.4"
46
+ version: "0"
47
47
  type: :development
48
48
  version_requirements: *id003
49
49
  - !ruby/object:Gem::Dependency
@@ -54,7 +54,7 @@ dependencies:
54
54
  requirements:
55
55
  - - "="
56
56
  - !ruby/object:Gem::Version
57
- version: 3.0.5
57
+ version: 3.0.7
58
58
  type: :development
59
59
  version_requirements: *id004
60
60
  - !ruby/object:Gem::Dependency
@@ -63,9 +63,9 @@ dependencies:
63
63
  requirement: &id005 !ruby/object:Gem::Requirement
64
64
  none: false
65
65
  requirements:
66
- - - ~>
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: "1.5"
68
+ version: "0"
69
69
  type: :development
70
70
  version_requirements: *id005
71
71
  - !ruby/object:Gem::Dependency
@@ -74,9 +74,9 @@ dependencies:
74
74
  requirement: &id006 !ruby/object:Gem::Requirement
75
75
  none: false
76
76
  requirements:
77
- - - ~>
77
+ - - ">="
78
78
  - !ruby/object:Gem::Version
79
- version: "0.6"
79
+ version: "0"
80
80
  type: :development
81
81
  version_requirements: *id006
82
82
  - !ruby/object:Gem::Dependency
@@ -85,12 +85,34 @@ dependencies:
85
85
  requirement: &id007 !ruby/object:Gem::Requirement
86
86
  none: false
87
87
  requirements:
88
- - - ~>
88
+ - - ">="
89
89
  - !ruby/object:Gem::Version
90
- version: "0.6"
90
+ version: "0"
91
91
  type: :development
92
92
  version_requirements: *id007
93
- description: Create JSON templates using YAML and ERb
93
+ - !ruby/object:Gem::Dependency
94
+ name: journo
95
+ prerelease: false
96
+ requirement: &id008 !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: "0"
102
+ type: :development
103
+ version_requirements: *id008
104
+ - !ruby/object:Gem::Dependency
105
+ name: test_declarative
106
+ prerelease: false
107
+ requirement: &id009 !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: "0"
113
+ type: :development
114
+ version_requirements: *id009
115
+ description: Create JSON templates using YAML and Ember
94
116
  email:
95
117
  - alex@kernul.com
96
118
  executables: []
@@ -100,11 +122,10 @@ extensions: []
100
122
  extra_rdoc_files: []
101
123
 
102
124
  files:
103
- - .autotest
104
125
  - .gitignore
105
126
  - .travis.yml
127
+ - .yardopts
106
128
  - Gemfile
107
- - Gemfile.lock
108
129
  - LICENSE
109
130
  - README.md
110
131
  - Rakefile
@@ -112,7 +133,6 @@ files:
112
133
  - lib/jason.rb
113
134
  - lib/jason/rails_template_handler.rb
114
135
  - lib/jason/version.rb
115
- - test/rails/.autotest
116
136
  - test/rails/.gitignore
117
137
  - test/rails/Gemfile
118
138
  - test/rails/Gemfile.lock
@@ -170,7 +190,6 @@ signing_key:
170
190
  specification_version: 3
171
191
  summary: Insanely simple JSON templates
172
192
  test_files:
173
- - test/rails/.autotest
174
193
  - test/rails/.gitignore
175
194
  - test/rails/Gemfile
176
195
  - test/rails/Gemfile.lock
data/.autotest DELETED
@@ -1,9 +0,0 @@
1
- require 'bundler/setup'
2
-
3
- Autotest.add_hook :initialize do |at|
4
- at.testlib = 'minitest/unit'
5
-
6
- %w{test/rails}.each do |exception|
7
- at.add_exception(exception)
8
- end
9
- end
data/Gemfile.lock DELETED
@@ -1,93 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- jason (0.1.0)
5
-
6
- GEM
7
- remote: http://rubygems.org/
8
- specs:
9
- ZenTest (4.5.0)
10
- abstract (1.0.0)
11
- actionmailer (3.0.5)
12
- actionpack (= 3.0.5)
13
- mail (~> 2.2.15)
14
- actionpack (3.0.5)
15
- activemodel (= 3.0.5)
16
- activesupport (= 3.0.5)
17
- builder (~> 2.1.2)
18
- erubis (~> 2.6.6)
19
- i18n (~> 0.4)
20
- rack (~> 1.2.1)
21
- rack-mount (~> 0.6.13)
22
- rack-test (~> 0.5.7)
23
- tzinfo (~> 0.3.23)
24
- activemodel (3.0.5)
25
- activesupport (= 3.0.5)
26
- builder (~> 2.1.2)
27
- i18n (~> 0.4)
28
- activerecord (3.0.5)
29
- activemodel (= 3.0.5)
30
- activesupport (= 3.0.5)
31
- arel (~> 2.0.2)
32
- tzinfo (~> 0.3.23)
33
- activeresource (3.0.5)
34
- activemodel (= 3.0.5)
35
- activesupport (= 3.0.5)
36
- activesupport (3.0.5)
37
- arel (2.0.9)
38
- autotest (4.4.6)
39
- ZenTest (>= 4.4.1)
40
- builder (2.1.2)
41
- erubis (2.6.6)
42
- abstract (>= 1.0.0)
43
- i18n (0.5.0)
44
- json (1.5.1)
45
- mail (2.2.17)
46
- activesupport (>= 2.3.6)
47
- i18n (>= 0.4.0)
48
- mime-types (~> 1.16)
49
- treetop (~> 1.4.8)
50
- maruku (0.6.0)
51
- syntax (>= 1.0.0)
52
- mime-types (1.16)
53
- minitest (2.1.0)
54
- mocha (0.9.12)
55
- polyglot (0.3.1)
56
- rack (1.2.2)
57
- rack-mount (0.6.14)
58
- rack (>= 1.0.0)
59
- rack-test (0.5.7)
60
- rack (>= 1.0)
61
- rails (3.0.5)
62
- actionmailer (= 3.0.5)
63
- actionpack (= 3.0.5)
64
- activerecord (= 3.0.5)
65
- activeresource (= 3.0.5)
66
- activesupport (= 3.0.5)
67
- bundler (~> 1.0)
68
- railties (= 3.0.5)
69
- railties (3.0.5)
70
- actionpack (= 3.0.5)
71
- activesupport (= 3.0.5)
72
- rake (>= 0.8.7)
73
- thor (~> 0.14.4)
74
- rake (0.8.7)
75
- syntax (1.0.0)
76
- thor (0.14.6)
77
- treetop (1.4.9)
78
- polyglot (>= 0.3.1)
79
- tzinfo (0.3.26)
80
- yard (0.6.8)
81
-
82
- PLATFORMS
83
- ruby
84
-
85
- DEPENDENCIES
86
- autotest (~> 4.4)
87
- jason!
88
- json (~> 1.5)
89
- maruku (~> 0.6)
90
- minitest (~> 2.0)
91
- mocha (~> 0.9)
92
- rails (= 3.0.5)
93
- yard (~> 0.6)
data/test/rails/.autotest DELETED
@@ -1,5 +0,0 @@
1
- require 'bundler/setup'
2
-
3
- Autotest.add_hook :initialize do |at|
4
- at.testlib = 'minitest/unit'
5
- end