Permalink
Browse files

adding episode 248

  • Loading branch information...
1 parent bade6d7 commit b3b8f90db34f8457047ac968abfd1e235e705fa0 @ryanb committed Jan 10, 2011
Showing with 8,949 additions and 0 deletions.
  1. +9 −0 episode-248/README
  2. +4 −0 episode-248/list_maker/.gitignore
  3. +9 −0 episode-248/list_maker/Gemfile
  4. +84 −0 episode-248/list_maker/Gemfile.lock
  5. +7 −0 episode-248/list_maker/Rakefile
  6. +3 −0 episode-248/list_maker/app/controllers/application_controller.rb
  7. +13 −0 episode-248/list_maker/app/controllers/items_controller.rb
  8. +2 −0 episode-248/list_maker/app/helpers/application_helper.rb
  9. +23 −0 episode-248/list_maker/app/helpers/error_messages_helper.rb
  10. +2 −0 episode-248/list_maker/app/helpers/items_helper.rb
  11. +22 −0 episode-248/list_maker/app/helpers/layout_helper.rb
  12. +3 −0 episode-248/list_maker/app/models/item.rb
  13. +15 −0 episode-248/list_maker/app/views/items/index.html.erb
  14. +19 −0 episode-248/list_maker/app/views/layouts/application.html.erb
  15. +4 −0 episode-248/list_maker/config.ru
  16. +44 −0 episode-248/list_maker/config/application.rb
  17. +13 −0 episode-248/list_maker/config/boot.rb
  18. +22 −0 episode-248/list_maker/config/database.yml
  19. +5 −0 episode-248/list_maker/config/environment.rb
  20. +26 −0 episode-248/list_maker/config/environments/development.rb
  21. +49 −0 episode-248/list_maker/config/environments/production.rb
  22. +35 −0 episode-248/list_maker/config/environments/test.rb
  23. +7 −0 episode-248/list_maker/config/initializers/backtrace_silencers.rb
  24. +10 −0 episode-248/list_maker/config/initializers/inflections.rb
  25. +5 −0 episode-248/list_maker/config/initializers/mime_types.rb
  26. +7 −0 episode-248/list_maker/config/initializers/secret_token.rb
  27. +8 −0 episode-248/list_maker/config/initializers/session_store.rb
  28. +5 −0 episode-248/list_maker/config/locales/en.yml
  29. +4 −0 episode-248/list_maker/config/routes.rb
  30. +12 −0 episode-248/list_maker/db/migrate/20110103210206_create_items.rb
  31. +21 −0 episode-248/list_maker/db/schema.rb
  32. +7 −0 episode-248/list_maker/db/seeds.rb
  33. +2 −0 episode-248/list_maker/doc/README_FOR_APP
  34. 0 episode-248/list_maker/lib/tasks/.gitkeep
  35. +26 −0 episode-248/list_maker/public/404.html
  36. +26 −0 episode-248/list_maker/public/500.html
  37. 0 episode-248/list_maker/public/favicon.ico
  38. +42 −0 episode-248/list_maker/public/javascripts/application.js
  39. +7,179 −0 episode-248/list_maker/public/javascripts/jquery.js
  40. +167 −0 episode-248/list_maker/public/javascripts/jquery.min.js
  41. +212 −0 episode-248/list_maker/public/javascripts/jquery.offline.js
  42. +482 −0 episode-248/list_maker/public/javascripts/jquery.tmpl.js
  43. +7 −0 episode-248/list_maker/public/javascripts/json.js
  44. +159 −0 episode-248/list_maker/public/javascripts/rails.js
  45. +5 −0 episode-248/list_maker/public/robots.txt
  46. 0 episode-248/list_maker/public/stylesheets/.gitkeep
  47. +83 −0 episode-248/list_maker/public/stylesheets/application.css
  48. +6 −0 episode-248/list_maker/script/rails
  49. +5 −0 episode-248/list_maker/test/fixtures/items.yml
  50. +20 −0 episode-248/list_maker/test/functional/items_controller_test.rb
  51. +9 −0 episode-248/list_maker/test/performance/browsing_test.rb
  52. +13 −0 episode-248/list_maker/test/test_helper.rb
  53. +7 −0 episode-248/list_maker/test/unit/item_test.rb
  54. 0 episode-248/list_maker/vendor/plugins/.gitkeep
View
@@ -0,0 +1,9 @@
+Railscasts Episode #248: Offline Apps Part 2
+
+http://railscasts.com/episodes/248
+
+Commands
+
+ curl https://github.com/jquery/jquery-tmpl/raw/master/jquery.tmpl.js > public/javascripts/jquery.tmpl.js
+ curl https://github.com/wycats/jquery-offline/raw/master/lib/jquery.offline.js > public/javascripts/jquery.offline.js
+ curl https://github.com/wycats/jquery-offline/raw/master/lib/json.js > public/javascripts/json.js
@@ -0,0 +1,4 @@
+.bundle
+db/*.sqlite3
+log/*.log
+tmp/**/*
@@ -0,0 +1,9 @@
+source 'http://rubygems.org'
+
+gem 'rails', '3.0.3'
+gem 'sqlite3-ruby', '1.2.5', :require => 'sqlite3'
+gem 'jquery-rails'
+gem 'nifty-generators'
+gem "mocha", :group => :test
+
+gem "rack-offline"
@@ -0,0 +1,84 @@
+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.6)
+ builder (2.1.2)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ i18n (0.5.0)
+ jquery-rails (0.2.6)
+ rails (~> 3.0)
+ thor (~> 0.14.4)
+ mail (2.2.13)
+ activesupport (>= 2.3.6)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.16)
+ mocha (0.9.10)
+ rake
+ nifty-generators (0.4.3)
+ polyglot (0.3.1)
+ rack (1.2.1)
+ rack-mount (0.6.13)
+ rack (>= 1.0.0)
+ rack-offline (0.6.1)
+ 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)
+ sqlite3-ruby (1.2.5)
+ thor (0.14.6)
+ treetop (1.4.9)
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.23)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ jquery-rails
+ mocha
+ nifty-generators
+ rack-offline
+ rails (= 3.0.3)
+ 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'
+
+ListMaker::Application.load_tasks
@@ -0,0 +1,3 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+end
@@ -0,0 +1,13 @@
+class ItemsController < ApplicationController
+ respond_to :html, :json
+
+ def index
+ @items = Item.all
+ respond_with(@items)
+ end
+
+ def create
+ Item.create!(params[:item])
+ redirect_to items_url
+ 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] ||= "Invalid Fields"
+ options[:message] ||= "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 ItemsHelper
+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,3 @@
+class Item < ActiveRecord::Base
+ attr_accessible :name
+end
@@ -0,0 +1,15 @@
+<% title "Grocery List" %>
+
+<%= form_for Item.new do |f| %>
+ <p>
+ <%= f.text_field :name %>
+ <%= f.submit "Add" %>
+ </p>
+<% end %>
+
+<script type="text/html" id="item_template">
+ <li>${item.name}</li>
+</script>
+<ol id="items">
+ <li><em>Loading items...</em></li>
+</ol>
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html manifest="/application.manifest">
+ <head>
+ <title><%= content_for?(:title) ? yield(:title) : "Untitled" %></title>
+ <%= stylesheet_link_tag "application" %>
+ <%= javascript_include_tag :defaults, "jquery.tmpl", "json", "jquery.offline" %>
+ <%= 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,4 @@
+# This file is used by Rack-based servers to start the application.
+
+require ::File.expand_path('../config/environment', __FILE__)
+run ListMaker::Application
@@ -0,0 +1,44 @@
+require File.expand_path('../boot', __FILE__)
+
+require 'rails/all'
+
+ENV["RAILS_ASSET_ID"] = "" # disable timestamps at end of asset files for offline browsing
+
+# 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 ListMaker
+ 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
+ListMaker::Application.initialize!
@@ -0,0 +1,26 @@
+ListMaker::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
+
@@ -0,0 +1,49 @@
+ListMaker::Application.configure do
+ # Settings specified here will take precedence over those in config/application.rb
+
+ # The production environment is meant for finished, "live" apps.
+ # Code is not reloaded between requests
+ config.cache_classes = true
+
+ # Full error reports are disabled and caching is turned on
+ config.consider_all_requests_local = false
+ config.action_controller.perform_caching = true
+
+ # Specifies the header that your server uses for sending files
+ config.action_dispatch.x_sendfile_header = "X-Sendfile"
+
+ # For nginx:
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
+
+ # If you have no front-end server that supports something like X-Sendfile,
+ # just comment this out and Rails will serve the files
+
+ # See everything in the log (default is :info)
+ # config.log_level = :debug
+
+ # Use a different logger for distributed setups
+ # config.logger = SyslogLogger.new
+
+ # Use a different cache store in production
+ # config.cache_store = :mem_cache_store
+
+ # Disable Rails's static asset server
+ # In production, Apache or nginx will already do this
+ config.serve_static_assets = false
+
+ # Enable serving of images, stylesheets, and javascripts from an asset server
+ # config.action_controller.asset_host = "http://assets.example.com"
+
+ # Disable delivery errors, bad email addresses will be ignored
+ # config.action_mailer.raise_delivery_errors = false
+
+ # Enable threaded mode
+ # config.threadsafe!
+
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
+ # the I18n.default_locale when a translation can not be found)
+ config.i18n.fallbacks = true
+
+ # Send deprecation notices to registered listeners
+ config.active_support.deprecation = :notify
+end
Oops, something went wrong.

0 comments on commit b3b8f90

Please sign in to comment.