marble 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/.autotest +9 -0
  2. data/.gitignore +19 -0
  3. data/.travis.yml +6 -0
  4. data/.yardopts +3 -0
  5. data/Gemfile +2 -0
  6. data/Gemfile.lock +93 -0
  7. data/LICENSE +20 -0
  8. data/README.md +82 -0
  9. data/Rakefile +20 -0
  10. data/lib/marble.rb +274 -0
  11. data/lib/marble/rails_template_handler.rb +43 -0
  12. data/lib/marble/version.rb +4 -0
  13. data/marble.gemspec +29 -0
  14. data/test/rails/.autotest +5 -0
  15. data/test/rails/.gitignore +17 -0
  16. data/test/rails/Gemfile +11 -0
  17. data/test/rails/Gemfile.lock +87 -0
  18. data/test/rails/README.md +1 -0
  19. data/test/rails/Rakefile +4 -0
  20. data/test/rails/app/controllers/application_controller.rb +2 -0
  21. data/test/rails/app/controllers/test_controller.rb +6 -0
  22. data/test/rails/app/views/test/index.json.marble +4 -0
  23. data/test/rails/app/views/test/index.yaml.marble +4 -0
  24. data/test/rails/config.ru +4 -0
  25. data/test/rails/config/application.rb +15 -0
  26. data/test/rails/config/boot.rb +6 -0
  27. data/test/rails/config/environment.rb +5 -0
  28. data/test/rails/config/environments/development.rb +9 -0
  29. data/test/rails/config/environments/production.rb +9 -0
  30. data/test/rails/config/environments/test.rb +9 -0
  31. data/test/rails/config/initializers/secret_token.rb +1 -0
  32. data/test/rails/config/initializers/session_store.rb +1 -0
  33. data/test/rails/config/routes.rb +3 -0
  34. data/test/rails/public/404.html +26 -0
  35. data/test/rails/public/422.html +26 -0
  36. data/test/rails/public/500.html +26 -0
  37. data/test/rails/public/favicon.ico +0 -0
  38. data/test/rails/public/robots.txt +5 -0
  39. data/test/rails/script/rails +6 -0
  40. data/test/rails/test/integration/marble_test.rb +13 -0
  41. data/test/rails/test/test_helper.rb +3 -0
  42. data/test/test_helper.rb +7 -0
  43. data/test/test_marble.rb +127 -0
  44. metadata +204 -0
@@ -0,0 +1,43 @@
1
+ class Marble
2
+ # Rails plugin for using Marble as a template handler.
3
+ #
4
+ # Marble has three output formats: text, JSON, and YAML. The template
5
+ # handler calls `to_s`, `to_json`, and `to_yaml` for each format,
6
+ # respectively.
7
+ #
8
+ # Marble sets up a builder for you; simply use the `marble` variable to
9
+ # access the builder. To rename the builder to another, possibly shorter
10
+ # variable in order to save keystrokes, put the new variable name as the
11
+ # name of the block parameter:
12
+ #
13
+ # marble.hash do |m|
14
+ # m.free 'toast'
15
+ # end
16
+ #
17
+ # Marble loads this module only if it can find `ActionView`.
18
+ class RailsTemplateHandler
19
+ class_attribute :default_format
20
+ self.default_format = Mime::JSON
21
+
22
+ # Compile the Rails template.
23
+ #
24
+ # @param template [Class] the Rails template class
25
+ # @return [String] the compiled template
26
+ def call(template)
27
+ compiled = "builder = Marble.new;" +
28
+ "builder.build { |marble| #{template.source} }."
29
+
30
+ if template.formats.include?(:yaml)
31
+ compiled += 'to_yaml'
32
+ elsif template.formats.include?(:json)
33
+ compiled += 'to_json'
34
+ else
35
+ compiled += 'to_s'
36
+ end
37
+
38
+ compiled
39
+ end
40
+ end
41
+ end
42
+
43
+ ActionView::Template.register_template_handler(:marble, Marble::RailsTemplateHandler.new)
@@ -0,0 +1,4 @@
1
+ class Marble
2
+ # Marble version number
3
+ VERSION = '0.1.0'
4
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'marble/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'marble'
7
+ s.version = Marble::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Alexander Kern']
10
+ s.email = ['alex@kernul.com']
11
+ s.homepage = 'https://github.com/CapnKernul/marble'
12
+ s.summary = %q{Ruby object builder}
13
+ s.description = %q{DSL for creating complex Ruby hashes and arrays}
14
+
15
+ s.rubyforge_project = 'marble'
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ['lib']
21
+
22
+ s.add_development_dependency 'minitest', '~> 2.0'
23
+ s.add_development_dependency 'mocha', '~> 0.9'
24
+ s.add_development_dependency 'autotest', '~> 4.4'
25
+ s.add_development_dependency 'rails', '3.0.5'
26
+ s.add_development_dependency 'json', '~> 1.5'
27
+ s.add_development_dependency 'yard', '~> 0.6'
28
+ s.add_development_dependency 'maruku', '~> 0.6'
29
+ end
@@ -0,0 +1,5 @@
1
+ require 'bundler/setup'
2
+
3
+ Autotest.add_hook :initialize do |at|
4
+ at.testlib = 'minitest/unit'
5
+ end
@@ -0,0 +1,17 @@
1
+ *.rbc
2
+ *.sassc
3
+ .sass-cache
4
+ capybara-*.html
5
+ .rspec
6
+ /.bundle
7
+ /vendor/bundle
8
+ /log/*
9
+ /tmp/*
10
+ /db/*.sqlite3
11
+ /public/system/*
12
+ /coverage/
13
+ /spec/tmp/*
14
+ **.orig
15
+ config/*.yml
16
+ rerun.txt
17
+ pickle-email-*.html
@@ -0,0 +1,11 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rails', '3.0.5'
4
+ gem 'marble', :path => '../../'
5
+
6
+ group :development, :test do
7
+ gem 'minitest', '~> 2.0'
8
+ gem 'mocha', '~> 0.9'
9
+ gem 'autotest', '~> 4.4'
10
+ gem 'json', '~> 1.5'
11
+ end
@@ -0,0 +1,87 @@
1
+ PATH
2
+ remote: ../../
3
+ specs:
4
+ marble (0.0.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ ZenTest (4.5.0)
10
+ abstract (1.0.0)
11
+ actionmailer (3.0.5)
12
+ actionpack (= 3.0.5)
13
+ mail (~> 2.2.15)
14
+ actionpack (3.0.5)
15
+ activemodel (= 3.0.5)
16
+ activesupport (= 3.0.5)
17
+ builder (~> 2.1.2)
18
+ erubis (~> 2.6.6)
19
+ i18n (~> 0.4)
20
+ rack (~> 1.2.1)
21
+ rack-mount (~> 0.6.13)
22
+ rack-test (~> 0.5.7)
23
+ tzinfo (~> 0.3.23)
24
+ activemodel (3.0.5)
25
+ activesupport (= 3.0.5)
26
+ builder (~> 2.1.2)
27
+ i18n (~> 0.4)
28
+ activerecord (3.0.5)
29
+ activemodel (= 3.0.5)
30
+ activesupport (= 3.0.5)
31
+ arel (~> 2.0.2)
32
+ tzinfo (~> 0.3.23)
33
+ activeresource (3.0.5)
34
+ activemodel (= 3.0.5)
35
+ activesupport (= 3.0.5)
36
+ activesupport (3.0.5)
37
+ arel (2.0.9)
38
+ autotest (4.4.6)
39
+ ZenTest (>= 4.4.1)
40
+ builder (2.1.2)
41
+ erubis (2.6.6)
42
+ abstract (>= 1.0.0)
43
+ i18n (0.5.0)
44
+ json (1.5.1)
45
+ mail (2.2.15)
46
+ activesupport (>= 2.3.6)
47
+ i18n (>= 0.4.0)
48
+ mime-types (~> 1.16)
49
+ treetop (~> 1.4.8)
50
+ mime-types (1.16)
51
+ minitest (2.1.0)
52
+ mocha (0.9.12)
53
+ polyglot (0.3.1)
54
+ rack (1.2.2)
55
+ rack-mount (0.6.13)
56
+ rack (>= 1.0.0)
57
+ rack-test (0.5.7)
58
+ rack (>= 1.0)
59
+ rails (3.0.5)
60
+ actionmailer (= 3.0.5)
61
+ actionpack (= 3.0.5)
62
+ activerecord (= 3.0.5)
63
+ activeresource (= 3.0.5)
64
+ activesupport (= 3.0.5)
65
+ bundler (~> 1.0)
66
+ railties (= 3.0.5)
67
+ railties (3.0.5)
68
+ actionpack (= 3.0.5)
69
+ activesupport (= 3.0.5)
70
+ rake (>= 0.8.7)
71
+ thor (~> 0.14.4)
72
+ rake (0.8.7)
73
+ thor (0.14.6)
74
+ treetop (1.4.9)
75
+ polyglot (>= 0.3.1)
76
+ tzinfo (0.3.25)
77
+
78
+ PLATFORMS
79
+ ruby
80
+
81
+ DEPENDENCIES
82
+ autotest (~> 4.4)
83
+ json (~> 1.5)
84
+ marble!
85
+ minitest (~> 2.0)
86
+ mocha (~> 0.9)
87
+ rails (= 3.0.5)
@@ -0,0 +1 @@
1
+ Bare-bones Rails 3 application for testing Marble.
@@ -0,0 +1,4 @@
1
+ require File.expand_path('../config/application', __FILE__)
2
+ require 'rake'
3
+
4
+ MarbleApp::Application.load_tasks
@@ -0,0 +1,2 @@
1
+ class ApplicationController < ActionController::Base
2
+ end
@@ -0,0 +1,6 @@
1
+ class TestController < ApplicationController
2
+ def index
3
+ @instance_var = 'OK'
4
+ render 'index', :locals => { :local_var => 'OK' }
5
+ end
6
+ end
@@ -0,0 +1,4 @@
1
+ marble.hash do |m|
2
+ m.instance @instance_var
3
+ m.local local_var
4
+ end
@@ -0,0 +1,4 @@
1
+ marble.hash do |m|
2
+ m.instance @instance_var
3
+ m.local local_var
4
+ end
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run MarbleApp::Application
@@ -0,0 +1,15 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'action_controller/railtie'
4
+ require 'rails/test_unit/railtie'
5
+
6
+ # If you have a Gemfile, require the gems listed there, including any gems
7
+ # you've limited to :test, :development, or :production.
8
+ Bundler.require(:default, Rails.env) if defined?(Bundler)
9
+
10
+ module MarbleApp
11
+ class Application < Rails::Application
12
+ # Configure the default encoding used in templates for Ruby 1.9.
13
+ config.encoding = 'utf-8'
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+
3
+ # Set up gems listed in the Gemfile.
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
5
+
6
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ MarbleApp::Application.initialize!
@@ -0,0 +1,9 @@
1
+ MarbleApp::Application.configure do
2
+ config.cache_classes = false
3
+ config.whiny_nils = true
4
+ config.consider_all_requests_local = true
5
+ config.action_view.debug_rjs = true
6
+ config.action_controller.perform_caching = false
7
+ config.active_support.deprecation = :log
8
+ config.action_dispatch.best_standards_support = :builtin
9
+ end
@@ -0,0 +1,9 @@
1
+ MarbleApp::Application.configure do
2
+ config.cache_classes = true
3
+ config.consider_all_requests_local = false
4
+ config.action_controller.perform_caching = true
5
+ config.action_dispatch.x_sendfile_header = 'X-Sendfile'
6
+ config.serve_static_assets = false
7
+ config.i18n.fallbacks = true
8
+ config.active_support.deprecation = :notify
9
+ end
@@ -0,0 +1,9 @@
1
+ MarbleApp::Application.configure do
2
+ config.cache_classes = true
3
+ config.whiny_nils = true
4
+ config.consider_all_requests_local = true
5
+ config.action_controller.perform_caching = false
6
+ config.action_dispatch.show_exceptions = false
7
+ config.action_controller.allow_forgery_protection = false
8
+ config.active_support.deprecation = :stderr
9
+ end
@@ -0,0 +1 @@
1
+ MarbleApp::Application.config.secret_token = '5ddfeaf6267d5da9a3409c06628538253d49c742d72b512724abc93a89df4f37ae8dc9bafaeb4ebd0b40be6eb13ca47e4bcaedbf423ed8c6774d61de1abe51eb'
@@ -0,0 +1 @@
1
+ MarbleApp::Application.config.session_store :cookie_store, :key => '_marble_app_session'
@@ -0,0 +1,3 @@
1
+ MarbleApp::Application.routes.draw do
2
+ root :to => 'test#index'
3
+ end
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ <p>We've been notified about this issue and we'll take a look at it shortly.</p>
24
+ </div>
25
+ </body>
26
+ </html>
File without changes
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-Agent: *
5
+ # Disallow: /
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,13 @@
1
+ require 'test_helper'
2
+
3
+ class MarbleTest < ActionDispatch::IntegrationTest
4
+ def test_render_json
5
+ get '/', :format => :json
6
+ assert_equal({ 'instance' => 'OK', 'local' => 'OK' }, JSON.parse(response.body))
7
+ end
8
+
9
+ def test_render_yaml
10
+ get '/', :format => :yaml
11
+ assert_equal({ 'instance' => 'OK', 'local' => 'OK' }, YAML.load(response.body))
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ ENV['RAILS_ENV'] = 'test'
2
+ require File.expand_path('../../config/environment', __FILE__)
3
+ require 'rails/test_help'
@@ -0,0 +1,7 @@
1
+ require 'bundler/setup'
2
+ require 'minitest/autorun'
3
+ require 'minitest/pride'
4
+ require 'mocha'
5
+ require 'marble'
6
+
7
+ Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each { |f| require f }