Permalink
Browse files

adding episode 256

  • Loading branch information...
1 parent d17208d commit f02fe361b0cc5cb1dba35cab355f57becf10e78d @ryanb committed Mar 7, 2011
Showing with 9,923 additions and 0 deletions.
  1. +8 −0 episode-256/README
  2. +4 −0 episode-256/translate/.gitignore
  3. +7 −0 episode-256/translate/Gemfile
  4. +77 −0 episode-256/translate/Gemfile.lock
  5. +7 −0 episode-256/translate/Rakefile
  6. +3 −0 episode-256/translate/app/controllers/application_controller.rb
  7. +5 −0 episode-256/translate/app/controllers/home_controller.rb
  8. +10 −0 episode-256/translate/app/controllers/translations_controller.rb
  9. +2 −0 episode-256/translate/app/helpers/application_helper.rb
  10. +23 −0 episode-256/translate/app/helpers/error_messages_helper.rb
  11. +2 −0 episode-256/translate/app/helpers/home_helper.rb
  12. +22 −0 episode-256/translate/app/helpers/layout_helper.rb
  13. +2 −0 episode-256/translate/app/helpers/translations_helper.rb
  14. +2 −0 episode-256/translate/app/views/home/index.html.erb
  15. +19 −0 episode-256/translate/app/views/layouts/application.html.erb
  16. +25 −0 episode-256/translate/app/views/translations/index.html.erb
  17. +4 −0 episode-256/translate/config.ru
  18. +42 −0 episode-256/translate/config/application.rb
  19. +13 −0 episode-256/translate/config/boot.rb
  20. +22 −0 episode-256/translate/config/database.yml
  21. +5 −0 episode-256/translate/config/environment.rb
  22. +26 −0 episode-256/translate/config/environments/development.rb
  23. +49 −0 episode-256/translate/config/environments/production.rb
  24. +35 −0 episode-256/translate/config/environments/test.rb
  25. +7 −0 episode-256/translate/config/initializers/backtrace_silencers.rb
  26. +2 −0 episode-256/translate/config/initializers/i18n_backend.rb
  27. +10 −0 episode-256/translate/config/initializers/inflections.rb
  28. +5 −0 episode-256/translate/config/initializers/mime_types.rb
  29. +7 −0 episode-256/translate/config/initializers/secret_token.rb
  30. +8 −0 episode-256/translate/config/initializers/session_store.rb
  31. +5 −0 episode-256/translate/config/locales/en.yml
  32. +4 −0 episode-256/translate/config/routes.rb
  33. +7 −0 episode-256/translate/db/seeds.rb
  34. +2 −0 episode-256/translate/doc/README_FOR_APP
  35. 0 episode-256/translate/lib/tasks/.gitkeep
  36. +26 −0 episode-256/translate/public/404.html
  37. +26 −0 episode-256/translate/public/422.html
  38. +26 −0 episode-256/translate/public/500.html
  39. 0 episode-256/translate/public/favicon.ico
  40. BIN episode-256/translate/public/images/rails.png
  41. +2 −0 episode-256/translate/public/javascripts/application.js
  42. +965 −0 episode-256/translate/public/javascripts/controls.js
  43. +974 −0 episode-256/translate/public/javascripts/dragdrop.js
  44. +1,123 −0 episode-256/translate/public/javascripts/effects.js
  45. +6,001 −0 episode-256/translate/public/javascripts/prototype.js
  46. +175 −0 episode-256/translate/public/javascripts/rails.js
  47. +5 −0 episode-256/translate/public/robots.txt
  48. 0 episode-256/translate/public/stylesheets/.gitkeep
  49. +75 −0 episode-256/translate/public/stylesheets/application.css
  50. +6 −0 episode-256/translate/script/rails
  51. +9 −0 episode-256/translate/test/functional/home_controller_test.rb
  52. +9 −0 episode-256/translate/test/functional/translations_controller_test.rb
  53. +9 −0 episode-256/translate/test/performance/browsing_test.rb
  54. +13 −0 episode-256/translate/test/test_helper.rb
  55. +4 −0 episode-256/translate/test/unit/helpers/home_helper_test.rb
  56. +4 −0 episode-256/translate/test/unit/helpers/translations_helper_test.rb
  57. 0 episode-256/translate/vendor/plugins/.gitkeep
View
@@ -0,0 +1,8 @@
+Railscasts Episode #256: I18n Backends
+
+http://railscasts.com/episodes/256
+
+Commands
+
+ rails g controller translations index
+ brew install redis
@@ -0,0 +1,4 @@
+.bundle
+db/*.sqlite3
+log/*.log
+tmp/**/*
@@ -0,0 +1,7 @@
+source 'http://rubygems.org'
+
+gem 'rails', '3.0.3'
+gem 'sqlite3-ruby', '1.2.5', :require => 'sqlite3'
+gem 'nifty-generators'
+
+gem 'redis'
@@ -0,0 +1,77 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ actionmailer (3.0.3)
+ actionpack (= 3.0.3)
+ mail (~> 2.2.9)
+ actionpack (3.0.3)
+ activemodel (= 3.0.3)
+ activesupport (= 3.0.3)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.6)
+ i18n (~> 0.4)
+ rack (~> 1.2.1)
+ rack-mount (~> 0.6.13)
+ rack-test (~> 0.5.6)
+ tzinfo (~> 0.3.23)
+ activemodel (3.0.3)
+ activesupport (= 3.0.3)
+ builder (~> 2.1.2)
+ i18n (~> 0.4)
+ activerecord (3.0.3)
+ activemodel (= 3.0.3)
+ activesupport (= 3.0.3)
+ arel (~> 2.0.2)
+ tzinfo (~> 0.3.23)
+ activeresource (3.0.3)
+ activemodel (= 3.0.3)
+ activesupport (= 3.0.3)
+ activesupport (3.0.3)
+ arel (2.0.9)
+ builder (2.1.2)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ i18n (0.5.0)
+ mail (2.2.15)
+ activesupport (>= 2.3.6)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.16)
+ nifty-generators (0.4.5)
+ polyglot (0.3.1)
+ rack (1.2.1)
+ rack-mount (0.6.13)
+ rack (>= 1.0.0)
+ rack-test (0.5.7)
+ rack (>= 1.0)
+ rails (3.0.3)
+ actionmailer (= 3.0.3)
+ actionpack (= 3.0.3)
+ activerecord (= 3.0.3)
+ activeresource (= 3.0.3)
+ activesupport (= 3.0.3)
+ bundler (~> 1.0)
+ railties (= 3.0.3)
+ railties (3.0.3)
+ actionpack (= 3.0.3)
+ activesupport (= 3.0.3)
+ rake (>= 0.8.7)
+ thor (~> 0.14.4)
+ rake (0.8.7)
+ redis (2.1.1)
+ sqlite3-ruby (1.2.5)
+ thor (0.14.6)
+ treetop (1.4.9)
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.24)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ nifty-generators
+ rails (= 3.0.3)
+ redis
+ sqlite3-ruby (= 1.2.5)
@@ -0,0 +1,7 @@
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+require File.expand_path('../config/application', __FILE__)
+require 'rake'
+
+Translate::Application.load_tasks
@@ -0,0 +1,3 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+end
@@ -0,0 +1,5 @@
+class HomeController < ApplicationController
+ def index
+ end
+
+end
@@ -0,0 +1,10 @@
+class TranslationsController < ApplicationController
+ def index
+ @translations = TRANSLATION_STORE
+ end
+
+ def create
+ I18n.backend.store_translations(params[:locale], {params[:key] => params[:value]}, :escape => false)
+ redirect_to translations_url, :notice => "Added translation"
+ end
+end
@@ -0,0 +1,2 @@
+module ApplicationHelper
+end
@@ -0,0 +1,23 @@
+module ErrorMessagesHelper
+ # Render error messages for the given objects. The :message and :header_message options are allowed.
+ def error_messages_for(*objects)
+ options = objects.extract_options!
+ options[:header_message] ||= I18n.t(:"activerecord.errors.header", :default => "Invalid Fields")
+ options[:message] ||= I18n.t(:"activerecord.errors.message", :default => "Correct the following errors and try again.")
+ messages = objects.compact.map { |o| o.errors.full_messages }.flatten
+ unless messages.empty?
+ content_tag(:div, :class => "error_messages") do
+ list_items = messages.map { |msg| content_tag(:li, msg) }
+ content_tag(:h2, options[:header_message]) + content_tag(:p, options[:message]) + content_tag(:ul, list_items.join.html_safe)
+ end
+ end
+ end
+
+ module FormBuilderAdditions
+ def error_messages(options = {})
+ @template.error_messages_for(@object, options)
+ end
+ end
+end
+
+ActionView::Helpers::FormBuilder.send(:include, ErrorMessagesHelper::FormBuilderAdditions)
@@ -0,0 +1,2 @@
+module HomeHelper
+end
@@ -0,0 +1,22 @@
+# These helper methods can be called in your template to set variables to be used in the layout
+# This module should be included in all views globally,
+# to do so you may need to add this line to your ApplicationController
+# helper :layout
+module LayoutHelper
+ def title(page_title, show_title = true)
+ content_for(:title) { h(page_title.to_s) }
+ @show_title = show_title
+ end
+
+ def show_title?
+ @show_title
+ end
+
+ def stylesheet(*args)
+ content_for(:head) { stylesheet_link_tag(*args) }
+ end
+
+ def javascript(*args)
+ content_for(:head) { javascript_include_tag(*args) }
+ end
+end
@@ -0,0 +1,2 @@
+module TranslationsHelper
+end
@@ -0,0 +1,2 @@
+<h1><%= t "welcome" %></h1>
+<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title><%= content_for?(:title) ? yield(:title) : "Untitled" %></title>
+ <%= stylesheet_link_tag "application" %>
+ <%= javascript_include_tag :defaults %>
+ <%= csrf_meta_tag %>
+ <%= yield(:head) %>
+ </head>
+ <body>
+ <div id="container">
+ <% flash.each do |name, msg| %>
+ <%= content_tag :div, msg, :id => "flash_#{name}" %>
+ <% end %>
+ <%= content_tag :h1, yield(:title) if show_title? %>
+ <%= yield %>
+ </div>
+ </body>
+</html>
@@ -0,0 +1,25 @@
+<h1>Translations</h1>
+
+<ul>
+<% @translations.keys.each do |key| %>
+ <li><%= key %>: <%= @translations[key] %></li>
+<% end %>
+</ul>
+
+<h2>Add Translation</h2>
+
+<%= form_tag translations_path do %>
+ <p>
+ <%= label_tag :locale %><br />
+ <%= text_field_tag :locale %>
+ </p>
+ <p>
+ <%= label_tag :key %><br />
+ <%= text_field_tag :key %>
+ </p>
+ <p>
+ <%= label_tag :value %><br />
+ <%= text_field_tag :value %>
+ </p>
+ <p><%= submit_tag "Submit" %></p>
+<% end %>
@@ -0,0 +1,4 @@
+# This file is used by Rack-based servers to start the application.
+
+require ::File.expand_path('../config/environment', __FILE__)
+run Translate::Application
@@ -0,0 +1,42 @@
+require File.expand_path('../boot', __FILE__)
+
+require 'rails/all'
+
+# If you have a Gemfile, require the gems listed there, including any gems
+# you've limited to :test, :development, or :production.
+Bundler.require(:default, Rails.env) if defined?(Bundler)
+
+module Translate
+ class Application < Rails::Application
+ # Settings in config/environments/* take precedence over those specified here.
+ # Application configuration should go into files in config/initializers
+ # -- all .rb files in that directory are automatically loaded.
+
+ # Custom directories with classes and modules you want to be autoloadable.
+ # config.autoload_paths += %W(#{config.root}/extras)
+
+ # Only load the plugins named here, in the order given (default is alphabetical).
+ # :all can be used as a placeholder for all plugins not explicitly named.
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
+
+ # Activate observers that should always be running.
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
+
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
+ # config.time_zone = 'Central Time (US & Canada)'
+
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
+ # config.i18n.default_locale = :de
+
+ # JavaScript files you want as :defaults (application.js is always included).
+ # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
+
+ # Configure the default encoding used in templates for Ruby 1.9.
+ config.encoding = "utf-8"
+
+ # Configure sensitive parameters which will be filtered from the log file.
+ config.filter_parameters += [:password]
+ end
+end
@@ -0,0 +1,13 @@
+require 'rubygems'
+
+# Set up gems listed in the Gemfile.
+gemfile = File.expand_path('../../Gemfile', __FILE__)
+begin
+ ENV['BUNDLE_GEMFILE'] = gemfile
+ require 'bundler'
+ Bundler.setup
+rescue Bundler::GemNotFound => e
+ STDERR.puts e.message
+ STDERR.puts "Try running `bundle install`."
+ exit!
+end if File.exist?(gemfile)
@@ -0,0 +1,22 @@
+# SQLite version 3.x
+# gem install sqlite3-ruby (not necessary on OS X Leopard)
+development:
+ adapter: sqlite3
+ database: db/development.sqlite3
+ pool: 5
+ timeout: 5000
+
+# Warning: The database defined as "test" will be erased and
+# re-generated from your development database when you run "rake".
+# Do not set this db to the same as development or production.
+test:
+ adapter: sqlite3
+ database: db/test.sqlite3
+ pool: 5
+ timeout: 5000
+
+production:
+ adapter: sqlite3
+ database: db/production.sqlite3
+ pool: 5
+ timeout: 5000
@@ -0,0 +1,5 @@
+# Load the rails application
+require File.expand_path('../application', __FILE__)
+
+# Initialize the rails application
+Translate::Application.initialize!
@@ -0,0 +1,26 @@
+Translate::Application.configure do
+ # Settings specified here will take precedence over those in config/application.rb
+
+ # In the development environment your application's code is reloaded on
+ # every request. This slows down response time but is perfect for development
+ # since you don't have to restart the webserver when you make code changes.
+ config.cache_classes = false
+
+ # Log error messages when you accidentally call methods on nil.
+ config.whiny_nils = true
+
+ # Show full error reports and disable caching
+ config.consider_all_requests_local = true
+ config.action_view.debug_rjs = true
+ config.action_controller.perform_caching = false
+
+ # Don't care if the mailer can't send
+ config.action_mailer.raise_delivery_errors = false
+
+ # Print deprecation notices to the Rails logger
+ config.active_support.deprecation = :log
+
+ # Only use best-standards-support built into browsers
+ config.action_dispatch.best_standards_support = :builtin
+end
+
Oops, something went wrong.

0 comments on commit f02fe36

Please sign in to comment.