rabl-fast-json => rabl-rails

This commit is contained in:
ccocchi 2012-04-20 16:28:34 +02:00
parent f9e2f0766b
commit c12e14700f
23 changed files with 53 additions and 53 deletions

View File

@ -1,6 +1,6 @@
source "http://rubygems.org"
# Declare your gem's dependencies in rabl-fast-json.gemspec.
# Declare your gem's dependencies in rabl-rails.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec

View File

@ -1,7 +1,7 @@
PATH
remote: .
specs:
rabl-fast-json (0.1.0)
rabl-rails (0.1.0)
activesupport (~> 3.2.1)
GEM
@ -61,7 +61,7 @@ PLATFORMS
DEPENDENCIES
actionpack (~> 3.2.1)
rabl-fast-json!
rabl-rails!
railties (~> 3.2.1)
rspec-mocks
sqlite3

View File

@ -1,3 +1,3 @@
= RablFastJson
= RablRails
This project rocks and uses MIT-LICENSE.

2
Rakefile Normal file → Executable file
View File

@ -14,7 +14,7 @@
#
# RDoc::Task.new(:rdoc) do |rdoc|
# rdoc.rdoc_dir = 'rdoc'
# rdoc.title = 'RablFastJson'
# rdoc.title = 'RablRails'
# rdoc.options << '--line-numbers'
# rdoc.rdoc_files.include('README.rdoc')
# rdoc.rdoc_files.include('lib/**/*.rb')

View File

@ -1,2 +0,0 @@
require 'rabl-fast-json/renderers/base'
require 'rabl-fast-json/renderers/json'

View File

@ -4,19 +4,19 @@ require 'active_support'
require 'active_support/json'
require 'active_support/core_ext/class/attribute_accessors'
require 'rabl-fast-json/version'
require 'rabl-fast-json/template'
require 'rabl-fast-json/compiler'
require 'rabl-rails/version'
require 'rabl-rails/template'
require 'rabl-rails/compiler'
require 'rabl-fast-json/renderer'
require 'rabl-rails/renderer'
require 'rabl-fast-json/library'
require 'rabl-fast-json/handler'
require 'rabl-fast-json/railtie'
require 'rabl-rails/library'
require 'rabl-rails/handler'
require 'rabl-rails/railtie'
module RablFastJson
module RablRails
extend self
mattr_accessor :cache_templates

View File

@ -1,4 +1,4 @@
module RablFastJson
module RablRails
#
# Class that will compile RABL source code into a hash
# representing data structure

View File

@ -1,4 +1,4 @@
module RablFastJson
module RablRails
module Handlers
class Rabl
cattr_accessor :default_format
@ -6,7 +6,7 @@ module RablFastJson
def self.call(template)
%{
RablFastJson::Library.instance.
RablRails::Library.instance.
get_rendered_template(#{template.source.inspect}, self)
}
end

View File

@ -1,6 +1,6 @@
require 'singleton'
module RablFastJson
module RablRails
class Library
include Singleton
@ -19,7 +19,7 @@ module RablFastJson
end
def get_compiled_template(path, source)
if path && RablFastJson.cache_templates?
if path && RablRails.cache_templates?
@cached_templates[path] ||= Compiler.new.compile_source(source)
@cached_templates[path].dup
else

View File

@ -1,8 +1,8 @@
module RablFastJson
module RablRails
class Railtie < Rails::Railtie
initializer "rabl.initialize" do |app|
ActiveSupport.on_load(:action_view) do
ActionView::Template.register_template_handler :rabl, RablFastJson::Handlers::Rabl
ActionView::Template.register_template_handler :rabl, RablRails::Handlers::Rabl
end
end
end

View File

@ -0,0 +1,2 @@
require 'rabl-rails/renderers/base'
require 'rabl-rails/renderers/json'

View File

@ -1,4 +1,4 @@
module RablFastJson
module RablRails
module Renderers
class PartialError < StandardError; end

View File

@ -1,4 +1,4 @@
module RablFastJson
module RablRails
module Renderers
class JSON < Base
def format_output(hash)

View File

@ -1,4 +1,4 @@
module RablFastJson
module RablRails
class CompiledTemplate
attr_accessor :source, :data, :root_name

View File

@ -1,3 +1,3 @@
module RablFastJson
module RablRails
VERSION = '0.1.0'
end

View File

@ -1,4 +1,4 @@
# desc "Explaining what the task does"
# task :rabl-fast-json do
# task :rabl-rails do
# # Task goes here
# end

View File

@ -1,17 +1,17 @@
$:.push File.expand_path("../lib", __FILE__)
# Maintain your gem's version:
require "rabl-fast-json/version"
require "rabl-rails/version"
# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "rabl-fast-json"
s.version = RablFastJson::VERSION
s.name = "rabl-rails"
s.version = RablRails::VERSION
s.authors = ["TODO: Your name"]
s.email = ["TODO: Your email"]
s.homepage = "TODO"
s.summary = "TODO: Summary of RablFastJson."
s.description = "TODO: Description of RablFastJson."
s.summary = "TODO: Summary of RablRails."
s.description = "TODO: Description of RablRails."
s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.md"]
s.test_files = Dir["test/**/*"]

View File

@ -3,9 +3,9 @@ require 'test_helper'
class CacheTemplatesTest < ActiveSupport::TestCase
setup do
RablFastJson::Library.reset_instance
@library = RablFastJson::Library.instance
RablFastJson.cache_templates = true
RablRails::Library.reset_instance
@library = RablRails::Library.instance
RablRails.cache_templates = true
end
test "cache templates if perform_caching is active and cache_templates is enabled" do

View File

@ -4,11 +4,11 @@ class CompilerTest < ActiveSupport::TestCase
setup do
@user = User.new
@compiler = RablFastJson::Compiler.new
@compiler = RablRails::Compiler.new
end
test "compiler return a compiled template" do
assert_instance_of RablFastJson::CompiledTemplate, @compiler.compile_source("")
assert_instance_of RablRails::CompiledTemplate, @compiler.compile_source("")
end
test "object set data for the template" do
@ -91,10 +91,10 @@ class CompilerTest < ActiveSupport::TestCase
end
test "child with succint partial notation" do
mock_template = RablFastJson::CompiledTemplate.new
mock_template = RablRails::CompiledTemplate.new
mock_template.source = { :id => :id }
RablFastJson::Library.reset_instance
RablFastJson::Library.instance.stub(:get).with('users/base').and_return(mock_template)
RablRails::Library.reset_instance
RablRails::Library.instance.stub(:get).with('users/base').and_return(mock_template)
t = @compiler.compile_source(%{child(:user, :partial => 'users/base') })
assert_equal( {:user => { :_data => :user, :id => :id } }, t.source)
@ -119,8 +119,8 @@ class CompilerTest < ActiveSupport::TestCase
test "extends use other template source as itself" do
template = mock('template', :source => { :id => :id })
RablFastJson::Library.reset_instance
RablFastJson::Library.instance.stub(:get).with('users/base').and_return(template)
RablRails::Library.reset_instance
RablRails::Library.instance.stub(:get).with('users/base').and_return(template)
t = @compiler.compile_source(%{ extends 'users/base' })
assert_equal({ :id => :id }, t.source)
end

View File

@ -15,7 +15,7 @@ class DeepNestingTest < ActiveSupport::TestCase
end
setup do
RablFastJson::Library.reset_instance
RablRails::Library.reset_instance
@post = Post.new(42, 'I rock !')
@user = User.new(1, 'foobar', 'male')
@user.stub(:posts).and_return([@post])
@ -50,7 +50,7 @@ class DeepNestingTest < ActiveSupport::TestCase
{ :content => 'second' }
]
}]
}), RablFastJson::Library.instance.get_rendered_template(source, @context))
}), RablRails::Library.instance.get_rendered_template(source, @context))
end
end

View File

@ -2,7 +2,7 @@ require 'test_helper'
class NonRestfulResponseTest < ActiveSupport::TestCase
setup do
RablFastJson::Library.reset_instance
RablRails::Library.reset_instance
@user = User.new(1, 'foo', 'male')
@user.stub_chain(:posts, :count).and_return(10)
@ -30,6 +30,6 @@ class NonRestfulResponseTest < ActiveSupport::TestCase
:id => 1,
:name => 'foo'
}
}), RablFastJson::Library.instance.get_rendered_template(source, @context))
}), RablRails::Library.instance.get_rendered_template(source, @context))
end
end

View File

@ -10,12 +10,12 @@ class TestJsonRenderer < ActiveSupport::TestCase
@context.stub(:instance_variable_get).with(:@data).and_return(@data)
@context.stub(:instance_variable_get).with(:@_assigns).and_return({})
@template = RablFastJson::CompiledTemplate.new
@template = RablRails::CompiledTemplate.new
@template.data = :@data
end
def render_json_output
RablFastJson::Renderers::JSON.new(@context).render(@template).to_s
RablRails::Renderers::JSON.new(@context).render(@template).to_s
end
test "render object wth empty template" do
@ -83,10 +83,10 @@ class TestJsonRenderer < ActiveSupport::TestCase
@data.stub(:respond_to?).with(:empty?).and_return(false)
# Stub Library#get
t = RablFastJson::CompiledTemplate.new
t = RablRails::CompiledTemplate.new
t.source = { :name => :name }
RablFastJson::Library.reset_instance
RablFastJson::Library.instance.should_receive(:get).with('users/base').and_return(t)
RablRails::Library.reset_instance
RablRails::Library.instance.should_receive(:get).with('users/base').and_return(t)
@template.data = false
@template.source = { :user => ->(s) { partial('users/base', :object => @user) } }
@ -98,7 +98,7 @@ class TestJsonRenderer < ActiveSupport::TestCase
@template.data = false
@template.source = { :user => ->(s) { partial('users/base') } }
assert_raises(RablFastJson::Renderers::PartialError) { render_json_output }
assert_raises(RablRails::Renderers::PartialError) { render_json_output }
end
test "partial with empty values should not raise an error" do

View File

@ -21,7 +21,7 @@ class <<Singleton
alias_method_chain :included, :reset
end
require 'rabl-fast-json'
require 'rabl-rails'
module ActiveSupport
class TestCase