tilt-jbuilder 0.1.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 ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rvmrc ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use 1.9.3" > .rvmrc
9
+ environment_id="ruby-1.9.3-p194@tilt-jbuilder"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.14.1 (stable)" # 1.10.1 seams as a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+
18
+ # First we attempt to load the desired environment directly from the environment
19
+ # file. This is very fast and efficient compared to running through the entire
20
+ # CLI and selector. If you want feedback on which environment was used then
21
+ # insert the word 'use' after --create as this triggers verbose mode.
22
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
+ then
25
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
+ [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
27
+ \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
28
+ else
29
+ # If the environment file has not yet been created, use the RVM CLI to select.
30
+ rvm --create "$environment_id" || {
31
+ echo "Failed to create RVM environment '${environment_id}'."
32
+ return 1
33
+ }
34
+ fi
35
+
36
+ # If you use bundler, this might be useful to you:
37
+ # if [[ -s Gemfile ]] && {
38
+ # ! builtin command -v bundle >/dev/null ||
39
+ # builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
40
+ # }
41
+ # then
42
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
43
+ # gem install bundler
44
+ # fi
45
+ # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
46
+ # then
47
+ # bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
48
+ # fi
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tilt-jbuilder.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Anthony Smith
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.rdoc ADDED
@@ -0,0 +1,48 @@
1
+ = tilt-jbuilder
2
+
3
+ Adds support for rendering Jbuilder templates using Tilt.
4
+
5
+ == Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'tilt-jbuilder'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install tilt-jbuilder
18
+
19
+ == Usage
20
+
21
+ require 'tilt/jbuilder.rb'
22
+
23
+ template = Tilt::JbuilderTemplate.new("templates/awesomeness.json.jbuilder")
24
+ teplate.render
25
+
26
+ # With locals
27
+ template = Tilt::JbuilderTemplate.new { "json.author name" }
28
+ template.render(nil, :name => 'Anthony')
29
+
30
+ # With scope
31
+ template = Tilt::JbuilderTemplate.new { "json.author @name" }
32
+ scope = Object.new
33
+ scope.instance_variable_set :@name, 'Anthony'
34
+ template.render(scope)
35
+
36
+ # Block style
37
+ template = Tilt::JbuilderTemplate.new do |t|
38
+ lambda { |json| json.author 'Anthony'; json.target! }
39
+ end
40
+ template.render
41
+
42
+ == Contributing
43
+
44
+ 1. Fork it
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new :spec
6
+
7
+ task :default => :spec
@@ -0,0 +1,43 @@
1
+ require 'tilt/template'
2
+ require 'jbuilder'
3
+
4
+ module Tilt
5
+ class JbuilderTemplate < Template
6
+ self.default_mime_type = 'application/json'
7
+
8
+ def self.engine_initialized?
9
+ defined? ::Jbuilder
10
+ end
11
+
12
+ def initialize_engine
13
+ require_template_library 'jbuilder'
14
+ end
15
+
16
+ def prepare; end
17
+
18
+ def evaluate(scope, locals, &block)
19
+ scope ||= Object.new
20
+ context = scope.instance_eval { binding }
21
+ set_locals(locals, scope, context)
22
+ eval %{
23
+ Jbuilder.encode do |json|
24
+ if @_tilt_data.kind_of? Proc
25
+ return @_tilt_data.call(Jbuilder.new)
26
+ else
27
+ eval @_tilt_data, binding
28
+ end
29
+ end
30
+ }, context
31
+ end
32
+
33
+ private
34
+ def set_locals(locals, scope, context)
35
+ scope.send(:instance_variable_set, '@_jbuilder_locals', locals)
36
+ scope.send(:instance_variable_set, '@_tilt_data', data)
37
+ set_locals = locals.keys.map { |k| "#{k} = @_jbuilder_locals[#{k.inspect}]" }.join("\n")
38
+ eval set_locals, context
39
+ end
40
+ end
41
+
42
+ register Tilt::JbuilderTemplate, 'jbuilder'
43
+ end
@@ -0,0 +1,5 @@
1
+ module Tilt
2
+ module JbuilderTemplate
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,37 @@
1
+ require 'tilt'
2
+ require 'tilt/jbuilder'
3
+
4
+ describe Tilt::JbuilderTemplate do
5
+ it "should be registered for '.jbuilder' files" do
6
+ Tilt::JbuilderTemplate.should == Tilt['test.jbuilder']
7
+ end
8
+
9
+ it "should evaluate the template on #render" do
10
+ template = Tilt::JbuilderTemplate.new { "json.author 'Anthony'" }
11
+ "{\"author\":\"Anthony\"}".should == template.render
12
+ end
13
+
14
+ it "can be rendered more than once" do
15
+ template = Tilt::JbuilderTemplate.new { "json.author 'Anthony'" }
16
+ 3.times { "{\"author\":\"Anthony\"}".should == template.render }
17
+ end
18
+
19
+ it "should pass locals" do
20
+ template = Tilt::JbuilderTemplate.new { "json.author name" }
21
+ "{\"author\":\"Anthony\"}".should == template.render(Object.new, :name => 'Anthony')
22
+ end
23
+
24
+ it "should evaluate in an object scope" do
25
+ template = Tilt::JbuilderTemplate.new { "json.author @name" }
26
+ scope = Object.new
27
+ scope.instance_variable_set :@name, 'Anthony'
28
+ "{\"author\":\"Anthony\"}".should == template.render(scope)
29
+ end
30
+
31
+ it "should evaluate block style templates" do
32
+ template = Tilt::JbuilderTemplate.new do |t|
33
+ lambda { |json| json.author "Anthony"; json.target! }
34
+ end
35
+ "{\"author\":\"Anthony\"}".should == template.render
36
+ end
37
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/tilt/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Anthony Smith"]
6
+ gem.email = ["anthony@sticksnleaves.com"]
7
+ gem.description = %q{Jbuilder support for Tilt}
8
+ gem.summary = %q{Adds support for rendering Jbuilder templates in Tilt.}
9
+ gem.homepage = "https://github.com/anthonator/tilt-jbuilder"
10
+
11
+ gem.add_dependency 'tilt'
12
+ gem.add_dependency 'jbuilder'
13
+ gem.add_development_dependency 'rspec'
14
+
15
+ gem.files = `git ls-files`.split($\)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.name = "tilt-jbuilder"
19
+ gem.require_paths = ["lib"]
20
+ gem.version = Tilt::JbuilderTemplate::VERSION
21
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tilt-jbuilder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Anthony Smith
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: tilt
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: jbuilder
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
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
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Jbuilder support for Tilt
63
+ email:
64
+ - anthony@sticksnleaves.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - .rvmrc
71
+ - Gemfile
72
+ - LICENSE
73
+ - README.rdoc
74
+ - Rakefile
75
+ - lib/tilt/jbuilder.rb
76
+ - lib/tilt/version.rb
77
+ - spec/tilt-jbuilder_spec.rb
78
+ - tilt-jbuilder.gemspec
79
+ homepage: https://github.com/anthonator/tilt-jbuilder
80
+ licenses: []
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 1.8.24
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: Adds support for rendering Jbuilder templates in Tilt.
103
+ test_files:
104
+ - spec/tilt-jbuilder_spec.rb