rjson 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Jan De Poorter - Sumo Coders BVBA
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,39 @@
1
+ = rjson
2
+
3
+ RJSON is a template handler to create JSON views. RJSON expects views to return Ruby objects, and will then call to_json on it.
4
+
5
+ == Example
6
+ # show.json.rjson
7
+ {
8
+ :id => @item.id,
9
+ :name => @item.name
10
+ }
11
+
12
+ === RJSON Partials
13
+
14
+ RJSON also has special support for RJSON partials, so it shouldn't be a problem to do the following:
15
+
16
+ # items/index.json.rjson
17
+ # We're doing map because we need to return an array of rendered items
18
+ @items.map do |item|
19
+ render item
20
+ end
21
+
22
+ # items/_item.json.rjson
23
+ {
24
+ :id => @item.id,
25
+ :name => @item.name
26
+ }
27
+
28
+ === Regular partials
29
+ Regular erb partials will just render as string, as expected
30
+
31
+ === Installation
32
+ RJSON is a gem, so you can just include it in your Gemfile, and you can start using rjson templates in your app.
33
+
34
+ gem 'rjson'
35
+
36
+ == Copyright
37
+
38
+ Copyright (c) 2011 Jan De Poorter. See LICENSE.txt for
39
+ further details.
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require 'rake'
2
+ require 'jeweler'
3
+
4
+ Jeweler::Tasks.new do |gem|
5
+ gem.name = "rjson"
6
+ gem.homepage = "http://github.com/DefV/rjson"
7
+ gem.license = "MIT"
8
+ gem.summary = %Q{Template Handler for JSON}
9
+ gem.description = %Q{Template Handler for JSON}
10
+ gem.email = "jan@sumocoders.be"
11
+ gem.authors = ["Jan De Poorter"]
12
+ gem.add_runtime_dependency 'actionpack', '~> 3.0.0'
13
+ end
14
+ Jeweler::RubygemsDotOrgTasks.new
15
+
16
+ require 'rake/testtask'
17
+ Rake::TestTask.new(:test) do |test|
18
+ test.libs << 'lib' << 'test'
19
+ test.pattern = 'test/**/test_*.rb'
20
+ test.verbose = true
21
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
data/lib/rjson.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'rjson/handler'
2
+ require 'rjson/railtie' if defined?(Rails)
@@ -0,0 +1,20 @@
1
+ require 'action_view/template'
2
+ require 'rjson/string'
3
+
4
+ module RJSON
5
+ class Handler < ActionView::TemplateHandler
6
+ include ActionView::Template::Handlers::Compilable
7
+
8
+ self.default_format = Mime::JSON
9
+
10
+ def compile(template)
11
+ <<-COMPILED_METHOD
12
+ contents=begin;
13
+ #{template.source}
14
+ end
15
+
16
+ RJSON::String.new(contents.to_json)
17
+ COMPILED_METHOD
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ module RJSON
2
+ class Railtie < Rails::Railtie
3
+ initializer 'rjson.register_template_handler' do
4
+ ActionView::Template.register_template_handler :rjson, RJSON::Handler
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ module RJSON
2
+ class String < ::String
3
+ def encode_json(encoder)
4
+ # Don't encode, we're a JSON string already
5
+ self
6
+ end
7
+ end
8
+ end
data/rjson.gemspec ADDED
@@ -0,0 +1,48 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rjson}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jan De Poorter"]
12
+ s.date = %q{2011-03-01}
13
+ s.description = %q{Template Handler for JSON}
14
+ s.email = %q{jan@sumocoders.be}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ "LICENSE.txt",
21
+ "README.rdoc",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "lib/rjson.rb",
25
+ "lib/rjson/handler.rb",
26
+ "lib/rjson/railtie.rb",
27
+ "lib/rjson/string.rb",
28
+ "rjson.gemspec"
29
+ ]
30
+ s.homepage = %q{http://github.com/DefV/rjson}
31
+ s.licenses = ["MIT"]
32
+ s.require_paths = ["lib"]
33
+ s.rubygems_version = %q{1.5.2}
34
+ s.summary = %q{Template Handler for JSON}
35
+
36
+ if s.respond_to? :specification_version then
37
+ s.specification_version = 3
38
+
39
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
40
+ s.add_runtime_dependency(%q<actionpack>, ["~> 3.0.0"])
41
+ else
42
+ s.add_dependency(%q<actionpack>, ["~> 3.0.0"])
43
+ end
44
+ else
45
+ s.add_dependency(%q<actionpack>, ["~> 3.0.0"])
46
+ end
47
+ end
48
+
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rjson
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - Jan De Poorter
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-01 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: actionpack
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 3
32
+ - 0
33
+ - 0
34
+ version: 3.0.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description: Template Handler for JSON
38
+ email: jan@sumocoders.be
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - LICENSE.txt
45
+ - README.rdoc
46
+ files:
47
+ - LICENSE.txt
48
+ - README.rdoc
49
+ - Rakefile
50
+ - VERSION
51
+ - lib/rjson.rb
52
+ - lib/rjson/handler.rb
53
+ - lib/rjson/railtie.rb
54
+ - lib/rjson/string.rb
55
+ - rjson.gemspec
56
+ has_rdoc: true
57
+ homepage: http://github.com/DefV/rjson
58
+ licenses:
59
+ - MIT
60
+ post_install_message:
61
+ rdoc_options: []
62
+
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ hash: 3
80
+ segments:
81
+ - 0
82
+ version: "0"
83
+ requirements: []
84
+
85
+ rubyforge_project:
86
+ rubygems_version: 1.5.2
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: Template Handler for JSON
90
+ test_files: []
91
+