rabl 0.3.0 → 0.5.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.
Files changed (146) hide show
  1. data/.gitignore +2 -0
  2. data/.travis.yml +10 -0
  3. data/CHANGELOG.md +34 -0
  4. data/Gemfile +14 -1
  5. data/README.md +53 -4
  6. data/Rakefile +26 -1
  7. data/fixtures/ashared/NOTES +35 -0
  8. data/fixtures/ashared/README +35 -0
  9. data/fixtures/ashared/migrate/20111002092016_create_users.rb +15 -0
  10. data/fixtures/ashared/migrate/20111002092019_create_posts.rb +14 -0
  11. data/fixtures/ashared/migrate/20111002092024_create_phone_numbers.rb +16 -0
  12. data/fixtures/ashared/models/phone_number.rb +7 -0
  13. data/fixtures/ashared/models/post.rb +3 -0
  14. data/fixtures/ashared/models/user.rb +3 -0
  15. data/fixtures/ashared/views/layouts/application.html.erb +6 -0
  16. data/fixtures/ashared/views/posts/date.json.rabl +3 -0
  17. data/fixtures/ashared/views/posts/index.json.rabl +11 -0
  18. data/fixtures/ashared/views/posts/show.json.rabl +16 -0
  19. data/fixtures/ashared/views/users/index.rabl +3 -0
  20. data/fixtures/ashared/views/users/phone_number.rabl +6 -0
  21. data/fixtures/ashared/views/users/show.rabl +16 -0
  22. data/fixtures/padrino_test/.components +7 -0
  23. data/fixtures/padrino_test/.gitignore +7 -0
  24. data/fixtures/padrino_test/Gemfile +17 -0
  25. data/fixtures/padrino_test/Rakefile +3 -0
  26. data/fixtures/padrino_test/app/app.rb +59 -0
  27. data/fixtures/padrino_test/app/controllers/posts.rb +11 -0
  28. data/fixtures/padrino_test/app/controllers/users.rb +11 -0
  29. data/fixtures/padrino_test/app/helpers/posts_helper.rb +7 -0
  30. data/fixtures/padrino_test/app/helpers/users_helper.rb +7 -0
  31. data/fixtures/padrino_test/config.ru +9 -0
  32. data/fixtures/padrino_test/config/apps.rb +34 -0
  33. data/fixtures/padrino_test/config/boot.rb +29 -0
  34. data/fixtures/padrino_test/config/database.rb +43 -0
  35. data/fixtures/padrino_test/db/schema.rb +42 -0
  36. data/fixtures/padrino_test/public/favicon.ico +0 -0
  37. data/fixtures/padrino_test/test/app/controllers/posts_controller_test.rb +108 -0
  38. data/fixtures/padrino_test/test/app/controllers/users_controller_test.rb +87 -0
  39. data/fixtures/padrino_test/test/test.rake +18 -0
  40. data/fixtures/padrino_test/test/test_config.rb +18 -0
  41. data/fixtures/rails2/.gitignore +1 -0
  42. data/fixtures/rails2/Gemfile +8 -0
  43. data/fixtures/rails2/Rakefile +14 -0
  44. data/fixtures/rails2/app/controllers/application_controller.rb +10 -0
  45. data/fixtures/rails2/app/controllers/posts_controller.rb +15 -0
  46. data/fixtures/rails2/app/controllers/users_controller.rb +15 -0
  47. data/fixtures/rails2/config/boot.rb +129 -0
  48. data/fixtures/rails2/config/database.yml +16 -0
  49. data/fixtures/rails2/config/environment.rb +42 -0
  50. data/fixtures/rails2/config/environments/development.rb +17 -0
  51. data/fixtures/rails2/config/environments/production.rb +28 -0
  52. data/fixtures/rails2/config/environments/test.rb +28 -0
  53. data/fixtures/rails2/config/initializers/backtrace_silencers.rb +7 -0
  54. data/fixtures/rails2/config/initializers/cookie_verification_secret.rb +7 -0
  55. data/fixtures/rails2/config/initializers/inflections.rb +10 -0
  56. data/fixtures/rails2/config/initializers/mime_types.rb +5 -0
  57. data/fixtures/rails2/config/initializers/new_rails_defaults.rb +21 -0
  58. data/fixtures/rails2/config/initializers/session_store.rb +15 -0
  59. data/fixtures/rails2/config/locales/en.yml +5 -0
  60. data/fixtures/rails2/config/preinitializer.rb +20 -0
  61. data/fixtures/rails2/config/routes.rb +45 -0
  62. data/fixtures/rails2/db/schema.rb +40 -0
  63. data/fixtures/rails2/db/seeds.rb +7 -0
  64. data/fixtures/rails2/public/404.html +30 -0
  65. data/fixtures/rails2/public/422.html +30 -0
  66. data/fixtures/rails2/public/500.html +30 -0
  67. data/fixtures/rails2/public/favicon.ico +0 -0
  68. data/fixtures/rails2/public/images/rails.png +0 -0
  69. data/fixtures/rails2/public/index.html +275 -0
  70. data/fixtures/rails2/public/robots.txt +5 -0
  71. data/fixtures/rails2/script/about +4 -0
  72. data/fixtures/rails2/script/console +3 -0
  73. data/fixtures/rails2/script/dbconsole +3 -0
  74. data/fixtures/rails2/script/destroy +3 -0
  75. data/fixtures/rails2/script/generate +3 -0
  76. data/fixtures/rails2/script/performance/benchmarker +3 -0
  77. data/fixtures/rails2/script/performance/profiler +3 -0
  78. data/fixtures/rails2/script/plugin +3 -0
  79. data/fixtures/rails2/script/runner +3 -0
  80. data/fixtures/rails2/script/server +3 -0
  81. data/fixtures/rails2/test/functionals/posts_controller_test.rb +108 -0
  82. data/fixtures/rails2/test/functionals/users_controller_test.rb +87 -0
  83. data/fixtures/rails2/test/test_helper.rb +33 -0
  84. data/fixtures/rails3/.gitignore +4 -0
  85. data/fixtures/rails3/Gemfile +37 -0
  86. data/fixtures/rails3/Rakefile +12 -0
  87. data/fixtures/rails3/app/controllers/application_controller.rb +14 -0
  88. data/fixtures/rails3/app/controllers/posts_controller.rb +11 -0
  89. data/fixtures/rails3/app/controllers/users_controller.rb +11 -0
  90. data/fixtures/rails3/config.ru +4 -0
  91. data/fixtures/rails3/config/application.rb +42 -0
  92. data/fixtures/rails3/config/boot.rb +6 -0
  93. data/fixtures/rails3/config/database.yml +22 -0
  94. data/fixtures/rails3/config/environment.rb +5 -0
  95. data/fixtures/rails3/config/environments/development.rb +26 -0
  96. data/fixtures/rails3/config/environments/production.rb +49 -0
  97. data/fixtures/rails3/config/environments/test.rb +35 -0
  98. data/fixtures/rails3/config/initializers/backtrace_silencers.rb +7 -0
  99. data/fixtures/rails3/config/initializers/inflections.rb +10 -0
  100. data/fixtures/rails3/config/initializers/mime_types.rb +5 -0
  101. data/fixtures/rails3/config/initializers/secret_token.rb +7 -0
  102. data/fixtures/rails3/config/initializers/session_store.rb +8 -0
  103. data/fixtures/rails3/config/locales/en.yml +5 -0
  104. data/fixtures/rails3/config/routes.rb +61 -0
  105. data/fixtures/rails3/db/seeds.rb +7 -0
  106. data/fixtures/rails3/lib/tasks/.gitkeep +0 -0
  107. data/fixtures/rails3/public/404.html +26 -0
  108. data/fixtures/rails3/public/422.html +26 -0
  109. data/fixtures/rails3/public/500.html +26 -0
  110. data/fixtures/rails3/public/favicon.ico +0 -0
  111. data/fixtures/rails3/public/images/rails.png +0 -0
  112. data/fixtures/rails3/public/index.html +239 -0
  113. data/fixtures/rails3/public/robots.txt +5 -0
  114. data/fixtures/rails3/public/stylesheets/.gitkeep +0 -0
  115. data/fixtures/rails3/script/rails +6 -0
  116. data/fixtures/rails3/test/functional/posts_controller_test.rb +108 -0
  117. data/fixtures/rails3/test/functional/users_controller_test.rb +87 -0
  118. data/fixtures/rails3/test/test_helper.rb +26 -0
  119. data/fixtures/sinatra_test/Gemfile +13 -0
  120. data/fixtures/sinatra_test/Rakefile +6 -0
  121. data/fixtures/sinatra_test/app.rb +44 -0
  122. data/fixtures/sinatra_test/config.ru +7 -0
  123. data/fixtures/sinatra_test/test/functional/posts_controller_test.rb +108 -0
  124. data/fixtures/sinatra_test/test/functional/users_controller_test.rb +87 -0
  125. data/fixtures/sinatra_test/test/test_helper.rb +19 -0
  126. data/lib/rabl.rb +13 -1
  127. data/lib/rabl/builder.rb +14 -7
  128. data/lib/rabl/configuration.rb +41 -1
  129. data/lib/rabl/engine.rb +29 -19
  130. data/lib/rabl/helpers.rb +45 -18
  131. data/lib/rabl/template.rb +1 -1
  132. data/lib/rabl/version.rb +1 -1
  133. data/rabl.gemspec +6 -5
  134. data/test/builder_test.rb +4 -4
  135. data/test/configuration_test.rb +7 -22
  136. data/test/engine_test.rb +63 -44
  137. data/test/helpers_test.rb +68 -0
  138. data/test/integration/posts_controller_test.rb +108 -0
  139. data/test/integration/test_init.rb +35 -0
  140. data/test/integration/users_controller_test.rb +87 -0
  141. data/test/models/ormless.rb +2 -0
  142. data/test/models/user.rb +17 -6
  143. data/test/msgpack_engine_test.rb +332 -0
  144. data/test/silence.rb +21 -0
  145. data/test/teststrap.rb +22 -6
  146. metadata +160 -14
data/.gitignore CHANGED
@@ -3,3 +3,5 @@
3
3
  .rvmrc
4
4
  Gemfile.lock
5
5
  pkg/*
6
+ fixtures/rails2/log/*.log
7
+ tags
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ # http://about.travis-ci.org/docs/user/build-configuration/
2
+ before_script: "git submodule update --init"
3
+ rvm:
4
+ - 1.8.7
5
+ - 1.9.2
6
+ - rbx-2.0
7
+ - ree
8
+ notifications:
9
+ recipients:
10
+ - nesquena@gmail.com
data/CHANGELOG.md ADDED
@@ -0,0 +1,34 @@
1
+ # CHANGELOG
2
+
3
+ ## 0.5.1 (Unreleased)
4
+
5
+ ## 0.5.0
6
+
7
+ * Adds comprehensive fixture suite (padrino,rails2,rails3,sinatra)
8
+ * Travis CI Integration Testing
9
+ * Cleanup json configuration and related tests (Thanks mschulkind)
10
+ * Adds CHANGELOG to track changes
11
+ * Adds optional MessagePack format support (thanks byu)
12
+ * Explicit requires for ActiveSupport now in gemspec and lib
13
+ * Adds template support for regular (non-ORM) ruby objects (thanks plukevdh)
14
+ * Fixes bug with the child root not properly appearing in all cases
15
+ * Better stack traces by tracking source location in instance_eval (thanks skade)
16
+ * Fix issue with controller object detection failing in namespaces (thanks alunny)
17
+ * Fix ruby -w warnings (thanks achiu)
18
+ * Better partial implementation which passes options
19
+ * Better fetch_source implementation for Padrino (thanks skade)
20
+ * Better fetch_source implementation for Rails
21
+ * Added fetch_source implementation for Sinatra
22
+ * Lots of test refactorings / cleanup / improvement
23
+ * Code block name is now optional [Thanks brentmurphy]
24
+
25
+ ## 0.3.0
26
+
27
+ * Use multi_json to handle JSON encoding (Thanks kossnocorp)
28
+ * Fixes unit tests with hash order on 1.8.7
29
+
30
+ ## 0.2.8
31
+
32
+ * Fixes Rails 3.1 Compatibility (Thanks skyeagle)
33
+ * Fixes Ruby 1.8.6 Compatibility (Thanks Don)
34
+ * Adds much better riot unit testing (Thanks Achiu)
data/Gemfile CHANGED
@@ -1,8 +1,21 @@
1
- source "http://rubygems.org"
1
+ source :rubygems
2
2
 
3
3
  # Specify your gem's dependencies in rabl.gemspec
4
4
  gemspec
5
5
 
6
+ gem "rake"
7
+ gem "i18n", '~> 0.6'
8
+
6
9
  platforms :mri_18 do
7
10
  gem 'SystemTimer'
11
+ end
12
+
13
+ # FIXTURES
14
+ group :test do
15
+ gem 'rack-test', :require => "rack/test"
16
+ gem 'activerecord', :require => "active_record"
17
+ gem 'sqlite3'
18
+ gem 'padrino', '>= 0.10.2'
19
+ gem 'sinatra', '>= 1.2.0'
20
+ gem 'rails', '>= 2.3.0'
8
21
  end
data/README.md CHANGED
@@ -26,6 +26,8 @@ or add to your Gemfile:
26
26
  ```ruby
27
27
  # Gemfile
28
28
  gem 'rabl'
29
+ # Also add either `json` or `yajl-ruby` as the JSON parser
30
+ gem 'yajl-ruby'
29
31
  ```
30
32
 
31
33
  and run `bundle install` to install the dependency.
@@ -87,7 +89,9 @@ RABL is intended to require little to no configuration to get working. This is t
87
89
  Rabl.configure do |config|
88
90
  # Commented as these are the defaults
89
91
  # config.json_engine = nil # Any multi\_json engines
92
+ # config.msgpack_engine = nil # Defaults to ::MessagePack
90
93
  # config.include_json_root = true
94
+ # config.include_msgpack_root = true
91
95
  # config.include_xml_root = false
92
96
  # config.enable_json_callbacks = false
93
97
  # config.xml_options = { :dasherize => true, :skip_types => false }
@@ -105,6 +109,32 @@ gem 'yajl-ruby', :require => "yajl"
105
109
 
106
110
  and RABL will automatically start using that engine for encoding your JSON responses!
107
111
 
112
+ ### Message Pack ###
113
+
114
+ Rabl also includes optional support for [Message Pack](http://www.msgpack.org/) serialization format using the [msgpack gem](https://rubygems.org/gems/msgpack).
115
+ To enable, include the msgpack gem in your project's Gemfile. Then use Rabl as normal with the `msgpack` format (akin to json and xml formats).
116
+
117
+ ```ruby
118
+ # Gemfile
119
+ gem 'msgpack', '~> 0.4.5'
120
+ ```
121
+
122
+ One can additionally use a custom Message Pack implementation by setting the Rabl `msgpack_engine` configuration attribute. This custom message pack engine must conform to the MessagePack#pack method signature.
123
+
124
+ ```ruby
125
+ class CustomEncodeEngine
126
+ def self.pack string
127
+ # Custom Encoding by your own engine.
128
+ end
129
+ end
130
+
131
+ Rabl.configure do |config|
132
+ config.msgpack_engine = CustomEncodeEngine
133
+ end
134
+ ```
135
+
136
+ *NOTE*: Attempting to render the msgpack format without either including the msgpack gem or setting a `msgpack_engine` will cause an exception to be raised.
137
+
108
138
  ## Usage ##
109
139
 
110
140
  ### Object Assignment ###
@@ -234,6 +264,15 @@ code(:foo, :if => lambda { |m| m.has_foo? }) do |m|
234
264
  end
235
265
  ```
236
266
 
267
+ or don't pass a name and have the code block merged into the response:
268
+
269
+ ```ruby
270
+ code do |u|
271
+ { :full_name => u.first_name + " " + u.last_name }
272
+ # => { full_name : "Bob Johnson" }
273
+ end
274
+ ```
275
+
237
276
  You can use custom "code" nodes to create flexible representations of a value utilizing all the data from the model.
238
277
 
239
278
  ### Partials ###
@@ -327,6 +366,12 @@ Check out the [Issues](https://github.com/nesquena/rabl/issues) tab for a full l
327
366
  * Better Tilt template support (precompiling templates)
328
367
  * Benchmarks and performance optimizations
329
368
 
369
+ ## Continuous Integration
370
+
371
+ [![Continuous Integration status](https://secure.travis-ci.org/nesquena/rabl.png)](http://travis-ci.org/nesquena/rabl)
372
+
373
+ CI is hosted by [travis-ci.org](http://travis-ci.org).
374
+
330
375
  ## Authors and Contributors ##
331
376
 
332
377
  Thanks to [Miso](http://gomiso.com) for allowing me to create this for our applications and release this project!
@@ -334,12 +379,16 @@ Thanks to [Miso](http://gomiso.com) for allowing me to create this for our appli
334
379
  * [Nathan Esquenazi](https://github.com/nesquena) - Creator of the project
335
380
  * [Arthur Chiu](https://github.com/achiu) - Core Maintainer, Riot Testing Guru
336
381
  * [Tim Lee](https://github.com/timothy1ee) - RABL is an awesome name and was chosen by the Miso CTO.
337
- * [Rick Thomas](https://github.com/rickthomasjr) - Added options passing for extends and Sinatra testing
338
- * [Marjun](https://github.com/mpagalan) - Added xml option configurations
382
+ * [Rick Thomas](https://github.com/rickthomasjr) - Added options for extends and Sinatra testing
339
383
  * [Chris Kimpton](https://github.com/kimptoc) - Helping with documentation and wiki
384
+ * [Marjun](https://github.com/mpagalan) - Added xml option configurations
385
+ * [Anton Orel](https://github.com/skyeagle) - Added Rails 3.1 compatibility
340
386
  * [Sasha Koss](https://github.com/kossnocorp) - Added multi_json support
387
+ * [Matthew Schulkind](https://github.com/mschulkind) - Cleanup of configuration and tests
388
+ * [Luke van der Hoeven](https://github.com/plukevdh) - Support non-ORM objects in templates
341
389
 
342
- More to come hopefully! Please fork and contribute, any help is appreciated!
390
+ and many more contributors listed in the [CHANGELOG](https://github.com/nesquena/rabl/blob/master/CHANGELOG.md).
391
+ Please fork and contribute, any help in making this project better is appreciated!
343
392
 
344
393
  ## Inspirations ##
345
394
 
@@ -357,4 +406,4 @@ See the [examples](https://github.com/nesquena/rabl/tree/master/examples) direct
357
406
 
358
407
  ## Copyright
359
408
 
360
- Copyright © 2011 Nathan Esquenazi. See [MIT-LICENSE](https://github.com/nesquena/rabl/blob/master/MIT-LICENSE) for details.
409
+ Copyright © 2011 Nathan Esquenazi. See [MIT-LICENSE](https://github.com/nesquena/rabl/blob/master/MIT-LICENSE) for details.
data/Rakefile CHANGED
@@ -1,10 +1,35 @@
1
+ include Rake::DSL
2
+
1
3
  require 'bundler'
2
4
  Bundler::GemHelper.install_tasks
3
5
 
4
6
  require 'rake/testtask'
5
7
  Rake::TestTask.new(:test) do |test|
6
8
  test.libs << 'lib' << 'test'
7
- test.pattern = 'test/**/*_test.rb'
9
+ test.pattern = 'test/*_test.rb'
10
+ test.warning = true
8
11
  test.verbose = true
9
12
  test.ruby_opts = ['-rubygems']
10
13
  end
14
+
15
+ desc "Prepares the fixtures for being tested by installing dependencies"
16
+ task "test:setup" do
17
+ Dir[File.dirname(__FILE__) + "/fixtures/{padrino_test,sinatra_test,rails2,rails3}"].each do |fixture|
18
+ puts "\n*** Setting up for #{File.basename(fixture)} tests ***\n"
19
+ `export BUNDLE_GEMFILE=#{fixture}/Gemfile` if ENV['TRAVIS']
20
+ puts `cd #{fixture}; bundle install;`
21
+ end
22
+ end
23
+
24
+ desc "Executes the fixture tests"
25
+ task "test:fixtures" do
26
+ Dir[File.dirname(__FILE__) + "/fixtures/{padrino_test,sinatra_test,rails2,rails3}"].each do |fixture|
27
+ puts "\n*** Running tests for #{File.basename(fixture)}... ***\n"
28
+ puts `cd #{fixture}; bundle check; bundle exec rake test:rabl`
29
+ end
30
+ end
31
+
32
+ task "test:full" => [:test, "test:fixtures"]
33
+
34
+ desc "Run tests for rabl"
35
+ task :default => :test
@@ -0,0 +1,35 @@
1
+ # Padrino
2
+
3
+ cd fixtures/padrino_test
4
+ ln -s "../ashared/models" models
5
+ ln -s "../../ashared/views/" app/views
6
+ ln -s "../../ashared/migrate" db/migrate
7
+ ln ../../test/integration/posts_controller_test.rb test/app/controllers/posts_controller_test.rb
8
+ ln ../../test/integration/users_controller_test.rb test/app/controllers/users_controller_test.rb
9
+
10
+ # Rails 2
11
+
12
+ cd fixtures/rails2
13
+ ln -s "../../ashared/models" app/models
14
+ ln -s "../../ashared/views/" app/views
15
+ ln -s "../../ashared/migrate" db/migrate
16
+ ln ../../test/integration/posts_controller_test.rb test/functionals/posts_controller_test.rb
17
+ ln ../../test/integration/users_controller_test.rb test/functionals/users_controller_test.rb
18
+
19
+ # Rails 3
20
+
21
+ cd fixtures/rails3
22
+ ln -s "../../ashared/models" app/models
23
+ ln -s "../../ashared/views/" app/views
24
+ ln -s "../../ashared/migrate" db/migrate
25
+ ln ../../test/integration/posts_controller_test.rb test/functional/posts_controller_test.rb
26
+ ln ../../test/integration/users_controller_test.rb test/functional/users_controller_test.rb
27
+
28
+ # Sinatra
29
+
30
+ cd fixtures/sinatra_test
31
+ ln -s "../ashared/models" models
32
+ ln -s "../ashared/views/" views
33
+ ln -s "../../ashared/migrate" db/migrate
34
+ ln ../../test/integration/posts_controller_test.rb test/functional/posts_controller_test.rb
35
+ ln ../../test/integration/users_controller_test.rb test/functional/users_controller_test.rb
@@ -0,0 +1,35 @@
1
+ Fixtures to test RABL:
2
+
3
+ models:
4
+
5
+ user
6
+ t.string :username
7
+ t.string :email
8
+ t.string :location
9
+ t.boolean :is_admin
10
+ t.timestamps
11
+ posts
12
+ t.integer :user_id
13
+ t.string :title
14
+ t.text :body
15
+ t.timestamps
16
+ phone_number
17
+ t.integer :user_id
18
+ t.boolean :is_primary
19
+ t.string :area_code
20
+ t.string :prefix
21
+ t.string :suffix
22
+ t.string :name
23
+
24
+ controllers:
25
+
26
+ users
27
+ posts
28
+
29
+ layouts:
30
+
31
+ application.html.haml
32
+
33
+ views:
34
+ posts (index, show, date)
35
+ users (index, show)
@@ -0,0 +1,15 @@
1
+ class CreateUsers < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :users do |t|
4
+ t.string :username
5
+ t.string :email
6
+ t.string :location
7
+ t.boolean :is_admin
8
+ t.timestamps
9
+ end
10
+ end
11
+
12
+ def self.down
13
+ drop_table :users
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ class CreatePosts < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :posts do |t|
4
+ t.integer :user_id
5
+ t.string :title
6
+ t.text :body
7
+ t.timestamps
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table :posts
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ class CreatePhoneNumbers < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :phone_numbers do |t|
4
+ t.integer :user_id
5
+ t.boolean :is_primary
6
+ t.string :area_code
7
+ t.string :prefix
8
+ t.string :suffix
9
+ t.string :name
10
+ end
11
+ end
12
+
13
+ def self.down
14
+ drop_table :phone_numbers
15
+ end
16
+ end
@@ -0,0 +1,7 @@
1
+ class PhoneNumber < ActiveRecord::Base
2
+ belongs_to :user
3
+
4
+ def formatted
5
+ "(#{self.area_code}) #{self.prefix}-#{self.suffix}"
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ class Post < ActiveRecord::Base
2
+ belongs_to :user
3
+ end
@@ -0,0 +1,3 @@
1
+ class User < ActiveRecord::Base
2
+ has_many :phone_numbers
3
+ end
@@ -0,0 +1,6 @@
1
+ <head>
2
+ Not for RABL
3
+ </head>
4
+ <body>
5
+ Not for RABL
6
+ </body>
@@ -0,0 +1,3 @@
1
+ code(:day) { |d| d.day }
2
+ code(:hour) { |d| d.hour }
3
+ code(:full) { |d| d.iso8601 }
@@ -0,0 +1,11 @@
1
+ collection @posts => :articles
2
+
3
+ extends "posts/show"
4
+
5
+ node(:created_by_admin, :if => lambda { |p| p.user.is_admin }) do |p|
6
+ true
7
+ end
8
+
9
+ child({ :user => :admin }, { :if => lambda { |p| p.user.is_admin }}) do |p|
10
+ extends "users/show"
11
+ end
@@ -0,0 +1,16 @@
1
+ object @post
2
+
3
+ attributes :title, :body
4
+ attributes :created_at => :posted_at
5
+
6
+ child :user do
7
+ extends "users/show"
8
+ end
9
+
10
+ glue :user do
11
+ attributes :username => :author_name
12
+ end
13
+
14
+ code(:created_date) do |p|
15
+ partial("posts/date", :object => p.created_at)
16
+ end
@@ -0,0 +1,3 @@
1
+ collection @users
2
+
3
+ extends "users/show"
@@ -0,0 +1,6 @@
1
+ attributes :prefix, :suffix, :area_code
2
+ attributes :is_primary => :primary
3
+
4
+ node :formatted do |n|
5
+ n.formatted
6
+ end
@@ -0,0 +1,16 @@
1
+ object @user => :person
2
+
3
+ attributes :username, :email, :location
4
+ attributes :created_at => :registered_at
5
+
6
+ node :role do |user|
7
+ user.is_admin ? 'admin' : 'normal'
8
+ end
9
+
10
+ child :phone_numbers => :pnumbers do
11
+ extends "users/phone_number"
12
+ end
13
+
14
+ node :node_numbers do |u|
15
+ partial("users/phone_number", :object => u.phone_numbers)
16
+ end
@@ -0,0 +1,7 @@
1
+ ---
2
+ :orm: activerecord
3
+ :test: riot
4
+ :mock: none
5
+ :script: none
6
+ :renderer: haml
7
+ :stylesheet: none