tokamak 1.2.0 → 1.2.1

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.
@@ -7,7 +7,10 @@ require "bundler/setup"
7
7
  # Lib
8
8
  module Tokamak
9
9
  def self.builder_lookup(media_type)
10
- Tokamak::Builder::Base.global_media_types[media_type[/^([^\s\;]+)/, 1]]
10
+ builder = Tokamak::Builder::Base.global_media_types[media_type[/^([^\s\;]+)/, 1]]
11
+ builder.nil? ?
12
+ (raise Tokamak::BuilderError.new("Could not find a builder for the media type: #{media_type}")) :
13
+ builder
11
14
  end
12
15
  end
13
16
 
@@ -17,6 +17,19 @@ module Tokamak
17
17
  end
18
18
  end
19
19
 
20
+ module Rails3Adapter
21
+ def _pick_partial_template(path) #:nodoc:
22
+ return path unless path.is_a?(String)
23
+ prefix = controller_path unless path.include?(?/)
24
+ find_template(path, prefix, true).instance_eval do
25
+ unless respond_to?(:path)
26
+ def path; virtual_path end
27
+ end
28
+ self
29
+ end
30
+ end
31
+ end
32
+
20
33
  module Helpers
21
34
  # Load a partial template to execute in describe
22
35
  #
@@ -41,7 +54,12 @@ module Tokamak
41
54
  # end
42
55
  #
43
56
  def partial(partial_path, caller_binding = nil)
44
- template = _pick_partial_template(partial_path)
57
+ begin
58
+ template = _pick_partial_template(partial_path)
59
+ rescue NoMethodError
60
+ self.extend(Rails3Adapter)
61
+ template = _pick_partial_template(partial_path)
62
+ end
45
63
 
46
64
  # Create a context to assing variables
47
65
  if caller_binding.kind_of?(Hash)
@@ -2,7 +2,7 @@ module Tokamak
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
4
  MINOR = 2
5
- TINY = 0
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
 
@@ -0,0 +1,7 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+ require 'rake'
6
+
7
+ Rails3Skel::Application.load_tasks
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,18 @@
1
+ class TestController < ApplicationController
2
+ def show
3
+ @some_articles = [
4
+ {:id => 1, :title => "a great article", :updated => Time.now},
5
+ {:id => 2, :title => "another great article", :updated => Time.now}
6
+ ]
7
+ response.content_type = request.negotiated_type
8
+ end
9
+
10
+ def feed
11
+ @some_articles = [
12
+ {:id => 1, :title => "a great article", :updated => Time.now},
13
+ {:id => 2, :title => "another great article", :updated => Time.now}
14
+ ]
15
+ response.content_type = request.negotiated_type
16
+ end
17
+
18
+ end
@@ -0,0 +1,9 @@
1
+ member.values do |values|
2
+ values.id "uri:#{article[:id]}"
3
+ values.title article[:title]
4
+ values.updated article[:updated]
5
+ end
6
+
7
+ member.link("image", "http://example.com/image/1")
8
+ member.link("image", "http://example.com/image/2", :type => "application/json")
9
+
@@ -0,0 +1,24 @@
1
+ collection(@some_articles) do |collection|
2
+ collection.values do |values|
3
+ values.id "http://example.com/json"
4
+ values.title "Feed"
5
+ values.updated Time.now
6
+
7
+ values.author {
8
+ values.name "John Doe"
9
+ values.email "joedoe@example.com"
10
+ }
11
+
12
+ values.author {
13
+ values.name "Foo Bar"
14
+ values.email "foobar@example.com"
15
+ }
16
+ end
17
+
18
+ collection.link("next" , "http://a.link.com/next")
19
+ collection.link("previous", "http://a.link.com/previous")
20
+
21
+ collection.members(:root => "articles") do |member, article|
22
+ partial("feed_member", :locals => {:member => member, :article => article})
23
+ end
24
+ end
@@ -0,0 +1,31 @@
1
+ collection(@some_articles) do |collection|
2
+ collection.values do |values|
3
+ values.id "http://example.com/json"
4
+ values.title "Feed"
5
+ values.updated Time.now
6
+
7
+ values.author {
8
+ values.name "John Doe"
9
+ values.email "joedoe@example.com"
10
+ }
11
+
12
+ values.author {
13
+ values.name "Foo Bar"
14
+ values.email "foobar@example.com"
15
+ }
16
+ end
17
+
18
+ collection.link("next" , "http://a.link.com/next")
19
+ collection.link("previous", "http://a.link.com/previous")
20
+
21
+ collection.members(:root => "articles") do |member, article|
22
+ member.values do |values|
23
+ values.id "uri:#{article[:id]}"
24
+ values.title article[:title]
25
+ values.updated article[:updated]
26
+ end
27
+
28
+ member.link("image", "http://example.com/image/1")
29
+ member.link("image", "http://example.com/image/2", :type => "application/json")
30
+ end
31
+ 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 Rails3Skel::Application
@@ -0,0 +1,54 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ # Pick the frameworks you want:
4
+ # require "active_record/railtie"
5
+ require "action_controller/railtie"
6
+ require "action_mailer/railtie"
7
+ # require "active_resource/railtie"
8
+ require "rails/test_unit/railtie"
9
+
10
+ # If you have a Gemfile, require the gems listed there, including any gems
11
+ # you've limited to :test, :development, or :production.
12
+ Bundler.require(:default, Rails.env) if defined?(Bundler)
13
+
14
+ module Rails3Skel
15
+ class Application < Rails::Application
16
+ # Settings in config/environments/* take precedence over those specified here.
17
+ # Application configuration should go into files in config/initializers
18
+ # -- all .rb files in that directory are automatically loaded.
19
+
20
+ # Custom directories with classes and modules you want to be autoloadable.
21
+ # config.autoload_paths += %W(#{config.root}/extras)
22
+
23
+ # Only load the plugins named here, in the order given (default is alphabetical).
24
+ # :all can be used as a placeholder for all plugins not explicitly named.
25
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
26
+
27
+ # Activate observers that should always be running.
28
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
29
+
30
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
31
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
32
+ # config.time_zone = 'Central Time (US & Canada)'
33
+
34
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
35
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
36
+ # config.i18n.default_locale = :de
37
+
38
+ # JavaScript files you want as :defaults (application.js is always included).
39
+ config.action_view.javascript_expansions[:defaults] = %w()
40
+
41
+ # Configure the default encoding used in templates for Ruby 1.9.
42
+ config.encoding = "utf-8"
43
+
44
+ # Configure sensitive parameters which will be filtered from the log file.
45
+ config.filter_parameters += [:password]
46
+
47
+ config.middleware.use(Rack::Conneg) do |conneg|
48
+ conneg.set :accept_all_extensions, false
49
+ conneg.set :fallback, :html
50
+ conneg.ignore('/public/')
51
+ conneg.provide([:json,:xml])
52
+ end
53
+ end
54
+ 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
+ Rails3Skel::Application.initialize!
@@ -0,0 +1,26 @@
1
+ Rails3Skel::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the webserver when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.consider_all_requests_local = true
14
+ config.action_view.debug_rjs = true
15
+ config.action_controller.perform_caching = false
16
+
17
+ # Don't care if the mailer can't send
18
+ config.action_mailer.raise_delivery_errors = false
19
+
20
+ # Print deprecation notices to the Rails logger
21
+ config.active_support.deprecation = :log
22
+
23
+ # Only use best-standards-support built into browsers
24
+ config.action_dispatch.best_standards_support = :builtin
25
+ end
26
+
@@ -0,0 +1,49 @@
1
+ Rails3Skel::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The production environment is meant for finished, "live" apps.
5
+ # Code is not reloaded between requests
6
+ config.cache_classes = true
7
+
8
+ # Full error reports are disabled and caching is turned on
9
+ config.consider_all_requests_local = false
10
+ config.action_controller.perform_caching = true
11
+
12
+ # Specifies the header that your server uses for sending files
13
+ config.action_dispatch.x_sendfile_header = "X-Sendfile"
14
+
15
+ # For nginx:
16
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
17
+
18
+ # If you have no front-end server that supports something like X-Sendfile,
19
+ # just comment this out and Rails will serve the files
20
+
21
+ # See everything in the log (default is :info)
22
+ # config.log_level = :debug
23
+
24
+ # Use a different logger for distributed setups
25
+ # config.logger = SyslogLogger.new
26
+
27
+ # Use a different cache store in production
28
+ # config.cache_store = :mem_cache_store
29
+
30
+ # Disable Rails's static asset server
31
+ # In production, Apache or nginx will already do this
32
+ config.serve_static_assets = false
33
+
34
+ # Enable serving of images, stylesheets, and javascripts from an asset server
35
+ # config.action_controller.asset_host = "http://assets.example.com"
36
+
37
+ # Disable delivery errors, bad email addresses will be ignored
38
+ # config.action_mailer.raise_delivery_errors = false
39
+
40
+ # Enable threaded mode
41
+ # config.threadsafe!
42
+
43
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
44
+ # the I18n.default_locale when a translation can not be found)
45
+ config.i18n.fallbacks = true
46
+
47
+ # Send deprecation notices to registered listeners
48
+ config.active_support.deprecation = :notify
49
+ end
@@ -0,0 +1,35 @@
1
+ Rails3Skel::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Log error messages when you accidentally call methods on nil.
11
+ config.whiny_nils = true
12
+
13
+ # Show full error reports and disable caching
14
+ config.consider_all_requests_local = true
15
+ config.action_controller.perform_caching = false
16
+
17
+ # Raise exceptions instead of rendering exception templates
18
+ config.action_dispatch.show_exceptions = false
19
+
20
+ # Disable request forgery protection in test environment
21
+ config.action_controller.allow_forgery_protection = false
22
+
23
+ # Tell Action Mailer not to deliver emails to the real world.
24
+ # The :test delivery method accumulates sent emails in the
25
+ # ActionMailer::Base.deliveries array.
26
+ config.action_mailer.delivery_method = :test
27
+
28
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
29
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
30
+ # like if you have constraints or database-specific column types
31
+ # config.active_record.schema_format = :sql
32
+
33
+ # Print deprecation notices to the stderr
34
+ config.active_support.deprecation = :stderr
35
+ end
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,10 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format
4
+ # (all these examples are active by default):
5
+ # ActiveSupport::Inflector.inflections do |inflect|
6
+ # inflect.plural /^(ox)$/i, '\1en'
7
+ # inflect.singular /^(ox)en/i, '\1'
8
+ # inflect.irregular 'person', 'people'
9
+ # inflect.uncountable %w( fish sheep )
10
+ # end
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ Rails3Skel::Application.config.secret_token = 'a99f8d7966ca819b542a7974ce8f4e81d2082462dde13da8e6aa6d124db718d97562df564c7de9096b6f5f75b5bfb9e126245ebd6ba97d6b6f92ea0e91a8d976'
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Rails3Skel::Application.config.session_store :cookie_store, :key => '_rails3_skel_session'
4
+
5
+ # Use the database for sessions instead of the cookie-based default,
6
+ # which shouldn't be used to store highly confidential information
7
+ # (create the session table with "rails generate session_migration")
8
+ # Rails3Skel::Application.config.session_store :active_record_store
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
@@ -0,0 +1,58 @@
1
+ Rails3Skel::Application.routes.draw do
2
+ # The priority is based upon order of creation:
3
+ # first created -> highest priority.
4
+
5
+ # Sample of regular route:
6
+ # match 'products/:id' => 'catalog#view'
7
+ # Keep in mind you can assign values other than :controller and :action
8
+
9
+ # Sample of named route:
10
+ # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
11
+ # This route can be invoked with purchase_url(:id => product.id)
12
+
13
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
14
+ # resources :products
15
+
16
+ # Sample resource route with options:
17
+ # resources :products do
18
+ # member do
19
+ # get 'short'
20
+ # post 'toggle'
21
+ # end
22
+ #
23
+ # collection do
24
+ # get 'sold'
25
+ # end
26
+ # end
27
+
28
+ # Sample resource route with sub-resources:
29
+ # resources :products do
30
+ # resources :comments, :sales
31
+ # resource :seller
32
+ # end
33
+
34
+ # Sample resource route with more complex sub-resources
35
+ # resources :products do
36
+ # resources :comments
37
+ # resources :sales do
38
+ # get 'recent', :on => :collection
39
+ # end
40
+ # end
41
+
42
+ # Sample resource route within a namespace:
43
+ # namespace :admin do
44
+ # # Directs /admin/products/* to Admin::ProductsController
45
+ # # (app/controllers/admin/products_controller.rb)
46
+ # resources :products
47
+ # end
48
+
49
+ # You can have the root of your site routed with "root"
50
+ # just remember to delete public/index.html.
51
+ # root :to => "welcome#index"
52
+
53
+ # See how all your routes lay out with "rake routes"
54
+
55
+ # This is a legacy wild controller route that's not recommended for RESTful applications.
56
+ # Note: This route will make all actions in every controller accessible via GET requests.
57
+ match ':controller(/:action(/:id(.:format)))'
58
+ end
@@ -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'
@@ -7,7 +7,8 @@ begin
7
7
  require 'ruby-debug'
8
8
  rescue Exception => e; end
9
9
 
10
- require File.expand_path(File.dirname(__FILE__) + '/../../rails2_skel/config/environment.rb')
10
+ railsv = ENV["RAILS_MAJOR_VERSION"] || "2"
11
+ require File.expand_path(File.dirname(__FILE__) + "/../../rails#{railsv}_skel/config/environment.rb")
11
12
 
12
13
  # put the require below to use tokamak in your rails project
13
14
  require "tokamak/hook/rails"
@@ -15,9 +16,10 @@ require "tokamak/hook/rails"
15
16
  class Tokamak::Hook::RailsTest < ActionController::IntegrationTest
16
17
 
17
18
  def test_view_generation_with_json
18
- get '/test/show', {}, :accept => 'application/json'
19
+ self.accept = "application/json"
20
+ get '/test/show'
19
21
 
20
- json = @controller.response.body
22
+ json = (@controller || self).response.body
21
23
  hash = JSON.parse(json).extend(Methodize)
22
24
 
23
25
  assert_equal "John Doe" , hash.author.first.name
@@ -36,9 +38,10 @@ class Tokamak::Hook::RailsTest < ActionController::IntegrationTest
36
38
  end
37
39
 
38
40
  def test_view_generation_with_xml
39
- get '/test/show', {}, :accept => 'application/xml'
41
+ self.accept = "application/xml"
42
+ get '/test/show'
40
43
 
41
- xml = @controller.response.body
44
+ xml = (@controller || self).response.body
42
45
  xml = Nokogiri::XML::Document.parse(xml)
43
46
 
44
47
  assert_equal "John Doe" , xml.css("root > author").first.css("name").first.text
@@ -56,9 +59,10 @@ class Tokamak::Hook::RailsTest < ActionController::IntegrationTest
56
59
  end
57
60
 
58
61
  def test_view_generation_with_partial
59
- get '/test/feed', {}, :accept => 'application/xml'
62
+ self.accept = "application/xml"
63
+ get '/test/feed'
60
64
 
61
- xml = @controller.response.body
65
+ xml = (@controller || self).response.body
62
66
  xml = Nokogiri::XML::Document.parse(xml)
63
67
 
64
68
  assert_equal "John Doe" , xml.css("root > author").first.css("name").first.text
@@ -10,6 +10,17 @@ rescue Exception => e; end
10
10
  require "tokamak/hook/tilt"
11
11
 
12
12
  class Tokamak::Hook::TiltTest < Test::Unit::TestCase
13
+ def setup
14
+ @template_file = File.expand_path(File.dirname(__FILE__) + '/../../rails2_skel/app/views/test/show.tokamak')
15
+ end
16
+
17
+ def test_tokamak_builder_with_tilt_and_unsupported_media_type
18
+ e = assert_raise(Tokamak::BuilderError) do
19
+ template = Tokamak::Hook::Tilt::TokamakTemplate.new(@template_file, :media_type => 'unsupported/type')
20
+ template.render(self)
21
+ end
22
+ assert_equal "Could not find a builder for the media type: unsupported/type", e.message
23
+ end
13
24
 
14
25
  def test_tokamak_builder_integration_with_tilt
15
26
  @some_articles = [
@@ -17,7 +28,7 @@ class Tokamak::Hook::TiltTest < Test::Unit::TestCase
17
28
  {:id => 2, :title => "another great article", :updated => Time.now}
18
29
  ]
19
30
 
20
- template = Tokamak::Hook::Tilt::TokamakTemplate.new(File.expand_path(File.dirname(__FILE__) + '/../../rails2_skel/app/views/test/show.tokamak'), :media_type => "application/json")
31
+ template = Tokamak::Hook::Tilt::TokamakTemplate.new(@template_file, :media_type => "application/json")
21
32
  json = template.render(self, :@some_articles => @some_articles)
22
33
  hash = JSON.parse(json).extend(Methodize)
23
34
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tokamak
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 0
10
- version: 1.2.0
9
+ - 1
10
+ version: 1.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Luis Cipriani
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-11 00:00:00 -03:00
18
+ date: 2011-08-01 00:00:00 -03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -204,6 +204,27 @@ files:
204
204
  - test/rails2_skel/log/development.log
205
205
  - test/rails2_skel/Rakefile
206
206
  - test/rails2_skel/script/console
207
+ - test/rails3_skel/app/controllers/application_controller.rb
208
+ - test/rails3_skel/app/controllers/test_controller.rb
209
+ - test/rails3_skel/app/views/test/_feed_member.tokamak
210
+ - test/rails3_skel/app/views/test/feed.tokamak
211
+ - test/rails3_skel/app/views/test/show.tokamak
212
+ - test/rails3_skel/config/application.rb
213
+ - test/rails3_skel/config/boot.rb
214
+ - test/rails3_skel/config/environment.rb
215
+ - test/rails3_skel/config/environments/development.rb
216
+ - test/rails3_skel/config/environments/production.rb
217
+ - test/rails3_skel/config/environments/test.rb
218
+ - test/rails3_skel/config/initializers/backtrace_silencers.rb
219
+ - test/rails3_skel/config/initializers/inflections.rb
220
+ - test/rails3_skel/config/initializers/mime_types.rb
221
+ - test/rails3_skel/config/initializers/secret_token.rb
222
+ - test/rails3_skel/config/initializers/session_store.rb
223
+ - test/rails3_skel/config/locales/en.yml
224
+ - test/rails3_skel/config/routes.rb
225
+ - test/rails3_skel/config.ru
226
+ - test/rails3_skel/Rakefile
227
+ - test/rails3_skel/script/rails
207
228
  - test/test_helper.rb
208
229
  - test/tokamak/builder/base_test.rb
209
230
  - test/tokamak/builder/json_test.rb