Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: brentmurphy/rabl
base: b2bd8a0dd3
...
head fork: brentmurphy/rabl
compare: 1d9a630bdc
  • 5 commits
  • 4 files changed
  • 0 commit comments
  • 2 contributors
View
5 CHANGELOG.md
@@ -1,6 +1,8 @@
# CHANGELOG
-## 0.5.0 (Unreleased)
+## 0.5.1 (Unreleased)
+
+## 0.5.0
* Adds comprehensive fixture suite (padrino,rails2,rails3,sinatra)
* Travis CI Integration Testing
@@ -18,6 +20,7 @@
* Better fetch_source implementation for Rails
* Added fetch_source implementation for Sinatra
* Lots of test refactorings / cleanup / improvement
+ * Code block name is now optional [Thanks brentmurphy]
## 0.3.0
View
9 README.md
@@ -264,6 +264,15 @@ code(:foo, :if => lambda { |m| m.has_foo? }) do |m|
end
```
+or don't pass a name and have the code block merged into the response:
+
+```ruby
+code do |u|
+ { :full_name => u.first_name + " " + u.last_name }
+ # => { full_name : "Bob Johnson" }
+end
+```
+
You can use custom "code" nodes to create flexible representations of a value utilizing all the data from the model.
### Partials ###
View
2  lib/rabl/version.rb
@@ -1,3 +1,3 @@
module Rabl
- VERSION = "0.3.0"
+ VERSION = "0.5.0"
end
View
25 test/engine_test.rb
@@ -144,9 +144,9 @@
template = rabl %{
code(:foo, :if => lambda { |i| false }) { 'bar' }
}
- template.render(Object.new)
- end.equals "{}"
-
+ template.render(Object.new).split('').sort
+ end.equals "{}".split('').sort
+
asserts "that it can merge the result with a collection element given no name" do
template = rabl %{
collection @users
@@ -156,8 +156,23 @@
}
scope = Object.new
scope.instance_variable_set :@users, [User.new(:name => 'a'), User.new(:name => 'b')]
- template.render(scope)
- end.equals "[{\"user\":{\"name\":\"a\"}},{\"user\":{\"name\":\"b\"}}]"
+ template.render(scope).split('').sort
+ end.equals "[{\"user\":{\"name\":\"a\"}},{\"user\":{\"name\":\"b\"}}]".split('').sort
+
+ asserts "that it can merge the result on a child node given no name" do
+ template = rabl %{
+ object @user
+ attribute :name
+ child(@user) do
+ code do |user|
+ {:city => user.city}
+ end
+ end
+ }
+ scope = Object.new
+ scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA')
+ template.render(scope).split('').sort
+ end.equals "{\"user\":{\"name\":\"leo\",\"user\":{\"city\":\"LA\"}}}".split('').sort
end

No commit comments for this range

Something went wrong with that request. Please try again.